Skip to content

Bug: PEP 695 type aliases fail to unwrap with typing-extensions 4.13.0 #683

Closed
@airwoodix

Description

@airwoodix

Description

When poylfactory is used with typing_extensions 4.13.0, PEP 695 type aliases do not unwrap properly in polyfactory.utils.helpers.unwrap_annotation. See the MCVE below.

The issue was introduced by python/typing_extensions#477, which made typing_extensions.TypeAliasType and typing.TypeAliasType different types for Python 3.12 and 3.13. This breaks the detection in unwrap_annotation.

MCVE

import typing
from random import SystemRandom

import typing_extensions
from polyfactory.utils.helpers import unwrap_annotation

type MyInt = int

assert not isinstance(MyInt, typing_extensions.TypeAliasType)  # ok
assert isinstance(MyInt, typing.TypeAliasType)  # ok

unwrapped = unwrap_annotation(MyInt, random=SystemRandom())
assert unwrapped is MyInt  # unexpeced, but passes
assert unwrapped is int  # expected, but fails

Release Version

  • Python 3.12.2 (probably hits on any 3.12.x and 3.13.x)
  • typing_extensions 4.13.0
  • polyfactory 2.20.0

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions