diff --git a/tests/test_dataclass_like.py b/tests/test_dataclass_like.py index 29a0774..18ade10 100644 --- a/tests/test_dataclass_like.py +++ b/tests/test_dataclass_like.py @@ -144,7 +144,8 @@ def test_dataclass_like_1(): tgt = eval_typing(Hero) fmt = format_helper.format_class(tgt) - assert fmt == textwrap.dedent("""\ + # 3.15 inserts the module name in a place that 3.14 doesn't, so replace + assert fmt.replace("tests.test_dataclass_like.", "") == textwrap.dedent("""\ class Hero: id: int | None = None name: str diff --git a/tests/test_type_dir.py b/tests/test_type_dir.py index 94f8b41..736390a 100644 --- a/tests/test_type_dir.py +++ b/tests/test_type_dir.py @@ -190,13 +190,16 @@ def test_type_dir_link_2(): def test_type_dir_1a(): d = eval_typing(Final) - assert format_helper.format_class(d) == textwrap.dedent("""\ + # 3.15 inserts the module name in a place that 3.14 doesn't, so replace + assert format_helper.format_class(d).replace( + "tests.test_type_dir.", "" + ) == textwrap.dedent("""\ class Final: last: int | typing.Literal[True] iii: str | int | typing.Literal['gotcha!'] t: dict[str, str | int | typing.Literal['gotcha!']] fin: typing.Final[int] - x: tests.test_type_dir.Wrapper[int | None] + x: Wrapper[int | None] ordinary: str def foo(self: Self, a: int | None, *, b: int = 0) -> dict[str, int]: ... def base[Z](self: Self, a: int | Z | None, b: ~K) -> dict[str, int | Z]: ... diff --git a/tests/test_type_eval.py b/tests/test_type_eval.py index 7721bc4..c6d8fbd 100644 --- a/tests/test_type_eval.py +++ b/tests/test_type_eval.py @@ -1901,6 +1901,7 @@ def class_method(cls, x: int) -> int: ... def static_method(x: int) -> int: ... res = eval_typing(IndirectProtocol[C]) + fmt = format_helper.format_class(res) assert fmt == textwrap.dedent("""\ class IndirectProtocol[tests.test_type_eval.test_new_protocol_with_methods_01..C]: diff --git a/typemap/type_eval/_apply_generic.py b/typemap/type_eval/_apply_generic.py index fc43df1..2b95fa1 100644 --- a/typemap/type_eval/_apply_generic.py +++ b/typemap/type_eval/_apply_generic.py @@ -437,6 +437,7 @@ def flatten_class_new_proto(cls: type) -> type: nt.__name__ = f'{cls.__name__}{args_str}' nt.__qualname__ = f'{cls.__qualname__}{args_str}' + nt.__module__ = cls.__module__ del nt.__subclasshook__ return nt diff --git a/typemap/type_eval/_eval_operators.py b/typemap/type_eval/_eval_operators.py index 6d1f224..88c6ec0 100644 --- a/typemap/type_eval/_eval_operators.py +++ b/typemap/type_eval/_eval_operators.py @@ -1334,11 +1334,13 @@ def _eval_NewProtocol(*etyps: Member, ctx): # If the type evaluation context ctx = type_eval._get_current_context() if ctx.current_generic_alias: + module_name = ctx.current_generic_alias.__module__ if isinstance(ctx.current_generic_alias, types.GenericAlias): name = str(ctx.current_generic_alias) else: name = f"{ctx.current_generic_alias.__name__}[...]" - module_name = ctx.current_generic_alias.__module__ + if name.startswith(f'{module_name}.'): + name = name[len(module_name) + 1 :] dct["__module__"] = module_name diff --git a/uv.lock b/uv.lock index 52c99d0..65a11e2 100644 --- a/uv.lock +++ b/uv.lock @@ -3,7 +3,7 @@ revision = 3 requires-python = ">=3.14" [options] -exclude-newer = "2026-05-18T18:33:12.81463383Z" +exclude-newer = "0001-01-01T00:00:00Z" # This has no effect and is included for backwards compatibility when using relative exclude-newer values. exclude-newer-span = "P2D" [[package]] @@ -107,11 +107,11 @@ wheels = [ [[package]] name = "pygments" -version = "2.19.2" +version = "2.20.0" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/b0/77/a5b8c569bf593b0140bde72ea885a803b82086995367bf2037de0159d924/pygments-2.19.2.tar.gz", hash = "sha256:636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887", size = 4968631, upload-time = "2025-06-21T13:39:12.283Z" } +sdist = { url = "https://files.pythonhosted.org/packages/c3/b2/bc9c9196916376152d655522fdcebac55e66de6603a76a02bca1b6414f6c/pygments-2.20.0.tar.gz", hash = "sha256:6757cd03768053ff99f3039c1a36d6c0aa0b263438fcab17520b30a303a82b5f", size = 4955991, upload-time = "2026-03-29T13:29:33.898Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/c7/21/705964c7812476f378728bdf590ca4b771ec72385c533964653c68e86bdc/pygments-2.19.2-py3-none-any.whl", hash = "sha256:86540386c03d588bb81d44bc3928634ff26449851e99741617ecb9037ee5ec0b", size = 1225217, upload-time = "2025-06-21T13:39:07.939Z" }, + { url = "https://files.pythonhosted.org/packages/f4/7e/a72dd26f3b0f4f2bf1dd8923c85f7ceb43172af56d63c7383eb62b332364/pygments-2.20.0-py3-none-any.whl", hash = "sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176", size = 1231151, upload-time = "2026-03-29T13:29:30.038Z" }, ] [[package]]