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
()
| 26 | |
| 27 | |
| 28 | def _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 | |
| 52 | warnings.warn( |