Files
David Peter 7b3b6a0b8c [ty] Split ty_extensions into public and internal parts (#26586)
## Summary

Split `ty_extensions` into a public part (`ty_extensions`), and an
internal part (`ty_extensions._internal`). For now, move everything to
`_internal`, except for:

- `static_assert`
- `Unknown`
- `AlwaysTruthy`, `AlwaysFalsy`
- `Intersection`, `Not`
- `Top`, `Bottom`
- `JustFloat`, `JustComplex`
- `NamedTupleLike`
2026-07-07 02:32:21 -07:00

1.3 KiB

Class definitions

Deferred resolution of bases

Only the stringified name is deferred

If a class base contains a stringified name, only that name is deferred. Other names are resolved normally.

[environment]
python-version = "3.12"
from ty_extensions._internal import reveal_mro

A = int

class G[T]: ...
class C(A, G["B"]): ...

A = str
B = bytes

reveal_mro(C)  # revealed: (<class 'C'>, <class 'int'>, <class 'G[bytes]'>, typing.Generic, <class 'object'>)
reveal_mro(cls=C)  # revealed: (<class 'C'>, <class 'int'>, <class 'G[bytes]'>, typing.Generic, <class 'object'>)

Starred bases

Fixed-length tuples are unpacked when used as starred base classes:

from ty_extensions._internal import reveal_mro

class A: ...
class B: ...
class C: ...

bases = (A, B, C)

class Foo(*bases): ...

# revealed: (<class 'Foo'>, <class 'A'>, <class 'B'>, <class 'C'>, <class 'object'>)
reveal_mro(Foo)

Variable-length tuples cannot be unpacked, so they fall back to Unknown:

from ty_extensions._internal import reveal_mro

def get_bases() -> tuple[type, ...]:
    return (int, str)

# error: [unsupported-base] "Unsupported class base"
class Bar(*get_bases()): ...

# revealed: (<class 'Bar'>, Unknown, <class 'object'>)
reveal_mro(Bar)