Skip to content

Evaluate default parameter value in enclosing scope#12852

Merged
dhruvmanila merged 1 commit intomainfrom
dhruv/default-param
Aug 13, 2024
Merged

Evaluate default parameter value in enclosing scope#12852
dhruvmanila merged 1 commit intomainfrom
dhruv/default-param

Conversation

@dhruvmanila
Copy link
Copy Markdown
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
@github-actions
Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Copy Markdown
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
@dhruvmanila dhruvmanila deleted the dhruv/default-param branch August 13, 2024 13:55
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