Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/test_dataclass_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions tests/test_type_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
Expand Down
1 change: 1 addition & 0 deletions tests/test_type_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.<locals>.C]:
Expand Down
1 change: 1 addition & 0 deletions typemap/type_eval/_apply_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion typemap/type_eval/_eval_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading