-
Notifications
You must be signed in to change notification settings - Fork 46
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
Custom methods must be protected #127
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Uilian Ries <[email protected]>
Signed-off-by: Uilian Ries <[email protected]>
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: