mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
#17115,17116: Have modules initialize the __package__ and __loader__
attributes to None. The long-term goal is for people to be able to rely on these attributes existing and checking for None to see if they have been set. Since import itself sets these attributes when a loader does not the only instances when the attributes are None are from someone overloading __import__() and not using a loader or someone creating a module from scratch. This patch also unifies module initialization. Before you could have different attributes with default values depending on how the module object was created. Now the only way to not get the same default set of attributes is to circumvent initialization by calling ModuleType.__new__() directly.
This commit is contained in:
parent
4cfc0b5411
commit
4c14b5de1c
15 changed files with 264 additions and 220 deletions
|
@ -35,13 +35,20 @@ There are only a few functions special to module objects.
|
|||
single: __name__ (module attribute)
|
||||
single: __doc__ (module attribute)
|
||||
single: __file__ (module attribute)
|
||||
single: __package__ (module attribute)
|
||||
single: __loader__ (module attribute)
|
||||
|
||||
Return a new module object with the :attr:`__name__` attribute set to *name*.
|
||||
Only the module's :attr:`__doc__` and :attr:`__name__` attributes are filled in;
|
||||
the caller is responsible for providing a :attr:`__file__` attribute.
|
||||
The module's :attr:`__name__`, :attr:`__doc__`, :attr:`__package__`, and
|
||||
:attr:`__loader__` attributes are filled in (all but :attr:`__name__` are set
|
||||
to ``None``); the caller is responsible for providing a :attr:`__file__`
|
||||
attribute.
|
||||
|
||||
.. versionadded:: 3.3
|
||||
|
||||
.. versionchanged:: 3.4
|
||||
:attr:`__package__` and :attr:`__loader__` are set to ``None``.
|
||||
|
||||
|
||||
.. c:function:: PyObject* PyModule_New(const char *name)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue