-
To better organise the many attributes that a class may have, I sometimes like to group related attributes together in an inner-class object. Occasionally I would need to add fields to the inner object in a subclass, so I would involve the inner-class in inheritance too. # pyright: strict
from __future__ import annotations
class BaseComment:
submission: Submission
class Submission:
...
class BaseExtraSubmissionFieldsComment(BaseComment):
class Submission(BaseComment.Submission):
# Add more attributes, etc.
...
class Comment(BaseComment):
...
class ExtraSubmissionFieldsComment(Comment, BaseExtraSubmissionFieldsComment):
... In this situation I have, a subclass only adds new fields, all of which are related and should be grouped in the inner-class. (The reason I have the ‘base’ versions of the classes is because I don’t want to duplicate the attribute fields—and the rather messy Since the changes in version 1.1.229 (specifically #2936), the forth class definition errors with:
I’m not really sure if this error message is unsound or if my code needs fixing somehow? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think the error message is correct here. You can choose to ignore it if you know that you have defined your inner classes appropriately such that they do not create problems for multiple inheritance. This practice looks very fragile to me, so I wouldn't recommend this approach. |
Beta Was this translation helpful? Give feedback.
I think the error message is correct here. You can choose to ignore it if you know that you have defined your inner classes appropriately such that they do not create problems for multiple inheritance. This practice looks very fragile to me, so I wouldn't recommend this approach.