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
Next Next commit
🐛 Added Review Suggestions
We don't need to convert dict_keys/items to set.

Also fixed the comment saying literally the opposite of what was
happening
  • Loading branch information
JoaquimEsteves committed Dec 8, 2022
commit f7a7f4f84ac06e5dadc7d6ab05094cd2ca9cd782
13 changes: 6 additions & 7 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,20 +790,19 @@ def check_typeddict_call_with_kwargs(
orig_callee: Type | None,
) -> Type:
actual_keys = kwargs.keys()
found_set = set(actual_keys)
if not (callee.required_keys <= found_set <= set(callee.items.keys())):
if not (callee.required_keys <= actual_keys <= callee.items.keys()):
expected_keys = [
key
for key in callee.items.keys()
if key in callee.required_keys or key in found_set
if key in callee.required_keys or key in actual_keys
]
self.msg.unexpected_typeddict_keys(
callee, expected_keys=expected_keys, actual_keys=list(actual_keys), context=context
)
if callee.required_keys > found_set:
# found_set is not a sub-set of the required_keys
# This means we're dealing with something weird we can't
# properly type
if callee.required_keys > actual_keys:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is unreachable, there is callee.required_keys <= actual_keys in the enclosing if statement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello!

I believe this is correct as the callee.required_keys <= actual_keys has a not preceeding it.

Indeed, removing this return wil fail the test [case TestCannotCreateTypedDictInstanceWithMissingItems]

Let's imagine the following:

assert callee.items.keys == {1,2,3,4}
assert callee.required_keys == {1,2,3}
actual_keys = {1,2}

if not (required <= actual_keys <= callee.items.keys ):
    # call unexpected_typeddict_keys on the actual vs expected

    if required > actual:
        return AnyType

Will return AnyType and print out a single error message: "missing required key 3"

Whereas with actual_keys = {1,2,3, 'unrelated'} will print out "extra key 'unrelated' but not return AnyType; ie it will continue to check the TypedDict for any other errors (For example, the actual keys might all be accounted for but have the wrong type).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, right, I have missed the not.

# found_set is a sub-set of the required_keys
# This means we're missing some keys and as such, we can't
# properly type the object
return AnyType(TypeOfAny.from_error)

orig_callee = get_proper_type(orig_callee)
Expand Down