-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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: infer and display ellipsis type #13124
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, not sure about this approach
Type::EllipsisType => { | ||
// TODO: attribute lookup on Ellipsis type | ||
Type::Unknown | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this needs to be its own variant in the Type
enum... it's conceptually just an instance of types.EllipsisType
. types.EllipsisType
was only exposed on Python 3.10+, but typeshed already provides a nice little compatibility workaround for us here: https://github.com/python/typeshed/blob/f58dac1d62d33bb2255b762783d06463c40f5065/stdlib/builtins.pyi#L1849-L1865
(builtins.Ellipsis
is the same object as ...
)
>>> ...
Ellipsis
>>> Ellipsis
Ellipsis
>>> Ellipsis is ...
True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One interesting way in which ...
is special is that it's a singleton: it is the only instance of types.EllipsisType
that there is, or that there could be. But that can be thought of as just a sealed type that has exactly one member, and we've yet to implement a generalised way of handling sealed types. (We'll need them to tackle enums in Python!) See #12694.
Defer to the built-in type and leave notes about where and how we ought to be resolving to `typing.EllipsisType` instead of the current output, which is `Unknown | Literal[EllipsisType]`.
Summary
Just what it says on the tin: adds basic
EllipsisType
inference for any time...
appears in the AST.Test Plan
Test that
x = ...
produces exactly what we would expect.