Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] function signature representation #14304

Merged
merged 3 commits into from
Nov 14, 2024
Merged

[red-knot] function signature representation #14304

merged 3 commits into from
Nov 14, 2024

Conversation

carljm
Copy link
Contributor

@carljm carljm commented Nov 13, 2024

Summary

Add a typed representation of function signatures (parameters and return type) and infer it correctly from a function.

Convert existing usage of function return types to use the signature representation.

This does not yet add inferred types for parameters within function body scopes based on the annotations, but it should be easy to add as a next step.

Part of #14161 and #13693.

Test Plan

Added tests.

@carljm carljm added the red-knot Multi-file analysis & type inference label Nov 13, 2024
Copy link
Contributor

github-actions bot commented Nov 13, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@carljm carljm changed the title [red-knot] full function signature representation [red-knot] function signature representation Nov 13, 2024
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Looks good. My main feedback is whether its worth having separate fields for the different parameter kinds or if we instead want to store all parameters in a single slice and only distinguish them by a kind (which I think is what pyright does and we at least considered for the AST because concatenating parameters and always remembering the right order is awkward)

crates/red_knot_python_semantic/src/types.rs Outdated Show resolved Hide resolved
crates/red_knot_python_semantic/src/types/signatures.rs Outdated Show resolved Hide resolved
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.

Nice!

Base automatically changed from cjm/deftypes to main November 13, 2024 13:53
@carljm carljm enabled auto-merge (squash) November 14, 2024 23:30
@carljm carljm merged commit a48d779 into main Nov 14, 2024
16 checks passed
@carljm carljm deleted the cjm/signatures branch November 14, 2024 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants