Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
bpo-46571: improvetyping.no_type_check to skip foreign objects#31042
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
AlexWaygood commentedFeb 1, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Here's a slightly evil corner case that this patch doesn't account for: If I have a module # typing_test.pyclassA:classAA:foo:int Then, observe the following behaviour (with your patch applied): >>>fromtypingimportget_type_hints,no_type_check>>>importtyping_test>>>get_type_hints(typing_test.A.AA){'foo':<class'int'>}>>> @no_type_check...classA:...AA=typing_test.A.AA... ...>>>get_type_hints(typing_test.A.AA){} We might be able to get around this by looking at the |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
sobolevn commentedFeb 2, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@AlexWaygood good one! Very evil! I've addressed this. @JelleZijlstra I agree that we should also fix The problem is that >>>classSome:... @staticmethod...defst(x:int)->int: ...... @classmethod...defcl(cls,y:int)->int: ...>>>Some.st.__no_type_check__=True>>>Some.cl.__no_type_check__=TrueAttributeError:'method'objecthasnoattribute'__no_type_check__' Ideas? Moreover, do we need some special |
AlexWaygood commentedFeb 2, 2022
Doesn't look like you've pushed anything -- did you mean to? :) |
sobolevn commentedFeb 2, 2022
Not yet, I am still fighting |
sobolevn commentedFeb 2, 2022
Probably ifisinstance(obj,types.MethodType):obj.__func__.__no_type_check__=True is the way to go 🤔 Will write some more tests to be sure. |
JelleZijlstra left a comment
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.
Looks good.
Do you think this should be backported? I'm leaning no as it's a behavior change and nobody directly complained about the old behavior (looks like you found it while reviewing typing test coverage).
gvanrossum left a comment
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.
Agreed, a backport doesn't seem asked for.
Uh oh!
There was an error while loading.Please reload this page.
There are several changes:
no_type_checkdo not modify foreign functions. It was the same as withtypesexcept TypeErrorinno_type_checkwith a simple test case, it was not covered at alllambdatest is a good idea: becauselambdais a bit of both in class bodies: a function and an assignmentAre there any other cases we want to cover?
https://bugs.python.org/issue46571