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

[scope] Visit concatenated f-strings #411

Merged
merged 5 commits into from
Nov 6, 2020

Conversation

zsol
Copy link
Member

@zsol zsol commented Nov 3, 2020

Summary

This PR makes sure scope analysis visits nodes under a ConcatenatedString. This is important because ConcatenatedStrings may contain FormattedStrings which can contain further expressions. We only need to go deeper if the concatenated string is not part of a type annotation though (those can't contain f-strings).

Fixes #410.

Test Plan

Added unit test.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 3, 2020
Copy link
Contributor

@jimmylai jimmylai left a comment

Choose a reason for hiding this comment

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

LGTM with a minor comment.

Comment on lines 130 to 131
assert isinstance(b_referent, Assignment) # for the typechecker's eyes
self.assertEqual(b_referent.node, import_node)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we do this instead? We usually don't use assert because it's a noop in optimized mode.

if isinstance(b_referent, Assignment):
    self.assertEqual(b_referent.node, import_node)

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, but it doesn't matter much because there's a

self.assertIsInstance(b_referent, Assignment)

right above it, so if the assertion fails, no further code will be executed

@zsol zsol merged commit dd521f5 into Instagram:master Nov 6, 2020
@zsol zsol deleted the scope-concat-strings branch November 6, 2020 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ScopeProvider misses accesses within f-strings nested in concatenated strings
3 participants