-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Fix tests on Python 3.12 #162
Conversation
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.
The code looks good! A few comments about the tests. The only big concern I have is about typing.Unpack
-- I think we should backport python/cpython#104048 rather than just fiddling with the test to make it pass on 3.12.
Feels like we could probably share more code between _TypeVarMeta
, _ParamSpecMeta
and _TypeVarTupleMeta
, but that can definitely be tackled in a followup PR; no need to worry about it now.
class TypeVar(metaclass=_TypeVarMeta): | ||
"""Type variable.""" | ||
|
||
__module__ = 'typing' |
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.
heh
Co-authored-by: Alex Waygood <[email protected]>
I'm not sure that's feasible. The code is similar for all three, but not quite the same: they all take different arguments and map to different |
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.
The changes look good, and I confirmed that the tests all pass on CPython main
.
It looks like the tests do currently crash on 3.12 alpha7, due to this not being valid syntax until very recently:
typing_extensions/src/test_typing_extensions.py
Lines 2404 to 2405 in 40dbc09
class Foo[T](Protocol): | |
def meth(self, x: T) -> None: ... |
(See https://github.com/python/typing_extensions/actions/runs/5029362366/jobs/9020946297?pr=162)
So I suppose we could possibly make this sys.version_info
check more fine-grained:
typing_extensions/src/test_typing_extensions.py
Line 2399 in 40dbc09
if sys.version_info >= (3, 12): |
But also, the beta is about to be released, so maybe it doesn't matter too much?
Thanks! I'll push something to make it check for |
This brings in a fix for python 3.12: python/typing_extensions#162
With earlier versions of typing_extensions, the following traceback is seen: ``` Traceback (most recent call last): File ".../bin/mypy", line 5, in <module> from mypy.__main__ import console_entry File ".../lib/python3.12/site-packages/mypy/__main__.py", line 9, in <module> from mypy.main import main, process_options File ".../lib/python3.12/site-packages/mypy/main.py", line 12, in <module> from typing_extensions import Final File ".../lib/python3.12/site-packages/typing_extensions.py", line 1174, in <module> class TypeVar(typing.TypeVar, _DefaultMixin, _root=True): TypeError: type 'typing.TypeVar' is not an acceptable base type ``` The error is addressed in typing_extensions in python/typing_extensions#162, which is included in the 4.6.0 release.
With earlier versions of typing_extensions, the following traceback is seen: ``` Traceback (most recent call last): File ".../bin/mypy", line 5, in <module> from mypy.__main__ import console_entry File ".../lib/python3.12/site-packages/mypy/__main__.py", line 9, in <module> from mypy.main import main, process_options File ".../lib/python3.12/site-packages/mypy/main.py", line 12, in <module> from typing_extensions import Final File ".../lib/python3.12/site-packages/typing_extensions.py", line 1174, in <module> class TypeVar(typing.TypeVar, _DefaultMixin, _root=True): TypeError: type 'typing.TypeVar' is not an acceptable base type ``` The error is addressed in typing_extensions in python/typing_extensions#162, which is included in the 4.6.0 release.
…n#17312) With earlier versions of typing_extensions, the following traceback is seen: ``` Traceback (most recent call last): File ".../bin/mypy", line 5, in <module> from mypy.__main__ import console_entry File ".../lib/python3.12/site-packages/mypy/__main__.py", line 9, in <module> from mypy.main import main, process_options File ".../lib/python3.12/site-packages/mypy/main.py", line 12, in <module> from typing_extensions import Final File ".../lib/python3.12/site-packages/typing_extensions.py", line 1174, in <module> class TypeVar(typing.TypeVar, _DefaultMixin, _root=True): TypeError: type 'typing.TypeVar' is not an acceptable base type ``` The error is addressed in typing_extensions in python/typing_extensions#162, which is included in the 4.6.0 release.
On current Python main, TypeVar cannot be subclassed. However, we still need to enhance TypeVar to add the
default=
argument. This PR introduces an alternative approach to achieve that: we create a dummy class that wrapstyping.TypeVar
and when instantiated, returns an instance oftyping.TypeVar
, possibly with some additional attributes. We also set__instancecheck__
so thatisinstance(x, typing_extensions.TypeVar)
continues to work.Also fix a few other minor test failures on current CPython main.