Skip to content

Comments

[red-knot] fix collapsing literal and its negation to object#17605

Merged
carljm merged 2 commits intomainfrom
cjm/unionfix
Apr 24, 2025
Merged

[red-knot] fix collapsing literal and its negation to object#17605
carljm merged 2 commits intomainfrom
cjm/unionfix

Conversation

@carljm
Copy link
Contributor

@carljm carljm commented Apr 24, 2025

Summary

Another follow-up to the unions-of-large-literals optimization. Restore the behavior that e.g. Literal[""] | ~Literal[""] collapses to object.

Test Plan

Added mdtests.

@carljm carljm added the ty Multi-file analysis & type inference label Apr 24, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Apr 24, 2025

mypy_primer results

No ecosystem changes detected ✅

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

This looks reasonable. Though I'm slightly concerned about the spiralling complexity here.

It would be nice if we could find a way to unify the branches here so that we don't have to repeat the same somewhat complex logic three times over. But that doesn't have to be done in this PR; it can wait for a followup.

@carljm carljm enabled auto-merge (squash) April 24, 2025 13:51
@carljm carljm merged commit ac6219e into main Apr 24, 2025
32 checks passed
@carljm carljm deleted the cjm/unionfix branch April 24, 2025 13:55
dcreager added a commit that referenced this pull request Apr 24, 2025
* main:
  [red-knot] fix collapsing literal and its negation to object (#17605)
  [red-knot] Add more tests for protocols (#17603)
  [red-knot] Ban direct instantiations of `Protocol` classes (#17597)
  [`pyupgrade`] Preserve parenthesis when fixing native literals containing newlines (`UP018`) (#17220)
  [`airflow`] fix typos (`AIR302`, `AIR312`) (#17574)
  [red-knot] Special case `@abstractmethod` for function type (#17591)
  [red-knot] Emit diagnostics for isinstance() and issubclass() calls where a non-runtime-checkable protocol is the second argument (#17561)
  [red-knot] Infer the members of a protocol class (#17556)
  [red-knot] Add `FunctionType::to_overloaded` (#17585)
  [red-knot] Add mdtests for `global` statement (#17563)
  [syntax-errors] Make duplicate parameter names a semantic error (#17131)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants