Replies: 2 comments 1 reply
-
I tried creating a reprex, seems workable so my vote so far is to clarify things with an
Output:
|
Beta Was this translation helpful? Give feedback.
-
So I tried the above and I got a test failure, I think it was on I found a couple of Stack Overflow threads covering the same situation we have regarding a parent class accessing attributes and methods defined only in a child class: https://stackoverflow.com/questions/28564245/do-i-have-to-define-attributes-in-the-base-class-in-python There doesn't seem to be a strong consensus, so the way things are set up now seem to be OK from an execution standpoint. But we can enhance how the code is read by humans and by tools by making use of Python's abstract class features. So it's no big deal at the moment I think, but I would like to revisit this later once I get a better handle on understanding this (or maybe someone better at OOP gets involved) . |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been working on annotating
__repr__
of the Triangle class and it looks like it inherits this from TriangleDisplay. I guess this is meant to behave like an abstract class (first time ever using this term in conversation, I've only read about it), since it can't really be used on its own?Anyway, TriangleDisplay makes use of attributes and methods defined in other classes - for example,
_get_axis()
from sibling class TrianglePandas and.values
from Triangle which inherits TriangleDisplay further downstream. This is causing my IDE to throw a bunch of unresolved reference warnings since it can't figure out where these attributes/methods are defined.I've been able to get rid of these warnings by type hinting
self
as class Triangle.Which is how
__repr__
is actually used in practice, but this brings up the confusing issue of typingself
as a class that inherits TriangleDisplay rather than TriangleDisplay itself - so I'm not sure if I'm doing the best practice here.I was thinking maybe we can add an
__init__
to TriangleDisplay to assign it the inheriting triangle as an attribute, which we will then call via super() in the inheriting class. Another option would maybe just move the whole TriangleDisplay downstream as being an attribute of the Triangle class. I'm open to other ideas as well.Beta Was this translation helpful? Give feedback.
All reactions