Skip to content

Enhancement: Support Top-Down Parameter Name Completion for Lambda and Function Assignments (Contextual Scaffolding) #7992

Description

@rob3c

Description

Currently, Pylance/Pyright acts as a "Bottom-Up" validator. It waits for a function or lambda to be defined and then verifies if it matches a type hint. This results in a "blind" development experience where the developer must guess or manually look up parameter names (e.g., UI coordinates like x, y, w, h) even when the target type is explicitly defined.

The Request

Implement "Top-Down" contextual completion. When a lambda or function is being assigned to a variable with a known Protocol or Callable type, the language server should suggest the parameter names from that type during declaration.

Sample Code

from typing import Protocol

class UICallback(Protocol):
    def __call__(self, x: int, y: int, width: int, height: int) -> None: ...

# Expected Behavior:
# When I type 'lambda ', the autocomplete should suggest 'x, y, width, height'
handler: UICallback = lambda |

Why this is necessary

  1. Preventing "Dartboard" Coding: In complex callbacks (UI, data processing), remembering the exact order and naming of 4+ parameters is error-prone. The engine already possesses this data via the Protocol; it should surface it as a blueprint rather than just a safety net.
  2. Industry Standard: This is standard behavior in TypeScript (which Pyright draws inspiration from), C# and others. In those languages, the type context flows into the implementation.
  3. Keyword Significance: While positional matching is technically "enough" for some type-checkers, parameter names in Python are semantically important and often required for **kwargs or readability.

Alternatives Considered & Why They Fail

  • Parameter Tooltips: Currently non-functional for Protocols. Hovering over the variable or triggering signature help only displays the Protocol's name (e.g., UICallback) rather than expanding the call signature. It provides zero visibility into expected parameter names or types.
  • Peek Definition: This is the only current "fix", but it is a disruptive navigation-based workaround for information that should be surfaced contextually during assignment.

Final Thoughts

The request so far seems pretty reasonable to me and doable within current language constraints and the understanding Pylance has of the codebase. However, lambdas cannot be multi-line as far as I know. They just seem like the lowest hanging fruit for actually implementing this feature request. However, if you can find a way to surface this information using the "def ..." function definition syntax, that would be amazing!

Thanks in advance for your consideration!

Metadata

Metadata

Assignees

Labels

ai-triage-respondedIndicate whether the AI triage agent has responded to this issue.team needs to reproduceIssue has not been reproduced yet

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions