Skip to content
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 most tests on Python 3.13 #378

Merged
merged 5 commits into from
May 10, 2024
Merged

Fix most tests on Python 3.13 #378

merged 5 commits into from
May 10, 2024

Conversation

AlexWaygood
Copy link
Member

Helps with #377. Lots of changes to reflect changes in the PEP-696 implementation that were made upstream but had yet to be backported here.

There's still a couple of failing tests on Python 3.13 even with this PR, but this gets us a lot closer to a clean bill of health.

@AlexWaygood
Copy link
Member Author

@JelleZijlstra any idea what's up with the pickle test failing? It's only failing on Python 3.13, which suggests it might be an issue with the CPython implementation, and I can repro locally in my CPython clone:

(main) % ./python.exe                                                                                                                ~/dev/cpython
Python 3.14.0a0 (heads/main:66f8bb76a1, May  8 2024, 17:00:15) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import NoDefault
>>> import pickle
>>> pickle.dumps(NoDefault)
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    pickle.dumps(NoDefault)
    ~~~~~~~~~~~~^^^^^^^^^^^
_pickle.PicklingError: can't pickle 'NoDefaultType' object: typing.NoDefault
>>> import typing
>>> pickle.dumps(typing.NoDefault)
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    pickle.dumps(typing.NoDefault)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
_pickle.PicklingError: can't pickle 'NoDefaultType' object: typing.NoDefault

What I don't understand is why the pickling tests are passing in the CPython test suite: https://github.com/python/cpython/blob/7ac933e2609b2ef9b08ccf9c815b682b0e1ede2a/Lib/test/test_typing.py#L10230-L10234

Comment on lines 6303 to 6306
@skipIf(
sys.version_info[:5] == (3, 13, 0, "beta", 1),
"incorrectly raises TypeError in the first 3.13 beta"
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JelleZijlstra
Copy link
Member

The pickle thing is weird; I can reproduce it on CPython when I comment out the tests.addTests(doctest.DocTestSuite(typing)) call at the bottom of test_typing.py. Something must have a side effect but I'm not sure what.

@AlexWaygood
Copy link
Member Author

The pickle thing is weird; I can reproduce it on CPython when I comment out the tests.addTests(doctest.DocTestSuite(typing)) call at the bottom of test_typing.py. Something must have a side effect but I'm not sure what.

That is weird. I guess I'll skip the test over here for now.

@JelleZijlstra
Copy link
Member

Found it:

% ./python.exe
Python 3.14.0a0 (heads/main:7ac933e260, May 10 2024, 05:30:33) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import typing, pickle
>>> pickle.dumps(typing.NoDefault)
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    pickle.dumps(typing.NoDefault)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
_pickle.PicklingError: can't pickle 'NoDefaultType' object: typing.NoDefault
>>> typing.NoDefault.__doc__
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    typing.NoDefault.__doc__
AttributeError: 'NoDefaultType' object has no attribute '__doc__'. Did you mean: '__dir__'?
>>> pickle.dumps(typing.NoDefault)
b'\x80\x04\x95\x19\x00\x00\x00\x00\x00\x00\x00\x8c\x07_typing\x94\x8c\tNoDefault\x94\x93\x94.'
>>> typing.NoDefault.__doc__
'The type of the NoDefault singleton.'

The good news is that I think python/cpython#118897 fixes this. (Nikita just commented as much.)

@AlexWaygood
Copy link
Member Author

Alright, so just one failing test left now:

======================================================================
FAIL: test_async_contextmanager (test_typing_extensions.OtherABCTests.test_async_contextmanager)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/typing_extensions/typing_extensions/src/test_typing_extensions.py", line 1652, in test_async_contextmanager
    self.assertEqual(typing_extensions.AsyncContextManager[int].__args__, (int,))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Tuples differ: (<class 'int'>, bool | None) != (<class 'int'>,)

First tuple contains 1 additional elements.
First extra element 1:
bool | None

- (<class 'int'>, bool | None)
+ (<class 'int'>,)

The principled way of fixing that is to make typing_extensions.AsyncContextManager have an optional second type parameter, the same as typing.AsyncContextManager on py313+. But I think doing that might possibly involve backporting the whole typing._GenericAlias implementation from CPython, which I don't really wanna do in this PR.

@JelleZijlstra
Copy link
Member

Let's merge this now to fix a number of the tests; we can fix the rest separately.

@erlend-aasland
Copy link

Thanks for fixing these! Currently, the canopen test suite fails to run on Python 3.13; looks like this should do the trick. Is there a 4.11.1 release scheduled?

@AlexWaygood
Copy link
Member Author

Thanks for fixing these! Currently, the canopen test suite fails to run on Python 3.13; looks like this should do the trick. Is there a 4.11.1 release scheduled?

If we cut a new release right now, it would break pydantic, which would be very bad (#381) -- we've broken pydantic before, and the experience was extremely chaotic for us, we definitely don't want to do it again 🙃

I've opened a PR to fix pydantic's tests with the typing_extensions main branch here: pydantic/pydantic#9426.

@erlend-aasland
Copy link

Great! I'm watching pydantic/pydantic#9426 and keeping an eye out for new releases of typing-extensions :)

@AlexWaygood
Copy link
Member Author

typing_extensions 4.12.0rc1 is now out @erlend-aasland! :D https://pypi.org/project/typing-extensions/4.12.0rc1/

@JelleZijlstra
Copy link
Member

The final release should happen in a week (next Thursday).

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

Successfully merging this pull request may close these issues.

None yet

3 participants