+
Skip to content

fix: avoid conflict with freezegun #3836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025

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
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载