◐ Shell
clean mode source ↗

Typing concepts: add that object | Any and Never | Any can be simplified by JelleZijlstra · Pull Request #2052 · python/typing

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 bound int. That is, it represents an unknown set of objects which may be as large as object, or as small as int, but no smaller.

Equivalent gradual types can, however, be simplified from unions […]