Let's say I have on object x. I want to check if x is of a type I support (let's say it's lists, sets, strings and None. And without types that inherit from them), so I figured I'll just check
type(x) in (list, set, str, NoneType)
However, NoneType cannot be referable. Is there a clean solution, or must I do something like this?
x is None or type(x) in (list, set, str)
Is there a standard way to access <type 'NoneType'>?
Thanks.
type(None)?NoneTypetotypesalong with other inaccessible types (FunctionType,FrameType, etc.) in 3.0, until Guido asked (a) whether anyone could imagine writingtypes.NoneTypeinstead oftype(None)(after all, digging up a frame object to calltypeon it isn't trivial, butNoneis always right there), and (b) whether there was a good use forisinstancechecks onNoneexcept as part of some set you built up out of like (since there is only oneNoneTypevalue, and you're supposed to test it withis), and everyone agreed he was right.isinstance(x, (str, list, set, type(None))). I'm also interested in figure out which approach could be considered more pythonic.