Skip to content
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

python <3.8: math functions shouldn't accept any object with __index__ method #6213

Closed
Akuli opened this issue Oct 30, 2021 · 0 comments · Fixed by #6216
Closed

python <3.8: math functions shouldn't accept any object with __index__ method #6213

Akuli opened this issue Oct 30, 2021 · 0 comments · Fixed by #6216

Comments

@Akuli
Copy link
Collaborator

Akuli commented Oct 30, 2021

Runtime:

akuli@akuli-desktop:/tmp$ cat asd.py
class Foo:
    def __index__(self):
        return 1
akuli@akuli-desktop:/tmp$ python3.7 -c 'import math, asd; math.sin(asd.Foo())'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: must be real number, not Foo
akuli@akuli-desktop:/tmp$ python3.8 -c 'import math, asd; math.sin(asd.Foo())'
akuli@akuli-desktop:/tmp$ 

Stub:

_SupportsFloatOrIndex = Union[SupportsFloat, SupportsIndex]

def sin(__x: _SupportsFloatOrIndex) -> float: ...

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 a pull request may close this issue.

1 participant