Open DylanYoung opened 2 years ago
I can reproduce this with:
git clone https://github.com/DylanYoung/django-csp
cd django-csp
git checkout GH-36
pip install tox
tox -e pypy3.9-main
But there is a lot of stuff going on here that I don't understand. I don't see why coverage would affect things, or why PyPy would behave differently, but they do.
A clue: Python 3.9 also fails if you use the Python tracer instead of the C tracer (the --timid
option).
A simpler reproducer:
class Foo:
pass
from django.utils.functional import LazyObject
class LazyFoo(LazyObject):
def _setup(self):
self._wrapped = Foo()
assert isinstance(LazyFoo(), Foo)
Assertion fails with coverage on.
So I've tried this and it happens with hunter too 🙃 This fails:
import hunter
hunter.trace()
from django.utils.functional import LazyObject
class Foo:
pass
class LazyFoo(LazyObject):
def _setup(self):
self._wrapped = Foo()
assert isinstance(LazyFoo(), Foo)
This works:
import hunter
from django.utils.functional import LazyObject
hunter.trace()
class Foo:
pass
class LazyFoo(LazyObject):
def _setup(self):
self._wrapped = Foo()
assert isinstance(LazyFoo(), Foo)
I believe something goes wrong in the LazyObject class definition when it's traced.
Ok this is the minimal reproducer (seems to fail both for pypy and cpython):
import sys
def tracer(frame, event, _):
return tracer
sys.settrace(tracer)
class Foo:
pass
class FancyFoo:
def bug(self):
super()
@property
def __class__(self):
return Foo
assert isinstance(FancyFoo(), Foo)
The PyPy issue has moved to https://github.com/pypy/pypy/issues/3750.
Describe the bug Odd failure on PyPy, but not CPython. See PyPy bug for details: https://foss.heptapod.net/pypy/pypy/-/issues/3751
To Reproduce How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:
Also fails on 3.8.
coverage debug sys
is helpful.Output redacted for sensitive info.
pip freeze
is helpful.Also fails on Django 4.1a1
See linked PyPy issue: https://foss.heptapod.net/pypy/pypy/-/issues/3751 And related Django thread: https://code.djangoproject.com/ticket/28358#comment:13 And Django commit that introduced the issue: https://github.com/django/django/commit/97d7990abde3fe4b525ae83958fd0b52d6a1d13f
On this branch: https://github.com/DylanYoung/django-csp/tree/GH-36
Both exhibit the problem. No error when coverage is not used.
Expected behavior
No error.
Additional Info
See this comment for how to repro: https://foss.heptapod.net/pypy/pypy/-/issues/3751#note_185362