Skip to content

Improve unification of conditional expressions #1094

Closed
@ZeeD

Description

@ZeeD

I have this snippet of code

from typing import Any,List

class Node:
    def __init__(self, value:Any, *, children:List['Node']=None) -> None:
        self.value = value
        self.children = [] if children is None else children # type: List[Node]

if I use mypy I get

Tree.py: note: In member "__init__" of class "Node":
Tree.py:10: error: Incompatible types in assignment (expression has type "object", variable has type List[Node])

I think it's something related to the children parameter setted to None, but the problem is... how do I specify that yes, maybe the children parameter can be None, but self.children, by construction is always a List of Nodes?

Metadata

Metadata

Assignees

Labels

bugmypy got something wrong

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions