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

Tests are broken on 3.13 due to TypedDict kwargs removal #204

Closed
JelleZijlstra opened this issue May 27, 2023 · 1 comment · Fixed by #212
Closed

Tests are broken on 3.13 due to TypedDict kwargs removal #204

JelleZijlstra opened this issue May 27, 2023 · 1 comment · Fixed by #212

Comments

@JelleZijlstra
Copy link
Member

Because of python/cpython#104891, unit tests fail when run against current CPython main:

======================================================================
ERROR: test_basics_keywords_syntax (__main__.TypedDictTests.test_basics_keywords_syntax)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jelle/py/typing_extensions/src/test_typing_extensions.py", line 2804, in test_basics_keywords_syntax
    Emp = TypedDict('Emp', name=str, id=int)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: TypedDict() got an unexpected keyword argument 'name'

======================================================================
ERROR: test_typeddict_special_keyword_names (__main__.TypedDictTests.test_typeddict_special_keyword_names)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jelle/py/typing_extensions/src/test_typing_extensions.py", line 2820, in test_typeddict_special_keyword_names
    TD = TypedDict("TD", cls=type, self=object, typename=str, _typename=int,
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: TypedDict() got some positional-only arguments passed as keyword arguments: 'typename, fields'

This is because on 3.12+ we re-export typing.TypedDict, which no longer supports kwargs on 3.13. We emit DeprecationWarnings for kwargs-based TypedDict creation on all versions.

We have some time before we really need to worry about 3.13, but we should decide how to handle this. Options I can see:

  1. Leave the code as is: kwargs-based typing_extensions.TypedDict will work on 3.12 and lower, but not on 3.13 and up. I am not sure if this is strictly against SemVer, but I feel typing_extensions generally has the goal of working the same on all Python versions.
  2. Increment the major version of typing-extensions and release typing-extensions 5 without TypedDict kwargs support. I don't want to do this: a major version upgrade would be very disruptive and this minor change isn't worth that cost.
  3. Remove kwargs-based TypedDicts on all Python versions without incrementing the major version. Although it feels unlikely this will break a lot of users, it goes against our declared versioning policy. We should not do this.
  4. Re-implement TypedDict on 3.13+ again with kwargs support, and leave it around forever. (Or until we eventually decide to do a major version upgrade for other reasons.) Not great, but the maintenance cost isn't huge, and it keeps typing-extensions working the same way on all Python versions.

I think I'm leaning towards option 1, but I'd also be OK with 4. 2 and 3 are out.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented May 27, 2023

I'd go with option 1.

With that option, upgrading typing_extensions will continue to not break anyone. Upgrading Python will break people to an extent that CPython has already determined to be okay. I don't see any need for us to be more conservative than CPython here, given that breakage will be tied to the Python upgrade. We're a backport not a forward port

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 a pull request may close this issue.

2 participants