Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions six.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,22 @@ def python_2_unicode_compatible(klass):
return klass


def pkgname(globals):
"""
Return the package name of a module.

On Python 2 under __future__.absolute_import __package__ is None until an
explcit relative import is attempted.

six.pgkname(globals()) is equivalent to __package__ on Python 3.
"""
pkgname_ = globals.get("__package__")
if pkgname_ is not None:
return pkgname_
modname = globals.get("__name__")
return modename if "__path__" in globals else modname.rpartition(".")[0]


# Complete the moves implementation.
# This code is at the end of this module to speed up module loading.
# Turn this module into a package.
Expand Down