chrisyxlee,
@chrisyxlee@hachyderm.io avatar

TIL in my adventures, the proper way to set up a class that returns itself is to use the Self typing annotation and return values by calling self.__class__ on the new value

from typing import Self  
class ImActuallyAString(str):  
 def one_longer(self) -> Self:  
 return self.__class__(self + "one")  

ᕕ( ᐛ )ᕗ (please tell me if I'm wrong lol)

  • All
  • Subscribed
  • Moderated
  • Favorites
  • python
  • kavyap
  • normalnudes
  • everett
  • DreamBathrooms
  • ethstaker
  • magazineikmin
  • thenastyranch
  • Youngstown
  • GTA5RPClips
  • slotface
  • khanakhh
  • vwfavf
  • rosin
  • mdbf
  • provamag3
  • Leos
  • Durango
  • tacticalgear
  • InstantRegret
  • cubers
  • osvaldo12
  • ngwrru68w68
  • anitta
  • tester
  • modclub
  • cisconetworking
  • megavids
  • JUstTest
  • All magazines