Do not attempt to rewrite non-source files

This commit is contained in:
Anthony Sottile 2019-06-25 08:00:20 -07:00
parent a54e2e19f5
commit b991810f32
1 changed files with 2 additions and 0 deletions

View File

@ -69,6 +69,8 @@ class AssertionRewritingHook:
# python3.5 - python3.6: `namespace`
# python3.7+: `None`
or spec.origin in {None, "namespace"}
# we can only rewrite source files
or not isinstance(spec.loader, importlib.machinery.SourceFileLoader)
# if the file doesn't exist, we can't rewrite it
or not os.path.exists(spec.origin)
):