Skip to content

Use alias names in error messages #2968

Open
@rhettinger

Description

@rhettinger

Given:

from typing import Tuple
from math import hypot

Point = Tuple[float, ...]
Centroid = Point

def dist(p: Centroid, q: Point) -> float:
    px, py = p
    qx, qy = q
    return hypot(px - qx, py - qy)

print( dist('xyz', (3.5, 7.2)) )

mypy detect the incorrect first argument:

$ mypy tmp.py
tmp.py:12: error: Argument 1 to "dist" has incompatible type "str"; expected Tuple[float, ...]

However, it would be much nicer is the error reporting could have used the alias name:

tmp.py:12: error: Argument 1 to "dist" has incompatible type "str"; expected "Centroid", which expands to Tuple[float, ...]

I realize it may be easy to do, but it would improve the usability of aliases.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions