GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update TypedDictType.__init__ signature to preserve backward compat by JukkaL · Pull Request #21590 · python/mypy

Update TypedDictType.__init__ signature to preserve backward compat #21590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
JukkaL merged 2 commits into master from typeddict-init-sig
Jun 4, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Update TypedDictType.__init__ signature to preserve backward compat #21590

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
02888d0
Update TypedDictType.__init__ signature to preserve backward compat
JukkaL Jun 4, 2026
bfa3d70
Fix error code
JukkaL Jun 4, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
Update TypedDictType.__init__ signature to preserve backward compat
The new signature added a new parameter in the middle of the signature,
which may break plugins that use positional arguments. Add the
new parameter to the end of the parameter list so that existing
calls will continue to work. This looks a bit ugly, but backward
compatibility is the priority here.
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@JukkaL
JukkaL committed Jun 4, 2026
commit 02888d0b9323324d9db7ce82a9ecf29567656ca1

There are no files selected for viewing

5 changes: 4 additions & 1 deletion 5 mypy/copytype.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ def visit_tuple_type(self, t: TupleType) -> ProperType:

def visit_typeddict_type(self, t: TypedDictType) -> ProperType:
return self.copy_common(
t, TypedDictType(t.items, t.required_keys, t.readonly_keys, t.is_closed, t.fallback)
t,
TypedDictType(
t.items, t.required_keys, t.readonly_keys, t.fallback, is_closed=t.is_closed
),
)

def visit_literal_type(self, t: LiteralType) -> ProperType:
Expand Down
2 changes: 1 addition & 1 deletion 2 mypy/expandtype.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def _possible_callable_kwargs(cls, repl: Parameters, dict_type: Instance) -> Pro
return Instance(dict_type.type, [dict_type.args[0], extra_items])
# TODO: when PEP 728 `extra_items` is implemented, pass extra_items below.
is_closed = extra_items is None
return TypedDictType(kwargs, required_names, set(), is_closed, fallback=dict_type)
return TypedDictType(kwargs, required_names, set(), dict_type, is_closed=is_closed)

def visit_type_var_tuple(self, t: TypeVarTupleType) -> Type:
# Sometimes solver may need to expand a type variable with (a copy of) itself
Expand Down
2 changes: 1 addition & 1 deletion 2 mypy/exprtotype.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def expr_to_unanalyzed_type(
value, options, allow_new_syntax, expr, lookup_qualified=lookup_qualified
)
result = TypedDictType(
items, set(), set(), False, Instance(MISSING_FALLBACK, ()), expr.line, expr.column
items, set(), set(), Instance(MISSING_FALLBACK, ()), expr.line, expr.column
)
result.extra_items_from = extra_items_from
return result
Expand Down
2 changes: 1 addition & 1 deletion 2 mypy/fastparse.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2143,7 +2143,7 @@ def visit_Dict(self, n: ast3.Dict) -> Type:
continue
return self.invalid_type(n)
items[item_name.value] = self.visit(value)
result = TypedDictType(items, set(), set(), False, _dummy_fallback, n.lineno, n.col_offset)
result = TypedDictType(items, set(), set(), _dummy_fallback, n.lineno, n.col_offset)
result.extra_items_from = extra_items_from
return result

Expand Down
4 changes: 3 additions & 1 deletion 4 mypy/join.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,9 @@ def visit_typeddict_type(self, t: TypedDictType) -> ProperType:

fallback = self.s.create_anonymous_fallback()
is_closed = self.s.is_closed and t.is_closed
return TypedDictType(items, required_keys, readonly_keys, is_closed, fallback)
return TypedDictType(
items, required_keys, readonly_keys, fallback, is_closed=is_closed
)
elif isinstance(self.s, Instance):
return join_types(self.s, t.fallback)
else:
Expand Down
4 changes: 3 additions & 1 deletion 4 mypy/meet.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,9 @@ def visit_typeddict_type(self, t: TypedDictType) -> ProperType:

fallback = self.s.create_anonymous_fallback()
required_keys = self.s.required_keys | t.required_keys
return TypedDictType(items, required_keys, readonly_keys, is_closed, fallback)
return TypedDictType(
items, required_keys, readonly_keys, fallback, is_closed=is_closed
)
elif isinstance(self.s, Instance) and is_subtype(t, self.s):
return t
else:
Expand Down
2 changes: 1 addition & 1 deletion 2 mypy/nativeparse.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ def read_type(state: State, data: ReadBuffer) -> Type:
extra_items_from.append(val)
else:
td_items[key] = val
typeddict_type = TypedDictType(td_items, set(), set(), False, _dummy_fallback)
typeddict_type = TypedDictType(td_items, set(), set(), _dummy_fallback)
typeddict_type.extra_items_from = extra_items_from
read_loc(data, typeddict_type)
expect_end_tag(data)
Expand Down
2 changes: 1 addition & 1 deletion 2 mypy/semanal_typeddict.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ def build_typeddict_typeinfo(
assert fallback is not None
info = existing_info or self.api.basic_new_typeinfo(name, fallback, line)
typeddict_type = TypedDictType(
item_types, required_keys, readonly_keys, is_closed, fallback
item_types, required_keys, readonly_keys, fallback, is_closed=is_closed
)
any_placeholder = has_placeholder(typeddict_type)
if typeddict_data:
Expand Down
17 changes: 17 additions & 0 deletions 17 mypy/test/testtypes.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
ProperType,
TupleType,
Type,
TypedDictType,
TypeOfAny,
TypeType,
TypeVarId,
Expand Down Expand Up @@ -223,6 +224,22 @@ def test_indirection_no_infinite_recursion(self) -> None:
modules = visitor.modules
assert modules == {"__main__", "builtins"}

def test_typeddict_type_constructor_signature(self) -> None:
typ = TypedDictType({"x": self.fx.o}, {"x"}, set(), self.fx.a, 10, 20)

assert typ.fallback is self.fx.a
assert_equal(typ.line, 10)
assert_equal(typ.column, 20)
assert not typ.is_closed

closed = TypedDictType({"x": self.fx.o}, {"x"}, set(), self.fx.a, is_closed=True)
assert closed.is_closed

with self.assertRaises(TypeError):
TypedDictType( # type: ignore[call-arg]
{"x": self.fx.o}, {"x"}, set(), self.fx.a, 10, 20, True
)


class TypeOpsSuite(Suite):
def setUp(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion 2 mypy/type_visitor.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ def visit_typeddict_type(self, t: TypedDictType, /) -> Type:
items,
t.required_keys,
t.readonly_keys,
t.is_closed,
# TODO: This appears to be unsafe.
cast(Any, t.fallback.accept(self)),
t.line,
t.column,
is_closed=t.is_closed,
)
self.set_cached(t, result)
return result
Expand Down
2 changes: 1 addition & 1 deletion 2 mypy/typeanal.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ def visit_typeddict_type(self, t: TypedDictType) -> Type:
fallback = t.fallback
is_closed = t.is_closed
return TypedDictType(
items, required_keys, readonly_keys, is_closed, fallback, t.line, t.column
items, required_keys, readonly_keys, fallback, t.line, t.column, is_closed=is_closed
)

def visit_raw_expression_type(self, t: RawExpressionType) -> Type:
Expand Down
15 changes: 11 additions & 4 deletions 15 mypy/types.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3048,10 +3048,11 @@ def __init__(
items: dict[str, Type],
required_keys: set[str],
readonly_keys: set[str],
is_closed: bool,
fallback: Instance,
line: int = -1,
column: int = -1,
*,
is_closed: bool = False,
) -> None:
super().__init__(line, column)
self.items = items
Expand Down Expand Up @@ -3112,8 +3113,8 @@ def deserialize(cls, data: JsonDict) -> TypedDictType:
{n: deserialize_type(t) for (n, t) in data["items"]},
set(data["required_keys"]),
set(data["readonly_keys"]),
bool(data["is_closed"]),
Instance.deserialize(data["fallback"]),
is_closed=bool(data["is_closed"]),
)

def write(self, data: WriteBuffer) -> None:
Expand All @@ -3133,8 +3134,8 @@ def read(cls, data: ReadBuffer) -> TypedDictType:
read_type_map(data),
set(read_str_list(data)),
set(read_str_list(data)),
read_bool(data),
fallback,
is_closed=read_bool(data),
)
assert read_tag(data) == END_TAG
return ret
Expand Down Expand Up @@ -3178,7 +3179,13 @@ def copy_modified(
items = {k: v for (k, v) in items.items() if k in item_names}
required_keys &= set(item_names)
return TypedDictType(
items, required_keys, readonly_keys, is_closed, fallback, self.line, self.column
items,
required_keys,
readonly_keys,
fallback,
self.line,
self.column,
is_closed=is_closed,
)

def zip(self, right: TypedDictType) -> Iterable[tuple[str, Type, Type]]:
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.