diff --git a/six.py b/six.py index 4c303ff97..9683dad9f 100644 --- a/six.py +++ b/six.py @@ -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.