KEMBAR78
Item "type" of "Union[Type[Foo], Type[Bar]]" has no attribute "x" · Issue #4155 · python/mypy · GitHub
Skip to content

Item "type" of "Union[Type[Foo], Type[Bar]]" has no attribute "x" #4155

@Daenyth

Description

@Daenyth
# mypy 0.530
foo.py:14: warning: Returning Any from function declared to return "int"
foo.py:14: error: Item "type" of "Union[Type[Foo], Type[Bar]]" has no attribute "x"
from typing import *

class Foo(NamedTuple):
    a: int
    @classmethod
    def x(cls) -> int: return 1

class Bar(NamedTuple):
    a: int
    @classmethod
    def x(cls) -> int: return 1

def foo(t: Type[Union[Foo, Bar]]) -> int:
    return t.x()

If I make them usual classes instead of namedtuples, it works

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions