mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 05:54:25 +08:00
Magic methods fixes for reverse methods
This commit is contained in:
@@ -661,15 +661,19 @@ def _infer_comparison_part(inference_state, context, left, operator, right):
|
||||
|
||||
method_name = operator_to_magic_method[str_operator]
|
||||
magic_methods = left.py__getattribute__(method_name)
|
||||
if not magic_methods:
|
||||
reverse_method_name = reverse_operator_to_magic_method[str_operator]
|
||||
magic_methods = left.py__getattribute__(reverse_method_name)
|
||||
|
||||
if magic_methods:
|
||||
result = magic_methods.execute_with_values(right)
|
||||
if result:
|
||||
return result
|
||||
|
||||
if not magic_methods:
|
||||
reverse_method_name = reverse_operator_to_magic_method[str_operator]
|
||||
magic_methods = right.py__getattribute__(reverse_method_name)
|
||||
|
||||
result = magic_methods.execute_with_values(left)
|
||||
if result:
|
||||
return result
|
||||
|
||||
result = ValueSet([left, right])
|
||||
debug.dbg('Used operator %s resulting in %s', operator, result)
|
||||
return result
|
||||
|
||||
@@ -159,6 +159,25 @@ from datetime import datetime, timedelta
|
||||
#? datetime()
|
||||
(datetime() - timedelta())
|
||||
#? timedelta()
|
||||
(datetime() - datetime())
|
||||
#? timedelta()
|
||||
(timedelta() - datetime())
|
||||
#? timedelta()
|
||||
(timedelta() - timedelta())
|
||||
|
||||
# -----------------
|
||||
# magic methods
|
||||
# -----------------
|
||||
|
||||
class C:
|
||||
def __sub__(self, other) -> int: ...
|
||||
def __radd__(self, other) -> float: ...
|
||||
|
||||
#? int()
|
||||
(C() - object())
|
||||
#? C() object()
|
||||
(object() - C())
|
||||
#? C() object()
|
||||
(C() + object())
|
||||
#? float()
|
||||
(object() + C())
|
||||
|
||||
Reference in New Issue
Block a user