fix Narrow types based on collection containment #2706#2710
fix Narrow types based on collection containment #2706#2710asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Improves containment-based type narrowing so that x in <typed collection> can narrow x to a finite domain derived from the RHS container’s typed element/key domain (preserving literal precision for typed dict, tuple, list, set, and frozenset, including frozenset(...) calls).
Changes:
- Add helper routines to derive a finite “membership domain” type from RHS container types (including TypedDict keys and typed container element types).
- Extend the syntactic fast-path for membership narrowing to recognize
frozenset(<literal container>). - Add a regression test covering narrowing for
inchecks against typed collection variables and inlinefrozenset(...).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyrefly/lib/alt/narrow.rs |
Implements finite-domain membership narrowing from typed RHS containers and recognizes inline frozenset(...) for the literal fast-path. |
pyrefly/lib/test/narrow.rs |
Adds a test ensuring in-based narrowing works for typed dict/tuple/list/set/frozenset and frozenset(("a",)). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
it's weird that mypy primer timed out, i wonder if there is a perf regression somewhere |
@yangdanny97 I've also started seeing mypy_primer timeouts in the past day or so (but only with the GitHub workflow). |
containment narrowing now derives finite membership domains directly from typed RHS containers instead of relying only on the generic iterable/mapping decomposition. That preserves literal precision for typed dict, tuple, list, set, and frozenset values, and the literal fast path now also recognizes inline frozenset(...) calls
|
Diff from mypy_primer, showing the effect of this PR on open source code: urllib3 (https://github.com/urllib3/urllib3)
- ERROR src/urllib3/util/ssl_.py:235:66-237:14: No matching overload found for function `dict.get` called with arguments: (int | None, Literal[TLSVersion.MINIMUM_SUPPORTED]) [no-matching-overload]
- ERROR src/urllib3/util/ssl_.py:238:66-240:14: No matching overload found for function `dict.get` called with arguments: (int | None, Literal[TLSVersion.MAXIMUM_SUPPORTED]) [no-matching-overload]
- ERROR src/urllib3/util/ssl_.py:254:35-54: `int | Unknown` is not assignable to attribute `minimum_version` with type `TLSVersion` [bad-assignment]
+ ERROR src/urllib3/util/ssl_.py:254:35-54: `int` is not assignable to attribute `minimum_version` with type `TLSVersion` [bad-assignment]
- ERROR src/urllib3/util/ssl_.py:259:35-54: `int | Unknown` is not assignable to attribute `maximum_version` with type `TLSVersion` [bad-assignment]
+ ERROR src/urllib3/util/ssl_.py:259:35-54: `int` is not assignable to attribute `maximum_version` with type `TLSVersion` [bad-assignment]
pydantic (https://github.com/pydantic/pydantic)
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `allow_inf_nan` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `allowed_schemes` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `arguments_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `auto_collapse` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `choices` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `cls` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `cls_name` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `cls_repr` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `coerce_numbers_to_str` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `collect_init_only` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `computed_fields` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `config` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `custom_error_context` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `custom_error_message` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `custom_error_type` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `custom_init` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `dataclass_name` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `decimal_places` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `default` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `default_factory` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `default_factory_takes_data` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `default_host` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `default_path` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `default_port` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `definitions` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `discriminator` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `expected` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `extra_behavior` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `extras_keys_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `extras_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `fail_fast` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `fields` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `from_attributes` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `frozen` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `function_name` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `ge` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `generic_origin` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `gt` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `host_required` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `items_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `json_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `json_schema_input_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `keys_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `lax_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `le` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `lt` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `max_digits` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `max_length` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `members` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `microseconds_precision` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `min_length` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `missing` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `mode` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `model_name` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `multiple_of` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `now_op` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `now_utc_offset` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `on_error` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `pattern` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `post_init` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `python_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `regex_engine` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `return_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `revalidate_instances` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `root_model` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `schema_ref` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `slots` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `steps` [bad-typed-dict-key]
- ERROR pydantic/json_schema.py:2380:60-68: Invalid key for TypedDict `AfterValidatorFunctionSchema`, got `str` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `strict` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `strict_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `strip_whitespace` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `sub_type` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `to_lower` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `to_upper` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `total` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `tz_constraint` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `validate_by_alias` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `validate_by_name` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `validate_default` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `values_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `var_args_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `var_kwargs_mode` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `var_kwargs_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `variadic_item_index` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AfterValidatorFunctionSchema` does not have key `version` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `allow_inf_nan` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `allowed_schemes` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `arguments_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `auto_collapse` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `choices` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `cls` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `cls_name` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `cls_repr` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `coerce_numbers_to_str` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `collect_init_only` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `computed_fields` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `config` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `custom_error_context` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `custom_error_message` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `custom_error_type` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `custom_init` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `dataclass_name` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `decimal_places` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `default` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `default_factory` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `default_factory_takes_data` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `default_host` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `default_path` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `default_port` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `definitions` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `discriminator` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `expected` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `extra_behavior` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `extras_keys_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `extras_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `fail_fast` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `fields` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `from_attributes` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `frozen` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `function` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `function_name` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `ge` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `generic_origin` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `gt` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `host_required` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `items_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `json_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `json_schema_input_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `keys_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `lax_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `le` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `lt` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `max_digits` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `max_length` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `members` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `microseconds_precision` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `min_length` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `missing` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `mode` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `model_name` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `multiple_of` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `now_op` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `now_utc_offset` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `on_error` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `pattern` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `post_init` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `python_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `regex_engine` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `return_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `revalidate_instances` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `root_model` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `schema_ref` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `slots` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `steps` [bad-typed-dict-key]
- ERROR pydantic/json_schema.py:2380:60-68: Invalid key for TypedDict `AnySchema`, got `str` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `strict` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `strict_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `strip_whitespace` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `sub_type` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `to_lower` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `to_upper` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `total` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `tz_constraint` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `validate_by_alias` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `validate_by_name` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `validate_default` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `values_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `var_args_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `var_kwargs_mode` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `var_kwargs_schema` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `variadic_item_index` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `AnySchema` does not have key `version` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `allow_inf_nan` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `allowed_schemes` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `auto_collapse` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `choices` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `cls` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `cls_name` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `cls_repr` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `coerce_numbers_to_str` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `collect_init_only` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `computed_fields` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `config` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `custom_error_context` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `custom_error_message` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `custom_error_type` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `custom_init` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `dataclass_name` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `decimal_places` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `default` [bad-typed-dict-key]
+ ERROR pydantic/json_schema.py:2380:60-68: TypedDict `ArgumentsSchema` does not have key `default_factory` [bad-typed-dict-key]
... (truncated 4159 lines) ...
pylint (https://github.com/pycqa/pylint)
- ERROR pylint/checkers/stdlib.py:703:71-85: Argument `str | Unknown | None` is not assignable to parameter `func_name` with type `str` in function `StdlibChecker._check_open_call` [bad-argument-type]
schema_salad (https://github.com/common-workflow-language/schema_salad)
- ERROR schema_salad/avro/schema.py:712:36-50: Argument `Unknown | None` is not assignable to parameter `atype` with type `str` in function `PrimitiveSchema.__init__` [bad-argument-type]
pip (https://github.com/pypa/pip)
+ WARN iterative_resolve_scc: SCC CalcId(pip._vendor.msgpack.fallback, /home/runner/work/pyrefly/pyrefly/primer_base/projects/pip/src/pip/_vendor/msgpack/fallback.py, KeyClassField(class1, _unpack)) exceeded 5 iterations; committing last answers
streamlit (https://github.com/streamlit/streamlit)
+ WARN lib/streamlit/elements/widgets/button.py:111:16-47: Redundant cast: `Literal['left', 'right']` is the same type as `Literal['left', 'right']` [redundant-cast]
meson (https://github.com/mesonbuild/meson)
+ WARN mesonbuild/interpreter/interpreter.py:1164:36-54: Redundant cast: `Literal['c', 'cpp', 'cs', 'cuda', 'cython', 'd', 'fortran', 'java', 'linearasm', 'masm', 'nasm', 'objc', 'objcpp', 'rust', 'swift', 'vala']` is the same type as `Literal['c', 'cpp', 'cs', 'cuda', 'cython', 'd', 'fortran', 'java', 'linearasm', 'masm', 'nasm', 'objc', 'objcpp', 'rust', 'swift', 'vala']` [redundant-cast]
+ WARN mesonbuild/interpreter/mesonmain.py:294:22-40: Redundant cast: `Literal['c', 'cpp', 'cs', 'cuda', 'cython', 'd', 'fortran', 'java', 'linearasm', 'masm', 'nasm', 'objc', 'objcpp', 'rust', 'swift', 'vala']` is the same type as `Literal['c', 'cpp', 'cs', 'cuda', 'cython', 'd', 'fortran', 'java', 'linearasm', 'masm', 'nasm', 'objc', 'objcpp', 'rust', 'swift', 'vala']` [redundant-cast]
static-frame (https://github.com/static-frame/static-frame)
+ ERROR static_frame/core/interface.py:1577:35-48: Argument `type[InterfaceBatchDatetime] | type[InterfaceBatchString] | type[InterfaceBatchTranspose] | type[InterfaceBatchValues] | type[InterfaceDatetime[Unknown]] | type[InterfaceHashlib] | type[InterfaceString[Unknown]] | type[InterfaceTranspose[Unknown]] | type[InterfaceValues[Unknown]] | type[TypeClinic]` is not assignable to parameter `cls_interface` with type `type[Interface]` in function `InterfaceRecord.gen_from_accessor` [bad-argument-type]
mypy (https://github.com/python/mypy)
- ERROR mypyc/irbuild/util.py:142:13-23: Cannot set item in `MypycAttrs` [unsupported-operation]
- ERROR mypyc/irbuild/util.py:143:19-22: Cannot set item in `dict[MypycAttr, int]` [unsupported-operation]
Tanjun (https://github.com/FasterSpeeding/Tanjun)
- ERROR tanjun/context/menu.py:144:16-28: Returned type `CommandType` is not assignable to declared return type `Literal[CommandType.MESSAGE, CommandType.USER]` [bad-return]
cloud-init (https://github.com/canonical/cloud-init)
- WARN iterative_resolve_scc: SCC CalcId(cloudinit.sources.helpers.ec2, /home/runner/work/pyrefly/pyrefly/primer_base/projects/cloud-init/cloudinit/sources/helpers/ec2.py, KeyClassField(class1, _materialize)) exceeded 5 iterations; committing last answers
- WARN iterative_resolve_scc: SCC CalcId(cloudinit.sources.helpers.aliyun, /home/runner/work/pyrefly/pyrefly/primer_base/projects/cloud-init/cloudinit/sources/helpers/aliyun.py, Key::Definition(_process_dict_values 85:9-29)) exceeded 5 iterations; committing last answers
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ ERROR pymongo/common.py:386:12-17: Returned type `Literal['nearest', 'primary', 'primaryPreferred', 'secondary', 'secondaryPreferred']` is not assignable to declared return type `_ServerMode` [bad-return]
|
Primer Diff Classification❌ 1 regression(s) | ✅ 8 improvement(s) | ➖ 1 neutral | 10 project(s) total 1 regression(s) across static-frame. error kinds:
Detailed analysis❌ Regression (1)static-frame (+1)
✅ Improvement (8)urllib3 (+2, -4)
The new 'bad-assignment' errors claiming Overall, pyrefly got better at type narrowing and removed false positives while potentially catching real type inconsistencies.
pylint (-1)
schema_salad (-1)
streamlit (+1)
meson (+2)
mypy (-2)
Tanjun (-1)
The PR improved containment narrowing to derive finite membership domains from typed containers like frozenset, allowing pyrefly to correctly understand that after the assertion,
mongo-python-driver (+1)
➖ Neutral (1)pydantic (+1, -1)
Was this helpful? React with 👍 or 👎 Classification by primer-classifier (1 heuristic, 9 LLM) |
Summary
Fixes #2706
containment narrowing now derives finite membership domains directly from typed RHS containers instead of relying only on the generic iterable/mapping decomposition.
That preserves literal precision for typed dict, tuple, list, set, and frozenset values, and the literal fast path now also recognizes inline frozenset(...) calls
Test Plan
add the test in issue