Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

sminnee
Copy link
Contributor

@sminnee sminnee commented May 22, 2025

The original implementation meant that self is passed to default_timer. When freezegun overrides this with a function that doesn't take an argument, it causes a runtime error.

By setting the _time value in the init method, self isn't passed automatically as the first argument

Although I found this issue using freezegun alongside fonttools, it affects anything that overrides time.perf_counter

The original implementation meant that self is passed to default_timer. When freezegun
overrides this with a function that doesn't take an argument, it casues a runtime error.

By setting the _time value in the init method, self isn't passed automatically as the
first argument
@sminnee
Copy link
Contributor Author

sminnee commented May 22, 2025

Here's a simple demonstration of the underlying issue

def test_fn():
    return "bar"


class TestA:
    _fn = test_fn

    def __init__(self):
        self.foo = self._fn()


class TestB:
    def __init__(self):
        self._fn = test_fn
        self.foo = self._fn()


try:
    print("TestA result:", TestA().foo)
except Exception as e:
    print("Exception from TestA:", e)

try:
    print("TestB result:", TestB().foo)
except Exception as e:
    print("Exception from TestB:", e)

This script will output

Exception from TestA: test_fn() takes 0 positional arguments but 1 was given
TestB result: bar

@anthrotype anthrotype merged commit ad964a1 into fonttools:main May 28, 2025
11 checks passed
@anthrotype
Copy link
Member

hey @sminnee, I changed this slightly so that it is still defined at the class level but won't be a bound method that takes self any more, see a228454

it should still work for your use case I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants