Skip to content

[red-knot] support typing.Any in annotations #14544

@carljm

Description

@carljm

We have an internal representation (Type::Any) for the dynamic type Any, but we don't yet understand the typing.Any symbol as a spelling for that type in a type expression.

To add this, we'll need to track typing.Any as a KnownInstance (similar to the existing support for typing.Union, typing.Optional, typing.Literal), and add support for it in Type::in_type_expression, so that when TypeInferenceBuilder::infer_type_expression comes across the symbol in an annotation, we understand that annotation as describing the Any type.

We'll want to add mdtests for the "happy path" case like this:

x: Any = 1
x = "foo"

def f():
    reveal_type(x)  # revealed: Any

We'll also want edge-case tests showing that typing.Any can be aliased to a different name, and still works (that is, we are recognizing typing.Any under any name, not just pattern-matching on the local name), and similarly that a locally-defined class named Any simply means its own instance type, not Type::Any, in an annotation.

Metadata

Metadata

Assignees

Labels

tyMulti-file analysis & type inference

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions