@@ -510,9 +510,14 @@ def __repr__(self, firstPass=True):
510
510
pass
511
511
return "\n " .join (to_print )
512
512
513
- def clone (self ):
513
+ def clone (self , ** kwargs ):
514
514
"""Return a new, un-owned `Variable` like `self`.
515
515
516
+ Parameters
517
+ ----------
518
+ **kwargs : dict
519
+ Optional "name" keyword argument for the copied instance. Same as `self.name` if value not provided.
520
+
516
521
Returns
517
522
-------
518
523
Variable instance
@@ -523,7 +528,8 @@ def clone(self):
523
528
Tags and names are copied to the returned instance.
524
529
525
530
"""
526
- cp = self .__class__ (self .type , None , None , self .name )
531
+ name = kwargs .pop ("name" , self .name )
532
+ cp = self .__class__ (type = self .type , owner = None , index = None , name = name , ** kwargs )
527
533
cp .tag = copy (self .tag )
528
534
return cp
529
535
@@ -621,8 +627,8 @@ def __getstate__(self):
621
627
class AtomicVariable (Variable [_TypeType , None ]):
622
628
"""A node type that has no ancestors and should never be considered an input to a graph."""
623
629
624
- def __init__ (self , type : _TypeType , ** kwargs ):
625
- super ().__init__ (type , None , None , ** kwargs )
630
+ def __init__ (self , type : _TypeType , name : Optional [ str ] = None , ** kwargs ):
631
+ super ().__init__ (type = type , owner = None , index = None , name = name , ** kwargs )
626
632
627
633
@abc .abstractmethod
628
634
def signature (self ):
@@ -656,6 +662,12 @@ def index(self, value):
656
662
if value is not None :
657
663
raise ValueError ("AtomicVariable instances cannot have an index." )
658
664
665
+ def clone (self , ** kwargs ):
666
+ name = kwargs .pop ("name" , self .name )
667
+ cp = self .__class__ (type = self .type , name = name , ** kwargs )
668
+ cp .tag = copy (self .tag )
669
+ return cp
670
+
659
671
660
672
class NominalVariable (AtomicVariable [_TypeType ]):
661
673
"""A variable that enables alpha-equivalent comparisons."""
@@ -682,12 +694,13 @@ def _str(self):
682
694
683
695
return cls .__instances__ [(typ , id )]
684
696
685
- def __init__ (self , id : _IdType , typ : _TypeType , ** kwargs ):
697
+ def __init__ (self , id : _IdType , typ : _TypeType , name : Optional [ str ] = None ):
686
698
self .id = id
687
- super ().__init__ (typ , ** kwargs )
699
+ super ().__init__ (type = typ , name = name )
688
700
689
- def clone (self ):
690
- return self
701
+ def clone (self , ** kwargs ):
702
+ name = kwargs .pop ("name" , self .name )
703
+ return self .__class__ (id = self .id , typ = self .type , name = name , ** kwargs )
691
704
692
705
def __eq__ (self , other ):
693
706
if self is other :
@@ -744,8 +757,7 @@ def __str__(self):
744
757
name = name [:10 ] + "..." + name [- 10 :]
745
758
return f"{ type (self ).__name__ } {{{ name } }}"
746
759
747
- def clone (self ):
748
- """Return `self`, because there's no reason to clone a constant."""
760
+ def clone (self , ** kwargs ):
749
761
return self
750
762
751
763
@property
0 commit comments