| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The definition of AnyStr as given makes sense only in Python 3, as observed by @srittau. To prevent confusion, this PR changes the definition to use Text instead of str. I also changed the two places where AnyStr was defined as an example, and made a few other related adjustments: - Remove mention of None as modifying the type, which is not true as of python#689. - Move Text up in the list of convenience definition because we now need it for the definition of AnyStr. - Modify definition of Optional to use `None` instead of `type(None)`, because the latter is not a valid static type.
| What should the default value look like? Any of the options ``""``, | ||
| ``b""`` or ``None`` fails to satisfy the type constraint (actually, | ||
| ``None`` will *modify* the type to become ``Optional[AnyStr]``). | ||
| ``b""`` or ``None`` fails to satisfy the type constraint. |
There was a problem hiding this comment.
Good call.
Sorry, something went wrong.
| * Optional, defined by ``Optional[t] == Union[t, type(None)]`` | ||
|
|
||
| * AnyStr, defined as ``TypeVar('AnyStr', str, bytes)`` | ||
| * Optional, defined by ``Optional[t] == Union[t, None]`` |
There was a problem hiding this comment.
Another good call. Perhaps the section on "Using None" should also be revised? It currently says
When used in a type hint, the expression None is considered equivalent to type(None).
But that's false -- at least for mypy, and IIRC we once discussed this and decided that this is intentional: type(None) is not acceptable at all in type hints!
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
The definition of AnyStr as given makes sense only in Python 3, as observed by @srittau. To prevent confusion, this PR changes the definition to use Text instead of str.
I also changed the two places where AnyStr was defined as an example, and made a few other related adjustments: