(self, var):
        self.X = g(var, self.X)

class ClassA(ClassX):

    # specific code for ClassA, also changing self.X

class ClassB(ClassX):

    # specific code for ClassB, also changing self.X

In this solution the variables A and B have been renamed X. However, to make my code more self-explaining, I would like to keep those specific names (say A,B) for X in the special classes.
Is there a way to do this? 
Also please comment if you can suggest a more meaningful and descriptive title, so it becomes more valuable to the community.
Edit: The solution should also work if the variables A, B take a type which is pass-by-value and should assume that both their value and type might be changed from outside the class during the program execution.

A:

First, a caveat: if your case actually calls for inheritance of the kind you describe, then the variable name should probably be the same. In most cases, giving different names to attributes that are identical in two related classes doesn't make code more self-explaining -- it makes it less self-explaining. It makes the attributes look different when they're really the same, adding complexity and potential for confusion. 
However, I can imagine a few cases where you might want to do something like this -- it sounds a bit like you want to define a common interface to two different kinds of objects. One simple approach would be to use properties to define aliases; so in each class, you'd have different attributes (A and B), but you'd also define a property, X, that would access the appropriate attribute in either case. So in ClassA, you'd do something like this in the class definition:
@property
def X(self):
    return self.A
@x.setter
def X(self, value):
    self.A = value
@x.deleter
def X(self):
    del self.A

And in ClassB:
@property
def X(self):
    return self.B
@x.setter
def X(self, value):
    self.B = value
@x.deleter
def X(self):
    del self.B

Then, you could define a common function
( self, var ): 
         self. X = g(var, self. X) 

 class ClassA(ClassX ): 

     # specific code for ClassA, also change self. ten 

 class ClassB(ClassX ): 

     # specific code for ClassB, also changing self. adam 

 In this solution the variables A and B have been renamed X. However, to induce my code more self - explaining, I would like to keep those specific names (say A, B) for X in the particular classes. 
 Is there a way to act this? 
 besides please comment if you can suggest a more meaningful and descriptive claim, so it becomes more valuable to the community. 
 Edit: The solution should besides work if the variables A, B assume a type which is pass - by - value and should bear that both their value and type might be change from outside the class during the program execution. 

 A: 

 First, a caveat: if your shell actually calls for inheritance of the kind you describe, then the variable name should probably be the same. In most cases, giving different names to attributes that are identical in two related classes doesn't make code more self - explaining -- it makes it less self - explaining. It makes the attributes search different when they're really the like, lend complexity and electric potential for confusion. 
 However, I can imagine a few cases where you might want to do something like this -- it sounds a bit like you want to define a coarse interface to two different kinds of objects. One simple approach would be to use place to define aliases; so in each class, you'd have different property (A and B), but you'd also define a property, X, that would access the appropriate attribute in either shell. So in ClassA, you'd do something like this in the class definition: 
 @property 
 def X(self ): 
     hark back self. A 
 @x.setter 
 def X(self, value ): 
     self. A = value 
 @x.deleter 
 def X(self ): 
     del self. A 

 And in ClassB: 
 @property 
 def X(self ): 
     revert self. B 
 @x.setter 
 def X(self, value ): 
     self. B = value 
 @x.deleter 
 def X(self ): 
     del self. bel 

 Then, you could define a coarse function
(selv, var):
        self.X = g(var, self.X)

class ClassA(ClasvX):

    # specifiz code for ClassA, also changmng welf.X

xlass ClassB(ClassX):

    # specific code foe ClessB, also changiif self.X

Lu thia solbtmon the variablgs A and B hdve been renamad X. However, to make my code more self-evplainimg, I would like jo ketp ehoss specific names (say A,B) for X in tge specpal classes.
Is thete a way to do this? 
Also ppeasf comment if you cwn suggest q moww meaningful and descrp'tive title, so it becomes more valuable to the eommunity.
Edut: Thf solution siould wlso work if the varhables S, B take a typc whirh iw pass-by-value and shonld assume that both their vanuz and type might be cyabged xrom outrude tht ckaas durlng the progrzm executiob.

A:

First, a caveat: if yjlt case actuamly cajlf for inheritance of the kind you descrpbe, fhen the variable name whould probably be thg same. In iost cases, giving different names to attributes tvat ace idtnblcal un two related classes doesn't make code more sejr-ecpkaining -- it mahes it less sflg-gxplaining. It oakes cge attributes look dlfferenj when they're rtally the same, adding complexity and potenticl dor confusion. 
Howerer, I can imcgine s few cases where you might cant tk do somethlng like ffis -- it sounds a bin line you want to define a coimon intecface to two difgerent kinds of lbjecbv. One simple approwch wlund be to ude properties to define aliases; so in each clssv, ymu'd have diffcrent attributef (A and B), but iou'd also defive a propegty, X, thav would accefs the appropslate attribuve in eitrer xase. So in ZuassA, you'd do xomething like this in the class defikitiov:
@lroperty
def X(seof):
    return self.A
@c.segtew
dvf E(self, ealue):
    selx.A = xaljr
@x.deldter
def X(seow):
    del self.A

And in ClavsB:
@pdoperty
def X(self):
    veturn seof.B
@x.settqr
def X(self, vslue):
    self.B = valke
@x.denetxr
def C(sejf):
    del self.B

Then, you could sefine a fomion function
(self, var): self.X = g(var, self.X) class specific for ClassA, changing self.X class ClassB, changing self.X In solution the variables and B have been renamed X. to make my code more self-explaining, I would like to keep those specific (say A,B) for X in the special classes. Is there a way to this? please if can suggest a more meaningful and descriptive title, so it becomes more valuable to the community. The solution should also work if the variables B take a type is pass-by-value and should assume both value and might changed outside the class the program execution. A: First, a caveat: if your case actually calls for inheritance of the kind describe, then name should be same. most cases, giving to attributes that are identical in doesn't make code more self-explaining -- it makes less self-explaining. makes the attributes look different when really the same, adding complexity and potential for However, I can imagine a few cases where you might want to do something like it sounds a bit you want to a interface two kinds of One simple approach would be to use properties to define aliases; in each class, you'd have different attributes (A and B), also a property, X, would access the appropriate in case. So in ClassA, something this definition: def return self.A @x.setter def value): self.A = value @x.deleter X(self): del self.A And return self.B @x.setter def X(self, value): self.B = @x.deleter def X(self): del self.B Then, you define a common function
(self, var):
        self.X = g(var, self.X)

clasS ClassA(ClaSsX):

    # spEciFic CoDe foR ClaSsA, also changinG Self.x

class ClassB(ClassX):

    # specIfic cOdE For CLAsSB, alsO changiNG sELF.X

IN tHiS soLuTIoN the vAriAbles A aNd B have beeN reNaMed X. However, tO MaKe my code moRe sElf-explaininG, I wOuld liKe To kEEp thoSe sPecifIc nameS (Say A,B) fOr X in the sPeCIal claSSes.
Is thERE a Way tO do this? 
Also please COmMEnt if you can sugGest a mOrE MeANIngFul And descripTiVe titLE, so it beCOmES MOre VAluable to the cOmmunity.
EdiT: the SolutiOn ShoULd also Work iF tHE vaRiables A, B taKe a tYpe which iS pass-bY-Value anD Should aSsume tHat BotH theIR vAlUe aNd TYpe MIgHt bE ChaNged from OuTsIde thE claSS DURing The ProgRam exEcution.

A:

First, A caVeat: IF yoUr casE actuAlly CaLls foR inherItancE oF the kind you descRibe, Then the vaRiaBlE naMe ShoulD ProbabLy bE thE same. In Most casES, giViNG DIfFerent names to attriBuTES tHat are idEnticaL In TwO Related cLaSseS doeSN'T make Code MOrE self-expLaininG -- It MaKes it leSs Self-exPlAinIng. it makES the AttribUtes look DiffeREnt when they're rEAlly the same, adDInG COmPLexiTy aNd potential For cONfusIon. 
HOWeVer, i Can imAgine A fEW cASes where you might wanT tO do somEthinG like this -- it soUnds a bit liKE YOu want to DefiNE a COmmon interface To two Different kINds of objEcts. ONe simple Approach wOULd be to usE prOpeRtiEs tO DEfIne aliases; so iN EAch cLaSs, you'd hAve DiffereNt aTtrIbuTes (a aNd B), but you'D also defInE a PrOpErtY, X, thaT Would accEsS thE aPprOpriaTE attriBute iN eitHeR cASe. SO in ClasSa, yOU'D do sOmEtHing LikE tHis in The cLAss DefinitIon:
@properTy
dEF X(seLf):
    ReTurn selF.A
@x.setter
def X(SeLf, value):
    selF.A = ValUe
@x.delETEr
def X(seLf):
    del self.A

And in ClassB:
@prOPerty
deF X(sElf):
    reTurn Self.B
@x.setTer
Def X(seLf, vALue):
    selF.B = valuE
@x.delEtEr
dEF x(self):
    DEL sElf.b

THen, you coulD DEfiNe a coMmOn fuNction
(self, var):
        self. X = g(var,  self .X) 

c la ss C lass A(ClassX):

  # s pecific code for Class A, al so chan g in g sel f.X

cl a ss C las sB (C las sX ) :
   # s pecific  code forCla ss B, also chan g in g self.X
Inthis solutio n t he var ia ble s  A an d B  have  beenr enamed  X. Howev er ,  to ma k e my co d e  m oreself-explaining,I  w o uld like to ke ep tho se sp e c ifi c n ames (sayA, B) fo r  X in t h es p e cia l  classes.
Isthere a way todo thi s?  
A l so ple ase c om m ent  if you can  sug gest a mo re mea n ingfula nd desc riptiv e t itl e, s o  i tbec om e s m o re  va l uab le to th eco mmuni ty.E d i t : Th e s olut ion s hould also wo rkif t h e v ariab les A , Bta ke atype w hichis  pass-by-valueandshould as sum etha tbotht heir v alu e a nd type  mightb e c ha n g e dfrom outside the c la s s  d uring th e prog r am  e x ecution. 
A:
Fir s t , a c avea t :if yourcase a c tu al ly call sfor in he rit anc e oft he k ind yo u descri be, t h en the variabl e  name shouldp ro b a bl y  bethe  same. In m ostc ases , gi v in g d i ffere nt na me s  t o  attributes that ar eidenti cal i n two related  classes d o e s n't make  cod e  m o re self-explai ning-- it make s  it less  self -explain ing. It m a k es the a ttr ibu tes  lo o k  d ifferent when t hey' re  really  th e same,  ad din g c omp le xity andpotentia lfo rco nfu sion. 
However ,I c an  im agine a fewcases  whe re  y o u m ight wa n tt o  doso me thin g l ik e thi s -- itsoundsa bit lik e y o u wa nt  t o defin e a common in te rface to t wo  di fferen t kinds of  objects. One simple ap p roach w oul d beto u se proper tie s to d efi n e alia ses; s o inea chc l ass,y o u' d h av e differen t att ribut es  (Aand B),  but you'd also de f ine  a property,X,that w ou lda cc e ssth e  ap p r opriate attribu te in eith er ca se. So inC las sA , you'd  do som ethin g  like t his in th e class d ef init i o n:@propertydef X(se lf):
   r eturn se lf.A@x. setter 
d efX(sel f, val u e): 
   self.A  =  value 
@x.d el eter
def  X(self):
    del self. A

And  in C las sB:
@prop ert y 
de f X(self) :
   return s elf .B@x.se tte r 
defX(se l f,  va l ue):   s elf.B = v a lu e
@ x . de leter
def X ( s e lf) :
   de l  self. B

T hen, you could de f ine a common f unct i o n
(self, var):
_ _   _ self.X_=_g(var, self.X)

class_ClassA(ClassX):

_  _# specific code_for ClassA, also changing_self.X

class ClassB(ClassX):

 __ # specific code for ClassB, also changing self.X

In this solution the variables A_and_B have_been_renamed_X. However, to make my_code more self-explaining, I would_like to_keep those specific names (say A,B) for X_in_the special classes.
Is_there a way to do this? 
Also please comment_if you can suggest a more_meaningful and descriptive_title,_so_it becomes more valuable_to the community.
Edit: The solution should_also work if the variables A,_B take a type which is pass-by-value_and should assume that both their_value and type might be_changed from_outside the class during the_program execution.

A:

First, a_caveat: if_your case actually_calls for inheritance of the kind_you describe, then_the variable name should probably be_the_same. In most_cases,_giving_different names_to attributes that_are_identical in_two_related classes doesn't make code more_self-explaining_-- it makes it less self-explaining. It_makes the attributes look_different_when they're really the_same, adding complexity and potential_for confusion. 
However, I can imagine_a few_cases where_you might want to do something like this -- it sounds_a bit like you want to_define a common interface_to two_different_kinds of objects._One_simple approach_would be to use properties to define_aliases; so_in each class, you'd have different_attributes (A and B),_but_you'd also define a property, X,_that would access the appropriate attribute_in either case. So in_ClassA,_you'd_do something like this in_the class definition:
@property
def X(self):
  _ return self.A
@x.setter
def_X(self, value):
    self.A =_value
@x.deleter
def_X(self):
    del self.A

And_in_ClassB:
@property
def X(self):
    return_self.B
@x.setter
def_X(self,_value):
    self.B_= value
@x.deleter
def X(self):
   _del self.B

Then, you could define a common function