@@ -308,6 +308,9 @@ def _is_object(node: ast.AST | None, name: str, *, from_: Container[str]) -> boo
308
308
_is_BaseException = partial (_is_object , name = "BaseException" , from_ = {"builtins" })
309
309
_is_TypeAlias = partial (_is_object , name = "TypeAlias" , from_ = _TYPING_MODULES )
310
310
_is_NamedTuple = partial (_is_object , name = "NamedTuple" , from_ = _TYPING_MODULES )
311
+ _is_deprecated = partial (
312
+ _is_object , name = "deprecated" , from_ = {"typing_extensions" , "warnings" }
313
+ )
311
314
_is_TypedDict = partial (
312
315
_is_object , name = "TypedDict" , from_ = _TYPING_MODULES | {"mypy_extensions" }
313
316
)
@@ -958,6 +961,7 @@ class PyiVisitor(ast.NodeVisitor):
958
961
all_name_occurrences : Counter [str ]
959
962
960
963
string_literals_allowed : NestingCounter
964
+ long_strings_allowed : NestingCounter
961
965
in_function : NestingCounter
962
966
in_class : NestingCounter
963
967
visiting_arg : NestingCounter
@@ -975,6 +979,7 @@ def __init__(self, filename: str) -> None:
975
979
self .typealias_decls = defaultdict (list )
976
980
self .all_name_occurrences = Counter ()
977
981
self .string_literals_allowed = NestingCounter ()
982
+ self .long_strings_allowed = NestingCounter ()
978
983
self .in_function = NestingCounter ()
979
984
self .in_class = NestingCounter ()
980
985
self .visiting_arg = NestingCounter ()
@@ -1156,6 +1161,11 @@ def visit_Call(self, node: ast.Call) -> None:
1156
1161
if _is_bad_TypedDict (node ):
1157
1162
self .error (node , Y031 )
1158
1163
return
1164
+ elif _is_deprecated (function ):
1165
+ with self .string_literals_allowed .enabled (), self .long_strings_allowed .enabled ():
1166
+ for arg in chain (node .args , node .keywords ):
1167
+ self .visit (arg )
1168
+ return
1159
1169
elif (
1160
1170
isinstance (function , ast .Attribute )
1161
1171
and isinstance (function .value , ast .Name )
@@ -1176,7 +1186,10 @@ def visit_Call(self, node: ast.Call) -> None:
1176
1186
def visit_Constant (self , node : ast .Constant ) -> None :
1177
1187
if isinstance (node .value , str ) and not self .string_literals_allowed .active :
1178
1188
self .error (node , Y020 )
1179
- elif isinstance (node .value , (str , bytes )):
1189
+ elif (
1190
+ isinstance (node .value , (str , bytes ))
1191
+ and not self .long_strings_allowed .active
1192
+ ):
1180
1193
if len (node .value ) > 50 :
1181
1194
self .error (node , Y053 )
1182
1195
elif isinstance (node .value , (int , float , complex )):
0 commit comments