Skip to content

Get rid of mypy's # type: ignore[unreachable] comments #221

Description

@Saransh-cpp

Right now mypy throws a bunch of errors in this particular code block -

def _class_to_name(cls: typing.Type[VectorProtocol]) -> str:
if issubclass(cls, Momentum):
if issubclass(cls, Vector2D): # type: ignore[unreachable]
return "Momentum2D" # type: ignore[unreachable]
elif issubclass(cls, Vector3D): # type: ignore[unreachable]
return "Momentum3D" # type: ignore[unreachable]
elif issubclass(cls, Vector4D): # type: ignore[unreachable]
return "Momentum4D" # type: ignore[unreachable]

saying -

error: Subclass of "VectorProtocol", "Momentum", and "Vector2D" cannot exist: would have inconsistent method resolution order  [unreachable]

These errors have been suppressed using the type: ignore[unreachable] comments, but this should be fixed. The type: ignore[unreachable] comments should be removed from Vector (these are the only type: ignore[unreachable] comments left in the codebase).


Guessing it is not understanding that Type[VectorProtocol] can (sometimes) pass a subclass of Momentum check? Might be worth updating that. But not in this PR, these are (all) fine for now.

Originally posted by @henryiii in #219 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions