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

Evaluate default parameter value in enclosing scope #12852

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

dhruvmanila
Copy link
Member

Summary

This PR fixes a bug in the semantic model where it would evaluate the default parameter value in the type parameter scope. For example,

def foo[T1: int](a = T1):
    pass

Here, the T1 in a = T1 is undefined but Ruff doesn't flag it (https://play.ruff.rs/ba2f7c2f-4da6-417e-aa2a-104aa63e6d5e).

The fix here is to evaluate the default parameter value in the enclosing scope instead.

Test Plan

Add a test case which includes the above code under F821 (undefined-name) and validate the snapshot.

@dhruvmanila dhruvmanila added the bug Something isn't working label Aug 13, 2024
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

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 catch, LGTM!

@dhruvmanila dhruvmanila merged commit 899a523 into main Aug 13, 2024
20 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/default-param branch August 13, 2024 13:55
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants