Skip to content

Behaviour of Type[Any] #3098

@dmoisset

Description

@dmoisset

Currently a Type[Any] is considered to have the same attributes as Type[object]. However, actually it probably has many attributes that could be used, especially when the Any comes from a module without stubs. Consider the following example:

from typing import Type
from some_module import Candy, Lollipop  # some_module has no stubs/annotations

class CandyFactory:
    manufactured_candy: Type[Candy]

cf = CandyFactory()
cf.manufactured_candy = Lollipop

print(cf.manufactured_candy.sugar_level)

Then running:

$ mypy --ignore-missing-imports candy.py 
candy.py:11: error: Type[Any] has no attribute "sugar_level"

Which seems to go a bit against the idea of gradual typing and intention of Any.

One possible solution is to consider that Type[Any] == Any, I think this actually would not miss anything that could be catched now, while reducing false positives.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions