Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what module is NoneType in?
#1
what module is NoneType in? i didn't find it in the library, language, tutorial, or using documentation or in module "types".
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Not sure if this answers your question but look at https://docs.python.org/3/library/stdtyp...ull-object
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
I think it is in module 'builtins' (with an s)
Reply
#4
(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__.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
(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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
it doesn't mention "NoneType", which is what i am looking for. see post #1.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#7
see the discussion here: https://stackoverflow.com/a/21706626/4046632
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
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.
Reply
#9
>>> __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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#10
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020