diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -218,17 +218,17 @@ ABC hierarchy:: .. class:: Finder An abstract base class representing a :term:`finder`. .. deprecated:: 3.3 Use :class:`MetaPathFinder` or :class:`PathEntryFinder` instead. - .. method:: find_module(fullname, path=None) + .. abstractmethod:: find_module(fullname, path=None) An abstact method for finding a :term:`loader` for the specified module. Originally specified in :pep:`302`, this method was meant for use in :data:`sys.meta_path` and in the path-based import subsystem. .. versionchanged:: 3.4 Returns ``None`` when called instead of raising :exc:`NotImplementedError`. @@ -438,17 +438,17 @@ ABC hierarchy:: .. class:: ResourceLoader An abstract base class for a :term:`loader` which implements the optional :pep:`302` protocol for loading arbitrary resources from the storage back-end. - .. method:: get_data(path) + .. abstractmethod:: get_data(path) An abstract method to return the bytes for the data located at *path*. Loaders that have a file-like storage back-end that allows storing arbitrary data can implement this abstract method to give direct access to the data stored. :exc:`OSError` is to be raised if the *path* cannot be found. The *path* is expected to be constructed using a module's :attr:`__file__` attribute or an item from a package's :attr:`__path__`. @@ -474,17 +474,17 @@ ABC hierarchy:: it be overridden if possible for performance. .. index:: single: universal newlines; importlib.abc.InspectLoader.get_source method .. versionchanged:: 3.4 No longer abstract and a concrete implementation is provided. - .. method:: get_source(fullname) + .. abstractmethod:: get_source(fullname) An abstract method to return the source of a module. It is returned as a text string using :term:`universal newlines`, translating all recognized line separators into ``'\n'`` characters. Returns ``None`` if no source is available (e.g. a built-in module). Raises :exc:`ImportError` if the loader cannot find the module specified. .. versionchanged:: 3.4 @@ -525,17 +525,17 @@ ABC hierarchy:: .. class:: ExecutionLoader An abstract base class which inherits from :class:`InspectLoader` that, when implemented, helps a module to be executed as a script. The ABC represents an optional :pep:`302` protocol. - .. method:: get_filename(fullname) + .. abstractmethod:: get_filename(fullname) An abstract method that is to return the value of :attr:`__file__` for the specified module. If no path is available, :exc:`ImportError` is raised. If source code is available, then the method should return the path to the source file, regardless of whether a bytecode was used to load the module. diff --git a/Doc/tools/sphinxext/pyspecific.py b/Doc/tools/sphinxext/pyspecific.py --- a/Doc/tools/sphinxext/pyspecific.py +++ b/Doc/tools/sphinxext/pyspecific.py @@ -136,16 +136,36 @@ class PyDecoratorFunction(PyDecoratorMix return PyModulelevel.run(self) class PyDecoratorMethod(PyDecoratorMixin, PyClassmember): def run(self): self.name = 'py:method' return PyClassmember.run(self) +class PyAbstractMethod(PyClassmember): + def get_signature_prefix(self, sig): + return 'abstractmethod ' + + def get_index_text(self, modname, name_cls): + name, cls = name_cls + try: + clsname, methname = name.rsplit('.', 1) + except ValueError: + if modname: + return '%s() (in module %s)' % (name, modname) + else: + return '%s()' % name + if modname: + return '%s() (%s.%s abstract method)' % (methname, modname, + clsname) + else: + return '%s() (%s abstract method)' % (methname, clsname) + + # Support for documenting version of removal in deprecations class DeprecatedRemoved(Directive): has_content = True required_arguments = 2 optional_arguments = 1 final_argument_whitespace = True option_spec = {} @@ -356,9 +376,10 @@ def setup(app): app.add_builder(suspicious.CheckSuspiciousMarkupBuilder) app.add_description_unit('opcode', 'opcode', '%s (opcode)', parse_opcode_signature) app.add_description_unit('pdbcommand', 'pdbcmd', '%s (pdb command)', parse_pdb_command) app.add_description_unit('2to3fixer', '2to3fixer', '%s (2to3 fixer)') app.add_directive_to_domain('py', 'decorator', PyDecoratorFunction) app.add_directive_to_domain('py', 'decoratormethod', PyDecoratorMethod) + app.add_directive_to_domain('py', 'abstractmethod', PyAbstractMethod) app.add_directive('miscnews', MiscNews)