Skip to content

fix Type Narrowing Depends on Order of Keyword Arguments #4187#4199

Open
asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:4187
Open

fix Type Narrowing Depends on Order of Keyword Arguments #4187#4199
asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:4187

Conversation

@asukaminato0721

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4187

Updated subtype inference to preserve quantified types when a union contains a bare inference variable, preventing argument-order-dependent widening to the TypeVar bound.

Test Plan

add test

@github-actions

Copy link
Copy Markdown

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

apprise (https://github.com/caronc/apprise)
- ERROR apprise/plugins/vapid/__init__.py:356:20-43: Object of class `dict` has no attribute `load` [missing-attribute]
- ERROR apprise/plugins/vapid/__init__.py:391:16-22: `not in` is not supported between `object` and `WebPushSubscriptionManager` [unsupported-operation]
- ERROR apprise/plugins/vapid/__init__.py:405:28-65: Argument `EllipticCurvePublicKey | Unknown | None` is not assignable to parameter `public_key` with type `EllipticCurvePublicKey` in function `apprise.utils.pem.ApprisePEMController.encrypt_webpush` [bad-argument-type]
- ERROR apprise/plugins/vapid/__init__.py:405:47-53: Cannot index into `WebPushSubscriptionManager` [bad-index]
- ERROR apprise/plugins/vapid/__init__.py:406:29-67: Argument `bytes | Unknown | None` is not assignable to parameter `auth_secret` with type `bytes` in function `apprise.utils.pem.ApprisePEMController.encrypt_webpush` [bad-argument-type]
- ERROR apprise/plugins/vapid/__init__.py:406:48-54: Cannot index into `WebPushSubscriptionManager` [bad-index]
- ERROR apprise/plugins/vapid/__init__.py:609:42-70: Argument `bytes | None` is not assignable to parameter `data` with type `bytes` in function `apprise.utils.base64.base64_urlencode` [bad-argument-type]

xarray (https://github.com/pydata/xarray)
- ERROR xarray/backends/api.py:1369:48-63: Argument `set[_FLike]` is not assignable to parameter `paths_to_remove` with type `set[ReadBuffer[Unknown] | _FLike]` in function `_remove_path` [bad-argument-type]
- ERROR xarray/backends/api.py:1371:31-44: Argument `NestedSequence[ReadBuffer[Unknown] | _FLike]` is not assignable to parameter `object` with type `NestedSequence[_FLike] | _FLike` in function `list.append` [bad-argument-type]
+ ERROR xarray/core/variable.py:470:27-31: Argument `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype]] | _SupportsArray[dtype] | bytes | complex | str | T_DuckArray` is not assignable to parameter `new_data` with type `_arrayapi[Any, Unknown] | _arrayfunction[Any, Unknown]` in function `xarray.namedarray.core.NamedArray._check_shape` [bad-argument-type]
+ ERROR xarray/core/variable.py:471:22-26: `Buffer | _NestedSequence[bytes | complex | str] | _NestedSequence[_SupportsArray[dtype]] | _SupportsArray[dtype] | bytes | complex | str | T_DuckArray` is not assignable to attribute `_data` with type `_arrayapi[Any, Unknown] | _arrayfunction[Any, Unknown]` [bad-assignment]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type Narrowing Depends on Order of Keyword Arguments

1 participant