Custom methods must be protected#127
Conversation
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
| mock = ConanFile(conanfile.output, None) | ||
| valid_attrs = get_methods(mock) | ||
| current_attrs = get_methods(conanfile) | ||
| invalid_attrs = re.findall(r"def (__.*[^_])\s?\(", conanfile_content, re.MULTILINE) |
There was a problem hiding this comment.
I don't get it, you query valid attrs and current attrs, why query invalid attrs with different method?
isn't result the same as current_attrs - valid_attrs?
There was a problem hiding this comment.
private methods are not filtered by dir method. e.g. def __foo(self):
| """) | ||
| tools.save('conanfile.py', content=conanfile) | ||
| output = self.conan(['create', '.', 'name/version@user/test']) | ||
| self.assertIn("ERROR: [CUSTOM METHODS (KB-H036)] Custom methods must be declared as " |
There was a problem hiding this comment.
might be too strict, as we may define some magic methods (__str__, __eq__, __new__, __init__, __enter__, __dir__, etc)?
There was a problem hiding this comment.
but it's the exception you know. It sounds like cccl and other few recipes. We know that is not a regular case, but new contributors can use private instead of protected when writing a recipe, for instance.
|
@uilianries also, I wonder, why do we forbid to use private members? is it somehow bad/harmful? |
|
@SSE4 private attributes are not bad, but how many times we needed them for a recipe? Maybe twice all this time, only for workarounds and helpers, which are not the regular flow. |
closes #126
Wiki:
#KB-H036: "CUSTOM METHODS"
When a new method have to be added to the recipe, and it is not a default one provided by ConanFile, it must added as protected: