SF.net SVN: docutils:[9810 ] trunk/docutils/docutils
aa-turner--- via Docutils-checkins <[email protected]>
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 9810
http://sourceforge.net/p/docutils/code/9810
Author: aa-turner
Date: 2024-08-01 07:22:07 +0000 (Thu, 01 Aug 2024)
Log Message:
-----------
Add simple return type hints to ``docutils``
Modified Paths:
--------------
trunk/docutils/docutils/core.py
trunk/docutils/docutils/io.py
trunk/docutils/docutils/languages/__init__.py
trunk/docutils/docutils/nodes.py
trunk/docutils/docutils/parsers/__init__.py
trunk/docutils/docutils/parsers/docutils_xml.py
trunk/docutils/docutils/parsers/null.py
trunk/docutils/docutils/parsers/recommonmark_wrapper.py
trunk/docutils/docutils/parsers/rst/__init__.py
trunk/docutils/docutils/parsers/rst/directives/__init__.py
trunk/docutils/docutils/parsers/rst/directives/tables.py
trunk/docutils/docutils/parsers/rst/roles.py
trunk/docutils/docutils/parsers/rst/states.py
trunk/docutils/docutils/parsers/rst/tableparser.py
trunk/docutils/docutils/readers/__init__.py
trunk/docutils/docutils/readers/doctree.py
trunk/docutils/docutils/readers/pep.py
trunk/docutils/docutils/statemachine.py
trunk/docutils/docutils/transforms/__init__.py
trunk/docutils/docutils/transforms/components.py
trunk/docutils/docutils/transforms/frontmatter.py
trunk/docutils/docutils/transforms/misc.py
trunk/docutils/docutils/transforms/parts.py
trunk/docutils/docutils/transforms/peps.py
trunk/docutils/docutils/transforms/references.py
trunk/docutils/docutils/transforms/universal.py
trunk/docutils/docutils/transforms/writer_aux.py
trunk/docutils/docutils/utils/__init__.py
trunk/docutils/docutils/utils/code_analyzer.py
trunk/docutils/docutils/utils/math/__init__.py
trunk/docutils/docutils/utils/math/math2html.py
trunk/docutils/docutils/utils/math/mathml_elements.py
trunk/docutils/docutils/utils/math/tex2mathml_extern.py
trunk/docutils/docutils/utils/roman.py
trunk/docutils/docutils/utils/smartquotes.py
trunk/docutils/docutils/writers/__init__.py
trunk/docutils/docutils/writers/_html_base.py
trunk/docutils/docutils/writers/docutils_xml.py
trunk/docutils/docutils/writers/html4css1/__init__.py
trunk/docutils/docutils/writers/html5_polyglot/__init__.py
trunk/docutils/docutils/writers/latex2e/__init__.py
trunk/docutils/docutils/writers/manpage.py
trunk/docutils/docutils/writers/null.py
trunk/docutils/docutils/writers/odf_odt/__init__.py
trunk/docutils/docutils/writers/odf_odt/prepstyles.py
trunk/docutils/docutils/writers/odf_odt/pygmentsformatter.py
trunk/docutils/docutils/writers/pep_html/__init__.py
trunk/docutils/docutils/writers/pseudoxml.py
trunk/docutils/docutils/writers/s5_html/__init__.py
trunk/docutils/docutils/writers/xetex/__init__.py
Modified: trunk/docutils/docutils/core.py
===================================================================
--- trunk/docutils/docutils/core.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/core.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -38,7 +38,7 @@
def __init__(self, reader=None, parser=None, writer=None,
source=None, source_class=io.FileInput,
destination=None, destination_class=io.FileOutput,
- settings=None):
+ settings=None) -> None:
"""
Initial setup.
@@ -89,7 +89,7 @@
self._stderr = io.ErrorOutput()
- def set_reader(self, reader, parser=None, parser_name=None):
+ def set_reader(self, reader, parser=None, parser_name=None) -> None:
"""Set `self.reader` by name.
The "paser_name" argument is deprecated,
@@ -102,12 +102,12 @@
elif self.parser is not None:
self.reader.parser = self.parser
- def set_writer(self, writer_name):
+ def set_writer(self, writer_name) -> None:
"""Set `self.writer` by name."""
writer_class = writers.get_writer_class(writer_name)
self.writer = writer_class()
- def set_components(self, reader_name, parser_name, writer_name):
+ def set_components(self, reader_name, parser_name, writer_name) -> None:
warnings.warn('`Publisher.set_components()` will be removed in '
'Docutils 2.0. Specify component names '
'at instantiation.',
@@ -162,7 +162,7 @@
def process_programmatic_settings(self, settings_spec,
settings_overrides,
- config_section):
+ config_section) -> None:
if self.settings is None:
defaults = settings_overrides.copy() if settings_overrides else {}
# Propagate exceptions by default when used programmatically:
@@ -173,7 +173,7 @@
def process_command_line(self, argv=None, usage=None, description=None,
settings_spec=None, config_section=None,
- **defaults):
+ **defaults) -> None:
"""
Parse command line arguments and set ``self.settings``.
@@ -188,7 +188,7 @@
argv = sys.argv[1:]
self.settings = option_parser.parse_args(argv)
- def set_io(self, source_path=None, destination_path=None):
+ def set_io(self, source_path=None, destination_path=None) -> None:
if self.source is None:
self.set_source(source_path=source_path)
if self.destination is None:
@@ -233,7 +233,7 @@
encoding=self.settings.output_encoding,
error_handler=self.settings.output_encoding_error_handler)
- def apply_transforms(self):
+ def apply_transforms(self) -> None:
self.document.transformer.populate_from_components(
(self.source, self.reader, self.reader.parser, self.writer,
self.destination))
@@ -281,7 +281,7 @@
sys.exit(exit_status)
return output
- def debugging_dumps(self):
+ def debugging_dumps(self) -> None:
if not self.document:
return
if self.settings.dump_settings:
@@ -304,7 +304,7 @@
print(self.document.pformat().encode(
'raw_unicode_escape'), file=self._stderr)
- def prompt(self):
+ def prompt(self) -> None:
"""Print info and prompt when waiting for input from a terminal."""
try:
if not (self.source.isatty() and self._stderr.isatty()):
@@ -326,7 +326,7 @@
'on an empty line):',
file=self._stderr)
- def report_Exception(self, error):
+ def report_Exception(self, error) -> None:
if isinstance(error, utils.SystemMessage):
self.report_SystemMessage(error)
elif isinstance(error, UnicodeEncodeError):
@@ -348,12 +348,12 @@
Python version ({sys.version.split()[0]}), your OS type & version, \
and the command line used.""", file=self._stderr)
- def report_SystemMessage(self, error):
+ def report_SystemMessage(self, error) -> None:
print('Exiting due to level-%s (%s) system message.' % (
error.level, utils.Reporter.levels[error.level]),
file=self._stderr)
- def report_UnicodeError(self, error):
+ def report_UnicodeError(self, error) -> None:
data = error.object[error.start:error.end]
self._stderr.write(
'%s\n'
@@ -658,7 +658,7 @@
return output
-def _name_arg_warning(*name_args):
+def _name_arg_warning(*name_args) -> None:
for component, name_arg in zip(('reader', 'parser', 'writer'), name_args):
if name_arg is not None:
warnings.warn(f'Argument "{component}_name" will be removed in '
@@ -787,7 +787,7 @@
# "Entry points" with functionality of the "tools/rst2*.py" scripts
# cf. https://packaging.python.org/en/latest/specifications/entry-points/
-def rst2something(writer, documenttype, doc_path=''):
+def rst2something(writer, documenttype, doc_path='') -> None:
# Helper function for the common parts of `rst2*()`
# writer: writer name
# documenttype: output document type
@@ -801,41 +801,41 @@
publish_cmdline(writer=writer, description=description)
-def rst2html():
+def rst2html() -> None:
rst2something('html', 'HTML', 'user/html.html#html')
-def rst2html4():
+def rst2html4() -> None:
rst2something('html4', 'XHTML 1.1', 'user/html.html#html4css1')
-def rst2html5():
+def rst2html5() -> None:
rst2something('html5', 'HTML5', 'user/html.html#html5-polyglot')
-def rst2latex():
+def rst2latex() -> None:
rst2something('latex', 'LaTeX', 'user/latex.html')
-def rst2man():
+def rst2man() -> None:
rst2something('manpage', 'Unix manual (troff)', 'user/manpage.html')
-def rst2odt():
+def rst2odt() -> None:
rst2something('odt', 'OpenDocument text (ODT)', 'user/odt.html')
-def rst2pseudoxml():
+def rst2pseudoxml() -> None:
rst2something('pseudoxml', 'pseudo-XML (test)', 'ref/doctree.html')
-def rst2s5():
+def rst2s5() -> None:
rst2something('s5', 'S5 HTML slideshow', 'user/slide-shows.html')
-def rst2xetex():
+def rst2xetex() -> None:
rst2something('xetex', 'LaTeX (XeLaTeX/LuaLaTeX)', 'user/latex.html')
-def rst2xml():
+def rst2xml() -> None:
rst2something('xml', 'Docutils-native XML', 'ref/doctree.html')
Modified: trunk/docutils/docutils/io.py
===================================================================
--- trunk/docutils/docutils/io.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/io.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -60,7 +60,7 @@
return None
-def error_string(err):
+def error_string(err) -> str:
"""Return string representation of Exception `err`.
"""
return f'{err.__class__.__name__}: {err}'
@@ -83,7 +83,7 @@
default_source_path = None
def __init__(self, source=None, source_path=None, encoding='utf-8',
- error_handler='strict'):
+ error_handler='strict') -> None:
self.encoding = encoding
"""Text encoding for the input source."""
@@ -102,7 +102,7 @@
self.successful_encoding = None
"""The encoding that successfully decoded the source data."""
- def __repr__(self):
+ def __repr__(self) -> str:
return '%s: source=%r, source_path=%r' % (self.__class__, self.source,
self.source_path)
@@ -218,7 +218,7 @@
default_destination_path = None
def __init__(self, destination=None, destination_path=None,
- encoding=None, error_handler='strict'):
+ encoding=None, error_handler='strict') -> None:
self.encoding = encoding
"""Text encoding for the output destination."""
@@ -234,7 +234,7 @@
if not destination_path:
self.destination_path = self.default_destination_path
- def __repr__(self):
+ def __repr__(self) -> str:
return ('%s: destination=%r, destination_path=%r'
% (self.__class__, self.destination, self.destination_path))
@@ -272,7 +272,7 @@
def __init__(self, destination=None, encoding=None,
encoding_errors='backslashreplace',
- decoding_errors='replace'):
+ decoding_errors='replace') -> None:
"""
:Parameters:
- `destination`: a file-like object,
@@ -303,7 +303,7 @@
self.decoding_errors = decoding_errors
"""Decoding error handler."""
- def write(self, data):
+ def write(self, data) -> None:
"""
Write `data` to self.destination. Ignore, if self.destination is False.
@@ -329,7 +329,7 @@
self.destination.write(str(data, self.encoding,
self.decoding_errors))
- def close(self):
+ def close(self) -> None:
"""
Close the error-output stream.
@@ -358,7 +358,7 @@
"""
def __init__(self, source=None, source_path=None,
encoding='utf-8', error_handler='strict',
- autoclose=True, mode='r'):
+ autoclose=True, mode='r') -> None:
"""
:Parameters:
- `source`: either a file-like object (which is read directly), or
@@ -421,7 +421,7 @@
"""
return self.read().splitlines(True)
- def close(self):
+ def close(self) -> None:
if self.source is not sys.stdin:
self.source.close()
@@ -440,7 +440,7 @@
def __init__(self, destination=None, destination_path=None,
encoding=None, error_handler='strict', autoclose=True,
- handle_io_errors=None, mode=None):
+ handle_io_errors=None, mode=None) -> None:
"""
:Parameters:
- `destination`: either a file-like object (which is written
@@ -545,7 +545,7 @@
self.close()
return data
- def close(self):
+ def close(self) -> None:
if self.destination not in (sys.stdout, sys.stderr):
self.destination.close()
self.opened = False
@@ -561,7 +561,7 @@
# Used by core.publish_cmdline_to_binary() which is also deprecated.
mode = 'wb'
- def __init__(self, *args, **kwargs):
+ def __init__(self, *args, **kwargs) -> None:
warnings.warn('"BinaryFileOutput" is obsoleted by "FileOutput"'
' and will be removed in Docutils 0.24.',
DeprecationWarning, stacklevel=2)
@@ -614,7 +614,7 @@
default_source_path = 'null input'
- def read(self):
+ def read(self) -> str:
"""Return an empty string."""
return ''
@@ -625,7 +625,7 @@
default_destination_path = 'null output'
- def write(self, data):
+ def write(self, data) -> None:
"""Do nothing, return None."""
pass
Modified: trunk/docutils/docutils/languages/__init__.py
===================================================================
--- trunk/docutils/docutils/languages/__init__.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/languages/__init__.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -31,7 +31,7 @@
fallback = 'en'
# TODO: use a dummy module returning empty strings?, configurable?
- def __init__(self):
+ def __init__(self) -> None:
self.cache = {}
def import_from_packages(self, name, reporter=None):
Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/nodes.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -61,10 +61,10 @@
return None
@document.setter
- def document(self, value):
+ def document(self, value) -> None:
self._document = value
- def __bool__(self):
+ def __bool__(self) -> bool:
"""
Node instances are always true, even if they're empty. A node is more
than a simple container. Its boolean "truth" does not depend on
@@ -101,7 +101,7 @@
"""Return a string representation of this Node."""
raise NotImplementedError
- def setup_child(self, child):
+ def setup_child(self, child) -> None:
child.parent = self
if self.document:
child.document = self.document
@@ -352,13 +352,13 @@
DeprecationWarning, stacklevel=2)
return str.__new__(cls, data)
- def shortrepr(self, maxlen=18):
+ def shortrepr(self, maxlen=18) -> str:
data = self
if len(data) > maxlen:
data = data[:maxlen-4] + ' ...'
return '<%s: %r>' % (self.tagname, str(data))
- def __repr__(self):
+ def __repr__(self) -> str:
return self.shortrepr(maxlen=68)
def astext(self):
@@ -398,11 +398,11 @@
def lstrip(self, chars=None):
return self.__class__(str.lstrip(self, chars))
- def validate(self, recursive=True):
+ def validate(self, recursive=True) -> None:
"""Validate Docutils Document Tree element ("doctree")."""
# Text nodes have no attributes and no children.
- def check_position(self):
+ def check_position(self) -> None:
"""Hook for additional checks of the parent's content model."""
# no special placement requirements for Text nodes
@@ -511,7 +511,7 @@
child_text_separator = '\n\n'
"""Separator for child nodes, used by `astext()` method."""
- def __init__(self, rawsource='', *children, **attributes):
+ def __init__(self, rawsource='', *children, **attributes) -> None:
self.rawsource = rawsource
"""The raw text from which this element was constructed.
@@ -555,7 +555,7 @@
element.appendChild(child._dom_node(domroot))
return element
- def __repr__(self):
+ def __repr__(self) -> str:
data = ''
for c in self.children:
data += c.shortrepr()
@@ -568,7 +568,7 @@
else:
return '<%s: %s>' % (self.__class__.__name__, data)
- def shortrepr(self):
+ def shortrepr(self) -> str:
if self['names']:
return '<%s "%s"...>' % (self.__class__.__name__,
'; '.join(self['names']))
@@ -575,7 +575,7 @@
else:
return '<%s...>' % self.tagname
- def __str__(self):
+ def __str__(self) -> str:
if self.children:
return '%s%s%s' % (self.starttag(),
''.join(str(c) for c in self.children),
@@ -583,7 +583,7 @@
else:
return self.emptytag()
- def starttag(self, quoteattr=None):
+ def starttag(self, quoteattr=None) -> str:
# the optional arg is used by the docutils_xml writer
if quoteattr is None:
quoteattr = pseudo_quoteattr
@@ -603,17 +603,17 @@
parts.append('%s=%s' % (name, value))
return '<%s>' % ' '.join(parts)
- def endtag(self):
+ def endtag(self) -> str:
return '</%s>' % self.tagname
- def emptytag(self):
+ def emptytag(self) -> str:
attributes = ('%s="%s"' % (n, v) for n, v in self.attlist())
return '<%s/>' % ' '.join((self.tagname, *attributes))
- def __len__(self):
+ def __len__(self) -> int:
return len(self.children)
- def __contains__(self, key):
+ def __contains__(self, key) -> bool:
# Test for both, children and attributes with operator ``in``.
if isinstance(key, str):
return key in self.attributes
@@ -631,7 +631,7 @@
raise TypeError('element index must be an integer, a slice, or '
'an attribute name string')
- def __setitem__(self, key, item):
+ def __setitem__(self, key, item) -> None:
if isinstance(key, str):
self.attributes[str(key)] = item
elif isinstance(key, int):
@@ -646,7 +646,7 @@
raise TypeError('element index must be an integer, a slice, or '
'an attribute name string')
- def __delitem__(self, key):
+ def __delitem__(self, key) -> None:
if isinstance(key, str):
del self.attributes[key]
elif isinstance(key, int):
@@ -689,10 +689,10 @@
def get(self, key, failobj=None):
return self.attributes.get(key, failobj)
- def hasattr(self, attr):
+ def hasattr(self, attr) -> bool:
return attr in self.attributes
- def delattr(self, attr):
+ def delattr(self, attr) -> None:
if attr in self.attributes:
del self.attributes[attr]
@@ -716,15 +716,15 @@
except AttributeError:
return fallback
- def append(self, item):
+ def append(self, item) -> None:
self.setup_child(item)
self.children.append(item)
- def extend(self, item):
+ def extend(self, item) -> None:
for node in item:
self.append(node)
- def insert(self, index, item):
+ def insert(self, index, item) -> None:
if isinstance(item, Node):
self.setup_child(item)
self.children.insert(index, item)
@@ -734,7 +734,7 @@
def pop(self, i=-1):
return self.children.pop(i)
- def remove(self, item):
+ def remove(self, item) -> None:
self.children.remove(item)
def index(self, item, start=0, stop=sys.maxsize):
@@ -748,13 +748,13 @@
return None
return self.parent[i-1] if i > 0 else None
- def is_not_default(self, key):
+ def is_not_default(self, key) -> int:
if self[key] == [] and key in self.list_attributes:
return 0
else:
return 1
- def update_basic_atts(self, dict_):
+ def update_basic_atts(self, dict_) -> None:
"""
Update basic attributes ('ids', 'names', 'classes',
'dupnames', but not 'source') from node or dictionary `dict_`.
@@ -766,7 +766,7 @@
for att in self.basic_attributes:
self.append_attr_list(att, dict_.get(att, []))
- def append_attr_list(self, attr, values):
+ def append_attr_list(self, attr, values) -> None:
"""
For each element in values, if it does not exist in self[attr], append
it.
@@ -779,7 +779,7 @@
if value not in self[attr]:
self[attr].append(value)
- def coerce_append_attr_list(self, attr, value):
+ def coerce_append_attr_list(self, attr, value) -> None:
"""
First, convert both self[attr] and value to a non-string sequence
type; if either is not already a sequence, convert it to a list of one
@@ -794,7 +794,7 @@
value = [value]
self.append_attr_list(attr, value)
- def replace_attr(self, attr, value, force=True):
+ def replace_attr(self, attr, value, force=True) -> None:
"""
If self[attr] does not exist or force is True or omitted, set
self[attr] to value, otherwise do nothing.
@@ -803,7 +803,7 @@
if force or self.get(attr) is None:
self[attr] = value
- def copy_attr_convert(self, attr, value, replace=True):
+ def copy_attr_convert(self, attr, value, replace=True) -> None:
"""
If attr is an attribute of self, set self[attr] to
[self[attr], value], otherwise set self[attr] to value.
@@ -814,7 +814,7 @@
if self.get(attr) is not value:
self.coerce_append_attr_list(attr, value)
- def copy_attr_coerce(self, attr, value, replace):
+ def copy_attr_coerce(self, attr, value, replace) -> None:
"""
If attr is an attribute of self and either self[attr] or value is a
list, convert all non-sequence values to a sequence of 1 element and
@@ -830,7 +830,7 @@
else:
self.replace_attr(attr, value, replace)
- def copy_attr_concatenate(self, attr, value, replace):
+ def copy_attr_concatenate(self, attr, value, replace) -> None:
"""
If attr is an attribute of self and both self[attr] and value are
lists, concatenate the two sequences, setting the result to
@@ -845,7 +845,7 @@
else:
self.replace_attr(attr, value, replace)
- def copy_attr_consistent(self, attr, value, replace):
+ def copy_attr_consistent(self, attr, value, replace) -> None:
"""
If replace is True or self[attr] is None, replace self[attr] with
value. Otherwise, do nothing.
@@ -854,7 +854,7 @@
self.replace_attr(attr, value, replace)
def update_all_atts(self, dict_, update_fun=copy_attr_consistent,
- replace=True, and_source=False):
+ replace=True, and_source=False) -> None:
"""
Updates all attributes from node or dictionary `dict_`.
@@ -892,7 +892,7 @@
update_fun(self, att, dict_[att], replace)
def update_all_atts_consistantly(self, dict_, replace=True,
- and_source=False):
+ and_source=False) -> None:
"""
Updates all attributes from node or dictionary `dict_`.
@@ -913,7 +913,7 @@
and_source)
def update_all_atts_concatenating(self, dict_, replace=True,
- and_source=False):
+ and_source=False) -> None:
"""
Updates all attributes from node or dictionary `dict_`.
@@ -937,7 +937,7 @@
and_source)
def update_all_atts_coercion(self, dict_, replace=True,
- and_source=False):
+ and_source=False) -> None:
"""
Updates all attributes from node or dictionary `dict_`.
@@ -961,7 +961,7 @@
self.update_all_atts(dict_, Element.copy_attr_coerce, replace,
and_source)
- def update_all_atts_convert(self, dict_, and_source=False):
+ def update_all_atts_convert(self, dict_, and_source=False) -> None:
"""
Updates all attributes from node or dictionary `dict_`.
@@ -982,10 +982,10 @@
self.update_all_atts(dict_, Element.copy_attr_convert,
and_source=and_source)
- def clear(self):
+ def clear(self) -> None:
self.children = []
- def replace(self, old, new):
+ def replace(self, old, new) -> None:
"""Replace one child `Node` with another child or children."""
index = self.index(old)
if isinstance(new, Node):
@@ -994,7 +994,7 @@
elif new is not None:
self[index:index+1] = new
- def replace_self(self, new):
+ def replace_self(self, new) -> None:
"""
Replace `self` node with `new`, where `new` is a node or a
list of nodes.
@@ -1076,7 +1076,7 @@
copy.extend([child.deepcopy() for child in self.children])
return copy
- def note_referenced_by(self, name=None, id=None):
+ def note_referenced_by(self, name=None, id=None) -> None:
"""Note that this Element has been referenced by its name
`name` or id `id`."""
self.referenced = True
@@ -1094,7 +1094,7 @@
by_id.referenced = True
@classmethod
- def is_not_list_attribute(cls, attr):
+ def is_not_list_attribute(cls, attr) -> bool:
"""
Returns True if and only if the given attribute is NOT one of the
basic list attributes defined for all Elements.
@@ -1102,7 +1102,7 @@
return attr not in cls.list_attributes
@classmethod
- def is_not_known_attribute(cls, attr):
+ def is_not_known_attribute(cls, attr) -> bool:
"""
Return True if `attr` is NOT defined for all Element instances.
@@ -1177,7 +1177,7 @@
child = None
return [] if child is None else [child, *ichildren]
- def _report_child(self, child, category):
+ def _report_child(self, child, category) -> str:
# Return a str reporting a missing child or child of wrong category.
try:
type = category.__name__
@@ -1192,7 +1192,7 @@
return (f'{msg} Expecting child of type <{type}>, '
f'not {child.starttag()}.')
- def check_position(self):
+ def check_position(self) -> None:
"""Hook for additional checks of the parent's content model.
Raise ValidationError, if `self` is at an invalid position.
@@ -1336,7 +1336,7 @@
list_attributes = Element.list_attributes + ('backrefs',)
valid_attributes = Element.valid_attributes + ('backrefs',)
- def add_backref(self, refid):
+ def add_backref(self, refid) -> None:
self['backrefs'].append(refid)
@@ -1379,7 +1379,7 @@
child_text_separator = ''
"""Separator for child nodes, used by `astext()` method."""
- def __init__(self, rawsource='', text='', *children, **attributes):
+ def __init__(self, rawsource='', text='', *children, **attributes) -> None:
if text:
textnode = Text(text)
Element.__init__(self, rawsource, textnode, *children,
@@ -1393,7 +1393,7 @@
valid_attributes = Element.valid_attributes + ('xml:space',)
- def __init__(self, rawsource='', text='', *children, **attributes):
+ def __init__(self, rawsource='', text='', *children, **attributes) -> None:
super().__init__(rawsource, text, *children, **attributes)
self.attributes['xml:space'] = 'preserve'
@@ -1571,7 +1571,7 @@
# Additional restrictions for `subtitle` and `transition` are tested
# with the respective `check_position()` methods.
- def __init__(self, settings, reporter, *args, **kwargs):
+ def __init__(self, settings, reporter, *args, **kwargs) -> None:
Element.__init__(self, *args, **kwargs)
self.current_source = None
@@ -1725,7 +1725,7 @@
self.ids[id] = node
return id
- def set_name_id_map(self, node, id, msgnode=None, explicit=None):
+ def set_name_id_map(self, node, id, msgnode=None, explicit=None) -> None:
"""
`self.nameids` maps names to IDs, while `self.nametypes` maps names to
booleans representing hyperlink type (True==explicit,
@@ -1766,7 +1766,7 @@
self.nameids[name] = id
self.nametypes[name] = explicit
- def set_duplicate_name_id(self, node, id, name, msgnode, explicit):
+ def set_duplicate_name_id(self, node, id, name, msgnode, explicit) -> None:
old_id = self.nameids[name]
old_explicit = self.nametypes[name]
self.nametypes[name] = old_explicit or explicit
@@ -1808,66 +1808,66 @@
if msgnode is not None:
msgnode += msg
- def has_name(self, name):
+ def has_name(self, name) -> bool:
return name in self.nameids
# "note" here is an imperative verb: "take note of".
- def note_implicit_target(self, target, msgnode=None):
+ def note_implicit_target(self, target, msgnode=None) -> None:
id = self.set_id(target, msgnode)
self.set_name_id_map(target, id, msgnode, explicit=False)
- def note_explicit_target(self, target, msgnode=None):
+ def note_explicit_target(self, target, msgnode=None) -> None:
id = self.set_id(target, msgnode)
self.set_name_id_map(target, id, msgnode, explicit=True)
- def note_refname(self, node):
+ def note_refname(self, node) -> None:
self.refnames.setdefault(node['refname'], []).append(node)
- def note_refid(self, node):
+ def note_refid(self, node) -> None:
self.refids.setdefault(node['refid'], []).append(node)
- def note_indirect_target(self, target):
+ def note_indirect_target(self, target) -> None:
self.indirect_targets.append(target)
if target['names']:
self.note_refname(target)
- def note_anonymous_target(self, target):
+ def note_anonymous_target(self, target) -> None:
self.set_id(target)
- def note_autofootnote(self, footnote):
+ def note_autofootnote(self, footnote) -> None:
self.set_id(footnote)
self.autofootnotes.append(footnote)
- def note_autofootnote_ref(self, ref):
+ def note_autofootnote_ref(self, ref) -> None:
self.set_id(ref)
self.autofootnote_refs.append(ref)
- def note_symbol_footnote(self, footnote):
+ def note_symbol_footnote(self, footnote) -> None:
self.set_id(footnote)
self.symbol_footnotes.append(footnote)
- def note_symbol_footnote_ref(self, ref):
+ def note_symbol_footnote_ref(self, ref) -> None:
self.set_id(ref)
self.symbol_footnote_refs.append(ref)
- def note_footnote(self, footnote):
+ def note_footnote(self, footnote) -> None:
self.set_id(footnote)
self.footnotes.append(footnote)
- def note_footnote_ref(self, ref):
+ def note_footnote_ref(self, ref) -> None:
self.set_id(ref)
self.footnote_refs.setdefault(ref['refname'], []).append(ref)
self.note_refname(ref)
- def note_citation(self, citation):
+ def note_citation(self, citation) -> None:
self.citations.append(citation)
- def note_citation_ref(self, ref):
+ def note_citation_ref(self, ref) -> None:
self.set_id(ref)
self.citation_refs.setdefault(ref['refname'], []).append(ref)
self.note_refname(ref)
- def note_substitution_def(self, subdef, def_name, msgnode=None):
+ def note_substitution_def(self, subdef, def_name, msgnode=None) -> None:
name = whitespace_normalize_name(def_name)
if name in self.substitution_defs:
msg = self.reporter.error(
@@ -1882,19 +1882,19 @@
# case-insensitive mapping:
self.substitution_names[fully_normalize_name(name)] = name
- def note_substitution_ref(self, subref, refname):
+ def note_substitution_ref(self, subref, refname) -> None:
subref['refname'] = whitespace_normalize_name(refname)
- def note_pending(self, pending, priority=None):
+ def note_pending(self, pending, priority=None) -> None:
self.transformer.add_pending(pending, priority)
- def note_parse_message(self, message):
+ def note_parse_message(self, message) -> None:
self.parse_messages.append(message)
- def note_transform_message(self, message):
+ def note_transform_message(self, message) -> None:
self.transform_messages.append(message)
- def note_source(self, source, offset):
+ def note_source(self, source, offset) -> None:
self.current_source = source
if offset is None:
self.current_line = offset
@@ -2301,7 +2301,7 @@
'level', 'line', 'type')
content_model = ((Body, '+'),) # (%body.elements;)+
- def __init__(self, message=None, *children, **attributes):
+ def __init__(self, message=None, *children, **attributes) -> None:
rawsource = attributes.pop('rawsource', '')
if message:
p = paragraph('', message)
@@ -2312,7 +2312,7 @@
print('system_message: children=%r' % (children,))
raise
- def astext(self):
+ def astext(self) -> str:
line = self.get('line', '')
return '%s:%s: (%s/%s) %s' % (self['source'], line, self['type'],
self['level'], Element.astext(self))
@@ -2348,7 +2348,7 @@
"""
def __init__(self, transform, details=None,
- rawsource='', *children, **attributes):
+ rawsource='', *children, **attributes) -> None:
Element.__init__(self, rawsource, *children, **attributes)
self.transform = transform
@@ -2514,7 +2514,7 @@
Used to ensure transitional compatibility with existing 3rd-party writers.
"""
- def __init__(self, document):
+ def __init__(self, document) -> None:
self.document = document
def dispatch_visit(self, node):
@@ -2603,19 +2603,19 @@
raise NotImplementedError
-def _call_default_visit(self, node):
+def _call_default_visit(self, node) -> None:
self.default_visit(node)
-def _call_default_departure(self, node):
+def _call_default_departure(self, node) -> None:
self.default_departure(node)
-def _nop(self, node):
+def _nop(self, node) -> None:
pass
-def _add_node_class_names(names):
+def _add_node_class_names(names) -> None:
"""Save typing with dynamic assignments:"""
for _name in names:
setattr(GenericNodeVisitor, "visit_" + _name, _call_default_visit)
@@ -2632,7 +2632,7 @@
Make a complete copy of a tree or branch, including element attributes.
"""
- def __init__(self, document):
+ def __init__(self, document) -> None:
GenericNodeVisitor.__init__(self, document)
self.parent_stack = []
self.parent = []
@@ -2640,7 +2640,7 @@
def get_tree_copy(self):
return self.parent[0]
- def default_visit(self, node):
+ def default_visit(self, node) -> None:
"""Copy the current node, and make it the new acting parent."""
newnode = node.copy()
self.parent.append(newnode)
@@ -2647,7 +2647,7 @@
self.parent_stack.append(self.parent)
self.parent = newnode
- def default_departure(self, node):
+ def default_departure(self, node) -> None:
"""Restore the previous acting parent."""
self.parent = self.parent_stack.pop()
@@ -2657,7 +2657,7 @@
class ValidationError(ValueError):
"""Invalid Docutils Document Tree Element."""
- def __init__(self, msg, problematic_element=None):
+ def __init__(self, msg, problematic_element=None) -> None:
super().__init__(msg)
self.problematic_element = problematic_element
@@ -2827,7 +2827,7 @@
}
-def dupname(node, name):
+def dupname(node, name) -> None:
node['dupnames'].append(name)
node['names'].remove(name)
# Assume that `node` is referenced, even though it isn't;
@@ -2870,7 +2870,7 @@
for name in names]
-def pseudo_quoteattr(value):
+def pseudo_quoteattr(value) -> str:
"""Quote attributes for pseudo-xml"""
return '"%s"' % value
Modified: trunk/docutils/docutils/parsers/__init__.py
===================================================================
--- trunk/docutils/docutils/parsers/__init__.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/parsers/__init__.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -58,7 +58,7 @@
"""Override to parse `inputstring` into document tree `document`."""
raise NotImplementedError('subclass must override this method')
- def setup_parse(self, inputstring, document):
+ def setup_parse(self, inputstring, document) -> None:
"""Initial parse setup. Call at start of `self.parse()`."""
self.inputstring = inputstring
# provide fallbacks in case the document has only generic settings
@@ -68,7 +68,7 @@
self.document = document
document.reporter.attach_observer(document.note_parse_message)
- def finish_parse(self):
+ def finish_parse(self) -> None:
"""Finalize parse details. Call at end of `self.parse()`."""
self.document.reporter.detach_observer(
self.document.note_parse_message)
Modified: trunk/docutils/docutils/parsers/docutils_xml.py
===================================================================
--- trunk/docutils/docutils/parsers/docutils_xml.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/parsers/docutils_xml.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -38,7 +38,7 @@
'validate': True,
}
- def parse(self, inputstring, document):
+ def parse(self, inputstring, document) -> None:
"""
Parse `inputstring` and populate `document`, a "document tree".
@@ -175,7 +175,7 @@
return node
-def append_text(node, text, unindent):
+def append_text(node, text, unindent) -> None:
# Format `text`, wrap in a TextElement and append to `node`.
# Skip if `text` is empty or just formatting whitespace.
if not text:
Modified: trunk/docutils/docutils/parsers/null.py
===================================================================
--- trunk/docutils/docutils/parsers/null.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/parsers/null.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -16,5 +16,5 @@
config_section = 'null parser'
config_section_dependencies = ('parsers',)
- def parse(self, inputstring, document):
+ def parse(self, inputstring, document) -> None:
pass
Modified: trunk/docutils/docutils/parsers/recommonmark_wrapper.py
===================================================================
--- trunk/docutils/docutils/parsers/recommonmark_wrapper.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/parsers/recommonmark_wrapper.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -100,7 +100,7 @@
# Post-Processing
# ---------------
- def finish_parse(self):
+ def finish_parse(self) -> None:
"""Finalize parse details. Call at end of `self.parse()`."""
document = self.document
@@ -157,7 +157,7 @@
# now we are ready to call the upstream function:
super().finish_parse()
- def visit_document(self, node):
+ def visit_document(self, node) -> None:
"""Dummy function to prevent spurious warnings.
cf. https://github.com/readthedocs/recommonmark/issues/177
@@ -166,5 +166,5 @@
# Overwrite parent method with version that
# doesn't pass deprecated `rawsource` argument to nodes.Text:
- def visit_text(self, mdnode):
+ def visit_text(self, mdnode) -> None:
self.current_node.append(nodes.Text(mdnode.literal))
Modified: trunk/docutils/docutils/parsers/rst/__init__.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/__init__.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/parsers/rst/__init__.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -150,7 +150,7 @@
config_section = 'restructuredtext parser'
config_section_dependencies = ('parsers',)
- def __init__(self, rfc2822=False, inliner=None):
+ def __init__(self, rfc2822=False, inliner=None) -> None:
if rfc2822:
self.initial_state = 'RFC2822Body'
else:
@@ -161,7 +161,7 @@
def get_transforms(self):
return super().get_transforms() + [universal.SmartQuotes]
- def parse(self, inputstring, document):
+ def parse(self, inputstring, document) -> None:
"""Parse `inputstring` and populate `document`, a document tree."""
self.setup_parse(inputstring, document)
# provide fallbacks in case the document has only generic settings
@@ -199,7 +199,7 @@
instead!
"""
- def __init__(self, level, message):
+ def __init__(self, level, message) -> None:
"""Set error `message` and `level`"""
Exception.__init__(self)
self.level = level
@@ -317,7 +317,7 @@
"""May the directive have content?"""
def __init__(self, name, arguments, options, content, lineno,
- content_offset, block_text, state, state_machine):
+ content_offset, block_text, state, state_machine) -> None:
self.name = name
self.arguments = arguments
self.options = options
@@ -375,7 +375,7 @@
raise self.error('Content block expected for the "%s" directive; '
'none found.' % self.name)
- def add_name(self, node):
+ def add_name(self, node) -> None:
"""Append self.options['name'] to node['names'] if it exists.
Also normalize the name string and register it as explicit target.
Modified: trunk/docutils/docutils/parsers/rst/directives/__init__.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/__init__.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/parsers/rst/directives/__init__.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -133,7 +133,7 @@
return directive, messages
-def register_directive(name, directive):
+def register_directive(name, directive) -> None:
"""
Register a nonstandard application-defined directive function.
Language lookups are not needed for such functions.
@@ -431,7 +431,7 @@
% (argument, format_values(values)))
-def format_values(values):
+def format_values(values) -> str:
return '%s, or "%s"' % (', '.join('"%s"' % s for s in values[:-1]),
values[-1])
Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/tables.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/parsers/rst/directives/tables.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -89,7 +89,7 @@
line=self.lineno)
raise SystemMessagePropagation(error)
- def set_table_width(self, table_node):
+ def set_table_width(self, table_node) -> None:
if 'width' in self.options:
table_node['width'] = self.options.get('width')
@@ -116,7 +116,7 @@
raise SystemMessagePropagation(error)
return col_widths
- def extend_short_rows_with_empty_cells(self, columns, parts):
+ def extend_short_rows_with_empty_cells(self, columns, parts) -> None:
for part in parts:
for row in part:
if len(row) < columns:
@@ -206,7 +206,7 @@
lineterminator = '\n'
quoting = csv.QUOTE_MINIMAL
- def __init__(self, options):
+ def __init__(self, options) -> None:
if 'delim' in options:
self.delimiter = options['delim']
if 'keepspace' in options:
@@ -247,7 +247,7 @@
lineterminator = '\n'
quoting = csv.QUOTE_MINIMAL
- def __init__(self):
+ def __init__(self) -> None:
warnings.warn('CSVTable.HeaderDialect will be removed '
'in Docutils 1.0',
DeprecationWarning, stacklevel=2)
@@ -254,7 +254,7 @@
super().__init__()
@staticmethod
- def check_requirements():
+ def check_requirements() -> None:
warnings.warn('CSVTable.check_requirements()'
' is not required with Python 3'
' and will be removed in Docutils 0.22.',
Modified: trunk/docutils/docutils/parsers/rst/roles.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/roles.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/parsers/rst/roles.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -154,7 +154,7 @@
return None, messages # Error message will be generated by caller.
-def register_canonical_role(name, role_fn):
+def register_canonical_role(name, role_fn) -> None:
"""
Register an interpreted text role by its canonical name.
@@ -166,7 +166,7 @@
_role_registry[name.lower()] = role_fn
-def register_local_role(name, role_fn):
+def register_local_role(name, role_fn) -> None:
"""
Register an interpreted text role by its local or language-dependent name.
@@ -178,7 +178,7 @@
_roles[name.lower()] = role_fn
-def set_implicit_options(role_fn):
+def set_implicit_options(role_fn) -> None:
"""
Add customization options to role functions, unless explicitly set or
disabled.
@@ -189,7 +189,7 @@
role_fn.options['class'] = directives.class_option
-def register_generic_role(canonical_name, node_class):
+def register_generic_role(canonical_name, node_class) -> None:
"""For roles which simply wrap a given `node_class` around the text."""
role = GenericRole(canonical_name, node_class)
register_canonical_role(canonical_name, role)
@@ -202,7 +202,7 @@
The interpreted text is simply wrapped with the provided node class.
"""
- def __init__(self, role_name, node_class):
+ def __init__(self, role_name, node_class) -> None:
self.name = role_name
self.node_class = node_class
@@ -215,7 +215,9 @@
class CustomRole:
"""Wrapper for custom interpreted text roles."""
- def __init__(self, role_name, base_role, options=None, content=None):
+ def __init__(
+ self, role_name, base_role, options=None, content=None,
+ ) -> None:
self.name = role_name
self.base_role = base_role
self.options = getattr(base_role, 'options', None)
@@ -411,7 +413,7 @@
unimplemented_role)
-def set_classes(options):
+def set_classes(options) -> None:
"""Deprecated. Obsoleted by ``normalize_options()``."""
warnings.warn('The auxiliary function roles.set_classes() is obsoleted'
' by roles.normalize_options() and will be removed'
Modified: trunk/docutils/docutils/parsers/rst/states.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/states.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/parsers/rst/states.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -129,7 +129,7 @@
"""Stores data attributes for dotted-attribute access."""
- def __init__(self, **keywordargs):
+ def __init__(self, **keywordargs) -> None:
self.__dict__.update(keywordargs)
@@ -142,7 +142,7 @@
"""
def run(self, input_lines, document, input_offset=0, match_titles=True,
- inliner=None):
+ inliner=None) -> None:
"""
Parse `input_lines` and modify the `document` node in place.
@@ -209,12 +209,12 @@
nested_sm = NestedStateMachine
nested_sm_cache = []
- def __init__(self, state_machine, debug=False):
+ def __init__(self, state_machine, debug=False) -> None:
self.nested_sm_kwargs = {'state_classes': state_classes,
'initial_state': 'Body'}
StateWS.__init__(self, state_machine, debug)
- def runtime_init(self):
+ def runtime_init(self) -> None:
StateWS.runtime_init(self)
memo = self.state_machine.memo
self.memo = memo
@@ -226,7 +226,7 @@
if not hasattr(self.reporter, 'get_source_and_line'):
self.reporter.get_source_and_line = self.state_machine.get_source_and_line # noqa:E501
- def goto_line(self, abs_line_offset):
+ def goto_line(self, abs_line_offset) -> None:
"""
Jump to input line `abs_line_offset`, ignoring jumps past the end.
"""
@@ -319,12 +319,12 @@
state_machine.unlink()
return state_machine.abs_line_offset(), blank_finish
- def section(self, title, source, style, lineno, messages):
+ def section(self, title, source, style, lineno, messages) -> None:
"""Check for a valid subsection and create one if it checks out."""
if self.check_subsection(source, style, lineno):
self.new_subsection(title, lineno, messages)
- def check_subsection(self, source, style, lineno):
+ def check_subsection(self, source, style, lineno) -> bool:
"""
Check for a valid subsection header. Return True or False.
@@ -463,12 +463,12 @@
Parse inline markup; call the `parse()` method.
"""
- def __init__(self):
+ def __init__(self) -> None:
self.implicit_dispatch = []
"""List of (pattern, bound method) tuples, used by
`self.implicit_inline`."""
- def init_customizations(self, settings):
+ def init_customizations(self, settings) -> None:
# lookahead and look-behind expressions for inline markup rules
if getattr(settings, 'character_level_inline_markup', False):
start_string_prefix = '(^|(?<!\x00))'
@@ -1493,7 +1493,7 @@
field = field[:field.rfind(':')] # strip off trailing ':' etc.
return field
- def parse_field_body(self, indented, offset, node):
+ def parse_field_body(self, indented, offset, node) -> None:
self.nested_parse(indented, input_offset=offset, node=node)
def option_marker(self, match, context, next_state):
@@ -1633,13 +1633,13 @@
line.indent = len(match.group(1)) - 1
return line, messages, blank_finish
- def nest_line_block_lines(self, block):
+ def nest_line_block_lines(self, block) -> None:
for index in range(1, len(block)):
if getattr(block[index], 'indent', None) is None:
block[index].indent = block[index - 1].indent
self.nest_line_block_segment(block)
- def nest_line_block_segment(self, block):
+ def nest_line_block_segment(self, block) -> None:
indents = [item.indent for item in block]
least = min(indents)
new_items = []
@@ -2092,7 +2092,7 @@
substitution_node, subname, self.parent)
return [substitution_node], blank_finish
- def disallowed_inside_substitution_definitions(self, node):
+ def disallowed_inside_substitution_definitions(self, node) -> bool:
if (node['ids']
or isinstance(node, nodes.reference) and node.get('anonymous')
or isinstance(node, nodes.footnote_reference) and node.get('auto')): # noqa: E501
@@ -2379,7 +2379,7 @@
nodelist, blank_finish = self.comment(match)
return nodelist + errors, blank_finish
- def explicit_list(self, blank_finish):
+ def explicit_list(self, blank_finish) -> None:
"""
Create a nested state machine for a series of explicit markup
constructs (including anonymous hyperlink targets).
@@ -2629,7 +2629,7 @@
No nested parsing is done (including inline markup parsing).
"""
- def parse_field_body(self, indented, offset, node):
+ def parse_field_body(self, indented, offset, node) -> None:
"""Override `Body.parse_field_body` for simpler parsing."""
lines = []
for line in list(indented) + ['']:
@@ -3054,7 +3054,7 @@
self.parent += msg
return [], 'Body', []
- def short_overline(self, context, blocktext, lineno, lines=1):
+ def short_overline(self, context, blocktext, lineno, lines=1) -> None:
msg = self.reporter.info(
'Possible incomplete section title.\nTreating the overline as '
"ordinary text because it's so short.",
@@ -3080,7 +3080,7 @@
'text': r''}
initial_transitions = ('initial_quoted', 'text')
- def __init__(self, state_machine, debug=False):
+ def __init__(self, state_machine, debug=False) -> None:
RSTState.__init__(self, state_machine, debug)
self.messages = []
self.initial_lineno = None
Modified: trunk/docutils/docutils/parsers/rst/tableparser.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/tableparser.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/parsers/rst/tableparser.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -35,7 +35,7 @@
from the table's start line.
"""
- def __init__(self, *args, **kwargs):
+ def __init__(self, *args, **kwargs) -> None:
self.offset = kwargs.pop('offset', 0)
DataError.__init__(self, *args)
@@ -143,7 +143,7 @@
head_body_separator_pat = re.compile(r'\+=[=+]+=\+ *$')
- def setup(self, block):
+ def setup(self, block) -> None:
self.block = block[:] # make a copy; it may be modified
self.block.disconnect() # don't propagate changes to parent
self.bottom = len(block) - 1
@@ -190,7 +190,7 @@
if not self.check_parse_complete():
raise TableMarkupError('Malformed table; parse incomplete.')
- def mark_done(self, top, left, bottom, right):
+ def mark_done(self, top, left, bottom, right) -> None:
"""For keeping track of how much of each text column has been seen."""
before = top - 1
after = bottom - 1
@@ -198,7 +198,7 @@
assert self.done[col] == before
self.done[col] = after
- def check_parse_complete(self):
+ def check_parse_complete(self) -> bool:
"""Each text column should have been completely seen."""
last = self.bottom - 1
for col in range(self.right):
@@ -372,7 +372,7 @@
head_body_separator_pat = re.compile('=[ =]*$')
span_pat = re.compile('-[ -]*$')
- def setup(self, block):
+ def setup(self, block) -> None:
self.block = block[:] # make a copy; it will be modified
self.block.disconnect() # don't propagate changes to parent
# Convert top & bottom borders to column span underlines:
@@ -386,7 +386,7 @@
self.rowseps = {0: [0]}
self.colseps = {0: [0]}
- def parse_table(self):
+ def parse_table(self) -> None:
"""
First determine the column boundaries from the top border, then
process rows. Each row may consist of multiple lines; accumulate
@@ -459,7 +459,7 @@
i += 1
return cells
- def parse_row(self, lines, start, spanline=None):
+ def parse_row(self, lines, start, spanline=None) -> None:
"""
Given the text `lines` of a row, parse it and append to `self.table`.
@@ -529,7 +529,7 @@
self.table[first_body_row:])
-def update_dict_of_lists(master, newdata):
+def update_dict_of_lists(master, newdata) -> None:
"""
Extend the list values of `master` with those from `newdata`.
Modified: trunk/docutils/docutils/readers/__init__.py
===================================================================
--- trunk/docutils/docutils/readers/__init__.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/readers/__init__.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -35,7 +35,7 @@
universal.ExposeInternals,
universal.StripComments]
- def __init__(self, parser=None, parser_name=None):
+ def __init__(self, parser=None, parser_name=None) -> None:
"""
Initialize the Reader instance.
@@ -67,7 +67,7 @@
"""Raw text input; either a single string or, for more complex cases,
a collection of strings."""
- def set_parser(self, parser_name):
+ def set_parser(self, parser_name) -> None:
"""Set `self.parser` by name."""
parser_class = parsers.get_parser_class(parser_name)
self.parser = parser_class()
@@ -81,7 +81,7 @@
self.parse()
return self.document
- def parse(self):
+ def parse(self) -> None:
"""Parse `self.input` into a document tree."""
self.document = document = self.new_document()
self.parser.parse(self.input, document)
Modified: trunk/docutils/docutils/readers/doctree.py
===================================================================
--- trunk/docutils/docutils/readers/doctree.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/readers/doctree.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -29,7 +29,7 @@
config_section = 'doctree reader'
config_section_dependencies = ('readers',)
- def parse(self):
+ def parse(self) -> None:
"""
No parsing to do; refurbish the document tree instead.
Overrides the inherited method.
Modified: trunk/docutils/docutils/readers/pep.py
===================================================================
--- trunk/docutils/docutils/readers/pep.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/readers/pep.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -41,7 +41,7 @@
inliner_class = rst.states.Inliner
- def __init__(self, parser=None, parser_name=None):
+ def __init__(self, parser=None, parser_name=None) -> None:
"""`parser` should be ``None``, `parser_name` is ignored.
The default parser is "rst" with PEP-specific settings
Modified: trunk/docutils/docutils/statemachine.py
===================================================================
--- trunk/docutils/docutils/statemachine.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/statemachine.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -128,7 +128,7 @@
results of processing in a list.
"""
- def __init__(self, state_classes, initial_state, debug=False):
+ def __init__(self, state_classes, initial_state, debug=False) -> None:
"""
Initialize a `StateMachine` object; add state objects.
@@ -171,7 +171,7 @@
line changes. Observers are called with one argument, ``self``.
Cleared at the end of `run()`."""
- def unlink(self):
+ def unlink(self) -> None:
"""Remove circular references to objects no longer required."""
for state in self.states.values():
state.unlink()
@@ -381,7 +381,7 @@
# # list(self.input_lines.lines())))
return src, srcline
- def insert_input(self, input_lines, source):
+ def insert_input(self, input_lines, source) -> None:
self.input_lines.insert(self.line_offset + 1, '',
source='internal padding after '+source,
offset=len(input_lines))
@@ -461,7 +461,7 @@
raise DuplicateStateError(statename)
self.states[statename] = state_class(self, self.debug)
- def add_states(self, state_classes):
+ def add_states(self, state_classes) -> None:
"""
Add `state_classes` (a list of `State` subclasses).
"""
@@ -468,7 +468,7 @@
for state_class in state_classes:
self.add_state(state_class)
- def runtime_init(self):
+ def runtime_init(self) -> None:
"""
Initialize `self.states`.
"""
@@ -475,7 +475,7 @@
for state in self.states.values():
state.runtime_init()
- def error(self):
+ def error(self) -> None:
"""Report error details."""
type, value, module, line, function = _exception_data()
print('%s: %s' % (type, value), file=sys.stderr)
@@ -483,7 +483,7 @@
print('module %s, line %s, function %s' % (module, line, function),
file=sys.stderr)
- def attach_observer(self, observer):
+ def attach_observer(self, observer) -> None:
"""
The `observer` parameter is a function or bound method which takes two
arguments, the source and offset of the current line.
@@ -490,10 +490,10 @@
"""
self.observers.append(observer)
- def detach_observer(self, observer):
+ def detach_observer(self, observer) -> None:
self.observers.remove(observer)
- def notify_observers(self):
+ def notify_observers(self) -> None:
for observer in self.observers:
try:
info = self.input_lines.info(self.line_offset)
@@ -579,7 +579,7 @@
defaults.
"""
- def __init__(self, state_machine, debug=False):
+ def __init__(self, state_machine, debug=False) -> None:
"""
Initialize a `State` object; make & add initial transitions.
@@ -615,7 +615,7 @@
self.nested_sm_kwargs = {'state_classes': [self.__class__],
'initial_state': self.__class__.__name__}
- def runtime_init(self):
+ def runtime_init(self) -> None:
"""
Initialize this `State` before running the state machine; called from
`self.state_machine.run()`.
@@ -622,11 +622,11 @@
"""
pass
- def unlink(self):
+ def unlink(self) -> None:
"""Remove circular references to objects no longer required."""
self.state_machine = None
- def add_initial_transitions(self):
+ def add_initial_transitions(self) -> None:
"""Make and add transitions listed in `self.initial_transitions`."""
if self.initial_transitions:
names, transitions = self.make_transitions(
@@ -937,7 +937,7 @@
"""Default initial whitespace transitions, added before those listed in
`State.initial_transitions`. May be overridden in subclasses."""
- def __init__(self, state_machine, debug=False):
+ def __init__(self, state_machine, debug=False) -> None:
"""
Initialize a `StateSM` object; extends `State.__init__()`.
@@ -953,7 +953,7 @@
if self.known_indent_sm_kwargs is None:
self.known_indent_sm_kwargs = self.indent_sm_kwargs
- def add_initial_transitions(self):
+ def add_initial_transitions(self) -> None:
"""
Add whitespace-specific transitions before those defined in subclass.
@@ -1071,7 +1071,7 @@
"""
def __init__(self, initlist=None, source=None, items=None,
- parent=None, parent_offset=None):
+ parent=None, parent_offset=None) -> None:
self.data = []
"""The actual list of data, flattened from various sources."""
@@ -1097,10 +1097,10 @@
self.items = [(source, i) for i in range(len(initlist))]
assert len(self.data) == len(self.items), 'data mismatch'
- def __str__(self):
+ def __str__(self) -> str:
return str(self.data)
- def __repr__(self):
+ def __repr__(self) -> str:
return f'{self.__class__.__name__}({self.data}, items={self.items})'
def __lt__(self, other): return self.data < self.__cast(other) # noqa
@@ -1116,10 +1116,10 @@
else:
return other
- def __contains__(self, item):
+ def __contains__(self, item) -> bool:
return item in self.data
- def __len__(self):
+ def __len__(self) -> int:
return len(self.data)
# The __getitem__()/__setitem__() methods check whether the index
@@ -1135,7 +1135,7 @@
else:
return self.data[i]
- def __setitem__(self, i, item):
+ def __setitem__(self, i, item) -> None:
if isinstance(i, slice):
assert i.step in (None, 1), 'cannot handle slice with stride'
if not isinstance(item, ViewList):
@@ -1152,7 +1152,7 @@
if self.parent:
self.parent[i + self.parent_offset] = item
- def __delitem__(self, i):
+ def __delitem__(self, i) -> None:
try:
del self.data[i]
del self.items[i]
@@ -1206,7 +1206,7 @@
self.data.extend(other.data)
self.items.extend(other.items)
- def append(self, item, source=None, offset=0):
+ def append(self, item, source=None, offset=0) -> None:
if source is None:
self.extend(item)
else:
@@ -1266,7 +1266,7 @@
del self.data[-n:]
del self.items[-n:]
- def remove(self, item):
+ def remove(self, item) -> None:
index = self.index(item)
del self[index]
@@ -1276,12 +1276,12 @@
def index(self, item):
return self.data.index(item)
- def reverse(self):
+ def reverse(self) -> None:
self.data.reverse()
self.items.reverse()
self.parent = None
- def sort(self, *args):
+ def sort(self, *args) -> None:
tmp = sorted(zip(self.data, self.items), *args)
self.data = [entry[0] for entry in tmp]
self.items = [entry[1] for entry in tmp]
@@ -1305,7 +1305,7 @@
"""Return offset for index `i`."""
return self.info(i)[1]
- def disconnect(self):
+ def disconnect(self) -> None:
"""Break link between this list and parent list."""
self.parent = None
@@ -1314,7 +1314,7 @@
for (value, (source, offset)) in zip(self.data, self.items):
yield source, offset, value
- def pprint(self):
+ def pprint(self) -> None:
"""Print the list in `grep` format (`source:offset:value` lines)"""
for line in self.xitems():
print("%s:%d:%s" % line)
@@ -1324,7 +1324,7 @@
"""A `ViewList` with string-specific methods."""
- def trim_left(self, length, start=0, end=sys.maxsize):
+ def trim_left(self, length, start=0, end=sys.maxsize) -> None:
"""
Trim `length` characters off the beginning of each item, in-place,
from index `start` to `end`. No whitespace-checking is done on the
@@ -1435,7 +1435,7 @@
block.data = [line[indent:] for line in block.data]
return block
- def pad_double_width(self, pad_char):
+ def pad_double_width(self, pad_char) -> None:
"""Pad all double-width characters in `self` appending `pad_char`.
For East Asian language support.
@@ -1450,7 +1450,7 @@
new.append(pad_char)
self.data[i] = ''.join(new)
- def replace(self, old, new):
+ def replace(self, old, new) -> None:
"""Replace all occurrences of substring `old` with `new`."""
for i in range(len(self.data)):
self.data[i] = self.data[i].replace(old, new)
Modified: trunk/docutils/docutils/transforms/__init__.py
===================================================================
--- trunk/docutils/docutils/transforms/__init__.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/transforms/__init__.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -37,7 +37,7 @@
default_priority = None
"""Numerical priority of this transform, 0 through 999 (override)."""
- def __init__(self, document, startnode=None):
+ def __init__(self, document, startnode=None) -> None:
"""
Initial setup for in-place document transforms.
"""
@@ -72,7 +72,7 @@
https://docutils.sourceforge.io/docs/peps/pep-0258.html#transformer
"""
- def __init__(self, document):
+ def __init__(self, document) -> None:
self.transforms = []
"""List of transforms to apply. Each item is a 4-tuple:
``(priority string, transform class, pending node or None, kwargs)``.
@@ -100,7 +100,7 @@
"""Internal serial number to keep track of the add order of
transforms."""
- def add_transform(self, transform_class, priority=None, **kwargs):
+ def add_transform(self, transform_class, priority=None, **kwargs) -> None:
"""
Store a single transform. Use `priority` to override the default.
`kwargs` is a dictionary whose contents are passed as keyword
@@ -114,7 +114,7 @@
(priority_string, transform_class, None, kwargs))
self.sorted = False
- def add_transforms(self, transform_list):
+ def add_transforms(self, transform_list) -> None:
"""Store multiple transforms, with default priorities."""
for transform_class in transform_list:
priority_string = self.get_priority_string(
@@ -123,7 +123,7 @@
(priority_string, transform_class, None, {}))
self.sorted = False
- def add_pending(self, pending, priority=None):
+ def add_pending(self, pending, priority=None) -> None:
"""Store a transform with an associated `pending` node."""
transform_class = pending.transform
if priority is None:
@@ -133,7 +133,7 @@
(priority_string, transform_class, pending, {}))
self.sorted = False
- def get_priority_string(self, priority):
+ def get_priority_string(self, priority) -> str:
"""
Return a string, `priority` combined with `self.serialno`.
@@ -142,7 +142,7 @@
self.serialno += 1
return '%03d-%03d' % (priority, self.serialno)
- def populate_from_components(self, components):
+ def populate_from_components(self, components) -> None:
"""
Store each component's default transforms and reference resolvers
@@ -167,7 +167,7 @@
resolvers.sort(key=keyfun)
self.unknown_reference_resolvers += resolvers
- def apply_transforms(self):
+ def apply_transforms(self) -> None:
"""Apply all of the stored transforms, in priority order."""
self.document.reporter.attach_observer(
self.document.note_transform_message)
Modified: trunk/docutils/docutils/transforms/components.py
===================================================================
--- trunk/docutils/docutils/transforms/components.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/transforms/components.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -41,7 +41,7 @@
default_priority = 780
- def apply(self):
+ def apply(self) -> None:
pending = self.startnode
component_type = pending.details['component'] # 'reader' or 'writer'
formats = (pending.details['format']).split(',')
Modified: trunk/docutils/docutils/transforms/frontmatter.py
===================================================================
--- trunk/docutils/docutils/transforms/frontmatter.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/transforms/frontmatter.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -35,7 +35,7 @@
Abstract base class for DocTitle and SectionSubTitle transforms.
"""
- def promote_title(self, node):
+ def promote_title(self, node) -> bool:
"""
Transform the following tree::
@@ -78,7 +78,7 @@
assert isinstance(node[0], nodes.title)
return True
- def promote_subtitle(self, node):
+ def promote_subtitle(self, node) -> bool:
"""
Transform the following node tree::
@@ -197,7 +197,7 @@
default_priority = 320
- def set_metadata(self):
+ def set_metadata(self) -> None:
"""
Set document['title'] metadata title from the following
sources, listed in order of priority:
@@ -213,7 +213,7 @@
nodes.title):
self.document['title'] = self.document[0].astext()
- def apply(self):
+ def apply(self) -> None:
if self.document.settings.setdefault('doctitle_xform', True):
# promote_(sub)title defined in TitlePromoter base class.
if self.promote_title(self.document):
@@ -251,7 +251,7 @@
default_priority = 350
- def apply(self):
+ def apply(self) -> None:
if not self.document.settings.setdefault('sectsubtitle_xform', True):
return
for section in self.document.findall(nodes.section):
@@ -355,7 +355,7 @@
"""Canonical field name (lowcased) to node class name mapping for
bibliographic fields (field_list)."""
- def apply(self):
+ def apply(self) -> None:
if not self.document.settings.setdefault('docinfo_xform', True):
return
document = self.document
@@ -423,7 +423,7 @@
nodelist.append(topics[name])
return nodelist
- def check_empty_biblio_field(self, field, name):
+ def check_empty_biblio_field(self, field, name) -> bool:
if len(field[-1]) < 1:
field[-1] += self.document.reporter.warning(
f'Cannot extract empty bibliographic field "{name}".',
@@ -431,7 +431,7 @@
return False
return True
- def check_compound_biblio_field(self, field, name):
+ def check_compound_biblio_field(self, field, name) -> bool:
# Check that the `field` body contains a single paragraph
# (i.e. it must *not* be a compound element).
f_body = field[-1]
Modified: trunk/docutils/docutils/transforms/misc.py
===================================================================
--- trunk/docutils/docutils/transforms/misc.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/transforms/misc.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -26,7 +26,7 @@
default_priority = 990
- def apply(self):
+ def apply(self) -> None:
pending = self.startnode
pending.details['callback'](pending)
pending.parent.remove(pending)
@@ -41,7 +41,7 @@
default_priority = 210
- def apply(self):
+ def apply(self) -> None:
pending = self.startnode
parent = pending.parent
child = pending
@@ -93,11 +93,11 @@
default_priority = 830
- def apply(self):
+ def apply(self) -> None:
for node in self.document.findall(nodes.transition):
self.visit_transition(node)
- def visit_transition(self, node):
+ def visit_transition(self, node) -> None:
index = node.parent.index(node)
previous_sibling = node.previous_sibling()
msg = ''
Modified: trunk/docutils/docutils/transforms/parts.py
===================================================================
--- trunk/docutils/docutils/transforms/parts.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/transforms/parts.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -28,7 +28,7 @@
default_priority = 710
"""Should be applied before `Contents`."""
- def apply(self):
+ def apply(self) -> None:
self.maxdepth = self.startnode.details.get('depth', None)
self.startvalue = self.startnode.details.get('start', 1)
self.prefix = self.startnode.details.get('prefix', '')
@@ -44,7 +44,7 @@
self.document.settings.sectnum_prefix = self.prefix
self.document.settings.sectnum_suffix = self.suffix
- def update_section_numbers(self, node, prefix=(), depth=0):
+ def update_section_numbers(self, node, prefix=(), depth=0) -> None:
depth += 1
if prefix:
sectnum = 1
@@ -84,7 +84,7 @@
default_priority = 720
- def apply(self):
+ def apply(self) -> None:
# let the writer (or output software) build the contents list?
toc_by_writer = getattr(self.document.settings, 'use_latex_toc', False)
# TODO: handle "generate_oowriter_toc" setting of the "ODT" writer.
Modified: trunk/docutils/docutils/transforms/peps.py
===================================================================
--- trunk/docutils/docutils/transforms/peps.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/transforms/peps.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -145,7 +145,7 @@
default_priority = 380
- def apply(self):
+ def apply(self) -> None:
language = languages.get_language(self.document.settings.language_code,
self.document.reporter)
name = language.labels['contents']
@@ -171,7 +171,7 @@
default_priority = 520
- def apply(self):
+ def apply(self) -> None:
doc = self.document
i = len(doc) - 1
refsect = copyright = None
@@ -201,7 +201,7 @@
refsect.append(pending)
self.document.note_pending(pending, 1)
- def cleanup_callback(self, pending):
+ def cleanup_callback(self, pending) -> None:
"""
Remove an empty "References" section.
@@ -219,7 +219,7 @@
default_priority = 760
- def apply(self):
+ def apply(self) -> None:
visitor = PEPZeroSpecial(self.document)
self.document.walk(visitor)
self.startnode.parent.remove(self.startnode)
@@ -238,10 +238,10 @@
pep_url = Headers.pep_url
- def unknown_visit(self, node):
+ def unknown_visit(self, node) -> None:
pass
- def visit_reference(self, node):
+ def visit_reference(self, node) -> None:
node.replace_self(mask_email(node))
def visit_field_list(self, node):
@@ -248,19 +248,19 @@
if 'rfc2822' in node['classes']:
raise nodes.SkipNode
- def visit_tgroup(self, node):
+ def visit_tgroup(self, node) -> None:
self.pep_table = node['cols'] == 4
self.entry = 0
- def visit_colspec(self, node):
+ def visit_colspec(self, node) -> None:
self.entry += 1
if self.pep_table and self.entry == 2:
node['classes'].append('num')
- def visit_row(self, node):
+ def visit_row(self, node) -> None:
self.entry = 0
- def visit_entry(self, node):
+ def visit_entry(self, node) -> None:
self.entry += 1
if self.pep_table and self.entry == 2 and len(node) == 1:
node['classes'].append('num')
Modified: trunk/docutils/docutils/transforms/references.py
===================================================================
--- trunk/docutils/docutils/transforms/references.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/transforms/references.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -37,7 +37,7 @@
default_priority = 260
- def apply(self):
+ def apply(self) -> None:
for target in self.document.findall(nodes.target):
# Only block-level targets without reference (like ".. _target:"):
if (isinstance(target.parent, nodes.TextElement)
@@ -112,7 +112,7 @@
default_priority = 440
- def apply(self):
+ def apply(self) -> None:
anonymous_refs = []
anonymous_targets = []
for node in self.document.findall(nodes.reference):
@@ -207,13 +207,13 @@
default_priority = 460
- def apply(self):
+ def apply(self) -> None:
for target in self.document.indirect_targets:
if not target.resolved:
self.resolve_indirect_target(target)
self.resolve_indirect_references(target)
- def resolve_indirect_target(self, target):
+ def resolve_indirect_target(self, target) -> None:
refname = target.get('refname')
if refname is None:
reftarget_id = target['refid']
@@ -257,7 +257,7 @@
del target['refname']
target.resolved = 1
- def nonexistent_indirect_target(self, target):
+ def nonexistent_indirect_target(self, target) -> None:
if target['refname'] in self.document.nameids:
self.indirect_target_error(target, 'which is a duplicate, and '
'cannot be used as a unique reference')
@@ -264,10 +264,10 @@
else:
self.indirect_target_error(target, 'which does not exist')
- def circular_indirect_reference(self, target):
+ def circular_indirect_reference(self, target) -> None:
self.indirect_target_error(target, 'forming a circular reference')
- def indirect_target_error(self, target, explanation):
+ def indirect_target_error(self, target, explanation) -> None:
naming = ''
reflist = []
if target['names']:
@@ -290,7 +290,7 @@
ref.replace_self(prb)
target.resolved = 1
- def resolve_indirect_references(self, target):
+ def resolve_indirect_references(self, target) -> None:
if target.hasattr('refid'):
attname = 'refid'
call_method = self.document.note_refid
@@ -350,7 +350,7 @@
default_priority = 640
- def apply(self):
+ def apply(self) -> None:
for target in self.document.findall(nodes.target):
if target.hasattr('refuri'):
refuri = target['refuri']
@@ -370,12 +370,12 @@
default_priority = 660
- def apply(self):
+ def apply(self) -> None:
for target in self.document.findall(nodes.target):
if not target.hasattr('refuri') and not target.hasattr('refid'):
self.resolve_reference_ids(target)
- def resolve_reference_ids(self, target):
+ def resolve_reference_ids(self, target) -> None:
"""
Given::
@@ -489,7 +489,7 @@
'\u2663', # ♣ ♣ club suit
]
- def apply(self):
+ def apply(self) -> None:
self.autofootnote_labels = []
startnum = self.document.autofootnote_start
self.document.autofootnote_start = self.number_footnotes(startnum)
@@ -526,7 +526,7 @@
self.autofootnote_labels.append(label)
return startnum
- def number_footnote_references(self, startnum):
+ def number_footnote_references(self, startnum) -> None:
"""Assign numbers to autonumbered footnote references."""
i = 0
for ref in self.document.autofootnote_refs:
@@ -559,7 +559,7 @@
ref.resolved = 1
i += 1
- def symbolize_footnotes(self):
+ def symbolize_footnotes(self) -> None:
"""Add symbols indexes to "[*]"-style footnotes and references."""
labels = []
for footnote in self.document.symbol_footnotes:
@@ -596,7 +596,7 @@
footnote.add_backref(ref['ids'][0])
i += 1
- def resolve_footnotes_and_citations(self):
+ def resolve_footnotes_and_citations(self) -> None:
"""
Link manually-labeled footnotes and citations to/from their
references.
@@ -612,7 +612,7 @@
reflist = self.document.citation_refs[label]
self.resolve_references(citation, reflist)
- def resolve_references(self, note, reflist):
+ def resolve_references(self, note, reflist) -> None:
assert len(note['ids']) == 1
id = note['ids'][0]
for ref in reflist:
@@ -766,12 +766,12 @@
"""The TargetNotes transform has to be applied after `IndirectHyperlinks`
but before `Footnotes`."""
- def __init__(self, document, startnode):
+ def __init__(self, document, startnode) -> None:
Transform.__init__(self, document, startnode=startnode)
self.classes = startnode.details.get('class', [])
- def apply(self):
+ def apply(self) -> None:
notes = {}
nodelist = []
for target in self.document.findall(nodes.target):
@@ -847,7 +847,7 @@
default_priority = 850
- def apply(self):
+ def apply(self) -> None:
visitor = DanglingReferencesVisitor(
self.document,
self.document.transformer.unknown_reference_resolvers)
@@ -877,15 +877,15 @@
class DanglingReferencesVisitor(nodes.SparseNodeVisitor):
- def __init__(self, document, unknown_reference_resolvers):
+ def __init__(self, document, unknown_reference_resolvers) -> None:
nodes.SparseNodeVisitor.__init__(self, document)
self.document = document
self.unknown_reference_resolvers = unknown_reference_resolvers
- def unknown_visit(self, node):
+ def unknown_visit(self, node) -> None:
pass
- def visit_reference(self, node):
+ def visit_reference(self, node) -> None:
if node.resolved or not node.hasattr('refname'):
return
refname = node['refname']
Modified: trunk/docutils/docutils/transforms/universal.py
===================================================================
--- trunk/docutils/docutils/transforms/universal.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/transforms/universal.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -36,7 +36,7 @@
default_priority = 820
- def apply(self):
+ def apply(self) -> None:
header_nodes = self.generate_header()
if header_nodes:
decoration = self.document.get_decoration()
@@ -99,10 +99,10 @@
default_priority = 840
- def not_Text(self, node):
+ def not_Text(self, node) -> bool:
return not isinstance(node, nodes.Text)
- def apply(self):
+ def apply(self) -> None:
if self.document.settings.expose_internals:
for node in self.document.findall(self.not_Text):
for att in self.document.settings.expose_internals:
@@ -121,7 +121,7 @@
default_priority = 860
- def apply(self):
+ def apply(self) -> None:
messages = [*self.document.parse_messages,
*self.document.transform_messages]
loose_messages = [msg for msg in messages if not msg.parent]
@@ -145,7 +145,7 @@
default_priority = 870
- def apply(self):
+ def apply(self) -> None:
removed_ids = [] # IDs of removed system messages
for node in tuple(self.document.findall(nodes.system_message)):
if node['level'] < self.document.reporter.report_level:
@@ -174,7 +174,7 @@
default_priority = 880
- def apply(self):
+ def apply(self) -> None:
for msg in self.document.transform_messages:
if not msg.parent:
self.document += msg
@@ -189,7 +189,7 @@
default_priority = 740
- def apply(self):
+ def apply(self) -> None:
if self.document.settings.strip_comments:
for node in tuple(self.document.findall(nodes.comment)):
node.parent.remove(node)
@@ -205,7 +205,7 @@
default_priority = 420
- def apply(self):
+ def apply(self) -> None:
if self.document.settings.strip_elements_with_classes:
self.strip_elements = {*self.document.settings
.strip_elements_with_classes}
@@ -224,7 +224,7 @@
except ValueError:
pass
- def check_classes(self, node):
+ def check_classes(self, node) -> bool:
if not isinstance(node, nodes.Element):
return False
for class_value in node['classes'][:]:
@@ -258,7 +258,7 @@
em- and en-dashes (---, --) and ellipses (...).
"""
- def __init__(self, document, startnode):
+ def __init__(self, document, startnode) -> None:
Transform.__init__(self, document, startnode=startnode)
self.unsupported_languages = set()
@@ -275,7 +275,7 @@
txt = re.sub('(?<=\x00)([-\\\'".`])', r'\\\1', str(node))
yield 'plain', txt
- def apply(self):
+ def apply(self) -> None:
smart_quotes = self.document.settings.setdefault('smart_quotes',
False)
if not smart_quotes:
@@ -346,7 +346,7 @@
default_priority = 835 # between misc.Transitions and universal.Messages
- def apply(self):
+ def apply(self) -> None:
if not getattr(self.document.settings, 'validate', False):
return
for node in self.document.findall():
Modified: trunk/docutils/docutils/transforms/writer_aux.py
===================================================================
--- trunk/docutils/docutils/transforms/writer_aux.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/transforms/writer_aux.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -40,7 +40,7 @@
default_priority = 920
- def apply(self):
+ def apply(self) -> None:
language = languages.get_language(self.document.settings.language_code,
self.document.reporter)
for node in self.document.findall(nodes.Admonition):
Modified: trunk/docutils/docutils/utils/__init__.py
===================================================================
--- trunk/docutils/docutils/utils/__init__.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/utils/__init__.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -25,7 +25,7 @@
class SystemMessage(ApplicationError):
- def __init__(self, system_message, level):
+ def __init__(self, system_message, level) -> None:
Exception.__init__(self, system_message.astext())
self.level = level
@@ -75,8 +75,16 @@
ERROR_LEVEL,
SEVERE_LEVEL) = range(5)
- def __init__(self, source, report_level, halt_level, stream=None,
- debug=False, encoding=None, error_handler='backslashreplace'):
+ def __init__(
+ self,
+ source,
+ report_level,
+ halt_level,
+ stream=None,
+ debug=False,
+ encoding=None,
+ error_handler='backslashreplace',
+ ) -> None:
"""
:Parameters:
- `source`: The path to or description of the source data.
@@ -126,7 +134,7 @@
self.max_level = -1
"""The highest level system message generated so far."""
- def attach_observer(self, observer):
+ def attach_observer(self, observer) -> None:
"""
The `observer` parameter is a function or bound method which takes one
argument, a `nodes.system_message` instance.
@@ -133,10 +141,10 @@
"""
self.observers.append(observer)
- def detach_observer(self, observer):
+ def detach_observer(self, observer) -> None:
self.observers.remove(observer)
- def notify_observers(self, message):
+ def notify_observers(self, message) -> None:
for observer in self.observers:
observer(message)
@@ -452,7 +460,7 @@
return document
-def clean_rcs_keywords(paragraph, keyword_substitutions):
+def clean_rcs_keywords(paragraph, keyword_substitutions) -> None:
if len(paragraph) == 1 and isinstance(paragraph[0], nodes.Text):
textnode = paragraph[0]
for pattern, substitution in keyword_substitutions:
@@ -723,7 +731,7 @@
return taglist
-def xml_declaration(encoding=None):
+def xml_declaration(encoding=None) -> str:
"""Return an XML text declaration.
Include an encoding declaration, if `encoding`
@@ -745,7 +753,7 @@
to explicitly call the close() method.
"""
- def __init__(self, output_file=None, dependencies=()):
+ def __init__(self, output_file=None, dependencies=()) -> None:
"""
Initialize the dependency list, automatically setting the
output file to `output_file` (see `set_output()`) and adding
@@ -759,7 +767,7 @@
self.set_output(output_file)
self.add(*dependencies)
- def set_output(self, output_file):
+ def set_output(self, output_file) -> None:
"""
Set the output file and clear the list of already added
dependencies.
@@ -775,7 +783,7 @@
else:
self.file = open(output_file, 'w', encoding='utf-8')
- def add(self, *paths):
+ def add(self, *paths) -> None:
"""
Append `path` to `self.list` unless it is already there.
@@ -790,7 +798,7 @@
if self.file is not None:
self.file.write(path+'\n')
- def close(self):
+ def close(self) -> None:
"""
Close the output file.
"""
@@ -798,7 +806,7 @@
self.file.close()
self.file = None
- def __repr__(self):
+ def __repr__(self) -> str:
try:
output_file = self.file.name
except AttributeError:
Modified: trunk/docutils/docutils/utils/code_analyzer.py
===================================================================
--- trunk/docutils/docutils/utils/code_analyzer.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/utils/code_analyzer.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -44,7 +44,7 @@
'none': skip lexical analysis.
"""
- def __init__(self, code, language, tokennames='short'):
+ def __init__(self, code, language, tokennames='short') -> None:
"""
Set up a lexical analyzer for `code` in `language`.
"""
@@ -118,7 +118,7 @@
``(['ln'], '<the line number>')`` token added for every code line.
Multi-line tokens are split."""
- def __init__(self, tokens, startline, endline):
+ def __init__(self, tokens, startline, endline) -> None:
self.tokens = tokens
self.startline = startline
# pad linenumbers, e.g. endline == 100 -> fmt_str = '%3d '
Modified: trunk/docutils/docutils/utils/math/__init__.py
===================================================================
--- trunk/docutils/docutils/utils/math/__init__.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/utils/math/__init__.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -33,7 +33,7 @@
The additional attribute `details` may hold a list of Docutils
nodes suitable as children for a ``<system_message>``.
"""
- def __init__(self, msg, details=[]):
+ def __init__(self, msg, details=[]) -> None:
super().__init__(msg)
self.details = details
@@ -64,7 +64,7 @@
return env
-def wrap_math_code(code, as_block):
+def wrap_math_code(code, as_block) -> str:
# Wrap math-code in mode-switching TeX command/environment.
# If `as_block` is True, use environment for displayed equation(s).
if as_block:
Modified: trunk/docutils/docutils/utils/math/math2html.py
===================================================================
--- trunk/docutils/docutils/utils/math/math2html.py 2024-08-01 06:49:33 UTC (rev 9809)
+++ trunk/docutils/docutils/utils/math/math2html.py 2024-08-01 07:22:07 UTC (rev 9810)
@@ -40,13 +40,13 @@
prefix = None
- def debug(cls, message):
+ def debug(cls, message) -> None:
"Show a debug message"
if not Trace.debugmode or Trace.quietmode:
return
Trace.show(message, sys.stdout)
- def message(cls, message):
+ def message(cls, message) -> None:
"Show a trace message"
if Trace.quietmode:
return
@@ -54,7 +54,7 @@
message = Trace.prefix + message
Trace.show(message, sys.stdout)
- def error(cls, message):
+ def error(cls, message) -> None:
"Show an error message"
message = '* ' + message
if Trace.prefix and Trace.showlinesmode:
@@ -61,7 +61,7 @@
message = Trace.prefix + message
Trace.show(message, sys.stderr)
- def show(cls, message, channel):
+ def show(cls, message, channel) -> None:
"Show a message out of a channel"
channel.write(message + '\n')
@@ -540,7 +540,7 @@
class CommandLineParser:
"A parser for runtime options"
- def __init__(self, options):
+ def __init__(self, options) -> None:
self.options = options
def parseoptions(self, args):
@@ -619,7 +619,7 @@
branches = {}
- def parseoptions(self, args):
+ def parseoptions(self, args) -> None:
"Parse command line options"
Options.location = args[0]
del args[0]
@@ -630,7 +630,7 @@
self.usage()
self.processoptions()
- def processoptions(self):
+ def processoptions(self) -> None:
"Process all options parsed."
if Options.help:
self.usage()
@@ -641,7 +641,7 @@
if param.endswith('mode'):
setattr(Trace, param, getattr(self, param[:-4]))
- def usage(self):
+ def usage(self) -> None:
"Show correct usage"
Trace.error(f'Usage: {pathlib.Path(Options.location).parent}'
' [options] "input string"')
@@ -648,7 +648,7 @@
Trace.error('Convert input string with LaTeX math to MathML')
self.showoptions()
- def showoptions(self):
+ def showoptions(self) -> None:
"Show all possible options"
Trace.error(' --help: show this online help')
Trace.error(' --quiet: disables all runtime messages')
@@ -657,7 +657,7 @@
Trace.error(' --simplemath: do not generate fancy math constructions')
sys.exit()
- def showversion(self):
+ def showversion(self) -> None:
"Return the current eLyXer version string"
Trace.error('math2html '+__version__)
sys.exit()
@@ -693,7 +693,7 @@
All other containers are silently ignored.
"""
- def __init__(self, config):
+ def __init__(self, config) -> None:
self.allowed = config['allowed']
self.extracted = config['extracted']
@@ -706,7 +706,7 @@
container.recursivesearch(locate, recursive, process)
return list
- def process(self, container, list):
+ def process(self, container, list) -> None:
"Add allowed containers."
name = container.__class__.__name__
if name in self.allowed:
@@ -725,7 +725,7 @@
class Parser:
"A generic parser"
- def __init__(self):
+ def __init__(self) -> None:
self.begin = 0
self.parameters = {}
@@ -736,7 +736,7 @@
self.begin = reader.linenumber
return header
- def parseparameter(self, reader):
+ def parseparameter(self, reader) -> None:
"Parse a parameter"
split = reader.currentline().strip().split(' ', 1)
reader.nextline()
@@ -752,7 +752,7 @@
doublesplit = split[1].split('"')
self.parameters[key] = doublesplit[1]
- def parseending(self, reader, process):
+ def parseending(self, reader, process) -> None:
"Parse until the current ending is found"
if not self.ending:
Trace.error('No ending for ' + str(self))
@@ -760,13 +760,13 @@
while not reader.currentline().startswith(self.ending):
process()
- def parsecontainer(self, reader, contents):
+ def parsecontainer(self, reader, contents) -> None:
container = self.factory.createcontainer(reader)
if container:
container.parent = self.parent
contents.append(container)
- def __str__(self):
+ def __str__(self) -> str:
"Return a description"
return self.__class__.__name__ + ' (' + str(self.begin) + ')'
@@ -784,7 +784,7 @@
stack = []
- def __init__(self, container):
+ def __init__(self, container) -> None:
Parser.__init__(self)
self.ending = None
if container.__class__.__name__ in ContainerConfig.endings:
@@ -802,7 +802,7 @@
self.parsecontainer(reader, contents)
return contents
- def isending(self, reader):
+ def isending(self, reader) -> bool:
"Check if text is ending"
current = reader.currentline().split()
if len(current) == 0:
@@ -866,11 +866,11 @@
class ContainerOutput:
"The generic HTML output for a container."
- def gethtml(self, container):
+ def gethtml(self, container) -> None:
"Show an error."
Trace.error('gethtml() not implemented for ' + str(self))
- def isempty(self):
+ def isempty(self) -> bool:
"Decide if the output is empty: by default, not empty."
return False
@@ -881,7 +881,7 @@
"Return empty HTML code."
return []
- def isempty(self):
+ def isempty(self) -> bool:
"This output is particularly empty."
return True
@@ -967,7 +967,7 @@
return selfclosing + '\n'
return selfclosing
- def checktag(self, container):
+ def checktag(self, container) -> bool:
"Check that the tag is valid."
if not self.tag:
Trace.error('No tag in ' + str(container))
@@ -981,11 +981,11 @@
"Returns the output in the contents, but filtered:"
"some strings are replaced by others."
- def __init__(self):
+ def __init__(self) -> None:
"Initialize the filters."
self.filters = []
- def addfilter(self, original, replacement):
+ def addfilter(self, original, replacement) -> None:
"Add a new filter: replace the original by the replacement."
self.filters.append((original, replacement))
@@ -1020,10 +1020,10 @@
leavepending = False
- def __init__(self):
+ def __init__(self) -> None:
self.endinglist = EndingList()
- def checkbytemark(self):
+ def checkbytemark(self) -> None:
"Check for a Unicode byte mark and skip it."
if self.finished():
return
@@ -1030,17 +1030,17 @@
if ord(self.current()) == 0xfeff:
self.skipcurrent()
- def isout(self):
+ def isout(self) -> bool:
"Find out if we are out of the position yet."
Trace.error('Unimplemented isout()')
return True
- def current(self):
+ def current(self) -> str:
"Return the current character."
Trace.error('Unimplemented current()')
return ''
- def checkfor(self, string):
+ def checkfor(self, string) -> bool:
"Check for the given string in the current position."
Trace.error('Unimplemented checkfor()')
return False
@@ -1053,7 +1053,7 @@
return True
return self.endinglist.checkin(self)
- def skipcurrent(self):
+ def skipcurrent(self) -> str:
"Return the current character and skip it."
Trace.error('Unimplemented skipcurrent()')
return ''
@@ -1073,7 +1073,7 @@
"Glob a row of digits."
return self.glob(lambda: self.current().isdigit())
- def isidentifier(self):
+ def isidentifier(self) -> bool:
"Return if the current character is alphanumeric or _."
if self.current().isalnum() or self.current() == '_':
return True
@@ -1083,7 +1083,7 @@
"Glob alphanumeric and _ symbols."
return self.glob(self.isidentifier)
- def isvalue(self):
+ def isvalue(self) -> bool:
"Return if the current character is a value character:"
"not a bracket or a space."
if self.current().isspace():
@@ -1110,7 +1110,7 @@
"Glob a bit of text up until (excluding) any excluded character."
return self.glob(lambda: self.current() not in excluded)
- def pushending(self, ending, optional=False):
+ def pushending(self, ending, optional=False) -> None:
"Push a new ending to the bottom"
self.endinglist.add(ending, optional)
@@ -1135,18 +1135,18 @@
class EndingList:
"A list of position endings"
- def __init__(self):
+ def __init__(self) -> None:
self.endings = []
- def add(self, ending, optional=False):
+ def add(self, ending, optional=False) -> None:
"Add a new ending to the list"
self.endings.append(PositionEnding(ending, optional))
- def pickpending(self, pos):
+ def pickpending(self, pos) -> None:
"Pick any pending endings from a parse position."
self.endings += pos.endinglist.endings
- def checkin(self, pos):
+ def checkin(self, pos) -> bool:
"Search for an ending"
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
_______________________________________________
Docutils-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-checkins