diff --git a/CHANGES.rst b/CHANGES.rst index 937d2d0fa..784fa5c29 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -25,7 +25,12 @@ Unreleased - Changed an internal detail of how tomli is imported, so that tomli can use coverage.py for their own test suite (`issue 1228`_). +- Defend against an obscure possibility under code obfuscation, where a + function can have an argument called "self", but no local named "self" + (`pull request 1210`_). Thanks, Ben Carlsson. + .. _issue 1228: https://github.com/nedbat/coveragepy/issues/1228 +.. _pull request 1210: https://github.com/nedbat/coveragepy/pull/1210 .. _changes_60: diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 2642e6b1a..1c1fe0e9c 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -20,6 +20,7 @@ Arcadiy Ivanov Aron Griffis Artem Dayneko Arthur Deygin +Ben Carlsson Ben Finney Bernát Gábor Bill Hart diff --git a/tests/test_context.py b/tests/test_context.py index de972819f..36eff2f0d 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -278,6 +278,8 @@ class test_something: # pylint: disable=unused-variable assert get_qualname() is None def test_bug_1210(self): + # Under pyarmor (an obfuscator), a function can have a "self" argument, + # but then not have a "self" local. co = mock.Mock(co_name="a_co_name", co_argcount=1, co_varnames=["self"]) - frame = mock.Mock(f_code = co, f_locals={}) + frame = mock.Mock(f_code=co, f_locals={}) assert qualname_from_frame(frame) == "unittest.mock.a_co_name"