Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not emit Y053 for the argument to @deprecated() #444

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Other changes:
reduce the number of false positives from this check.
* Attempting to import `typing_extensions.Text` now causes Y039 to be emitted
rather than Y023.
* Y053 will no longer be emitted for the argument to `@typing_extensions.deprecated`.

## 23.10.0

Expand Down
15 changes: 14 additions & 1 deletion pyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ def _is_object(node: ast.AST | None, name: str, *, from_: Container[str]) -> boo
_is_BaseException = partial(_is_object, name="BaseException", from_={"builtins"})
_is_TypeAlias = partial(_is_object, name="TypeAlias", from_=_TYPING_MODULES)
_is_NamedTuple = partial(_is_object, name="NamedTuple", from_=_TYPING_MODULES)
_is_deprecated = partial(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is a little confusing. I considered _is_at_deprecated or _is_deprecated_decorator, but not sure that's much better. Note that we already have _is_final and _is_unused which have similar issues.

_is_object, name="deprecated", from_={"typing_extensions", "warnings"}
)
_is_TypedDict = partial(
_is_object, name="TypedDict", from_=_TYPING_MODULES | {"mypy_extensions"}
)
Expand Down Expand Up @@ -958,6 +961,7 @@ class PyiVisitor(ast.NodeVisitor):
all_name_occurrences: Counter[str]

string_literals_allowed: NestingCounter
long_strings_allowed: NestingCounter
in_function: NestingCounter
in_class: NestingCounter
visiting_arg: NestingCounter
Expand All @@ -975,6 +979,7 @@ def __init__(self, filename: str) -> None:
self.typealias_decls = defaultdict(list)
self.all_name_occurrences = Counter()
self.string_literals_allowed = NestingCounter()
self.long_strings_allowed = NestingCounter()
self.in_function = NestingCounter()
self.in_class = NestingCounter()
self.visiting_arg = NestingCounter()
Expand Down Expand Up @@ -1156,6 +1161,11 @@ def visit_Call(self, node: ast.Call) -> None:
if _is_bad_TypedDict(node):
self.error(node, Y031)
return
elif _is_deprecated(function):
with self.string_literals_allowed.enabled(), self.long_strings_allowed.enabled():
for arg in chain(node.args, node.keywords):
self.visit(arg)
return
elif (
isinstance(function, ast.Attribute)
and isinstance(function.value, ast.Name)
Expand All @@ -1176,7 +1186,10 @@ def visit_Call(self, node: ast.Call) -> None:
def visit_Constant(self, node: ast.Constant) -> None:
if isinstance(node.value, str) and not self.string_literals_allowed.active:
self.error(node, Y020)
elif isinstance(node.value, (str, bytes)):
elif (
isinstance(node.value, (str, bytes))
and not self.long_strings_allowed.active
):
if len(node.value) > 50:
self.error(node, Y053)
elif isinstance(node.value, (int, float, complex)):
Expand Down