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)
| 1355 | |
| 1356 | |
| 1357 | def _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 | |
| 1384 | def __import__(name, globals=None, locals=None, fromlist=(), level=0): |
no test coverage detected
searching dependent graphs…