fix False positive: bad-typed-dict-key with enums and TypedDict #3365#3372
fix False positive: bad-typed-dict-key with enums and TypedDict #3365#3372asukaminato0721 wants to merge 1 commit into
Conversation
|
Diff from mypy_primer, showing the effect of this PR on open source code: openlibrary (https://github.com/internetarchive/openlibrary)
+ ERROR openlibrary/core/bookshelves_events.py:14:16-85: `in` is not supported between `int` and `Generator[Literal[1, 2, 3]]` [unsupported-operation]
rotki (https://github.com/rotki/rotki)
+ ERROR rotkehlchen/db/cache.py:169:16-29: Returned type `((x: Unknown) -> Unknown) | ((value: str) -> Timestamp | None) | ((value: str) -> int | None) | ((value: str) -> tuple[SolanaAddress, SolanaAddress] | None) | ((value: str) -> ChecksumAddress)` is not assignable to declared return type `(str) -> ChecksumAddress | Timestamp | int | None` [bad-return]
apprise (https://github.com/caronc/apprise)
+ ERROR apprise/plugins/jira.py:780:22-782:10: No matching overload found for function `typing.MutableMapping.update` called with arguments: (dict[LiteralString, str]) [no-matching-overload]
core (https://github.com/home-assistant/core)
+ ERROR homeassistant/components/homeassistant_sky_connect/const.py:53:16-46: Object of class `tuple` has no attribute `usb_product_name` [missing-attribute]
|
Primer Diff Classification❌ 4 regression(s) | 4 project(s) total | +4 errors 4 regression(s) across openlibrary, rotki, apprise, core. error kinds:
Detailed analysis❌ Regression (4)openlibrary (+1)
rotki (+1)
Looking at the error message carefully, the returned type union includes:
The declared return type is Notably, the declared return type annotation is actually incomplete: However, this type inconsistency was previously invisible because older pyrefly (and mypy/pyright) did not compute the precise union of all enum member value types for This is a new error caused by the PR's changes to enum value resolution. While the underlying annotation is technically incomplete, the error is a practical false positive in the sense that the code works correctly at runtime and other type checkers don't flag it. The overly precise enum value type computation creates errors that are impractical for users to resolve without changing their enum patterns.
apprise (+1)
core (+1)
Suggested fixesSummary: The PR's changes to enum value type resolution in enums.rs cause 4 pyrefly-only regressions: overly precise literal types break generator/dict operations, incorrect tuple type for dataclass mixin enums, and overly specific callable unions cause bad-return errors. 1. In
2. In
Was this helpful? React with 👍 or 👎 Classification by primer-classifier (4 LLM) |
Summary
Fixes #3365
Test Plan