Skip to content

Conversation

@dcreager
Copy link
Member

There were many fields in Signature and friends that really had more to do with how a signature was being used — how it was looked up, details about an individual call site, etc. Those fields more properly belong in Bindings and friends.

This is a pure refactoring, and should not affect any tests or ecosystem projects.

I started on this journey in support of astral-sh/ty#462. It seemed worth pulling out as a separate PR.

One major concrete benefit of this refactoring is that we can now use CallableSignature directly in CallableType. (We can't use CallableSignature directly in that Type variant because signatures are not currently interned.)

@dcreager dcreager added the internal An internal refactor or improvement label May 27, 2025
@dcreager dcreager requested a review from sharkdp as a code owner May 27, 2025 19:50
@dcreager dcreager added the ty Multi-file analysis & type inference label May 27, 2025
@dcreager
Copy link
Member Author

/cc @dhruvmanila re the CallableType changes

@github-actions
Copy link
Contributor

github-actions bot commented May 27, 2025

mypy_primer results

No ecosystem changes detected ✅

Copy link
Member Author

Choose a reason for hiding this comment

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

The diff of this file is less chatty if you hide whitespace

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

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

Nice! This looks reasonable to me 👍

}

/// Returns the call signatures of a type.
/// Returns an empty [`Bindings`] that can be used to analyze a call to this type.
Copy link
Member

Choose a reason for hiding this comment

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

nit: It might be useful to provide a brief description on what "an empty Bindings" mean here as I don't think it's about an empty Bindings::elements but more about the fact that this is kind of an "initial" state before matching any parameters to the arguments and doing type checking.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! By "empty" I meant that you have to do more work to actually analyze a call site using the Bindings you get back. I reworded the comment and added some more detail to explain that better.

dcreager added 2 commits May 28, 2025 11:30
* main:
  [ty] Support ephemeral uv virtual environments (#18335)
  Add a `ViolationMetadata::rule` method (#18234)
  Return `DiagnosticGuard` from `Checker::report_diagnostic` (#18232)
  [flake8_use_pathlib]: Replace os.symlink with Path.symlink_to (PTH211) (#18337)
  [ty] Support cancellation and retry in the server (#18273)
  [ty] Synthetic function-like callables (#18242)
  [ty] Support publishing diagnostics in the server (#18309)
  Add Autofix for ISC003 (#18256)
  [`pyupgrade`]: new rule UP050 (`useless-class-metaclass-type`) (#18334)
  [pycodestyle] Make `E712` suggestion not assume a context (#18328)
@dcreager dcreager merged commit 452f992 into main May 28, 2025
35 checks passed
@dcreager dcreager deleted the dcreager/dunder-call branch May 28, 2025 17:11
carljm added a commit to MatthewMckee4/ruff that referenced this pull request May 28, 2025
* main: (246 commits)
  [ty] Simplify signature types, use them in `CallableType` (astral-sh#18344)
  [ty] Support ephemeral uv virtual environments (astral-sh#18335)
  Add a `ViolationMetadata::rule` method (astral-sh#18234)
  Return `DiagnosticGuard` from `Checker::report_diagnostic` (astral-sh#18232)
  [flake8_use_pathlib]: Replace os.symlink with Path.symlink_to (PTH211) (astral-sh#18337)
  [ty] Support cancellation and retry in the server (astral-sh#18273)
  [ty] Synthetic function-like callables (astral-sh#18242)
  [ty] Support publishing diagnostics in the server (astral-sh#18309)
  Add Autofix for ISC003 (astral-sh#18256)
  [`pyupgrade`]: new rule UP050 (`useless-class-metaclass-type`) (astral-sh#18334)
  [pycodestyle] Make `E712` suggestion not assume a context (astral-sh#18328)
  put similar dunder-call tests next to each other (astral-sh#18343)
  [ty] Derive `PartialOrd, Ord` for `KnownInstanceType` (astral-sh#18340)
  [ty] Simplify `Type::try_bool()` (astral-sh#18342)
  [ty] Simplify `Type::normalized` slightly (astral-sh#18339)
  [ty] Move arviz off the list of selected primer projects (astral-sh#18336)
  [ty] Add --config-file CLI arg (astral-sh#18083)
  [ty] Tell the user why we inferred a certain Python version when reporting version-specific syntax errors (astral-sh#18295)
  [ty] Implement implicit inheritance from `Generic[]` for PEP-695 generic classes (astral-sh#18283)
  [ty] Add hint if async context manager is used in non-async with statement (astral-sh#18299)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants