Christoph Reiter added the comment:

To add some info why we hit that bug:

https://bugs.python.org/issue24305 changed the warning stacklevel needed for 
import warnings from 8 to 2. As a result any code doing import warnings will 
likely hit that edge case when run with 3.5 and openafs installed. But I'm not 
sure if there is much code out there doing import warnings.. so ymmv.


For anyone with the same problem looking for a workaround:

I went through all Python versions and searched for the needed stacklevel.

def get_import_stacklevel(import_hook):
    """Returns the stacklevel value for warnings.warn() for when the warning
    gets emitted by an imported module, but the warning should point at the
    code doing the import.

    Pass import_hook=True if the warning gets generated by an import hook
    (warn() gets called in load_module(), see PEP302)
    """

    py_version = sys.version_info[:2]
    if py_version <= (3, 2):
        # 2.7 included
        return 4 if import_hook else 2
    elif py_version == (3, 3):
        return 8 if import_hook else 10
    elif py_version == (3, 4):
        return 10 if import_hook else 8
    else:
        # fixed again in 3.5+, see https://bugs.python.org/issue24305
        return 4 if import_hook else 2

----------
nosy: +lazka

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25493>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to