KEMBAR78
Use fully qualified name for class with confusing name such as "Any" · Issue #8372 · python/mypy · GitHub
Skip to content

Use fully qualified name for class with confusing name such as "Any" #8372

@JukkaL

Description

@JukkaL

The following example generates a confusing error message, since it's unclear which Any type it is referring to:

class Any: pass

x = Any()
x = 1  # Incompatible types in assignment 
       # (expression has type "int", variable has type "Any")

(It would be more confusing if the Any type is inferred from the return type of a function.)

It would be better to always use a fully qualified name for a class named Any in error messages (similarly also for None, Union, etc.).

This can also happen with classes that have names resembling built-in types:

class float: pass

x = float()
x = 0  # Incompatible types in assignment 
       # (expression has type "int", variable has type "float")

The relevant code seems to be in mypy.messages.format_type.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions