• Ephera@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    3 months ago

    How would you make it non-awful, without specifying static types?

    I guess, a unit test would catch it, but needing 100% test coverage to catch typos isn’t exactly great…

    • Ham Strokers Ejacula@reddthat.com
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      3 months ago

      I would do

      class MyClass:
          def __init__(self, value):
              self._whatever = value
      
          @property
          def whatever(self):
              return self._whatever
      

      Personally, I would type hint all of that but I’m just showing how you can do it without types. Your linter should be smart enough to say “hey dumbass did you mean this other thing”? Also since we didn’t create a setter you can’t arbitrarily overwrite the value of whatever so thats neat.

      And I’ll just say before I post that I’m on mobile and I’m sorry if the formatting is fucked. I’m not going to fix it.