|
51 | 51 | STRFTIME001 = "STRFTIME001 Linux-specific strftime code used."
|
52 | 52 | STRFTIME002 = "STRFTIME002 Windows-specific strftime code used."
|
53 | 53 |
|
| 54 | +if sys.version_info >= (3, 12): # pragma: no cover (<py312) |
| 55 | + StrOrConstant = ast.Constant |
| 56 | +else: # pragma: no cover (py312+) |
| 57 | + StrOrConstant = Union[ast.Str, ast.Constant] |
| 58 | + |
54 | 59 |
|
55 | 60 | class Visitor(flake8_helper.Visitor):
|
56 | 61 | """
|
@@ -85,34 +90,48 @@ def visit_Constant(self, node: ast.Constant) -> None:
|
85 | 90 | :param node: The node being visited
|
86 | 91 | """
|
87 | 92 |
|
88 |
| - if not isinstance(node.s, str): |
89 |
| - return |
| 93 | + if sys.version_info < (3, 8): # pragma: no cover (PY38+) |
| 94 | + if not isinstance(node.s, str): |
| 95 | + return |
| 96 | + else: # pragma: no cover (<PY38) |
| 97 | + if not isinstance(node.value, str): |
| 98 | + return |
90 | 99 |
|
91 | 100 | self._check_linux(node)
|
92 | 101 | self._check_windows(node)
|
93 | 102 |
|
94 |
| - def _check_linux(self, node: Union[ast.Str, ast.Constant]) -> None: |
| 103 | + def _check_linux(self, node: StrOrConstant) -> None: |
95 | 104 | """
|
96 | 105 | Perform the check for Linux-specific codes.
|
97 | 106 |
|
98 | 107 | :param node: The node being visited
|
99 | 108 | """
|
100 | 109 |
|
101 |
| - for match in self._linux_re.finditer(node.s): # pylint: disable=use-list-copy |
| 110 | + if sys.version_info < (3, 8): # pragma: no cover (PY38+) |
| 111 | + node_value = node.s |
| 112 | + else: # pragma: no cover (<PY38) |
| 113 | + node_value = node.value |
| 114 | + |
| 115 | + for match in self._linux_re.finditer(node_value): # pylint: disable=use-list-copy |
102 | 116 | self.errors.append((
|
103 | 117 | node.lineno,
|
104 | 118 | node.col_offset + match.span()[0],
|
105 | 119 | STRFTIME001, # pylint: disable=loop-global-usage
|
106 | 120 | ))
|
107 | 121 |
|
108 |
| - def _check_windows(self, node: Union[ast.Str, ast.Constant]) -> None: |
| 122 | + def _check_windows(self, node: StrOrConstant) -> None: |
109 | 123 | """
|
110 | 124 | Perform the check for Windows-specific codes.
|
111 | 125 |
|
112 | 126 | :param node: The node being visited
|
113 | 127 | """
|
114 | 128 |
|
115 |
| - for match in self._win_re.finditer(node.s): # pylint: disable=use-list-copy |
| 129 | + if sys.version_info < (3, 8): # pragma: no cover (PY38+) |
| 130 | + node_value = node.s |
| 131 | + else: # pragma: no cover (<PY38) |
| 132 | + node_value = node.value |
| 133 | + |
| 134 | + for match in self._win_re.finditer(node_value): # pylint: disable=use-list-copy |
116 | 135 | self.errors.append((
|
117 | 136 | node.lineno,
|
118 | 137 | node.col_offset + match.span()[0],
|
|
0 commit comments