Skip to content

Commit

Permalink
Improved format directives regex
Browse files Browse the repository at this point in the history
  • Loading branch information
netromdk committed Jan 12, 2020
1 parent 5e837ab commit 0ac202f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tests/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def test_format(self):

def test_strftime_directives(self):
visitor = visit("from datetime import datetime\ndatetime.now().strftime('%A %d. %B %Y')")
self.assertOnlyIn(("%A", "%d", "%B", "%Y"), visitor.strftime_directives())
self.assertOnlyIn(("A", "d", "B", "Y"), visitor.strftime_directives())
visitor = visit("from datetime import datetime\ndatetime.strptime('2018', '%Y')")
self.assertOnlyIn("%Y", visitor.strftime_directives())
self.assertOnlyIn("Y", visitor.strftime_directives())

def test_modules(self):
visitor = visit("import ast\nimport sys, argparse\nfrom os import *")
Expand Down
9 changes: 5 additions & 4 deletions vermin/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -2930,10 +2930,11 @@ def MOD_MEM_REQS():

# datetime+time strftime/strptime requirements: directive -> requirements
STRFTIME_REQS = {
"%G": (None, (3, 6)),
"%V": (None, (3, 6)),
"%f": ((2, 6), (3, 0)),
"%u": (None, (3, 6)),
"G": (None, (3, 6)),
"V": (None, (3, 6)),
"f": ((2, 6), (3, 0)),
"u": (None, (3, 6)),
}
}

# array.array typecode requirements: typecode -> requirements
Expand Down
2 changes: 1 addition & 1 deletion vermin/source_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .config import Config
from .utility import dotted_name, reverse_range, combine_versions, version_strings

STRFTIME_DIRECTIVE_REGEX = re.compile(r"(%\w)")
STRFTIME_DIRECTIVE_REGEX = re.compile(r"%(?:[-\.\d#\s\+])*(\w)")

class SourceVisitor(ast.NodeVisitor):
def __init__(self, config=None):
Expand Down

0 comments on commit 0ac202f

Please sign in to comment.