@@ -5,18 +5,11 @@ use crate::alt::answers::AnswersSolver;
5
5
use crate :: alt:: answers:: LookupAnswer ;
6
6
use crate :: alt:: types:: class_metadata:: ClassSynthesizedField ;
7
7
use crate :: alt:: types:: class_metadata:: ClassSynthesizedFields ;
8
+ use crate :: binding:: binding:: KeyClassField ;
8
9
use crate :: dunder;
9
10
use crate :: error:: collector:: ErrorCollector ;
10
11
use crate :: error:: kind:: ErrorKind ;
11
- use crate :: types:: callable:: Callable ;
12
- use crate :: types:: callable:: FuncMetadata ;
13
- use crate :: types:: callable:: Function ;
14
- use crate :: types:: callable:: Param ;
15
- use crate :: types:: callable:: ParamList ;
16
- use crate :: types:: callable:: Params ;
17
- use crate :: types:: callable:: Required ;
18
12
use crate :: types:: class:: Class ;
19
- use crate :: types:: types:: Type ;
20
13
21
14
// https://github.com/python/cpython/blob/a8ec511900d0d84cffbb4ee6419c9a790d131129/Lib/functools.py#L173
22
15
// conversion order of rich comparison methods:
@@ -42,23 +35,10 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
42
35
for other_cmp in conversion_order {
43
36
let other_cmp_field = cls. fields ( ) . find ( |f| * * f == * other_cmp) ;
44
37
if other_cmp_field. is_some ( ) {
45
- // FIXME: We should use the type from `other_cmp_field` instead of `cls_type`.
46
- // However, here we use the type of the class itself, which is not always correct.
47
- let cls_type = self . instantiate ( cls) ;
48
- let self_param = self . class_self_param ( cls, false ) ;
49
- let other_param =
50
- Param :: Pos ( Name :: new_static ( "other" ) , cls_type, Required :: Required ) ;
51
- return ClassSynthesizedField :: new ( Type :: Function ( Box :: new ( Function {
52
- signature : Callable {
53
- params : Params :: List ( ParamList :: new ( vec ! [ self_param, other_param] ) ) ,
54
- ret : self . stdlib . bool ( ) . clone ( ) . to_type ( ) ,
55
- } ,
56
- metadata : FuncMetadata :: def (
57
- self . module_info ( ) . name ( ) ,
58
- cls. name ( ) . clone ( ) ,
59
- cmp. clone ( ) ,
60
- ) ,
61
- } ) ) ) ;
38
+ let other_cmp_field =
39
+ self . get_from_class ( cls, & KeyClassField ( cls. index ( ) , other_cmp. clone ( ) ) ) ;
40
+ let ty = other_cmp_field. as_named_tuple_type ( ) ;
41
+ return ClassSynthesizedField :: new ( ty) ;
62
42
}
63
43
}
64
44
unreachable ! ( "No rich comparison method found for {}" , cmp) ;
0 commit comments