Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide six.pkgname to replace __package__ #301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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