Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c7824be
✨ Added new Error to TypedDict
JoaquimEsteves Nov 30, 2022
f19a7f7
🐛 Fixed 'missing keys' not being reported
JoaquimEsteves Nov 30, 2022
2a4220c
🐛 Early return in case there's missing or extra keys
JoaquimEsteves Nov 30, 2022
fcf4909
🧑‍🔬 Fixed simple error-code tests
JoaquimEsteves Nov 30, 2022
deb6543
Update test-data/unit/check-typeddict.test
JoaquimEsteves Dec 2, 2022
222869d
Update test-data/unit/check-errorcodes.test
JoaquimEsteves Dec 2, 2022
70c0a18
✨ We now typecheck despite having an extra-key
JoaquimEsteves Dec 5, 2022
eda0c8b
🧹 Setting an extra value on a TypedDict now has the correct error code
JoaquimEsteves Dec 5, 2022
25f3dbc
✨ We can now set an item and get the correct error code
JoaquimEsteves Dec 5, 2022
c7c687f
🧑‍🔬 Redid the `IgnotErrorCodeTypedDictNoteIgnore` test
JoaquimEsteves Dec 5, 2022
a275c86
🐈‍⬛ Black
JoaquimEsteves Dec 8, 2022
f7a7f4f
🐛 Added Review Suggestions
JoaquimEsteves Dec 8, 2022
06a3866
📝 Fixed docstring not being in the correct format.
JoaquimEsteves Dec 8, 2022
780e10d
🐛 Fixed ignoring unknown-key not silencing the 'Did you mean' message
JoaquimEsteves Dec 8, 2022
fb98524
Review Feedback - Better Docstrings
JoaquimEsteves Jan 23, 2023
708d322
📝 Added `unknown-key` to the `error_code_list`
JoaquimEsteves Jan 23, 2023
e4b82b6
🐛 Black and sphinx bugs
JoaquimEsteves Jan 23, 2023
1c9a623
Merge branch 'master' into master
JoaquimEsteves Jan 23, 2023
f4f0cd0
Merge branch 'master' into master
JoaquimEsteves Jan 23, 2023
957ba17
Apply suggestions from code review (docs)
ilevkivskyi Jan 25, 2023
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
Prev Previous commit
Apply suggestions from code review (docs)
  • Loading branch information
ilevkivskyi authored Jan 25, 2023
commit 957ba17201b41e9ed83b248503c19cda437d47fc
25 changes: 8 additions & 17 deletions docs/source/error_code_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -435,49 +435,40 @@ Check TypedDict Keys [typeddict-unknown-key]
--------------------------------------------

When constructing a ``TypedDict`` object, mypy checks whether the definition
contains unknown keys.

For convenience's sake, mypy will not generate an error when a ``TypedDict``
has extra keys if it's passed to a function as an argument.

However, it will generate an error when these are created.

Example:
contains unknown keys. For convenience's sake, mypy will not generate an error
when a ``TypedDict`` has extra keys if it's passed to a function as an argument.
However, it will generate an error when these are created. Example:

.. code-block:: python

from typing_extensions import TypedDict


class Point(TypedDict):
x: int
y: int


class Point3D(Point):
z: int


def add_x_coordinates(a: Point, b: Point) -> int:
return a["x"] + b["x"]


a: Point = {"x": 1, "y": 4}
b: Point3D = {"x": 2, "y": 5, "z": 6}
Comment thread
ilevkivskyi marked this conversation as resolved.

# OK
add_x_coordinates(a, b)
# Error: Extra key "z" for TypedDict "Point" [typeddict-unknown-key]
add_x_coordinates(a, {'x': 1, 'y': 4, 'z': 5})
add_x_coordinates(a, {"x": 1, "y": 4, "z": 5})


Setting an unknown value on a ``TypedDict`` will also generate this error:

.. code-block:: python

a: Point = {"x": 1, "y": 2}
# Error: Extra key "non-existant" for TypedDict "Point" [typeddict-unknown-key]
a['non-existant'] = 3
# Error: Extra key "z" for TypedDict "Point" [typeddict-unknown-key]
a["z"] = 3


Whereas reading an unknown value will generate the more generic/serious
Expand All @@ -486,8 +477,8 @@ Whereas reading an unknown value will generate the more generic/serious
.. code-block:: python

a: Point = {"x": 1, "y": 2}
# Error: TypedDict "Point" has no key "non-existant" [typeddict-item]
_ = a['non-existant']
# Error: TypedDict "Point" has no key "z" [typeddict-item]
_ = a["z"]


Check that type of target is known [has-type]
Expand Down