Skip to content

Commit 5f5454f

Browse files
committed
Correctly handle and ast.Constant objects where the values aren't strings.
1 parent ddc4bdb commit 5f5454f

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

flake8_strftime/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self) -> None:
5353
self.errors: List[Tuple[int, int, str]] = []
5454
self._from_imports: Dict[str, str] = {}
5555

56-
if sys.version_info < (3, 8): # pragma: no cover (<PY38)
56+
if sys.version_info < (3, 8): # pragma: no cover (PY38+)
5757

5858
def visit_Str(self, node: ast.Str):
5959
"""
@@ -65,7 +65,7 @@ def visit_Str(self, node: ast.Str):
6565
self._check_linux(node)
6666
self._check_windows(node)
6767

68-
else: # pragma: no cover (PY38+)
68+
else: # pragma: no cover (<PY38)
6969

7070
def visit_Constant(self, node: ast.Constant):
7171
"""
@@ -74,6 +74,9 @@ def visit_Constant(self, node: ast.Constant):
7474
:param node: The node being visited
7575
"""
7676

77+
if not isinstance(node.s, (str, bytes)):
78+
return
79+
7780
self._check_linux(node)
7881
self._check_windows(node)
7982

tests/flake8_strftime_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# stdlib
22
import ast
33

4+
# 3rd party
5+
import pytest
6+
47
# this package
58
from flake8_strftime import Plugin
69

@@ -31,3 +34,22 @@ def test_windows_specific():
3134
"1:22: STRFTIME002 Windows-specific strftime code used.",
3235
"1:26: STRFTIME002 Windows-specific strftime code used.",
3336
}
37+
38+
39+
@pytest.mark.parametrize(
40+
"source",
41+
[
42+
"test_none = None",
43+
"test_ellipsis = ...",
44+
"test_int = 42",
45+
"test_float = 1.0",
46+
"test_list = [1, 2, 3]",
47+
"test_tuple = (1, 2, 3)",
48+
"test_set = {1, 2, 3}",
49+
'test_dict = {"a": 1, "b": 2, "c": 3}',
50+
]
51+
)
52+
def test_issue_10(source: str):
53+
# https://github.com/domdfcoding/flake8_strftime/issues/10
54+
# This shouldn't raise an exception
55+
assert not list(Plugin(ast.parse(source)).run())

0 commit comments

Comments
 (0)