treyhunner,
@treyhunner@mastodon.social avatar

@chrisyxlee I always forget about typing.Self 👏

I'd call type(self)(...) on the new item. I prefer to avoid dunder attributes when there's a higher-level way to access the same thing.

This is not a universally agreed upon convention though, as there are parts of CPython's source code that use self.class and parts that use type(self). Most of the self.class parts are older and may have predated type(...) being usable (old-style classes didn't work well with type back in Python 2).

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