MCPcopy Index your code
hub / github.com/python/cpython / _calc___package__

Function _calc___package__

Lib/importlib/_bootstrap.py:1357–1381  ·  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

1355
1356
1357def _calc___package__(globals):
1358 """Calculate what __package__ should be.
1359
1360 __package__ is not guaranteed to be defined or could be set to None
1361 to represent that its proper value is unknown.
1362
1363 """
1364 package = globals.get('__package__')
1365 spec = globals.get('__spec__')
1366 if package is not None:
1367 if spec is not None and package != spec.parent:
1368 _warnings.warn("__package__ != __spec__.parent "
1369 f"({package!r} != {spec.parent!r})",
1370 DeprecationWarning, stacklevel=3)
1371 return package
1372 elif spec is not None:
1373 return spec.parent
1374 else:
1375 _warnings.warn("can't resolve package from __spec__ or __package__, "
1376 "falling back on __name__ and __path__",
1377 ImportWarning, stacklevel=3)
1378 package = globals['__name__']
1379 if '__path__' not in globals:
1380 package = package.rpartition('.')[0]
1381 return package
1382
1383
1384def __import__(name, globals=None, locals=None, fromlist=(), level=0):

Callers 1

__import__Function · 0.85

Calls 3

getMethod · 0.45
warnMethod · 0.45
rpartitionMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…