-
Notifications
You must be signed in to change notification settings - Fork 263
Typing concepts: add that object | Any and Never | Any can be simplified #2052
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
base: main
Are you sure you want to change the base?
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.
Looks good to me.
The exceptions are ``object`` and ``Never``. The union ``object | Any`` is equivalent to | ||
``object``, because ``object`` is a type containing all values and therefore the ``Any`` | ||
cannot add any values. Similarly, ``Never | Any`` is equivalent to ``Any``, because | ||
``Never`` is a type containing no values, so that including it in a union cannot add any | ||
values to the type. |
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.
There is another exception explained in the paragraph below (for equivalent gradual types). To be honest, I'm not sure if it really helps with clarity to add more exceptions here. It feels to me like the original intent of this paragraph was maybe just to explain that T | Any
is not generally reducible to a simpler form (Any
)?
Also, the existing sentence "It represents an unknown static type with lower bound T
" is only true if T
is fully-static.
Maybe both of these problems could be solved by going with something like:
This rule applies only to subtypes, not assignable-to. The union
T | Any
is not generally reducible to a simpler form. For example,int | Any
represents an unknown static type with lower boundint
. That is, it represents an unknown set of objects which may be as large asobject
, or as small asint
, but no smaller.Equivalent gradual types can, however, be simplified from unions […]
cannot add any values. Similarly, ``Never | Any`` is equivalent to ``Any``, because | ||
``Never`` is a type containing no values, so that including it in a union cannot add any | ||
values to the type. |
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.
Never | Any ≅ Any
can be generalized into Never | T ≅ T
(for all types T
), but I'm not sure if that axiom is already in the spec.
See https://discuss.python.org/t/interactions-with-never-leading-to-undesirable-assignability/99445/25
I feel this is a straightforward oversight so I don't think this needs to go through the full approval process.