freezegun
freezegun copied to clipboard
Python 3.10: TypeError: Tester.helper() takes 0 positional arguments but 1 was given
When running tests on Python 3.10.0b1, I get the following test failure:
_______________________________________________ Tester.test_class_decorator_respects_staticmethod ________________________________________________
self = <tests.test_datetimes.Tester object at 0x7fb072c03be0>
def test_class_decorator_respects_staticmethod(self):
> assert self.helper() == datetime.date(2012, 1, 14)
tests/test_datetimes.py:450:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
args = (<tests.test_datetimes.Tester object at 0x7fb072c03be0>,), kwargs = {}
time_factory = <freezegun.api.FrozenDateTimeFactory object at 0x7fb072c01810>
def wrapper(*args, **kwargs):
with self as time_factory:
if self.as_arg and self.as_kwarg:
assert False, "You can't specify both as_arg and as_kwarg at the same time. Pick one."
elif self.as_arg:
result = func(time_factory, *args, **kwargs)
elif self.as_kwarg:
kwargs[self.as_kwarg] = time_factory
result = func(*args, **kwargs)
else:
> result = func(*args, **kwargs)
E TypeError: Tester.helper() takes 0 positional arguments but 1 was given
freezegun/api.py:778: TypeError
staticmethods are now callable in Python 3.10 with changes from https://bugs.python.org/issue43682 . With this change the helper
which is a staticmethod and was not callable was not decorated before Python 3.10 . Now it gets decorated by wrapper and throws error.
class TestFoo:
@staticmethod
def helper():
return 1
def test_foo(self):
pass
for (attr, attr_value) in TestFoo.__dict__.items():
if not attr.startswith("_"):
print(attr, attr_value, callable(attr_value))
python3.9 /tmp/a.py
helper <staticmethod object at 0x7f6516280fd0> False
test_foo <function TestFoo.test_foo at 0x7f65162121f0> True
python3.10 /tmp/a.py
helper <staticmethod(<function TestFoo.helper at 0x7fb16e992050>)> True
test_foo <function TestFoo.test_foo at 0x7fb16e9920e0> True
Created PR : https://github.com/spulec/freezegun/pull/397 . I have also added a question about the staticmethod behavior in comment.
Python 3.10 has been released recently, is there a chance that the issue will be fixed soon?
Ping.
This was fixed in https://github.com/spulec/freezegun/pull/493
If I'm getting the timeline correct, it's part of freezegun >= 1.2.1