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

Use importlib #28

Merged
merged 4 commits into from
May 26, 2021
Merged

Use importlib #28

merged 4 commits into from
May 26, 2021

Conversation

rmanganiello
Copy link
Contributor

@rmanganiello rmanganiello commented Apr 1, 2021

Problem

Remove imp in favor of importlib

imp module is deprecated since Python 3.3

The previous implementation had some issues while trying to load python modules ( execute __init__.py files) when you specify a handler in a directory.

By using importlib these issues go away and the implementation is way easier.

Description of changes

  • Remove usages of imp.find_module and imp.load_module and use importlib.import_module.
  • Relax pylint version since the pinned version wasn't supported by Python 3.8.
  • Fix and improve tests.

Source

https://docs.python.org/3/library/imp.html#imp.find_module

Deprecated since version 3.3: Use importlib.util.find_spec() instead unless Python 3.3 compatibility is required, in which case use importlib.find_loader(). For example usage of the former case, see the Examples section of the importlib documentation.

https://docs.python.org/3/library/imp.html#imp.load_module

Deprecated since version 3.3: If previously used in conjunction with imp.find_module() then consider using importlib.import_module(), otherwise use the loader returned by the replacement you chose for imp.find_module(). If you called imp.load_module() and related functions directly with file path arguments then use a combination of importlib.util.spec_from_file_location() and importlib.util.module_from_spec(). See the Examples section of the importlib documentation for details of the various approaches.

https://docs.python.org/3/library/importlib.html#importlib.invalidate_caches

If you are dynamically importing a module that was created since the interpreter began execution (e.g., created a Python source file), you may need to call invalidate_caches() in order for the new module to be noticed by the import system.

@rmanganiello rmanganiello marked this pull request as ready for review April 1, 2021 17:50
@adamantike
Copy link

@carlzogh @edhzsz @krk
Gentle ping, based on other merge request approvals!

Copy link
Contributor

@carlzogh carlzogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for the contribution!

Copy link
Contributor

@edhzsz edhzsz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome and thanks!

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request semver-minor Requires a minor semantic versioning bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants