Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d7d2194

Browse files
committed
Integration of importdocs from the features/pep-420 repo.
1 parent 96d97ec commit d7d2194

7 files changed

Lines changed: 694 additions & 173 deletions

File tree

Doc/glossary.rst

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ Glossary
209209

210210
finder
211211
An object that tries to find the :term:`loader` for a module. It must
212-
implement a method named :meth:`find_module`. See :pep:`302` for
213-
details and :class:`importlib.abc.Finder` for an
214-
:term:`abstract base class`.
212+
implement either a method named :meth:`find_loader` or a method named
213+
:meth:`find_module`. See :pep:`302` and :pep:`420` for details and
214+
:class:`importlib.abc.Finder` for an :term:`abstract base class`.
215215

216216
floor division
217217
Mathematical division that rounds down to nearest integer. The floor
@@ -315,6 +315,10 @@ Glossary
315315
role in places where a constant hash value is needed, for example as a key
316316
in a dictionary.
317317

318+
importing
319+
The process by which Python code in one module is made available to
320+
Python code in another module.
321+
318322
importer
319323
An object that both finds and loads a module; both a
320324
:term:`finder` and :term:`loader` object.
@@ -440,6 +444,11 @@ Glossary
440444
include :class:`dict`, :class:`collections.defaultdict`,
441445
:class:`collections.OrderedDict` and :class:`collections.Counter`.
442446

447+
meta path finder
448+
A finder returned by a search of :data:`sys.meta_path`. Meta path
449+
finders are related to, but different from :term:`sys path finders <sys
450+
path finder>`.
451+
443452
metaclass
444453
The class of a class. Class definitions create a class name, a class
445454
dictionary, and a list of base classes. The metaclass is responsible for
@@ -464,6 +473,11 @@ Glossary
464473
for a member during lookup. See `The Python 2.3 Method Resolution Order
465474
<http://www.python.org/download/releases/2.3/mro/>`_.
466475

476+
module
477+
An object that serves as an organizational unit of Python code. Modules
478+
have a namespace contain arbitrary Python objects. Modules are loaded
479+
into Python by the process of :term:`importing`.
480+
467481
MRO
468482
See :term:`method resolution order`.
469483

@@ -496,6 +510,12 @@ Glossary
496510
functions are implemented by the :mod:`random` and :mod:`itertools`
497511
modules, respectively.
498512

513+
namespace package
514+
A :pep:`420` :term:`package` which serves only as a container for
515+
subpackages. Namespace packages may have no physical representation,
516+
and specifically are not like a :term:`regular package` because they
517+
have no ``__init__.py`` file.
518+
499519
nested scope
500520
The ability to refer to a variable in an enclosing definition. For
501521
instance, a function defined inside another function can refer to
@@ -516,6 +536,19 @@ Glossary
516536
(methods). Also the ultimate base class of any :term:`new-style
517537
class`.
518538

539+
package
540+
A Python module which can contain submodules or recursively,
541+
subpackages. Technically, a package is a Python module with an
542+
``__path__`` attribute.
543+
544+
path importer
545+
A built-in :term:`finder` / :term:`loader` that knows how to find and
546+
load modules from the file system.
547+
548+
portion
549+
A set of files in a single directory (possibly stored in a zip file)
550+
that contribute to a namespace package, as defined in :pep:`420`.
551+
519552
positional argument
520553
The arguments assigned to local names inside a function or method,
521554
determined by the order in which they were given in the call. ``*`` is
@@ -524,22 +557,22 @@ Glossary
524557
:term:`argument`.
525558

526559
provisional package
527-
A provisional package is one which has been deliberately excluded from the
528-
standard library's backwards compatibility guarantees. While major
560+
A provisional package is one which has been deliberately excluded from
561+
the standard library's backwards compatibility guarantees. While major
529562
changes to such packages are not expected, as long as they are marked
530563
provisional, backwards incompatible changes (up to and including removal
531564
of the package) may occur if deemed necessary by core developers. Such
532565
changes will not be made gratuitously -- they will occur only if serious
533566
flaws are uncovered that were missed prior to the inclusion of the
534567
package.
535568

536-
This process allows the standard library to continue to evolve over time,
537-
without locking in problematic design errors for extended periods of time.
538-
See :pep:`411` for more details.
569+
This process allows the standard library to continue to evolve over
570+
time, without locking in problematic design errors for extended periods
571+
of time. See :pep:`411` for more details.
539572

540573
Python 3000
541-
Nickname for the Python 3.x release line (coined long ago when the release
542-
of version 3 was something in the distant future.) This is also
574+
Nickname for the Python 3.x release line (coined long ago when the
575+
release of version 3 was something in the distant future.) This is also
543576
abbreviated "Py3k".
544577

545578
Pythonic
@@ -576,6 +609,14 @@ Glossary
576609
>>> C.D.meth.__qualname__
577610
'C.D.meth'
578611

612+
When used to refer to modules, the *fully qualified name* means the
613+
entire dotted path to the module, including any parent packages,
614+
e.g. ``email.mime.text``::
615+
616+
>>> import email.mime.text
617+
>>> email.mime.text.__name__
618+
'email.mime.text'
619+
579620
reference count
580621
The number of references to an object. When the reference count of an
581622
object drops to zero, it is deallocated. Reference counting is
@@ -584,6 +625,10 @@ Glossary
584625
:func:`~sys.getrefcount` function that programmers can call to return the
585626
reference count for a particular object.
586627

628+
regular package
629+
A traditional :term:`package`, such as a directory containing an
630+
``__init__.py`` file.
631+
587632
__slots__
588633
A declaration inside a class that saves memory by pre-declaring space for
589634
instance attributes and eliminating instance dictionaries. Though
@@ -626,6 +671,11 @@ Glossary
626671
:meth:`~collections.somenamedtuple._asdict`. Examples of struct sequences
627672
include :data:`sys.float_info` and the return value of :func:`os.stat`.
628673

674+
sys path finder
675+
A finder returned by a search of :data:`sys.path` by the :term:`path
676+
importer`. Sys path finders are related to, but different from
677+
:term:`meta path finders <meta path finder>`.
678+
629679
triple-quoted string
630680
A string which is bound by three instances of either a quotation mark
631681
(") or an apostrophe ('). While they don't provide any functionality

Doc/library/importlib.rst

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ are also provided to help in implementing the core ABCs.
128128
An abstract base class representing a :term:`finder`.
129129
See :pep:`302` for the exact definition for a finder.
130130

131+
.. method:: find_loader(self, fullname):
132+
133+
An abstract method for finding a :term:`loader` for the specified
134+
module. Returns a 2-tuple of ``(loader, portion)`` where portion is a
135+
sequence of file system locations contributing to part of a namespace
136+
package. The sequence may be empty. When present, `find_loader()` is
137+
preferred over `find_module()`.
138+
139+
.. versionadded: 3.3
140+
131141
.. method:: find_module(fullname, path=None)
132142

133143
An abstract method for finding a :term:`loader` for the specified
@@ -190,6 +200,13 @@ are also provided to help in implementing the core ABCs.
190200
(This is not set by the built-in import machinery,
191201
but it should be set whenever a :term:`loader` is used.)
192202

203+
.. method:: module_repr(module)
204+
205+
An abstract method which when implemented calculates and returns the
206+
given module's repr, as a string.
207+
208+
.. versionadded: 3.3
209+
193210
194211
.. class:: ResourceLoader
195212

@@ -270,14 +287,13 @@ are also provided to help in implementing the core ABCs.
270287

271288
Path to the file of the module.
272289

273-
.. method:: load_module(fullname=None)
290+
.. method:: load_module(fullname)
274291

275-
Calls
276-
``super().load_module(fullname if fullname is not None else self.name)``.
292+
Calls super's ``load_module()``.
277293

278294
.. method:: get_filename(fullname)
279295

280-
Returns :attr:`path` when ``fullname`` equals :attr:`name` or ``None``.
296+
Returns :attr:`path`.
281297

282298
.. method:: get_data(path)
283299

@@ -538,7 +554,6 @@ find and load modules.
538554

539555
.. versionadded:: 3.3
540556

541-
542557
.. function:: all_suffixes()
543558

544559
Returns a combined list of strings representing all file suffixes for
@@ -727,7 +742,7 @@ find and load modules.
727742

728743
Path to the extension module.
729744

730-
.. method:: load_module(fullname=None)
745+
.. method:: load_module(fullname)
731746

732747
Loads the extension module if and only if *fullname* is the same as
733748
:attr:`name` or is ``None``.

Doc/reference/datamodel.rst

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -651,17 +651,19 @@ Modules
651651
statement: import
652652
object: module
653653

654-
Modules are imported by the :keyword:`import` statement (see section
655-
:ref:`import`). A module object has a
656-
namespace implemented by a dictionary object (this is the dictionary referenced
657-
by the __globals__ attribute of functions defined in the module). Attribute
654+
Modules are a basic organizational unit of Python code, and are created by
655+
the :ref:`importmachinery` as invoked either by the :keyword:`import`
656+
statement (see section :ref:`import`) or by calling the built in
657+
:func:`__import__` function. A module object has a namespace implemented
658+
by a dictionary object (this is the dictionary referenced by the
659+
``__globals__`` attribute of functions defined in the module). Attribute
658660
references are translated to lookups in this dictionary, e.g., ``m.x`` is
659-
equivalent to ``m.__dict__["x"]``. A module object does not contain the code
660-
object used to initialize the module (since it isn't needed once the
661+
equivalent to ``m.__dict__["x"]``. A module object does not contain the
662+
code object used to initialize the module (since it isn't needed once the
661663
initialization is done).
662664

663-
Attribute assignment updates the module's namespace dictionary, e.g., ``m.x =
664-
1`` is equivalent to ``m.__dict__["x"] = 1``.
665+
Attribute assignment updates the module's namespace dictionary, e.g.,
666+
``m.x = 1`` is equivalent to ``m.__dict__["x"] = 1``.
665667

666668
.. index:: single: __dict__ (module attribute)
667669

@@ -683,11 +685,12 @@ Modules
683685

684686
Predefined (writable) attributes: :attr:`__name__` is the module's name;
685687
:attr:`__doc__` is the module's documentation string, or ``None`` if
686-
unavailable; :attr:`__file__` is the pathname of the file from which the module
687-
was loaded, if it was loaded from a file. The :attr:`__file__` attribute is not
688-
present for C modules that are statically linked into the interpreter; for
689-
extension modules loaded dynamically from a shared library, it is the pathname
690-
of the shared library file.
688+
unavailable; :attr:`__file__` is the pathname of the file from which the
689+
module was loaded, if it was loaded from a file. The :attr:`__file__`
690+
attribute may be missing for certain types of modules, such as C modules
691+
that are statically linked into the interpreter; for extension modules
692+
loaded dynamically from a shared library, it is the pathname of the shared
693+
library file.
691694

692695
Custom classes
693696
Custom class types are typically created by class definitions (see section

0 commit comments

Comments
 (0)