Skip to content

Type system feature overview #1889

@sharkdp

Description

@sharkdp

Type system features

This issue summarizes the support for various type system features in ty. Sections are organized to follow the structure of the Python typing specification, with some additional sections at the end.

If a top-level item is marked completed without any sub-items, you can generally expect that feature to be fully implemented (and we value any bug reports in case you find issues). If a top-level item is marked completed with open sub-items, the feature is generally working, but there might be some open issues — including but not limited to the ones listed (in this case, we also value any bug reports, but please search the issue tracker before doing so). If a top-level item is not checked, the feature is not implemented yet (it's probably not helpful to report bugs, but feel free to upvote the tracking issue or comment if you have useful information).

Special types and type qualifiers

Official documentation

tests: any.md, never.md, int_float_complex.md, final.md, classvar.md, annotated.md, union.md, instance_layout_conflict.md

Generics

Official documentation

tests: pep695/, legacy/, self.md, scoping.md

Protocols

Official documentation

tests: protocols.md

Type narrowing

Official documentation

tests: narrow/, type_guards.md

Tuples

Official documentation

tests: subscript/tuple.md, comparison/tuples.md, binary/tuples.md

NamedTuple

Official documentation

tests: named_tuple.md

  • Class syntax (class Foo(NamedTuple): ...)
  • Field access by name and index, slicing, unpacking
  • Default values, diagnostic for non-default after default
  • Read-only fields (assignment rejected)
  • Inheritance, generic NamedTuples
  • Multiple inheritance restriction
  • Underscore field name restriction
  • Prohibited attribute override check (_asdict, _make, …)
  • _fields, _field_defaults, _make, _asdict, _replace
  • Subtype of tuple[...]
  • super() restriction in NamedTuple methods
  • NamedTuple in type expressions
  • type[NamedTuple] in type expressions
    • Not fully supported
  • Functional syntax (NamedTuple("Foo", [...])) Support the functional syntax for NamedTuples #1049
  • collections.namedtuple: not tested
  • Subclass field conflicting with base class field: not tested

TypedDict

Official documentation

tests: typed_dict.md

Enums

Official documentation

tests: enums.md, comparison/enums.md

Literals

Official documentation

tests: literal.md, literal_string.md

  • Literal[0] (integer literals)
  • Literal["a"] (string literals)
  • Literal[b"a"] (bytes literals)
  • Literal[True] (boolean literals)
  • Literal[Color.RED] (enum literals)
  • Literal[None]
  • Nested Literal flattening
  • Union of literals simplification
  • Literal with type aliases
  • Invalid form diagnostics
  • LiteralString
  • LiteralString assignability
  • LiteralString narrowing
  • LiteralString cannot be parameterized
  • LiteralString cannot be subclassed

Callables

Official documentation

tests: callable.md, callable_instance.md

  • Callable[[X, Y], R] syntax
  • Callable[..., R] gradual form
  • Callable with ParamSpec
  • Callback protocols (__call__ method)
  • Callable assignability (contra/covariance)
  • Nested Callable types
  • Callable in unions/intersections
  • Invalid form diagnostics
  • Concatenate Support Concatenate special form #1535
  • Unpack for **kwargs typing Support typing.Unpack #1746

Overloads

Official documentation

tests: overloads.md, call/overloads.md

Dataclasses

Official documentation

tests: dataclasses.md, fields.md

dataclass_transform

Official documentation

tests: dataclass_transform.md

Constructors

Official documentation

tests: constructor.md

Type aliases

Official documentation

tests: pep695_type_aliases.md, pep613_type_aliases.md, implicit_type_aliases.md

Type checker directives

Official documentation

tests: directives/

  • cast(T, value)
  • Redundant cast diagnostic
  • assert_type(value, T)
  • assert_never(value)
  • reveal_type(value)
  • TYPE_CHECKING constant
  • @no_type_check decorator
  • type: ignore comments
  • ty: ignore comments
  • @deprecated decorator
  • @override decorator

Module resolution, imports, packages

Official documentation

tests: import/

Control flow analysis

tests: terminal_statements.md, exhaustiveness_checking.md, unreachable.md, exception/control_flow.md

Invalid overrides

(Liskov Substitution Principle checks, etc)

tests: liskov.md, override.md

Abstract base classes

tests: return_type.md, overloads.md

__slots__

tests: instance_layout_conflict.md

Special library features

Standard library:

Third-party library support (currently not decided how far we want to go here):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions