Skip to content

Conversation

@Josverl
Copy link

@Josverl Josverl commented Oct 11, 2025

This should help provide clarity on what does / does not work.

This also includes an improvement to support standard container generics such as List[int]

PEP 484	Type Hints Python 3.5
PEP 526	Syntax for Variable Annotations	Python 3.6
PEP 544	Protocols: Structural subtyping (static duck typing) Python 3.8
PEP 560	Core support for typing module and generic types Python 3.7
PEP 586	Literal Types Python 3.8
PEP 589	TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys Python 3.8
PEP 591	Adding a final qualifier to typing Python 3.8

Signed-off-by: Jos Verlinde <[email protected]>
…in typing alias specifications.

Signed-off-by: Jos Verlinde <[email protected]>
@stinos stinos merged commit c99a336 into stinos:builtintypingmodule Oct 13, 2025
13 of 62 checks passed
@stinos
Copy link
Owner

stinos commented Oct 13, 2025

Pulling in these changes to check.

Btw do these tests all pass with the typing implementation written in Python?

@Josverl
Copy link
Author

Josverl commented Oct 13, 2025

Btw do these tests all pass with the typing implementation written in Python?

yes they do, with the exclusion of the 'un-mutability' tests you added.
( but I have not pushed them yet - still banging into shape and comparing and reducing size )

Ans I also got collections.abc working by patching collections/__init__.py.
That should work the same for a collections.abc registered in .c

# optional collections.abc typing dummy module
try:
    # cannot use relative import here
    import collections.abc as abc
    import sys 
    sys.modules['collections.abc'] = abc
except ImportError:
    pass
# collections.abc
# minimal support for runtime typing
# type: ignore
try:
    from typing import __Ignore as ABC
    from typing import __getattr__ as __getattr__
except ImportError:
    pass
#tests/.../typing_syntax.py
# if "micropython" in sys.implementation.name:
#     # Verify assignment is not possible.
#     try:
#         typing.a = None
#         raise Exception()
#     except AttributeError:
#         pass
#     try:
#         typing[0] = None
#         raise Exception()
#     except TypeError:
#         pass
#     try:
#         List.a = None
#         raise Exception()
#     except AttributeError:
#         pass

@stinos
Copy link
Owner

stinos commented Oct 13, 2025

Using CPython 3.13.7, the .exp for typing_pep_0589.py comes out as

### PEP 589
Class-based Syntax
Using TypedDict Types
Totality and optional keys
Inheritance and required/optional mix
Runtime checks: TypedDict cannot be used with isinstance/class checks
TypedDict class not allowed for isinstance/class checks
Alternative functional syntax and constructors
<class 'dict'>
Inheritance examples
Totality and mixing with Required/NotRequired
Required/NotRequired with Annotated/ReadOnly examples
extra_items and closed examples
-[ ] FIXME: extra_items not supported by runtime typing implementation: _TypedDictMeta.__new__() got an unexpected keyword argument 'extra_items'
-[ ] FIXME: closed parameter not supported by runtime typing implementation: _TypedDictMeta.__new__() got an unexpected keyword argument 'closed'
Interaction with Mapping and dict conversions
-[ ] FIXME: extra_items not supported by runtime typing implementation _TypedDictMeta.__new__() got an unexpected keyword argument 'extra_items'

so looks like my CPython doesn't support that - do I need a different version?

For typing_pep_0591, is there a FIXME missing in

try:

    def fun(x: Final[List[int]]) -> None:  # Error!
        ...

except Exception:
    print("Expected: Final cannot be used for parameters or return types")

?

@Josverl
Copy link
Author

Josverl commented Oct 13, 2025

so looks like my CPython doesn't support that - do I need a different version?

No its not that -

While creating the tests I just worked my way up the versions until I hit 3.9.

While PEP 589 is listed on https://peps.python.org/topic/typing/ as implemented in Python 3.8

Also MicroPython has no actual support for TypedDict that I can find - I think I should have checked this before writing/copying a test for it.
So perhaps its better to document TypedDict as a cpydiff and remove it from the typing tests.

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.

2 participants