Skip to content

fix: use importlib.import_module instead of __import__ - #745

Merged
bhearsum merged 1 commit into
taskcluster:mainfrom
bhearsum:push-xkwxslkvomvz
Sep 3, 2025
Merged

fix: use importlib.import_module instead of __import__#745
bhearsum merged 1 commit into
taskcluster:mainfrom
bhearsum:push-xkwxslkvomvz

Conversation

@bhearsum

Copy link
Copy Markdown
Contributor

import_module is newer, and provides a couple of advantages over a bare __import__:

The import_module() function acts as a simplifying wrapper around importlib.import(). This means all semantics of the function are derived from importlib.import(). The most important difference between these two functions is that import_module() returns the specified package or module (e.g. pkg.mod), while import() returns the top-level package or module (e.g. pkg).

It's unclear if this will actually fix any problems in the real world, but there's no recent to use __import__ at this point AFAICT.

@bhearsum
bhearsum requested a review from a team as a code owner August 14, 2025 15:43
@bhearsum

bhearsum commented Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

The first version of this PR added a Callable return type to find_object. This is how it's used in practice, but broke tests, which highlights that it would be technically a breaking change to do so. I've removed that part.

@bhearsum
bhearsum force-pushed the push-xkwxslkvomvz branch 2 times, most recently from 5501c7b to 42f2030 Compare September 2, 2025 16:53
@bhearsum

bhearsum commented Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

@Eijebong - this has changed sufficiently enough that you probably ought to have another look at it.

@bhearsum
bhearsum requested review from Eijebong and removed request for abhishekmadan30 September 2, 2025 16:58
Comment thread src/taskgraph/generator.py Outdated
`import_module` is newer, and provides a couple of advantages over a bare `__import__`:
> The import_module() function acts as a simplifying wrapper around importlib.__import__(). This means all semantics of the function are derived from importlib.__import__(). The most important difference between these two functions is that import_module() returns the specified package or module (e.g. pkg.mod), while __import__() returns the top-level package or module (e.g. pkg).

It's unclear if this will actually fix any problems in the real world, but there's no recent to use `__import__` at this point AFAICT.
@bhearsum
bhearsum merged commit d57132e into taskcluster:main Sep 3, 2025
16 of 17 checks passed
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

Successfully merging this pull request may close these issues.

2 participants