Skip to content

Conversation

@AlexWaygood
Copy link
Member

Summary

We want to special-case these functions to allow us to introspect red-knot's inference of protocol types (see tests at https://github.com/astral-sh/ruff/blob/main/crates/red_knot_python_semantic/resources/mdtest/protocols.md). Doing this is a necessary precondition for adding the special casing.

Test Plan

I updated the known_function_roundtrip_from_str unit test. This PR doesn't actually add the special casing yet, so no new mdtests for now.

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Apr 17, 2025
@AlexWaygood AlexWaygood enabled auto-merge (squash) April 17, 2025 13:07
@AlexWaygood AlexWaygood disabled auto-merge April 17, 2025 13:07
@github-actions
Copy link
Contributor

mypy_primer results

No ecosystem changes detected ✅

Comment on lines +5899 to +5900
/// `typing(_extensions).is_protocol`
IsProtocol,
Copy link
Contributor

Choose a reason for hiding this comment

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

No, no, no! This is clearly the place where typing.dataclass_transform belongs.

@AlexWaygood AlexWaygood merged commit c36f3f5 into main Apr 17, 2025
23 checks passed
@AlexWaygood AlexWaygood deleted the alex/protocol-knownfunctions branch April 17, 2025 13:49
dcreager added a commit that referenced this pull request Apr 17, 2025
* main:
  [red-knot] Detect version-related syntax errors (#16379)
  [`pyflakes`] Add fix safety section (`F841`) (#17410)
  [red-knot] Add `KnownFunction` variants for `is_protocol`, `get_protocol_members` and `runtime_checkable` (#17450)
  Bump 0.11.6 (#17449)
  Auto generate `visit_source_order` (#17180)
  [red-knot] Initial tests for protocols (#17436)
  [red-knot] Dataclasses: synthesize `__init__` with proper signature (#17428)
  [red-knot] Dataclasses: support `order=True` (#17406)
dcreager added a commit that referenced this pull request Apr 18, 2025
* main: (123 commits)
  [red-knot] Handle explicit class specialization in type expressions (#17434)
  [red-knot] allow assignment expression in call compare narrowing (#17461)
  [red-knot] fix building unions with literals and AlwaysTruthy/AlwaysFalsy (#17451)
  [red-knot] Type narrowing for assertions (take 2) (#17345)
  [red-knot] class bases are not affected by __future__.annotations (#17456)
  [red-knot] Add support for overloaded functions (#17366)
  [`pyupgrade`] Add fix safety section to docs (`UP036`) (#17444)
  [red-knot] more type-narrowing in match statements (#17302)
  [red-knot] Add some narrowing for assignment expressions (#17448)
  [red-knot] Understand `typing.Protocol` and `typing_extensions.Protocol` as equivalent (#17446)
  Server: Use `min` instead of `max` to limit the number of threads (#17421)
  [red-knot] Detect version-related syntax errors (#16379)
  [`pyflakes`] Add fix safety section (`F841`) (#17410)
  [red-knot] Add `KnownFunction` variants for `is_protocol`, `get_protocol_members` and `runtime_checkable` (#17450)
  Bump 0.11.6 (#17449)
  Auto generate `visit_source_order` (#17180)
  [red-knot] Initial tests for protocols (#17436)
  [red-knot] Dataclasses: synthesize `__init__` with proper signature (#17428)
  [red-knot] Dataclasses: support `order=True` (#17406)
  [red-knot] Super-basic generic inference at call sites (#17301)
  ...
@carljm carljm mentioned this pull request Apr 24, 2025
5 tasks
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.

3 participants