Skip to content
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

[question] "python_requires_extend" vs Python class hierarchy #17006

Open
1 task done
MTomBosch opened this issue Sep 17, 2024 · 1 comment
Open
1 task done

[question] "python_requires_extend" vs Python class hierarchy #17006

MTomBosch opened this issue Sep 17, 2024 · 1 comment

Comments

@MTomBosch
Copy link

MTomBosch commented Sep 17, 2024

What is your question?

Hello,
we are using Conan 1.x and are having a question related to using python_required_extend in combination with a Python recipe class hierarchy.

We are having a Conan recipe, let's call it "required_extend" where the package() function is implemened with a reasonable default behaviour.

This required_extend is used in the following recipe class hierarchy.

base recipe ---python_required_extend--> required_extend
|
(Python class inheritance)
|
child recipe (implements package() function)
|
(Python class inheritance>
|
grand child recipe

When now running the export_pkg command on the "grandchild recipe" somehow not the package() function of the "child recipe" is called but the package() function of the "required_extend" recipe. Even defining a package() function in grandchild and calling super().package() is not working acc to my tests.

But when calling it on "child recipe" then the package() function is properly called.

Any explanation for this behaviour?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded
Copy link
Member

Hi @MTomBosch

Thanks for your question.

First, I'd like to point to the guidelines in https://docs.conan.io/2/knowledge/guidelines.html (which are basically a lesson learned valid for Conan 1.X too):

Keep python_requires as simple as possible. Avoid transitive python_requires, keep them as reduced as possible, and at most, require them explicitly in a “flat” structure, without python_requires requiring other python_requires. Avoid inheritance (via python_requires_extend) if not strictly necessary, and avoid multiple inheritance at all costs, as it is extremely complicated, and it does not work the same as the built-in Python one.

The explanation for this is that the python_extend mechanism is simply not regular "static" Python inheritance. It is forced dynamically, to inject a base class that is not even in disk when the class is loaded. So the normal Python inheritance rules do not apply here, and the injection of the python-requires-extend class happens way later in the process, after evaluating all the Python inheritance, then that base class will be injected, and it will take precedence over the others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants