diff options
Diffstat (limited to 'Lib/pydoc.py')
| -rwxr-xr-x | Lib/pydoc.py | 38 | 
1 files changed, 21 insertions, 17 deletions
| diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 0c7b60d..ee558bf 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -53,6 +53,7 @@ Richard Chamberlain, for the first implementation of textdoc.  import builtins  import importlib._bootstrap +import importlib._bootstrap_external  import importlib.machinery  import importlib.util  import inspect @@ -213,7 +214,7 @@ def classify_class_attrs(object):  def ispackage(path):      """Guess whether a path refers to a package directory."""      if os.path.isdir(path): -        for ext in ('.py', '.pyc', '.pyo'): +        for ext in ('.py', '.pyc'):              if os.path.isfile(os.path.join(path, '__init__' + ext)):                  return True      return False @@ -264,9 +265,8 @@ def synopsis(filename, cache={}):              # XXX We probably don't need to pass in the loader here.              spec = importlib.util.spec_from_file_location('__temp__', filename,                                                            loader=loader) -            _spec = importlib._bootstrap._SpecMethods(spec)              try: -                module = _spec.load() +                module = importlib._bootstrap._load(spec)              except:                  return None              del sys.modules['__temp__'] @@ -293,14 +293,13 @@ def importfile(path):      filename = os.path.basename(path)      name, ext = os.path.splitext(filename)      if is_bytecode: -        loader = importlib._bootstrap.SourcelessFileLoader(name, path) +        loader = importlib._bootstrap_external.SourcelessFileLoader(name, path)      else: -        loader = importlib._bootstrap.SourceFileLoader(name, path) +        loader = importlib._bootstrap_external.SourceFileLoader(name, path)      # XXX We probably don't need to pass in the loader here.      spec = importlib.util.spec_from_file_location(name, path, loader=loader) -    _spec = importlib._bootstrap._SpecMethods(spec)      try: -        return _spec.load() +        return importlib._bootstrap._load(spec)      except:          raise ErrorDuringImport(path, sys.exc_info()) @@ -1591,7 +1590,10 @@ def resolve(thing, forceload=0):      if isinstance(thing, str):          object = locate(thing, forceload)          if object is None: -            raise ImportError('no Python documentation found for %r' % thing) +            raise ImportError('''\ +No Python documentation found for %r. +Use help() to get the interactive help utility. +Use help(str) for help on the str class.''' % thing)          return object, thing      else:          name = getattr(thing, '__name__', None) @@ -1638,9 +1640,8 @@ def writedoc(thing, forceload=0):      try:          object, name = resolve(thing, forceload)          page = html.page(describe(object), html.document(object, name)) -        file = open(name + '.html', 'w', encoding='utf-8') -        file.write(page) -        file.close() +        with open(name + '.html', 'w', encoding='utf-8') as file: +            file.write(page)          print('wrote', name + '.html')      except (ImportError, ErrorDuringImport) as value:          print(value) @@ -1835,7 +1836,8 @@ class Helper:          if inspect.stack()[1][3] == '?':              self()              return '' -        return '<pydoc.Helper instance>' +        return '<%s.%s instance>' % (self.__class__.__module__, +                                     self.__class__.__qualname__)      _GoInteractive = object()      def __call__(self, request=_GoInteractive): @@ -1861,7 +1863,10 @@ has the same effect as typing a particular string at the help> prompt.                  break              request = replace(request, '"', '', "'", '').strip()              if request.lower() in ('q', 'quit'): break -            self.help(request) +            if request == 'help': +                self.intro() +            else: +                self.help(request)      def getline(self, prompt):          """Read one line, using input() when appropriate.""" @@ -1875,8 +1880,7 @@ has the same effect as typing a particular string at the help> prompt.      def help(self, request):          if type(request) is type(''):              request = request.strip() -            if request == 'help': self.intro() -            elif request == 'keywords': self.listkeywords() +            if request == 'keywords': self.listkeywords()              elif request == 'symbols': self.listsymbols()              elif request == 'topics': self.listtopics()              elif request == 'modules': self.listmodules() @@ -1889,6 +1893,7 @@ has the same effect as typing a particular string at the help> prompt.              elif request in self.keywords: self.showtopic(request)              elif request in self.topics: self.showtopic(request)              elif request: doc(request, 'Help on %s:', output=self._output) +            else: doc(str, 'Help on %s:', output=self._output)          elif isinstance(request, Helper): self()          else: doc(request, 'Help on %s:', output=self._output)          self.output.write('\n') @@ -2084,9 +2089,8 @@ class ModuleScanner:                      else:                          path = None                  else: -                    _spec = importlib._bootstrap._SpecMethods(spec)                      try: -                        module = _spec.load() +                        module = importlib._bootstrap._load(spec)                      except ImportError:                          if onerror:                              onerror(modname) | 
