-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Refactor is_named_instance
and refers_to_fullname
#11961
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
Conversation
@@ -117,6 +117,15 @@ | |||
'typing_extensions.Annotated', | |||
) | |||
|
|||
# We use this constant in various places when checking `tuple` subtyping: |
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.
Not related to your diff, but I wonder why Sized and Collection aren't in here.
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.
Do we need to open a new issue? 🤔
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.
Yes probably. I guess what this affects is whether a heterogeneous tuple type matches Sized
or Collection
?
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.
Done #11961
Looks like I've accedentaly noticed a bug. Here's the test definition of mypy/test-data/unit/check-async-await.test Lines 606 to 608 in f6ebf10
Later it is used as Old error message: New error message: >>> import types
>>> import asyncio
>>> @types.coroutine
... async def decorated_coroutine() -> int:
... return 1
...
>>> x = decorated_coroutine()
>>> type(x)
<class 'coroutine'>
>>> asyncio.run(x)
1
>>> async def main():
... y = decorated_coroutine()
... async for a in y:
... print(a)
...
>>> asyncio.run(main())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sobolev/Desktop/cpython/Lib/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/sobolev/Desktop/cpython/Lib/asyncio/base_events.py", line 637, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "<stdin>", line 3, in main
TypeError: 'async for' requires an object with __aiter__ method, got coroutine Double-checking: >>> import inspect
>>> inspect.isasyncgenfunction(decorated_coroutine)
False
>>> inspect.isasyncgen(decorated_coroutine())
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
False @JelleZijlstra do you agree? |
Sorry, I'm not sure I understand. Note that |
Ok, I see. Then, it is not a bug. Thanks! |
I saw that
refers_to_fullname
cannot use our newmypy.types.FINAL_DECORATOR_NAMES
constant to work. So, I've decided to allow that.In the process:
is_named_instance
function to allowTuple
as well (I useTuple
, because it is used for constants)is_named_instance
inrefers_to_fullname