Merge pull request #3613 from asottile/module_spec_warnings
Fix `ImportWarning` triggered by explicit relative imports
This commit is contained in:
1
changelog/3061.bugfix.rst
Normal file
1
changelog/3061.bugfix.rst
Normal file
@@ -0,0 +1 @@
|
||||
Fix ``ImportWarning`` triggered by explicit relative imports in assertion-rewritten package modules.
|
||||
@@ -45,6 +45,14 @@ else:
|
||||
return ast.Call(a, b, c, None, None)
|
||||
|
||||
|
||||
if sys.version_info >= (3, 4):
|
||||
from importlib.util import spec_from_file_location
|
||||
else:
|
||||
|
||||
def spec_from_file_location(*_, **__):
|
||||
return None
|
||||
|
||||
|
||||
class AssertionRewritingHook(object):
|
||||
"""PEP302 Import hook which rewrites asserts."""
|
||||
|
||||
@@ -213,6 +221,8 @@ class AssertionRewritingHook(object):
|
||||
# Normally, this attribute is 3.2+.
|
||||
mod.__cached__ = pyc
|
||||
mod.__loader__ = self
|
||||
# Normally, this attribute is 3.4+
|
||||
mod.__spec__ = spec_from_file_location(name, co.co_filename, loader=self)
|
||||
py.builtin.exec_(co, mod.__dict__)
|
||||
except: # noqa
|
||||
if name in sys.modules:
|
||||
|
||||
3
tox.ini
3
tox.ini
@@ -204,9 +204,6 @@ filterwarnings =
|
||||
ignore:.*type argument to addoption.*:DeprecationWarning
|
||||
# produced by python >=3.5 on execnet (pytest-xdist)
|
||||
ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning
|
||||
# ignore warning about package resolution using __spec__ or __package__
|
||||
# should be a temporary solution, see #3061 for discussion
|
||||
ignore:.*can't resolve package from __spec__ or __package__.*:ImportWarning
|
||||
|
||||
[flake8]
|
||||
max-line-length = 120
|
||||
|
||||
Reference in New Issue
Block a user