Fix attribute completion for expressions with comparison operators#14898
Fix attribute completion for expressions with comparison operators#14898krassowski merged 7 commits intoipython:mainfrom
Conversation
|
@krassowski |
I thought about checking against maths operators ( Given |
|
Do you think it might be a good idea to strip all operators except the dot operator? It seems to pass all the cases I can think of. |
krassowski
left a comment
There was a problem hiding this comment.
Do you think it might be a good idea to strip all operators except the dot operator? It seems to pass all the cases I can think of.
Makes sense. Can you add the a + b to test cases, and then run darker to make the CI pass?
…ith comparison operators
Fixes #14897
Description
Modified
_attr_matches()to check if an expression contains comparison operators(=, ==, !=, etc.)outside of parentheses. If so, it extracts the right-hand side of the operator for evaluation, providing appropriate completions.For parenthesized expressions like
(x==y).<tab>, the code preserves the entire expression to ensure it's evaluated as a bool.Fixing completions fully is quite tricky. The current implementation still has flaws, especially in cases where comparison operators are involved. For example:
{"==", "abc"}.<tab>In this case, dictionary methods are not shown because the logic incorrectly separates the expression at the
"=="operator.While the current solution resolves some major issues, it also introduces new, albeit minor, ones.
Feedback on better approaches or alternative strategies is highly appreciated.