Skip to content

Commit c7d988e

Browse files
Do not emit Y053 for the argument to @deprecated() (#444)
1 parent 5bc395d commit c7d988e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Other changes:
2929
reduce the number of false positives from this check.
3030
* Attempting to import `typing_extensions.Text` now causes Y039 to be emitted
3131
rather than Y023.
32+
* Y053 will no longer be emitted for the argument to `@typing_extensions.deprecated`.
3233

3334
## 23.10.0
3435

pyi.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ def _is_object(node: ast.AST | None, name: str, *, from_: Container[str]) -> boo
308308
_is_BaseException = partial(_is_object, name="BaseException", from_={"builtins"})
309309
_is_TypeAlias = partial(_is_object, name="TypeAlias", from_=_TYPING_MODULES)
310310
_is_NamedTuple = partial(_is_object, name="NamedTuple", from_=_TYPING_MODULES)
311+
_is_deprecated = partial(
312+
_is_object, name="deprecated", from_={"typing_extensions", "warnings"}
313+
)
311314
_is_TypedDict = partial(
312315
_is_object, name="TypedDict", from_=_TYPING_MODULES | {"mypy_extensions"}
313316
)
@@ -958,6 +961,7 @@ class PyiVisitor(ast.NodeVisitor):
958961
all_name_occurrences: Counter[str]
959962

960963
string_literals_allowed: NestingCounter
964+
long_strings_allowed: NestingCounter
961965
in_function: NestingCounter
962966
in_class: NestingCounter
963967
visiting_arg: NestingCounter
@@ -975,6 +979,7 @@ def __init__(self, filename: str) -> None:
975979
self.typealias_decls = defaultdict(list)
976980
self.all_name_occurrences = Counter()
977981
self.string_literals_allowed = NestingCounter()
982+
self.long_strings_allowed = NestingCounter()
978983
self.in_function = NestingCounter()
979984
self.in_class = NestingCounter()
980985
self.visiting_arg = NestingCounter()
@@ -1156,6 +1161,11 @@ def visit_Call(self, node: ast.Call) -> None:
11561161
if _is_bad_TypedDict(node):
11571162
self.error(node, Y031)
11581163
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
11591169
elif (
11601170
isinstance(function, ast.Attribute)
11611171
and isinstance(function.value, ast.Name)
@@ -1176,7 +1186,10 @@ def visit_Call(self, node: ast.Call) -> None:
11761186
def visit_Constant(self, node: ast.Constant) -> None:
11771187
if isinstance(node.value, str) and not self.string_literals_allowed.active:
11781188
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+
):
11801193
if len(node.value) > 50:
11811194
self.error(node, Y053)
11821195
elif isinstance(node.value, (int, float, complex)):

0 commit comments

Comments
 (0)