Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5842,7 +5842,11 @@ def visit_call_expr(self, expr: CallExpr) -> None:
expr.analyzed = PromoteExpr(target)
expr.analyzed.line = expr.line
expr.analyzed.accept(self)
elif refers_to_fullname(expr.callee, "builtins.dict"):
elif refers_to_fullname(expr.callee, "builtins.dict") and not (
isinstance(expr.callee, RefExpr)
and isinstance(expr.callee.node, TypeAlias)
and not expr.callee.node.no_args
):
expr.analyzed = self.translate_dict_call(expr)
elif refers_to_fullname(expr.callee, "builtins.divmod"):
if not self.check_fixed_args(expr, 2, "divmod"):
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/check-type-aliases.test
Original file line number Diff line number Diff line change
Expand Up @@ -1318,3 +1318,17 @@ from typing_extensions import TypeAlias

Foo: TypeAlias = ClassVar[int] # E: ClassVar[...] can't be used inside a type alias
[builtins fixtures/tuple.pyi]


[case testTypeAliasDict]
D = dict[str, int]
d = D()
reveal_type(d) # N: Revealed type is "builtins.dict[builtins.str, builtins.int]"
reveal_type(D()) # N: Revealed type is "builtins.dict[builtins.str, builtins.int]"
reveal_type(D(x=1)) # N: Revealed type is "builtins.dict[builtins.str, builtins.int]"
reveal_type(D(x="asdf")) # E: No overload variant of "dict" matches argument type "str" \
# N: Possible overload variants: \
# N: def __init__(self, **kwargs: int) -> dict[str, int] \
# N: def __init__(self, arg: Iterable[tuple[str, int]], **kwargs: int) -> dict[str, int] \
# N: Revealed type is "Any"
[builtins fixtures/dict.pyi]