- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3k
Feat/transitive deprecated ctors #20131
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
base: master
Are you sure you want to change the base?
Feat/transitive deprecated ctors #20131
Conversation
for more information, see https://pre-commit.ci
| Gets a class constructor type if it's used in a valid callable type context. | ||
| Considers the following cases as valid contexts: | ||
| * A plain `Callable` context is always treated as a valid context. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not want to add subtype checks for this case, as this seems like the most common case and at worst the user will get both a "deprecated" report and an "incompatible types in assignment" report.
| _valid_pep702_context = self._valid_pep702_type_context | ||
| self._valid_pep702_type_context = valid_pep702_type_context | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 0950c97 the same effect (avoiding false positives in the else branch of a conditional expression) could have also been implemented by doing this instead of having the boolean flag member self._valid_pep702_type_context:
with self.msg.filter_errors(filter_deprecated=not valid_pep702_type_context):
    ...I chose not to do this because it would just compute the deprecation warnings, which involves subtype checking, and discard it without usage.
| According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ | 
This is a follow-on to #20104 (do not merge until #20104 has been merged). The relevant commits on top of #20104 are the last 2:
As mentioned in #20104 (comment) it is likely a good idea to report implicit usages of
@deprecated()constructors in a callable-like context, e.g.This PR supports this in the following contexts if the class constructor or one of its overloads is
@deprecated():Callable, a compatible callback protocol, or a union with at least 1 such item;cc @sterliakov who initially suggested this expansion.