Skip to content

Python 3.13.0b1: test_typing_extensions: AttributeError: attribute '__default__' of 'typing.TypeVar' objects is not writable #377

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

Closed
befeleme opened this issue May 10, 2024 · 3 comments · Fixed by #382

Comments

@befeleme
Copy link

When building typing_extensions in Fedora with Python 3.13.0b1, test_typing_extensions fails with the traceback below.
I looked at the recent commits but they don't seem to tackle that. It hasn't yet been seen in the project's CI, probably because it still runs on alpha 6.

/usr/bin/python3 -m unittest discover
E
======================================================================
ERROR: test_typing_extensions (unittest.loader._FailedTest.test_typing_extensions)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_typing_extensions
Traceback (most recent call last):
  File "/usr/lib64/python3.13/unittest/loader.py", line 396, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib64/python3.13/unittest/loader.py", line 339, in _get_module_from_name
    __import__(name)
    ~~~~~~~~~~^^^^^^
  File "/builddir/build/BUILD/typing_extensions-4.11.0/src/test_typing_extensions.py", line 1148, in <module>
    T_a = TypeVar('T_a')
  File "/builddir/build/BUILD/typing_extensions-4.11.0/src/typing_extensions.py", line 1406, in __new__
    _set_default(typevar, default)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/typing_extensions-4.11.0/src/typing_extensions.py", line 1363, in _set_default
    type_param.__default__ = None
    ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: attribute '__default__' of 'typing.TypeVar' objects is not writable
@AlexWaygood AlexWaygood self-assigned this May 10, 2024
@AlexWaygood AlexWaygood removed their assignment May 10, 2024
@AlexWaygood
Copy link
Member

#378 fixed all but one test failure. The last remaining one is to do with AsyncContextManager having an optional second parameter on Python 3.13, but not in the backported version that typing_extensions provides.

@JelleZijlstra
Copy link
Member

@AlexWaygood the changes you made didn't look related to the test failure @befeleme pointed out here. Do you know what's going on here?

Also, there's another failure incoming due to changes I made for beta 2:

% ~/py/cpython/python.exe test_typing_extensions.py 
Traceback (most recent call last):
  File "/Users/jelle/py/typing_extensions/src/test_typing_extensions.py", line 42, in <module>
    from _typed_dict_test_helper import Foo, FooGeneric, VeryAnnotated
  File "/Users/jelle/py/typing_extensions/src/_typed_dict_test_helper.py", line 17, in <module>
    class FooGeneric(TypedDict, Generic[T]):
                                ~~~~~~~^^^
  File "/Users/jelle/py/cpython/Lib/typing.py", line 431, in inner
    return func(*args, **kwds)
  File "/Users/jelle/py/cpython/Lib/typing.py", line 1243, in _generic_class_getitem
    return _GenericAlias(cls, args)
  File "/Users/jelle/py/cpython/Lib/typing.py", line 1420, in __init__
    self.__parameters__ = _collect_parameters(
                          ~~~~~~~~~~~~~~~~~~~^
        args,
        ^^^^^
        enforce_default_ordering=enforce_default_ordering,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
TypeError: _collect_parameters() got an unexpected keyword argument 'enforce_default_ordering'

Will work on a fix for that one.

@AlexWaygood
Copy link
Member

AlexWaygood commented May 10, 2024

@AlexWaygood the changes you made didn't look related to the test failure @befeleme pointed out here. Do you know what's going on here?

The test failure @befeleme pointed out was more than a test failure: the test module was failing at import time. The failure was because the __default__ attribute on typing.TypeVar is read-only on py313+: in our implementation of PEP-696, we were creating instances of typing.TypeVar, then trying to monkeypatch __default__ attributes onto the TypeVar instances after creating them. But it's unnecessary to monkeypatch attributes onto instances of TypeVar on Python 3.13+, because the "real" TypeVar implementation has a default parameter for its constructor on Python 3.13+. So I fixed the error in #378 by simply not independently reimplementing TypeVar at all on Python 3.13+; instead, we now just from typing import TypeVar on Python 3.13+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants