Skip to content
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

Allow objects matching SupportsKeysAndGetItem to be unpacked #14990

Conversation

bryanforbes
Copy link
Contributor

Fixes #14986

This PR allows any object matching _typeshed.SupportsKeysAndGetItem[str, Any] to be unpacked with **.

@github-actions

This comment has been minimized.

mypy/test/data.py Outdated Show resolved Hide resolved
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@bryanforbes
Copy link
Contributor Author

@hauntsaninja I've got all but one unit test passing and the problem isn't obvious to me:

https://github.com/bryanforbes/mypy/blob/197916b1d357007c03a95c51df64feb582f5526f/test-data/unit/fine-grained-modules.test#L1280-L1309

The test reports that b, c, d, e, f, g, and h are all stale, so I've tried changing line 1300 to [stale b, c, d, e, f, g, h], but the next time I run the test, it tells me that a, b, c, d, e, f, g, and h are now stale. If I add a to the [stale] list, it goes back to reporting b through h as stale. Any help would be appreciated.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2023

Diff from mypy_primer, showing the effect of this PR on open source code:

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/infrastructure/process.py:235: error: List item 0 has incompatible type "object"; expected "Mapping[<nothing>, <nothing>]"  [list-item]
+ src/prefect/infrastructure/process.py:235: error: List item 0 has incompatible type "object"; expected "SupportsKeysAndGetItem[<nothing>, <nothing>]"  [list-item]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/structured_configs/_make_custom_builds.py:299: error: List item 0 has incompatible type "Optional[DataclassOptions]"; expected "Mapping[Any, Any]"  [list-item]
+ src/hydra_zen/structured_configs/_make_custom_builds.py:299: error: List item 0 has incompatible type "Optional[DataclassOptions]"; expected "SupportsKeysAndGetItem[Any, Any]"  [list-item]

@bryanforbes bryanforbes marked this pull request as ready for review April 6, 2023 22:25
Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great!

I don't understand what's going on with testAddModuleAfterCache3 an don't understand why adding two files fixes. But the core logic here seems good and unit tests should fail if typeshed ever makes enough changes that e.g. the protocol no longer exists or _typeshed is not in the builtins scc or whatever

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Objects matching SupportsKeysAndGetItem[str, Any] cannot be used after **
3 participants