ruff
14fbc2b1 - [ty] New `Type` variant for `TypedDict` (#19733)

Commit
60 days ago
[ty] New `Type` variant for `TypedDict` (#19733) ## Summary This PR adds a new `Type::TypedDict` variant. Before this PR, we treated `TypedDict`-based types as dynamic Todo-types, and I originally planned to make this change a no-op. And we do in fact still treat that new variant similar to a dynamic type when it comes to type properties such as assignability and subtyping. But then I somehow tricked myself into implementing some of the things correctly, so here we are. The two main behavioral changes are: (1) we now also detect generic `TypedDict`s, which removes a few false positives in the ecosystem, and (2) we now support *attribute* access (not key-based indexing!) on these types, i.e. we infer proper types for something like `MyTypedDict.__required_keys__`. Nothing exciting yet, but gets the infrastructure into place. Note that with this PR, the type of (the type) `MyTypedDict` itself is still represented as a `Type::ClassLiteral` or `Type::GenericAlias` (in case `MyTypedDict` is generic). Only inhabitants of `MyTypedDict` (instances of `dict` at runtime) are represented by `Type::TypedDict`. We may want to revisit this decision in the future, if this turns out to be too error-prone. Right now, we need to use `.is_typed_dict(db)` in all the right places to distinguish between actual (generic) classes and `TypedDict`s. But so far, it seemed unnecessary to add additional `Type` variants for these as well. part of https://github.com/astral-sh/ty/issues/154 ## Ecosystem impact The new diagnostics on `cloud-init` look like true positives to me. ## Test Plan Updated and new Markdown tests
Author
Parents
Loading