Skip to content

Conversation

@sobolevn
Copy link
Member

@sobolevn sobolevn commented Dec 9, 2021

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:
Снимок экрана 2021-12-09 в 18 38 15

You may ask: why not Union? dict[Union[type, float], str] looks strange to me. Also, some other similar places use join. But, I am open to discuss this.

I will add extra tests a bit later, I am currently too tired 😞

Closes #11691
Refs #11151

self.named_type('builtins.function'),
name=tag,
variables=[tv])
out = self.check_call(constructor,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a readability change only. Before and after:
Снимок экрана 2021-12-09 в 18 41 40
Снимок экрана 2021-12-09 в 18 41 52

@github-actions

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)
Copy link
Member Author

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?

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@97littleleaf11 97littleleaf11 self-requested a review December 16, 2021 06:26
@github-actions
Copy link
Contributor

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 pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spread dict not used to infer type

3 participants