Skip to content

Use abstract types from numbers #7217

Closed as not planned
Closed as not planned
@sobolevn

Description

@sobolevn

Right now types declared in numbers.pyi are not used.
This causes this problem:

from numbers import Real

def test(f: Real) -> Real:
    return f

test(1.32)
# error: Argument 1 to "test" has incompatible type "float"; expected "Real"

But, in runtime:

But, how can we type it? Options:

  1. Use a base class in builtins.pyi
  2. Use Real.register(float) in builtins.pyi
  3. Use Real.register(float) in numbers.pyi (as runtime does)

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