Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tracked by #14172
carljm opened this issue Nov 22, 2024 · 0 comments
Open
Tracked by #14172

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

carljm opened this issue Nov 22, 2024 · 0 comments
Assignees
Labels
red-knot Multi-file analysis & type inference

Comments

@carljm
Copy link
Contributor

carljm commented Nov 22, 2024

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.

@carljm carljm added the red-knot Multi-file analysis & type inference label Nov 22, 2024
@carljm carljm self-assigned this Nov 22, 2024
@carljm carljm changed the title [red-knot] [red-knot] support typing.Any in annotations Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

No branches or pull requests

1 participant