In Python 3, I would like to check whether value
is either string or None
.
One way to do this is
assert type(value) in { str, NoneType }
But where is NoneType
located in Python?
Without any import, using NoneType
produces NameError: name 'NoneType' is not defined
.
types.NoneType
is being reintroduced in Python 3.10.
Improved Modules
Reintroduced the
types.EllipsisType
,types.NoneType
andtypes.NotImplementedType
classes, providing a new set of types readily interpretable by type checkers. (Contributed by Bas van Beek in bpo-41810.)
The discussion about the change was motivated by a need for types.EllipsisType
, leading to types.NoneType
also being added for consistency.