Skip to content

python >=3.8: cmath functions should accept any object with __index__ #6214

Closed

Description

@Akuli

runtime:

akuli@akuli-desktop:/tmp$ cat asd.py
class Foo:
    def __index__(self):
        return 1
akuli@akuli-desktop:/tmp$ python3.7 -c 'import cmath, asd; cmath.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 cmath, asd; cmath.sin(asd.Foo())'
akuli@akuli-desktop:/tmp$ 

(The error message is wrong, the functions also accept complex numbers)

Stub:

_C = Union[SupportsFloat, SupportsComplex, complex]

def sin(__z: _C) -> complex: ...

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions