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
bpo-46571: improve typing.no_type_check to skip foreign objects
#31042
Conversation
|
Here's a slightly evil corner case that this patch doesn't account for: If I have a module # typing_test.py
class A:
class AA:
foo: intThen, observe the following behaviour (with your patch applied): >>> from typing import get_type_hints, no_type_check
>>> import typing_test
>>> get_type_hints(typing_test.A.AA)
{'foo': <class 'int'>}
>>> @no_type_check
... class A:
... AA = typing_test.A.AA
...
...
>>> get_type_hints(typing_test.A.AA)
{}We might be able to get around this by looking at the |
|
@AlexWaygood good one! Very evil! I've addressed this. @JelleZijlstra I agree that we should also fix The problem is that >>> class Some:
... @staticmethod
... def st(x: int) -> int: ...
... @classmethod
... def cl(cls, y: int) -> int: ...
>>> Some.st.__no_type_check__ = True
>>> Some.cl.__no_type_check__ = True
AttributeError: 'method' object has no attribute '__no_type_check__'Ideas? Moreover, do we need some special |
Doesn't look like you've pushed anything -- did you mean to? :) |
Not yet, I am still fighting |
|
Probably if isinstance(obj, types.MethodType):
obj.__func__.__no_type_check__ = Trueis the way to go Will write some more tests to be sure. |
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