MCPcopy Index your code
hub / github.com/RustPython/RustPython / _calc___package__

Function _calc___package__

Lib/importlib/_bootstrap.py:1438–1462  ·  view source on GitHub ↗

Calculate what __package__ should be. __package__ is not guaranteed to be defined or could be set to None to represent that its proper value is unknown.

(globals)

Source from the content-addressed store, hash-verified

1436
1437
1438def _calc___package__(globals):
1439 """Calculate what __package__ should be.
1440
1441 __package__ is not guaranteed to be defined or could be set to None
1442 to represent that its proper value is unknown.
1443
1444 """
1445 package = globals.get('__package__')
1446 spec = globals.get('__spec__')
1447 if package is not None:
1448 if spec is not None and package != spec.parent:
1449 _warnings.warn("__package__ != __spec__.parent "
1450 f"({package!r} != {spec.parent!r})",
1451 DeprecationWarning, stacklevel=3)
1452 return package
1453 elif spec is not None:
1454 return spec.parent
1455 else:
1456 _warnings.warn("can't resolve package from __spec__ or __package__, "
1457 "falling back on __name__ and __path__",
1458 ImportWarning, stacklevel=3)
1459 package = globals['__name__']
1460 if '__path__' not in globals:
1461 package = package.rpartition('.')[0]
1462 return package
1463
1464
1465def __import__(name, globals=None, locals=None, fromlist=(), level=0):

Callers 1

__import__Function · 0.70

Calls 3

getMethod · 0.45
warnMethod · 0.45
rpartitionMethod · 0.45

Tested by

no test coverage detected