The type of None is NoneType [not a built-in, it’s type(None)], but in typing we use None as a type:
my_var: None|int = 3
Besides of typing, Pyhon does not accept None as a type. Technically None is indeed not a type. OTOH None is quite special.
I think this difference between usage of None in typing and not-typing should be somehow addressed. I’m just not sure how.
My particular use-case looks like this. I will focus on the isinistance check:
def convert_wrapper(arg, ignore_types):
# ignored types may contain zero, one or more types
if isinstance(arg, ignore_types):
return arg
return convert(arg)
I want to be able to include None as an ignored type just like it is commonly used in typing.
Using a tuple doesn’t work. As a special case, None occurences must be replaced with type(None):
isinstance(arg, (int, None)) # TypeError in isinstance
isinstance(arg, (int, type(None))) # OK
Using a union seems to work, but there is again a special case:
isinstance(arg, typing.Union[*(int, None)]) # OK
isinstance(arg, typing.Union[*()])
# TypeError: Cannot take a Union of no types
I’d like to be able to make a test without handling special cases and if possible using the one obvious way. The least modification that would allow to do that is IMO to allow an empty type union - if it does not break anything else, of course.