@@ -556,29 +556,27 @@ def slots_setstate(self, state):
556
556
557
557
def add_repr (self , ns ):
558
558
if "__repr__" in self ._cls .__dict__ :
559
- meth = getattr (self ._cls , "__repr__" )
560
- else :
561
- meth = self ._add_method_dunders (_make_repr (self ._attrs , ns = ns ))
559
+ return self
562
560
563
- self ._cls_dict ["__repr__" ] = meth
561
+ self ._cls_dict ["__repr__" ] = self ._add_method_dunders (
562
+ _make_repr (self ._attrs , ns = ns )
563
+ )
564
564
return self
565
565
566
566
def add_str (self ):
567
567
if "__str__" in self ._cls .__dict__ :
568
- meth = getattr (self ._cls , "__str__" )
569
- else :
570
- repr = self ._cls_dict .get ("__repr__" )
571
- if repr is None :
572
- raise ValueError (
573
- "__str__ can only be generated if a __repr__ exists."
574
- )
568
+ return self
575
569
576
- def __str__ (self ):
577
- return self .__repr__ ()
570
+ repr = self ._cls_dict .get ("__repr__" )
571
+ if repr is None :
572
+ raise ValueError (
573
+ "__str__ can only be generated if a __repr__ exists."
574
+ )
578
575
579
- meth = self ._add_method_dunders (__str__ )
576
+ def __str__ (self ):
577
+ return self .__repr__ ()
580
578
581
- self ._cls_dict ["__str__" ] = meth
579
+ self ._cls_dict ["__str__" ] = self . _add_method_dunders ( __str__ )
582
580
return self
583
581
584
582
def make_unhashable (self ):
@@ -587,28 +585,27 @@ def make_unhashable(self):
587
585
588
586
def add_hash (self ):
589
587
if "__hash__" in self ._cls .__dict__ :
590
- meth = getattr (self ._cls , "__hash__" )
591
- else :
592
- meth = self ._add_method_dunders (_make_hash (self ._attrs ))
588
+ return self
593
589
594
- self ._cls_dict ["__hash__" ] = meth
590
+ self ._cls_dict ["__hash__" ] = self ._add_method_dunders (
591
+ _make_hash (self ._attrs )
592
+ )
595
593
return self
596
594
597
595
def add_init (self ):
598
596
if "__init__" in self ._cls .__dict__ :
599
- meth = getattr (self ._cls , "__init__" )
600
- else :
601
- meth = self ._add_method_dunders (
602
- _make_init (
603
- self ._attrs ,
604
- self ._has_post_init ,
605
- self ._frozen ,
606
- self ._slots ,
607
- self ._super_attr_map ,
608
- )
597
+ return self
598
+
599
+ self ._cls_dict ["__init__" ] = self ._add_method_dunders (
600
+ _make_init (
601
+ self ._attrs ,
602
+ self ._has_post_init ,
603
+ self ._frozen ,
604
+ self ._slots ,
605
+ self ._super_attr_map ,
609
606
)
607
+ )
610
608
611
- self ._cls_dict ["__init__" ] = meth
612
609
return self
613
610
614
611
def add_cmp (self ):
@@ -618,11 +615,9 @@ def add_cmp(self):
618
615
method_name = meth .__name__
619
616
620
617
if method_name in self ._cls .__dict__ :
621
- meth = getattr (self ._cls , method_name )
622
- else :
623
- meth = self ._add_method_dunders (meth )
618
+ continue
624
619
625
- cd [method_name ] = meth
620
+ cd [method_name ] = self . _add_method_dunders ( meth )
626
621
627
622
return self
628
623
0 commit comments