Skip to content

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

Closed
@JelleZijlstra

Description

@JelleZijlstra

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions