News for hackers. Stuff that matters.
Re:Why Today's Python Developers Are Embracing Type Hints by _flux on Sunday September 28, 2025 @06:43AM (#45403328)
I meant if you have two classes that need to refer to each other. But good pointer anyway, I hadn't noticed it, thanks!
Re:Why Today's Python Developers Are Embracing Type Hints by alfons_foobar on Sunday September 28, 2025 @07:54AM (#45403677)
I ran into some code recently where this pattern caused me so much headache - class A has an attribute which is an instance of class B, and class B has a "parent" attribute (which points to the instance of class A that class B is an attribute of):

  class Foo:
      def __init__(self, bar):
          self.bar = bar
  
  class Bar:
      def __init__(self, foo):
          self.foo = foo
Obviously both called into each other to do $THINGS... Pure madness.

So my suggestion: Try not to have interdependent classes :D

Re:Why Today's Python Developers Are Embracing Type Hints by _flux on Sunday September 28, 2025 @10:43AM (#45404688)
Well, at times having a parent pointer is rather useful! E.g. a callback registration will be able to unregister itself from everywhere where it has been registered to, upon request. (One would want to use weak references in this case.)
Re:Why Today's Python Developers Are Embracing Type Hints by alfons_foobar on Monday September 29, 2025 @10:30AM (#45414303)
Fair point!

Maybe I am just a bit burned by this particular example I ran into (where this pattern should IMO not have been used).