-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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.
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
Fixes how **
affects inference in {}
expressions, refs #11691
#11693
Conversation
@@ -3334,13 +3334,14 @@ def check_lst_expr(self, items: List[Expression], fullname: str, | |||
self.chk.named_generic_type(fullname, [tv]), | |||
self.named_type('builtins.function'), | |||
name=tag, | |||
variables=[tv]) | |||
out = self.check_call(constructor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment has been minimized.
This comment has been minimized.
mypy/join.py
Outdated
key, value = extract_key_value_types(item, mapping_type) | ||
keys.append(key) | ||
values.append(value) | ||
return join_type_list(keys), join_type_list(values) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we also need to handle: NoReturn
and TypedDict
types here. Any others?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: graphql-core (https://github.com/graphql-python/graphql-core)
+ src/graphql/utilities/extend_schema.py:200: error: Unused "type: ignore" comment
+ src/graphql/utilities/extend_schema.py:245: error: Unused "type: ignore" comment
+ src/graphql/utilities/extend_schema.py:353: error: Unused "type: ignore" comment
+ src/graphql/utilities/extend_schema.py:362: error: Unused "type: ignore" comment
pandera (https://github.com/pandera-dev/pandera)
+ pandera/schemas.py:324: error: Incompatible return value type (got "Dict[Any, object]", expected "Dict[str, str]") [return-value]
rclip (https://github.com/yurijmikhalevich/rclip)
- rclip/db.py:70: error: Argument 1 to "update" of "dict" has incompatible type "NewImage"; expected "Mapping[Any, None]"
ibis (https://github.com/ibis-project/ibis)
- ibis/backends/base/sql/registry/main.py:361: error: Argument 1 to "update" of "dict" has incompatible type "Dict[AnnotableMeta, Any]"; expected "Mapping[Type[Node], Any]"
- ibis/backends/impala/compiler.py:25: error: Argument 1 to "update" of "dict" has incompatible type "Dict[AnnotableMeta, Any]"; expected "Mapping[Type[Node], Any]"
+ ibis/backends/clickhouse/compiler.py:69: error: Incompatible types in assignment (expression has type "Dict[Type[Node], Any]", base class "ExprTranslator" defined the type as "Dict[AnnotableMeta, Any]")
black (https://github.com/psf/black)
+ src/blib2to3/pgen2/tokenize.py:581:31: error: Incompatible types in assignment (expression has type "Optional[Pattern[str]]", variable has type "Pattern[str]")
+ src/blib2to3/pgen2/tokenize.py:603:29: error: Incompatible types in assignment (expression has type "Optional[Pattern[str]]", variable has type "Pattern[str]")
core (https://github.com/home-assistant/core)
+ homeassistant/components/sentry/__init__.py:207: error: Unused "type: ignore" comment
|
This is a quite common problem, I've seen multiple issue reports about this.
So, the problem is: when a person uses
{**kwargs}
, it uses the same logic we have for.update()
call. But, this is not right..update()
indeed needs matching types.But, unpacking into a new dict should be allowed with any values.
To achive that I've decided to use
join
for key and value types. This is how it works:You may ask: why not
Union
?dict[Union[type, float], str]
looks strange to me. Also, some other similar places usejoin
. But, I am open to discuss this.I will add extra tests a bit later, I am currently too tired 😞
Closes #11691
Refs #11151