Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Lazy Package Imports
itself. Ruled by the owner in session and recorded on :issue:`2729`. Its
:file:`__init__.py` names each export in an import under ``if TYPE_CHECKING:``, for
the type checkers, and binds the ``__getattr__`` and ``__dir__`` that
:func:`~pcapkit.utilities.lazy.lazy_exports` returns; :mod:`pcapkit.const` re-exports
:func:`~pcapkit.utilities.importlib.lazy_exports` returns; :mod:`pcapkit.const` re-exports
its subpackages' ``__all__`` the same way. The one real import is of
:class:`~pcapkit.const.reg.apptype.apptype.AppType` and
:class:`~pcapkit.const.reg.apptype.apptype.TransportProtocol`, which
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Lazy Imports
============

.. module:: pcapkit.utilities.lazy
.. module:: pcapkit.utilities.importlib

:mod:`pcapkit.utilities.lazy` holds :func:`lazy_exports`, which gives a package the
:mod:`pcapkit.utilities.importlib` holds :func:`lazy_exports`, which gives a package the
:pep:`562` ``__getattr__`` and ``__dir__`` that import each name it exports the first
time the name is reached, rather than with the package itself. Every package under
:mod:`pcapkit.const` imports its enumerations that way (:issue:`2729`), so a caller
Expand All @@ -12,4 +12,4 @@ pays only for the enumerations it uses. This module imports nothing from

.. versionadded:: 1.6.0

.. autofunction:: pcapkit.utilities.lazy.lazy_exports
.. autofunction:: pcapkit.utilities.importlib.lazy_exports
4 changes: 2 additions & 2 deletions docs/source/pcapkit/utilities/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ built with: user-refined exceptions and warnings, logging, the tunable limits
of :mod:`~pcapkit.utilities.config`, a compatibility layer, timestamp
conversion, pickle reductions, the
:mod:`context variables <pcapkit.utilities.contextvars>` its modules share,
:mod:`lazy imports <pcapkit.utilities.lazy>` for a package's exports, and
:mod:`lazy imports <pcapkit.utilities.importlib>` for a package's exports, and
wrappers around third-party libraries. It imports nothing from :mod:`pcapkit`
outside itself; see :ref:`utilities-or-corekit`.

Expand All @@ -24,7 +24,7 @@ outside itself; see :ref:`utilities-or-corekit`.
datetime
pickle
contextvars
lazy
importlib

Version Compatibility
=====================
Expand Down
4 changes: 2 additions & 2 deletions pcapkit/const/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

Each enumeration is imported the first time it is reached -- as an attribute
of this package or of the subpackage holding it -- rather than with the
package, through :func:`~pcapkit.utilities.lazy.lazy_exports`
package, through :func:`~pcapkit.utilities.importlib.lazy_exports`
(:issue:`2729`). The subpackages themselves are imported with it, and import
none of their enumerations.

"""
from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
# IANA registration
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/arp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.arp.hardware import Hardware as ARP_Hardware
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/dccp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.dccp.ack_vector_state import AckVectorState as DCCP_AckVectorState
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/esp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.esp.cipher import Cipher as ESP_Cipher
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/ftp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.ftp.command import Command as FTP_Command
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/hip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.hip.certificate import Certificate as HIP_Certificate
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.http.error_code import ErrorCode as HTTP_ErrorCode
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/icmp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.icmp.destination_unreachable_code import \
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/icmpv6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.icmpv6.destination_unreachable_code import \
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/ieee802_11/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.ieee802_11.control_subtype import ControlSubtype as IEEE802_11_ControlSubtype
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/igmp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.igmp.record_type import RecordType as IGMP_RecordType
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/ipv4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.ipv4.classification_level import \
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/ipv6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.ipv6.extension_header import ExtensionHeader as IPv6_ExtensionHeader
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/ipx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.ipx.packet import Packet as IPX_Packet
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/l2tp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.l2tp.type import Type as L2TP_Type
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/linux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.linux.arphrd import ARPHRD as Linux_ARPHRD
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/mh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.mh.access_type import AccessType as MH_AccessType
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/ngap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.ngap.procedure_code import ProcedureCode as NGAP_ProcedureCode
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/ospf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.ospf.authentication import Authentication as OSPF_Authentication
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/pcapng/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.pcapng.block_type import BlockType as PCAPNG_BlockType
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/radiotap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.radiotap.ampdu_flags import AMPDUFlags as Radiotap_AMPDUFlags
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/reg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.reg.apptype import AppType as APPTYPE
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/reg/apptype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from pcapkit.const.reg.apptype.apptype import AppType, TransportProtocol
from pcapkit.corekit.infoclass import Info, info_final
from pcapkit.corekit.module import ModuleDescriptor
from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from typing import Any, ItemsView, Iterable, Iterator, Mapping, Optional, SupportsIndex, Type
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/sctp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.sctp.cause_code import CauseCode as SCTP_CauseCode
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/sslv2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.sslv2.handshake_type import HandshakeType as SSLv2_HandshakeType
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/tcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.tcp.checksum import Checksum as TCP_Checksum
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/tls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.tls.content_type import ContentType as TLS_ContentType
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/const/vlan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from pcapkit.const.vlan.priority_level import PriorityLevel as VLAN_PriorityLevel
Expand Down
4 changes: 2 additions & 2 deletions pcapkit/utilities/lazy.py → pcapkit/utilities/importlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"""Lazy Imports
==================

.. module:: pcapkit.utilities.lazy
.. module:: pcapkit.utilities.importlib

:mod:`pcapkit.utilities.lazy` holds :func:`lazy_exports`, which gives a package
:mod:`pcapkit.utilities.importlib` holds :func:`lazy_exports`, which gives a package
the :pep:`562` ``__getattr__`` and ``__dir__`` that import each name it exports
the first time the name is reached, rather than with the package itself. Every
package under :mod:`pcapkit.const` imports its enumerations that way
Expand Down
2 changes: 1 addition & 1 deletion tests/const/test_const_apptype_lazy_1538_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:attr:`AppType.__registries__ <pcapkit.const.reg.apptype.apptype.AppType.__registries__>`
the first time either is read. GitHub issue #2729 extended that to SCTP and
DCCP, and to every package under :mod:`pcapkit.const`, through
:func:`pcapkit.utilities.lazy.lazy_exports`; #2726 made the registries an
:func:`pcapkit.utilities.importlib.lazy_exports`; #2726 made the registries an
:class:`~pcapkit.corekit.infoclass.Info` rather than a :obj:`dict` subclass.

The subprocess checks run in a fresh interpreter, since the question is what a
Expand Down
2 changes: 1 addition & 1 deletion tests/const/test_const_lazy_exports_2729_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Every :mod:`pcapkit.const` package exports what it did eagerly (GitHub issue #2729).

Each package under :mod:`pcapkit.const` imports its enumerations on first use,
through :func:`pcapkit.utilities.lazy.lazy_exports`, and names them only under
through :func:`pcapkit.utilities.importlib.lazy_exports`, and names them only under
:data:`~typing.TYPE_CHECKING`, for the type checkers. These sweeps read the
packages off the tree, so a package the crawlers add is held to them the day it
lands, and hold every one to the eager behaviour that statement describes:
Expand Down
8 changes: 4 additions & 4 deletions tests/utilities/test_lazy_exports_2729_unit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
""":func:`pcapkit.utilities.lazy.lazy_exports`, on packages written for the test (GitHub issue #2729).
""":func:`pcapkit.utilities.importlib.lazy_exports`, on packages written for the test (GitHub issue #2729).

Every :mod:`pcapkit.const` package uses it, and
:mod:`tests.const.test_const_lazy_exports_2729_unit` sweeps those. Here it runs
Expand Down Expand Up @@ -32,7 +32,7 @@
#: subpackages', and records each module the tree imports in ``imported``.
TREE = {
'__init__.py': '''
from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

imported = []

Expand All @@ -43,7 +43,7 @@
'probe/__init__.py': '''
from typing import TYPE_CHECKING

from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

if TYPE_CHECKING:
from {NAME}.probe.sub import Deep
Expand Down Expand Up @@ -76,7 +76,7 @@ class Renamed:
VALUE = 1
''',
'probe/sub/__init__.py': '''
from pcapkit.utilities.lazy import lazy_exports
from pcapkit.utilities.importlib import lazy_exports

__all__ = ['Deep']

Expand Down
Loading