-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repair model attribute typing and docstrings #666
Comments
The first one seems like the least likely to get confused to me, as We could write something in the docstring like "we are only using init to define attributes, all attributes should be defined here so that they get documented" (or similar) to make it clear our purpose in using |
The behaviour of |
Oh, I somehow managed to confuse myself despite reading the example code and thought that the definitions would go within I don't see much difference between the options honestly so if you think the first option is better future proofed against improvements to |
I should have pointed out that there are two pairs of Base model + instance of Base Model, so we're choosing between The rest is mostly just me checking that that the attribute documentation can be made to inherit from the base class, which it can. |
Oh for god's sake. The two Base models are of course identical. 🫠 |
Of relevance here - with the move to It might be worth running |
Weirdly pylint isn't picking up |
Just to check, does this new change mean that this exception is no longer necessary: virtual_ecosystem/virtual_ecosystem/core/base_model.py Lines 597 to 598 in 517b0a3
|
Thats correct - in fact, we have to remove it or it won't work. |
With the change to the static model mechanism (#373), model attributes are now largely being defined in the
_setup
method, which means that the actual model class documentation is missing the model attributes: they are only picked up from__init__
or from class attributes.We need to fix this - our docs are broken until we do. From @dalonsoa's comments on Teams, we have two clean choices.
We start using
__init__
again in the models. It's banned at the moment - only theBaseModel.__init__
gets run and it can't be redefined. This is because__init__
shouldn't do anything but setup the static/non_static model mode and all actual stuff that needs to happen is isolated in_setup
, so it can conditionally executed based on the model mode. But we can just agree that actual models__init__
methods should be "logic-free" and are used simply to maintain the documentation and typing of model attributes. They have to callsuper().__init__()
.We document and type all of the model attributes as if they were class attributes (below the
class ModelName
line and outside of any method). We then don't have to use__init__
.I prefer option (1). Although it is a bit more verbose, it follows the canonical Python practice of declaring instance attributes in
__init__
. These are attributes that differ between instances, which is true for all of these attributes. In option 2, we are pretending they are class attributes, which should be things that are fixed across all class instances. The only reason we can do this is because we don't actually want to assign values to the attributes at a class level, only at an instance level.The code below shows the two options in a basic setup. The issue we are trying to fix is that attribute
eee
defined in_setup
is not documented insphinx
(and I don't think can be), and nearly all our model attributes are now in this state.This can be built in an API doc using:
The text was updated successfully, but these errors were encountered: