Skip to content

Current typehints for numbers.py are worse than useless. #14290

@MegaIng

Description

@MegaIng

While I understand that typing this module correctly is hard (or even impossible currently) to do, the current situation makes it impossible to use in a sane way since even the most simple of expressions result in false type errors. It would honestly be better to just not have any typing stubs for this module instead of the current ones. Two examples:

def f1(a: Complex, b: Complex) -> Complex:
    return a * b

def f2(a: Complex, b: Complex) -> Any:
    return a * b + b * a

Both of these functions result in error messages which might technically be correct in the sense that there are types out there for which these are errors at runtime, but the fact that you can't write them without type ignores or casts means that using this module in combination with type checking is counter productive for finding errors.

It would be strictly better to just remove the _ComplexLike protocol and just make subclasses require type ignores in their method definitions - it's more important for the users (like in the above example) to not have to provide type ignores than for implementers - there are fewer implementers and they probably have a clearer understanding of the edge cases to be aware of.

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