-
-
Notifications
You must be signed in to change notification settings - Fork 265
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
Infer modulo operations on strings #1617
Infer modulo operations on strings #1617
Conversation
ChangeLog
Outdated
@@ -26,6 +26,10 @@ Release date: TBA | |||
|
|||
Closes #104 | |||
|
|||
* Module (``%``) operations on strings are now correctly inferred. |
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 think we should call it %-formatting
to avoid sounding like the mathematical modulo operator.
tests/unittest_inference.py
Outdated
""", | ||
], | ||
) | ||
def test_string_modulation_uninferable(self, format_string: str) -> None: |
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.
Same
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 can't use %
in a function name. So percentage_formatting
then?
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.
How about c_style_formatting
old_string_formatting
, printf_style_formatting
or interpolation_formatting
? (I checked the python doc to see how it's called : https://docs.python.org/3/tutorial/inputoutput.html#old-string-formatting)
Pull Request Test Coverage Report for Build 2517492739
💛 - Coveralls |
astroid/inference.py
Outdated
const_node = nodes.const_factory(instance.value % values) | ||
except (TypeError, KeyError): | ||
return (util.Uninferable,) | ||
|
||
return (const_node,) |
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.
const_node = nodes.const_factory(instance.value % values) | |
except (TypeError, KeyError): | |
return (util.Uninferable,) | |
return (const_node,) | |
return (nodes.const_factory(instance.value % values),) | |
except (TypeError, KeyError): | |
return (util.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.
Done!
for pair in other.items: | ||
key = helpers.safe_infer(pair[0], context) | ||
if not isinstance(key, nodes.Const): | ||
return (util.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.
This line is not covered, I guess it's not worth 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.
Covered now!
Steps
Description
Closes #151
Type of Changes