@@ -436,17 +436,11 @@ impl PyContext {
436
436
}
437
437
438
438
pub fn new_tuple ( & self , elements : Vec < PyObjectRef > ) -> PyObjectRef {
439
- PyObject :: new (
440
- PyObjectPayload :: Sequence { elements : elements } ,
441
- self . tuple_type ( ) ,
442
- )
439
+ PyObject :: new ( PyObjectPayload :: Sequence { elements } , self . tuple_type ( ) )
443
440
}
444
441
445
442
pub fn new_list ( & self , elements : Vec < PyObjectRef > ) -> PyObjectRef {
446
- PyObject :: new (
447
- PyObjectPayload :: Sequence { elements : elements } ,
448
- self . list_type ( ) ,
449
- )
443
+ PyObject :: new ( PyObjectPayload :: Sequence { elements } , self . list_type ( ) )
450
444
}
451
445
452
446
pub fn new_set ( & self , elements : Vec < PyObjectRef > ) -> PyObjectRef {
@@ -469,12 +463,11 @@ impl PyContext {
469
463
470
464
pub fn new_scope ( & self , parent : Option < PyObjectRef > ) -> PyObjectRef {
471
465
let locals = self . new_dict ( ) ;
472
- let scope = Scope {
473
- locals : locals,
474
- parent : parent,
475
- } ;
466
+
467
+ let scope = Scope { locals, parent } ;
468
+
476
469
PyObject {
477
- payload : PyObjectPayload :: Scope { scope : scope } ,
470
+ payload : PyObjectPayload :: Scope { scope } ,
478
471
typ : None ,
479
472
}
480
473
. into_ref ( )
@@ -553,10 +546,7 @@ impl PyContext {
553
546
554
547
pub fn new_bound_method ( & self , function : PyObjectRef , object : PyObjectRef ) -> PyObjectRef {
555
548
PyObject :: new (
556
- PyObjectPayload :: BoundMethod {
557
- function : function,
558
- object : object,
559
- } ,
549
+ PyObjectPayload :: BoundMethod { function, object } ,
560
550
self . bound_method_type ( ) ,
561
551
)
562
552
}
@@ -581,10 +571,7 @@ impl PyContext {
581
571
let key = self . new_str ( key. to_string ( ) ) ;
582
572
objdict:: set_item_in_content ( elements, & key, & v) ;
583
573
}
584
- PyObjectPayload :: Module {
585
- name : _,
586
- ref mut dict,
587
- } => self . set_item ( dict, key, v) ,
574
+ PyObjectPayload :: Module { ref mut dict, .. } => self . set_item ( dict, key, v) ,
588
575
PyObjectPayload :: Scope { ref mut scope } => {
589
576
self . set_item ( & scope. locals , key, v) ;
590
577
}
@@ -601,13 +588,9 @@ impl PyContext {
601
588
602
589
pub fn set_attr ( & self , obj : & PyObjectRef , attr_name : & str , value : PyObjectRef ) {
603
590
match obj. borrow ( ) . payload {
604
- PyObjectPayload :: Module { name : _ , ref dict } => self . set_item ( dict, attr_name, value) ,
591
+ PyObjectPayload :: Module { ref dict, .. } => self . set_item ( dict, attr_name, value) ,
605
592
PyObjectPayload :: Instance { ref dict } => self . set_item ( dict, attr_name, value) ,
606
- PyObjectPayload :: Class {
607
- name : _,
608
- ref dict,
609
- mro : _,
610
- } => self . set_item ( dict, attr_name, value) ,
593
+ PyObjectPayload :: Class { ref dict, .. } => self . set_item ( dict, attr_name, value) ,
611
594
ref payload => unimplemented ! ( "set_attr unimplemented for: {:?}" , payload) ,
612
595
} ;
613
596
}
@@ -732,7 +715,7 @@ impl AttributeProtocol for PyObjectRef {
732
715
fn has_attr ( & self , attr_name : & str ) -> bool {
733
716
let obj = self . borrow ( ) ;
734
717
match obj. payload {
735
- PyObjectPayload :: Module { name : _ , ref dict } => dict. contains_key ( attr_name) ,
718
+ PyObjectPayload :: Module { ref dict, .. } => dict. contains_key ( attr_name) ,
736
719
PyObjectPayload :: Class { ref mro, .. } => {
737
720
class_has_item ( self , attr_name)
738
721
|| mro. into_iter ( ) . any ( |d| class_has_item ( d, attr_name) )
@@ -755,7 +738,7 @@ impl DictProtocol for PyObjectRef {
755
738
PyObjectPayload :: Dict { ref elements } => {
756
739
objdict:: content_contains_key_str ( elements, k)
757
740
}
758
- PyObjectPayload :: Module { name : _ , ref dict } => dict. contains_key ( k) ,
741
+ PyObjectPayload :: Module { ref dict, .. } => dict. contains_key ( k) ,
759
742
PyObjectPayload :: Scope { ref scope } => scope. locals . contains_key ( k) ,
760
743
ref payload => unimplemented ! ( "TODO {:?}" , payload) ,
761
744
}
@@ -764,16 +747,16 @@ impl DictProtocol for PyObjectRef {
764
747
fn get_item ( & self , k : & str ) -> Option < PyObjectRef > {
765
748
match self . borrow ( ) . payload {
766
749
PyObjectPayload :: Dict { ref elements } => objdict:: content_get_key_str ( elements, k) ,
767
- PyObjectPayload :: Module { name : _ , ref dict } => dict. get_item ( k) ,
750
+ PyObjectPayload :: Module { ref dict, .. } => dict. get_item ( k) ,
768
751
PyObjectPayload :: Scope { ref scope } => scope. locals . get_item ( k) ,
769
752
_ => panic ! ( "TODO" ) ,
770
753
}
771
754
}
772
755
773
756
fn get_key_value_pairs ( & self ) -> Vec < ( PyObjectRef , PyObjectRef ) > {
774
757
match self . borrow ( ) . payload {
775
- PyObjectPayload :: Dict { elements : _ } => objdict:: get_key_value_pairs ( self ) ,
776
- PyObjectPayload :: Module { name : _ , ref dict } => dict. get_key_value_pairs ( ) ,
758
+ PyObjectPayload :: Dict { .. } => objdict:: get_key_value_pairs ( self ) ,
759
+ PyObjectPayload :: Module { ref dict, .. } => dict. get_key_value_pairs ( ) ,
777
760
PyObjectPayload :: Scope { ref scope } => scope. locals . get_key_value_pairs ( ) ,
778
761
_ => panic ! ( "TODO" ) ,
779
762
}
@@ -815,10 +798,7 @@ impl PyFuncArgs {
815
798
for name in kwarg_names. iter ( ) . rev ( ) {
816
799
kwargs. push ( ( name. clone ( ) , args. pop ( ) . unwrap ( ) ) ) ;
817
800
}
818
- PyFuncArgs {
819
- args : args,
820
- kwargs : kwargs,
821
- }
801
+ PyFuncArgs { args, kwargs }
822
802
}
823
803
824
804
pub fn insert ( & self , item : PyObjectRef ) -> PyFuncArgs {
@@ -948,37 +928,26 @@ impl fmt::Debug for PyObjectPayload {
948
928
PyObjectPayload :: Complex { ref value } => write ! ( f, "complex {}" , value) ,
949
929
PyObjectPayload :: Bytes { ref value } => write ! ( f, "bytes/bytearray {:?}" , value) ,
950
930
PyObjectPayload :: MemoryView { ref obj } => write ! ( f, "bytes/bytearray {:?}" , obj) ,
951
- PyObjectPayload :: Sequence { elements : _ } => write ! ( f, "list or tuple" ) ,
952
- PyObjectPayload :: Dict { elements : _ } => write ! ( f, "dict" ) ,
953
- PyObjectPayload :: Set { elements : _ } => write ! ( f, "set" ) ,
931
+ PyObjectPayload :: Sequence { .. } => write ! ( f, "list or tuple" ) ,
932
+ PyObjectPayload :: Dict { .. } => write ! ( f, "dict" ) ,
933
+ PyObjectPayload :: Set { .. } => write ! ( f, "set" ) ,
954
934
PyObjectPayload :: WeakRef { .. } => write ! ( f, "weakref" ) ,
955
- PyObjectPayload :: Iterator {
956
- position : _,
957
- iterated_obj : _,
958
- } => write ! ( f, "iterator" ) ,
959
- PyObjectPayload :: Slice {
960
- start : _,
961
- stop : _,
962
- step : _,
963
- } => write ! ( f, "slice" ) ,
964
- & PyObjectPayload :: Range { range : _ } => write ! ( f, "range" ) ,
965
- & PyObjectPayload :: Code { ref code } => write ! ( f, "code: {:?}" , code) ,
966
- & PyObjectPayload :: Function { .. } => write ! ( f, "function" ) ,
967
- & PyObjectPayload :: Generator { .. } => write ! ( f, "generator" ) ,
968
- & PyObjectPayload :: BoundMethod {
935
+ PyObjectPayload :: Range { .. } => write ! ( f, "range" ) ,
936
+ PyObjectPayload :: Iterator { .. } => write ! ( f, "iterator" ) ,
937
+ PyObjectPayload :: Slice { .. } => write ! ( f, "slice" ) ,
938
+ PyObjectPayload :: Code { ref code } => write ! ( f, "code: {:?}" , code) ,
939
+ PyObjectPayload :: Function { .. } => write ! ( f, "function" ) ,
940
+ PyObjectPayload :: Generator { .. } => write ! ( f, "generator" ) ,
941
+ PyObjectPayload :: BoundMethod {
969
942
ref function,
970
943
ref object,
971
944
} => write ! ( f, "bound-method: {:?} of {:?}" , function, object) ,
972
- PyObjectPayload :: Module { name : _ , dict : _ } => write ! ( f, "module" ) ,
973
- PyObjectPayload :: Scope { scope : _ } => write ! ( f, "scope" ) ,
945
+ PyObjectPayload :: Module { .. } => write ! ( f, "module" ) ,
946
+ PyObjectPayload :: Scope { .. } => write ! ( f, "scope" ) ,
974
947
PyObjectPayload :: None => write ! ( f, "None" ) ,
975
- PyObjectPayload :: Class {
976
- ref name,
977
- dict : _,
978
- mro : _,
979
- } => write ! ( f, "class {:?}" , name) ,
980
- PyObjectPayload :: Instance { dict : _ } => write ! ( f, "instance" ) ,
981
- PyObjectPayload :: RustFunction { function : _ } => write ! ( f, "rust function" ) ,
948
+ PyObjectPayload :: Class { ref name, .. } => write ! ( f, "class {:?}" , name) ,
949
+ PyObjectPayload :: Instance { .. } => write ! ( f, "instance" ) ,
950
+ PyObjectPayload :: RustFunction { .. } => write ! ( f, "rust function" ) ,
982
951
PyObjectPayload :: Frame { .. } => write ! ( f, "frame" ) ,
983
952
}
984
953
}
@@ -1035,16 +1004,17 @@ impl PyObject {
1035
1004
PyObjectPayload :: Class {
1036
1005
ref name,
1037
1006
dict : ref _dict,
1038
- mro : _ ,
1007
+ ..
1039
1008
} => format ! ( "<class '{}'>" , name) ,
1040
- PyObjectPayload :: Instance { dict : _ } => format ! ( "<instance>" ) ,
1041
- PyObjectPayload :: Code { code : _ } => format ! ( "<code>" ) ,
1042
- PyObjectPayload :: Function { .. } => format ! ( "<func>" ) ,
1043
- PyObjectPayload :: Generator { .. } => format ! ( "<generator>" ) ,
1044
- PyObjectPayload :: Frame { .. } => format ! ( "<frame>" ) ,
1045
- PyObjectPayload :: BoundMethod { .. } => format ! ( "<bound-method>" ) ,
1046
- PyObjectPayload :: RustFunction { function : _ } => format ! ( "<rustfunc>" ) ,
1047
- PyObjectPayload :: Module { ref name, dict : _ } => format ! ( "<module '{}'>" , name) ,
1009
+
1010
+ PyObjectPayload :: Instance { .. } => "<instance>" . to_string ( ) ,
1011
+ PyObjectPayload :: Code { .. } => "<code>" . to_string ( ) ,
1012
+ PyObjectPayload :: Function { .. } => "<func>" . to_string ( ) ,
1013
+ PyObjectPayload :: Generator { .. } => "<generator>" . to_string ( ) ,
1014
+ PyObjectPayload :: Frame { .. } => "<frame>" . to_string ( ) ,
1015
+ PyObjectPayload :: BoundMethod { .. } => "<bound-method>" . to_string ( ) ,
1016
+ PyObjectPayload :: RustFunction { .. } => "<rustfunc>" . to_string ( ) ,
1017
+ PyObjectPayload :: Module { ref name, .. } => format ! ( "<module '{}'>" , name) ,
1048
1018
PyObjectPayload :: Scope { ref scope } => format ! ( "<scope '{:?}'>" , scope) ,
1049
1019
PyObjectPayload :: Slice {
1050
1020
ref start,
0 commit comments