8000 gh-104212: Explain how to port imp.load_source() by vstinner · Pull Request #105951 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-104212: Explain how to port imp.load_source() #105951

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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
move load_dynamic before
  • Loading branch information
vstinner committed Jun 20, 2023
commit 66dba52b6ee148a6d87162f19fda687f883c5d13
30 changes: 15 additions & 15 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1416,21 +1416,6 @@ Removed
loader.exec_module(module)
return module

* Replace ``imp.load_package()`` with::

import sys
import os.path
import importlib

def load_package(name, path):
old_path = list(sys.path)
try:
sys.path.insert(0, os.path.dirname(path))
return importlib.import_module(name)
finally:
sys.path.clear()
sys.path.extend(old_path)

* Replace ``imp.load_dynamic()`` with::

import importlib.machinery
Expand All @@ -1446,6 +1431,21 @@ Removed
loader.exec_module(module)
return module

* Replace ``imp.load_package()`` with::

import sys
import os.path
import importlib

def load_package(name, path):
old_path = list(sys.path)
try:
sys.path.insert(0, os.path.dirname(path))
return importlib.import_module(name)
finally:
sys.path.clear()
sys.path.extend(old_path)

* Replace ``imp.init_builtin()`` with::

import importlib.machinery
Expand Down
0