Skip to content

"incompatible default for argument" error message shows that types do match #4603

Closed
@kamahen

Description

@kamahen
mypy --python-version=3.6 --strict-optional --check-untyped-defs --disallow-incomplete-defs --warn-incomplete-stub --warn-redundant-casts --warn-no-return --warn-return-any --no-incremental /tmp/xx.py 
/tmp/xx.py:24: error: Incompatible default for argument "_DISPATCH" (default has type "Dict[int, Callable[[Base, Ctx], AstNode]]", argument has type "Dict[int, Callable[[Base, Ctx], AstNode]]")

Note that the two types in the error message are identical.

When I did reveal_type(_DISPATCH), I got:

Revealed type is 'builtins.dict[builtins.int*, def (node: lib2to3.pytree.Base, ctx: xx.Ctx) -> xx.AstNode]'

Here's the source (I'm sure it can be reduced further):

from lib2to3 import pytree
from lib2to3.pgen2 import token
from typing import Callable, Dict, FrozenSet, List, Optional, Sequence, Text

class AstNode:
    pass


class Ctx:
    pass


def cvt_token_name(node: pytree.Base, ctx: Ctx) -> AstNode:
    """Handle token.NAME."""
    return AstNode()


_DISPATCH = {
    token.NAME: cvt_token_name,
}


def cvt(node: pytree.Base,
        ctx: Ctx,
        _DISPATCH: Dict[int, Callable[[pytree.Base, Ctx], AstNode]] = _DISPATCH
        ) -> AstNode:
    return _DISPATCH[node.type](node, ctx)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions