-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Implement inference for JoinedStr
and FormattedValue
#2459
Implement inference for JoinedStr
and FormattedValue
#2459
Conversation
astroid/nodes/node_classes.py
Outdated
if node is util.Uninferable: | ||
result += "{Uninferable}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like we should exit early here and not continue to product "half" matching values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's philosophical, depending on the strategy for dealing with partially inferred collections of values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would help to make a decision about this if we could see a test case. At the moment, I do not think we should manufacture a constant that would never exist at runtime with the substring "Uninferable" in it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's "coincidental" coverage of this line in test_typing_extensions_types
based on the current implementation of typing, but it would be better to have explicit coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Jacob. I think Uninferable
makes sense to those that have worked on astroid
and pylint
, but this will also be shown to users who might have no idea what it means. I would be in favour of exiting early and not creating partially correct values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is useful to know which fragment(s) of a JoinedStr cause inference failure, but I agree that half-baked strings can be puzzling.
JoinedStr
and FormattedValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing this feature!
astroid/nodes/node_classes.py
Outdated
if node is util.Uninferable: | ||
result += "{Uninferable}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would help to make a decision about this if we could see a test case. At the moment, I do not think we should manufacture a constant that would never exist at runtime with the substring "Uninferable" in it.
astroid/nodes/node_classes.py
Outdated
if node is util.Uninferable: | ||
result += "{Uninferable}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's "coincidental" coverage of this line in test_typing_extensions_types
based on the current implementation of typing, but it would be better to have explicit coverage.
for more information, see https://pre-commit.ci
…ue' of github.com:ericvergnaud/astroid into support-value-inference-for-joinedstr-and-formatted-value
…ue' of github.com:ericvergnaud/astroid into support-value-inference-for-joinedstr-and-formatted-value # Conflicts: # ChangeLog
Great work ! |
Oh, I just saw the failing tests. I do think we need to address it. |
It's failing on main too, we've merged multiple MR with 3.13 failing in the last week. (Due to a New beta of python 3.13). I think we could (should?) fix it before astroid 3.3.0 release. |
TBH I'm 100% sure that the failure is unrelated to this PR. The test simply calls |
It's fixed in the 3.13rc1, which may not be on GH yet. |
See #2478 |
Type of Changes
Description
node.inferred()
would returnUninferable
if inference involved aJoinedStr
.JoinedStr
involvesFormattedValue
so this is addressed for both classes in the same PR