-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
[RFC] Ignore missing-return in compute methods #450
Comments
It is not possible for a static checker I mean, if you are inheriting a compute field method the field could not be defined in the class I mean, the definition of the field could be #repositoy1
class MetaClass...
discount = fields...(compute="_compute_discount")
def _compute_discount(self):
... #repositoy2
class InhClass...
_inherit = ...
def _compute_discount(self):
... The second class there are not a static way to know it is a method declared from Even the convention name could not be used since it not even is a See the following examples:
Notice the name starts with What about returning the original value even if it is returning Check the following cases returning the same original value:
I mean, in your example @api.depends("order_id", "order_id.general_discount")
def _compute_discount(self):
res = None
if hasattr(super(), "_compute_discount"):
res = super()._compute_discount()
for line in self:
line.discount = line.order_id.general_discount
return res Also, I think your code is a corner case since it inherits the original method but validating if it exists For these corner cases you can use a disable comment:
|
This follows the attempt of standardizing the inheritance converting fields to computed writable: |
if the field is re-defined in the same class, so it is possible to detect it for the static checker (Note: The example code in the description of this issue doesn't have the field definition as part of the class in this case it is not possible to detect it) |
Yes, the field should be redefined in the same class for converting it into compute. |
Thanks for the explanations @moylop260 🙂 👍 We'll adapt to this then |
Well, Moi is saying that it can be put the exception if the field is redefined in the same class, which is the case, so this may worth. Anyway, the debate about using this technique is still around. |
I just updated the main description with the final and real case of use Using this way it is possible to discard the lint |
Oh, sure! I missed that part 🙂 Thanks for reopening Moi. |
Fixes OCA#450. Compute methods are not supposed to return any value, even if there is a super() in it, since super() shouldn't return anything either. The only reliable way to ensure a field is computed is if has been declared in the same python module (file), so this exclusion only applies to a limited set of cases.
I don't find necessary to consider this case. Even though compute methods are generally not meant to return anything, I don't see why we should restrict that, and returning the super's result is always a good practice. Regarding the
Or even:
Second alternative would even be better than original proposal, as it's better for coverage. CC @antonag32 |
Fixes OCA#450. Compute methods are not supposed to return any value, even if there is a super() in it, since super() shouldn't return anything either. The only reliable way to ensure a field is computed is if has been declared in the same python module (file), so this exclusion only applies to a limited set of cases.
There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
Would it be possible to ignore compute methods for the
missing-return
directive? They aren't meant to return anything and would avoid little absurds like this where thereturn
is just superflous:The text was updated successfully, but these errors were encountered: