Commit f4ba4ec1 authored by Brett Cannon's avatar Brett Cannon

Issue #17177: Stop using imp in pydoc

parent df960682
...@@ -44,17 +44,16 @@ Richard Chamberlain, for the first implementation of textdoc. ...@@ -44,17 +44,16 @@ Richard Chamberlain, for the first implementation of textdoc.
""" """
# Known bugs that can't be fixed here: # Known bugs that can't be fixed here:
# - imp.load_module() cannot be prevented from clobbering existing # - synopsis() cannot be prevented from clobbering existing
# loaded modules, so calling synopsis() on a binary module file # loaded modules.
# changes the contents of any existing module with the same name.
# - If the __file__ attribute on a module is a relative path and # - If the __file__ attribute on a module is a relative path and
# the current directory is changed with os.chdir(), an incorrect # the current directory is changed with os.chdir(), an incorrect
# path will be displayed. # path will be displayed.
import builtins import builtins
import imp
import importlib._bootstrap import importlib._bootstrap
import importlib.machinery import importlib.machinery
import importlib.util
import inspect import inspect
import io import io
import os import os
...@@ -268,7 +267,7 @@ class ErrorDuringImport(Exception): ...@@ -268,7 +267,7 @@ class ErrorDuringImport(Exception):
def importfile(path): def importfile(path):
"""Import a Python source file or compiled file given its path.""" """Import a Python source file or compiled file given its path."""
magic = imp.get_magic() magic = importlib.util.MAGIC_NUMBER
with open(path, 'rb') as file: with open(path, 'rb') as file:
is_bytecode = magic == file.read(len(magic)) is_bytecode = magic == file.read(len(magic))
filename = os.path.basename(path) filename = os.path.basename(path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment