Python Forum

Full Version: what module is NoneType in?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
what module is NoneType in? i didn't find it in the library, language, tutorial, or using documentation or in module "types".
Not sure if this answers your question but look at https://docs.python.org/3/library/stdtyp...ull-object
I think it is in module 'builtins' (with an s)
(Nov-28-2019, 05:02 AM)buran Wrote: [ -> ]Not sure if this answers your question but look at https://docs.python.org/3/library/stdtyp...ull-object

no, it does not even mention it.

(Nov-28-2019, 12:07 PM)Gribouillis Wrote: [ -> ]I think it is in module 'builtins' (with an s)

seems to be the same thing as already there as __builtins__.
(Nov-28-2019, 03:23 PM)Skaperen Wrote: [ -> ]it does not even mention it.
Well, it does;
Quote:The Null Object¶
This object is returned by functions that don’t explicitly return a value. It supports no special operations. There is exactly one null object, named None (a built-in name). type(None)() produces the same singleton.

It is written as None.
it doesn't mention "NoneType", which is what i am looking for. see post #1.
However
>>> type(None).__module__
'builtins'
but
>>> __builtins__.NoneType
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'builtins' has no attribute 'NoneType'
Thus NoneType is hidden.
>>> __builtins__.type(None)
<class 'NoneType'>

Also there is very interesting link in one of the comments in the SO
https://docs.python.org/3/library/typing...pe-aliases
Quote:Note that None as a type hint is a special case and is replaced by type(None).

As I understand it, in python3 NoneType is only exposed through type(None)

And the question is why @Skaperen asked this question in the first place as it starts to look very much like XY problem
You're misinterpreting the code
>>> __builtins__.type
<class 'type'>
so __builtins__.type(None) is identical to type(None)

You can add the type yourself
>>> __builtins__.NoneType = type(None)
>>> NoneType
<class 'NoneType'>
This bug report seems worth reading as well.
Pages: 1 2