MCPcopy Create free account
hub / github.com/dateutil/dateutil / _importer_stacklevel

Function _importer_stacklevel

src/dateutil/zoneinfo/__init__.py:28–49  ·  view source on GitHub ↗

The ``stacklevel`` that attributes a warning to the importing code. This module can be imported through ``dateutil.__getattr__`` (e.g. by ``from dateutil import zoneinfo``), which calls ``importlib.import_module``; the warnings machinery skips the import system's own frames, but not

()

Source from the content-addressed store, hash-verified

26
27
28def _importer_stacklevel():
29 """The ``stacklevel`` that attributes a warning to the importing code.
30
31 This module can be imported through ``dateutil.__getattr__`` (e.g. by
32 ``from dateutil import zoneinfo``), which calls
33 ``importlib.import_module``; the warnings machinery skips the import
34 system's own frames, but not those two, so skip them here.
35 """
36 level = 1
37 frame = sys._getframe(1) # The body of this module
38 while frame.f_back is not None:
39 frame = frame.f_back
40 filename = frame.f_code.co_filename
41 if "importlib" in filename and "_bootstrap" in filename:
42 # The warnings machinery skips these frames without counting them.
43 continue
44
45 level += 1
46 if frame.f_globals.get("__name__") not in ("importlib", "dateutil"):
47 return level
48
49 return 2
50
51
52warnings.warn(

Callers 1

__init__.pyFile · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected