Skip to content

Conversation

@AlexWaygood
Copy link
Member

Summary

This PR adds diagnostics for isinstance() and issubclass() calls where the second argument is a protocol class that is not declared as runtime-checkable. Using @BurntSushi's new diagnostics infrastructure, it makes these diagnostics beautiful too! Here's a screenshot of what they look like in the terminal:

image

Test Plan

Existing mdtests updated, with new snapshots.

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Apr 22, 2025
Copy link
Member Author

Choose a reason for hiding this comment

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

This snapshot honestly feels much too big to me. I only really want to snapshot the new diagnostics for isinstance() and issubclass(); all the reveal_type diagnostics being snapshotted here are pretty noisy. But in order to get a smaller snapshot, I'd have to add another subheading to the protocols.md file, which would break the flow of my literate test suite ☹️

@github-actions
Copy link
Contributor

github-actions bot commented Apr 22, 2025

mypy_primer results

No ecosystem changes detected ✅

@AlexWaygood AlexWaygood force-pushed the alex/protocol-member-inference branch from afb9ea0 to 8906bc9 Compare April 22, 2025 19:03
@AlexWaygood AlexWaygood force-pushed the alex/runtime-checkable-protos branch from cc814e6 to 39e7f80 Compare April 22, 2025 19:06
@AlexWaygood AlexWaygood force-pushed the alex/protocol-member-inference branch from 8906bc9 to b4e8e97 Compare April 22, 2025 19:08
@AlexWaygood AlexWaygood force-pushed the alex/runtime-checkable-protos branch from 39e7f80 to a3a208f Compare April 22, 2025 19:09
@AlexWaygood AlexWaygood force-pushed the alex/protocol-member-inference branch from b4e8e97 to 1809727 Compare April 22, 2025 19:36
@AlexWaygood AlexWaygood force-pushed the alex/runtime-checkable-protos branch from a3a208f to cced1b9 Compare April 22, 2025 19:37
@AlexWaygood AlexWaygood force-pushed the alex/protocol-member-inference branch from 1809727 to 6aa7491 Compare April 22, 2025 19:44
@AlexWaygood AlexWaygood force-pushed the alex/runtime-checkable-protos branch from cced1b9 to 4b29d91 Compare April 22, 2025 19:45
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

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

Cool!

@AlexWaygood AlexWaygood force-pushed the alex/protocol-member-inference branch from 6aa7491 to a8fba56 Compare April 23, 2025 10:31
@AlexWaygood AlexWaygood force-pushed the alex/runtime-checkable-protos branch 4 times, most recently from 39538ba to 42c6400 Compare April 23, 2025 12:12
@AlexWaygood AlexWaygood force-pushed the alex/protocol-member-inference branch from e96e63f to 7ced9ed Compare April 23, 2025 21:31
Base automatically changed from alex/protocol-member-inference to main April 23, 2025 21:36
…ls where a non-runtime-checkable protocol is the second argument
@AlexWaygood AlexWaygood force-pushed the alex/runtime-checkable-protos branch from 42c6400 to 3db4f2f Compare April 23, 2025 21:37
@AlexWaygood AlexWaygood enabled auto-merge (squash) April 23, 2025 21:38
@AlexWaygood AlexWaygood merged commit e897f37 into main Apr 23, 2025
32 of 33 checks passed
@AlexWaygood AlexWaygood deleted the alex/runtime-checkable-protos branch April 23, 2025 21:40
@carljm carljm mentioned this pull request Apr 24, 2025
5 tasks
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