Skip to content

Support for nested classes in import_string #71014

Description

@KushagraB424

Description

In airflow_shared/module_loading/__init__.py, the import_string(dotted_path) utility currently contains a TODO noting that it only supports top-level classes:

# TODO: Add support for nested classes. Currently, it only works for top-level classes.

Airflow frequently relies on dotted path strings to dynamically load classes (e.g., operators, callbacks, secrets backends, etc.). Supporting nested classes allows developers to better encapsulate their code or utilize existing third-party libraries that rely on nested class structures.
The current limitation requires users to expose all classes at the top-level module scope if they are to be dynamically imported by Airflow. Addressing this known TODO will provide greater flexibility and make the module loading utility more robust.

Use case/motivation

Airflow frequently relies on dotted path strings to dynamically load classes (e.g., operators, callbacks, secrets backends, etc.). Supporting nested classes allows developers to better encapsulate their code or utilize existing third-party libraries that rely on nested class structures.
The current limitation requires users to expose all classes at the top-level module scope if they are to be dynamically imported by Airflow. Addressing this known TODO will provide greater flexibility and make the module loading utility more robust.

Related issues

None (resolves an existing TODO in airflow_shared/module_loading/__init__.py).

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions