SF.net SVN: docutils:[9863] trunk
milde--- via Docutils-checkins <[email protected]>
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 9863
http://sourceforge.net/p/docutils/code/9863
Author: milde
Date: 2024-08-07 14:05:58 +0000 (Wed, 07 Aug 2024)
Log Message:
-----------
Type-hinting fixups, mostly indentation.
Normalize indentation,
add explanation to NoQA number,
add summary to multi-line docstring,
shorten code.
Ignore flake8 rule requiring whitespace around "bitwise or" operator
(also used as Union operator in type annotations):
PEP8 says: "If operators with different priorities are used,
consider adding whitespace around the operators with the lowest
priority(ies). Use your own judgment; ..."
Modified Paths:
--------------
trunk/.flake8
trunk/docutils/.flake8
trunk/docutils/docs/dev/release.txt
trunk/docutils/docutils/__init__.py
trunk/docutils/docutils/core.py
trunk/docutils/docutils/examples.py
trunk/docutils/docutils/io.py
trunk/docutils/docutils/nodes.py
trunk/docutils/docutils/parsers/rst/directives/admonitions.py
trunk/docutils/docutils/utils/math/tex2mathml_extern.py
trunk/docutils/docutils/writers/manpage.py
trunk/docutils/test/alltests.py
trunk/docutils/tools/dev/quicktest.py
Modified: trunk/.flake8
===================================================================
--- trunk/.flake8 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/.flake8 2024-08-07 14:05:58 UTC (rev 9863)
@@ -18,9 +18,9 @@
# E129: "visually indented line with same indent as next logical line"
# allowed by PEP8
- E226,
- E228,
+ E226, E227, E228,
# E226: "missing whitespace around arithmetic operator"
+ # E227: "missing whitespace around bitwise or shift operator"
# E228: "missing whitespace around modulo operator"
# not generally frowned on by PEP8:
# "If operators with different priorities are used, consider adding
Modified: trunk/docutils/.flake8
===================================================================
--- trunk/docutils/.flake8 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/docutils/.flake8 2024-08-07 14:05:58 UTC (rev 9863)
@@ -18,9 +18,9 @@
# E129: "visually indented line with same indent as next logical line"
# allowed by PEP8
- E226,
- E228,
+ E226, E227, E228,
# E226: "missing whitespace around arithmetic operator"
+ # E227: "missing whitespace around bitwise or shift operator"
# E228: "missing whitespace around modulo operator"
# not generally frowned on by PEP8:
# "If operators with different priorities are used, consider adding
Modified: trunk/docutils/docs/dev/release.txt
===================================================================
--- trunk/docutils/docs/dev/release.txt 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/docutils/docs/dev/release.txt 2024-08-07 14:05:58 UTC (rev 9863)
@@ -61,7 +61,7 @@
``export PYTHONWARNINGS=default`` prints DeprecationWarnings in python3.
-* Generate wheel and source-distribution::
+* Generate wheel and source-distribution, e.g.::
python3 -m pip install build
python3 -m build .
@@ -121,8 +121,9 @@
-m "tagging release #.#"
* Update your source directory.
-* Rebuild wheel and source-distribution ::
+* Rebuild wheel and source-distribution, e.g::
+
python3 -m build
* Now upload to pypi::
Modified: trunk/docutils/docutils/__init__.py
===================================================================
--- trunk/docutils/docutils/__init__.py 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/docutils/docutils/__init__.py 2024-08-07 14:05:58 UTC (rev 9863)
@@ -62,26 +62,26 @@
from docutils.nodes import Element
from docutils.transforms import Transform
+ _Components = Literal['reader', 'parser', 'writer', 'input', 'output']
_OptionTuple = tuple[str, list[str], dict[str, Any]]
+ _ReleaseLevels = Literal['alpha', 'beta', 'candidate', 'final']
_SettingsSpecTuple = Union[
- tuple[
- Union[str, None], Union[str, None], Sequence[_OptionTuple],
- ],
- tuple[
- Union[str, None], Union[str, None], Sequence[_OptionTuple],
- Union[str, None], Union[str, None], Sequence[_OptionTuple],
- ],
- tuple[
- Union[str, None], Union[str, None], Sequence[_OptionTuple],
- Union[str, None], Union[str, None], Sequence[_OptionTuple],
- Union[str, None], Union[str, None], Sequence[_OptionTuple],
- ],
- ]
+ tuple[str|None, str|None, Sequence[_OptionTuple]],
+ tuple[str|None, str|None, Sequence[_OptionTuple],
+ str|None, str|None, Sequence[_OptionTuple]],
+ tuple[str|None, str|None, Sequence[_OptionTuple],
+ str|None, str|None, Sequence[_OptionTuple],
+ str|None, str|None, Sequence[_OptionTuple]],
+ ]
class _UnknownReferenceResolver(Protocol):
- def __call__(self, node: Element, /) -> bool: ... # NoQA: E704
+ """See `TransformSpec.unknown_reference_resolvers`."""
+
priority: int
+ def __call__(self, node: Element, /) -> bool:
+ ...
+
__docformat__ = 'reStructuredText'
__version__ = '0.22b.dev'
@@ -109,15 +109,15 @@
major: int
minor: int
micro: int
- releaselevel: Literal['alpha', 'beta', 'candidate', 'final']
+ releaselevel: _ReleaseLevels
serial: int
release: bool
- def __new__(
- cls, major: int = 0, minor: int = 0, micro: int = 0,
- releaselevel: Literal['alpha', 'beta', 'candidate', 'final'] = 'final',
- serial: int = 0, release: bool = True,
- ) -> VersionInfo:
+ def __new__(cls,
+ major: int = 0, minor: int = 0, micro: int = 0,
+ releaselevel: _ReleaseLevels = 'final',
+ serial: int = 0, release: bool = True,
+ ) -> VersionInfo:
releaselevels = ('alpha', 'beta', 'candidate', 'final')
if releaselevel not in releaselevels:
raise ValueError('releaselevel must be one of %r.'
@@ -298,7 +298,7 @@
the 'refname' attribute and mark the node as resolved::
del node['refname']
- node.resolved = 1
+ node.resolved = True
Each function must have a "priority" attribute which will affect the order
the unknown_reference_resolvers are run::
@@ -307,7 +307,7 @@
This hook is provided for 3rd party extensions.
Example use case: the `MoinMoin - ReStructured Text Parser`
- in ``sandbox/mmgilbe/rst.py``.
+ https://github.com/moinwiki/moin
"""
@@ -315,11 +315,9 @@
"""Base class for Docutils components."""
- component_type: ClassVar[
- Literal['reader', 'parser', 'writer', 'input', 'output'] | None
- ] = None
- """Name of the component type ('reader', 'parser', 'writer'). Override in
- subclasses."""
+ component_type: ClassVar[_Components | None] = None
+ """Name of the component type ('reader', 'parser', 'writer').
+ Override in subclasses."""
supported: ClassVar[tuple[str, ...]] = ()
"""Name and aliases for this component. Override in subclasses."""
Modified: trunk/docutils/docutils/core.py
===================================================================
--- trunk/docutils/docutils/core.py 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/docutils/docutils/core.py 2024-08-07 14:05:58 UTC (rev 9863)
@@ -194,11 +194,10 @@
if self.destination is None:
self.set_destination(destination_path=destination_path)
- def set_source(
- self,
- source: str | None = None,
- source_path: str | os.PathLike[str] | None = None,
- ) -> None:
+ def set_source(self,
+ source: str | None = None,
+ source_path: str | os.PathLike[str] | None = None,
+ ) -> None:
if source_path is None:
source_path = self.settings._source
else:
@@ -209,11 +208,10 @@
encoding=self.settings.input_encoding,
error_handler=self.settings.input_encoding_error_handler)
- def set_destination(
- self,
- destination: str | None = None,
- destination_path: str | os.PathLike[str] | None = None,
- ) -> None:
+ def set_destination(self,
+ destination: str | None = None,
+ destination_path: str | os.PathLike[str] | None = None,
+ ) -> None:
if destination_path is None:
if (self.settings.output and self.settings._destination
and self.settings.output != self.settings._destination):
Modified: trunk/docutils/docutils/examples.py
===================================================================
--- trunk/docutils/docutils/examples.py 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/docutils/docutils/examples.py 2024-08-07 14:05:58 UTC (rev 9863)
@@ -25,14 +25,13 @@
from docutils.core import Publisher
-def html_parts(
- input_string: str | bytes,
- source_path: str | os.PathLike[str] | None = None,
- destination_path: str | os.PathLike[str] | None = None,
- input_encoding: Literal['unicode'] | str = 'unicode',
- doctitle: bool = True,
- initial_header_level: int = 1,
-) -> dict[str, str]:
+def html_parts(input_string: str | bytes,
+ source_path: str | os.PathLike[str] | None = None,
+ destination_path: str | os.PathLike[str] | None = None,
+ input_encoding: Literal['unicode'] | str = 'unicode',
+ doctitle: bool = True,
+ initial_header_level: int = 1,
+ ) -> dict[str, str]:
"""
Given an input string, returns a dictionary of HTML document parts.
@@ -66,15 +65,14 @@
return parts
-def html_body(
- input_string: str | bytes,
- source_path: str | os.PathLike[str] | None = None,
- destination_path: str | os.PathLike[str] | None = None,
- input_encoding: Literal['unicode'] | str = 'unicode',
- output_encoding: Literal['unicode'] | str = 'unicode',
- doctitle: bool = True,
- initial_header_level: int = 1,
-) -> str | bytes:
+def html_body(input_string: str | bytes,
+ source_path: str | os.PathLike[str] | None = None,
+ destination_path: str | os.PathLike[str] | None = None,
+ input_encoding: Literal['unicode'] | str = 'unicode',
+ output_encoding: Literal['unicode'] | str = 'unicode',
+ doctitle: bool = True,
+ initial_header_level: int = 1,
+ ) -> str | bytes:
"""
Given an input string, returns an HTML fragment as a string.
@@ -96,12 +94,11 @@
return fragment
-def internals(
- source: str,
- source_path: str | os.PathLike[str] | None = None,
- input_encoding: Literal['unicode'] | str = 'unicode',
- settings_overrides: dict[str, Any] | None = None,
-) -> tuple[nodes.document, Publisher]:
+def internals(source: str,
+ source_path: str | os.PathLike[str] | None = None,
+ input_encoding: Literal['unicode'] | str = 'unicode',
+ settings_overrides: dict[str, Any] | None = None,
+ ) -> tuple[nodes.document, Publisher]:
"""
Return the document tree and publisher, for exploring Docutils internals.
Modified: trunk/docutils/docutils/io.py
===================================================================
--- trunk/docutils/docutils/io.py 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/docutils/docutils/io.py 2024-08-07 14:05:58 UTC (rev 9863)
@@ -36,11 +36,11 @@
# Return locale encoding also in UTF-8 mode
with warnings.catch_warnings():
warnings.simplefilter("ignore")
- _locale_encoding: str | None = (
- locale.getlocale()[1] or locale.getdefaultlocale()[1]
- ).lower()
+ _locale_encoding: str | None = (locale.getlocale()[1]
+ or locale.getdefaultlocale()[1]
+ ).lower()
except: # NoQA: E722
- # any other problems determining the locale -> use None
+ # Any problem determining the locale: use None
_locale_encoding = None
try:
codecs.lookup(_locale_encoding)
Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/docutils/docutils/nodes.py 2024-08-07 14:05:58 UTC (rev 9863)
@@ -1357,16 +1357,16 @@
) -> str:
# Return a str reporting a missing child or child of wrong category.
try:
- type_ = category.__name__
+ _type = category.__name__
except AttributeError:
- type_ = '> or <'.join(c.__name__ for c in category)
+ _type = '> or <'.join(c.__name__ for c in category)
msg = f'Element {self.starttag()} invalid:\n'
if child is None:
- return f'{msg} Missing child of type <{type_}>.'
+ return f'{msg} Missing child of type <{_type}>.'
if isinstance(child, Text):
- return (f'{msg} Expecting child of type <{type_}>, '
+ return (f'{msg} Expecting child of type <{_type}>, '
f'not text data "{child.astext()}".')
- return (f'{msg} Expecting child of type <{type_}>, '
+ return (f'{msg} Expecting child of type <{_type}>, '
f'not {child.starttag()}.')
def check_position(self) -> None:
@@ -2172,7 +2172,7 @@
class revision(Bibliographic, TextElement): pass
class status(Bibliographic, TextElement): pass
class date(Bibliographic, TextElement): pass
-class copyright(Bibliographic, TextElement): pass # NoQA: A001
+class copyright(Bibliographic, TextElement): pass # NoQA: A001 (builtin name)
class authors(Bibliographic, Element):
Modified: trunk/docutils/docutils/parsers/rst/directives/admonitions.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/admonitions.py 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/docutils/docutils/parsers/rst/directives/admonitions.py 2024-08-07 14:05:58 UTC (rev 9863)
@@ -96,6 +96,6 @@
node_class = nodes.tip
-class Warning(BaseAdmonition): # NoQA: A001
+class Warning(BaseAdmonition): # NoQA: A001 (overwrite builtin "Warning")
node_class = nodes.warning
Modified: trunk/docutils/docutils/utils/math/tex2mathml_extern.py
===================================================================
--- trunk/docutils/docutils/utils/math/tex2mathml_extern.py 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/docutils/docutils/utils/math/tex2mathml_extern.py 2024-08-07 14:05:58 UTC (rev 9863)
@@ -103,14 +103,13 @@
'--',
]
math_code = document_template % wrap_math_code(math_code, as_block)
+ error_tags = ('Error:', 'Warning:', 'Fatal:')
result1 = subprocess.run(args1, input=math_code,
capture_output=True, text=True)
if result1.stderr:
- result1.stderr = '\n'.join(
- line for line in result1.stderr.splitlines()
- if line.startswith(('Error:', 'Warning:', 'Fatal:'))
- )
+ result1.stderr = '\n'.join(line for line in result1.stderr.splitlines()
+ if line.startswith(error_tags))
_check_result(result1)
args2 = ['latexmlpost',
@@ -142,10 +141,8 @@
_msg_source = result2.stdout # latexmlpost reports errors in output
else:
_msg_source = result2.stderr # just in case
- result2.stderr = '\n'.join(
- line for line in _msg_source.splitlines()
- if line.startswith(('Error:', 'Warning:', 'Fatal:'))
- )
+ result2.stderr = '\n'.join(line for line in _msg_source.splitlines()
+ if line.startswith(error_tags))
_check_result(result2)
return result2.stdout
Modified: trunk/docutils/docutils/writers/manpage.py
===================================================================
--- trunk/docutils/docutils/writers/manpage.py 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/docutils/docutils/writers/manpage.py 2024-08-07 14:05:58 UTC (rev 9863)
@@ -197,7 +197,9 @@
class Translator(nodes.NodeVisitor):
"""
- Generate unix-like manual pages using the man macro package
+ Docutils to man page translator.
+
+ Generate unix-like manual pages using the "man macro package"
from a Docutils document tree.
"""
Modified: trunk/docutils/test/alltests.py
===================================================================
--- trunk/docutils/test/alltests.py 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/docutils/test/alltests.py 2024-08-07 14:05:58 UTC (rev 9863)
@@ -39,7 +39,7 @@
type[BaseException],
BaseException,
types.TracebackType,
- ]
+ ]
STDOUT = sys.__stdout__
@@ -48,9 +48,9 @@
"""Write to a file and stdout simultaneously."""
def __init__(self, filename: str) -> None:
- self.file: TextIO | None = open(
- filename, 'w', encoding='utf-8', errors='backslashreplace',
- )
+ self.file: TextIO | None = open(filename, mode='w',
+ encoding='utf-8',
+ errors='backslashreplace')
self.encoding: str = 'utf-8'
atexit.register(self.close)
@@ -82,9 +82,11 @@
class NumbersTestResult(unittest.TextTestResult):
"""Result class that counts subTests."""
- def addSubTest(
- self, test: TestCase, subtest: TestCase, error: ErrorTriple | None,
- ) -> None:
+ def addSubTest(self,
+ test: TestCase,
+ subtest: TestCase,
+ error: ErrorTriple | None,
+ ) -> None:
super().addSubTest(test, subtest, error)
self.testsRun += 1
if self.dots:
Modified: trunk/docutils/tools/dev/quicktest.py
===================================================================
--- trunk/docutils/tools/dev/quicktest.py 2024-08-07 14:05:34 UTC (rev 9862)
+++ trunk/docutils/tools/dev/quicktest.py 2024-08-07 14:05:58 UTC (rev 9863)
@@ -107,21 +107,16 @@
print(description)
-def _pretty(
- input_: str, document: nodes.document, optargs: _OptArgs,
-) -> str:
+def _pretty(input_: str, document: nodes.document, optargs: _OptArgs) -> str:
return document.pformat()
-def _rawxml(
- input_: str, document: nodes.document, optargs: _OptArgs,
-) -> str:
+def _rawxml(input_: str, document: nodes.document, optargs: _OptArgs) -> str:
return document.asdom().toxml()
-def _styledxml(
- input_: str, document: nodes.document, optargs: _OptArgs,
-) -> str:
+def _styledxml(input_: str, document: nodes.document, optargs: _OptArgs
+ ) -> str:
docnode = document.asdom().childNodes[0]
return '\n'.join(('<?xml version="1.0" encoding="ISO-8859-1"?>',
'<?xml-stylesheet type="text/xsl" href="%s"?>'
@@ -129,15 +124,12 @@
docnode.toxml()))
-def _prettyxml(
- input_: str, document: nodes.document, optargs: _OptArgs,
-) -> str:
+def _prettyxml(input_: str, document: nodes.document, optargs: _OptArgs
+ ) -> str:
return document.asdom().toprettyxml(' ', '\n')
-def _test(
- input_: str, document: nodes.document, optargs: _OptArgs,
-) -> str:
+def _test(input_: str, document: nodes.document, optargs: _OptArgs) -> str:
tq = '"""'
output = document.pformat() # same as _pretty()
return """\
@@ -168,15 +160,14 @@
'xml': _prettyxml,
'pretty': _pretty,
'test': _test,
-}
+ }
-def format(
- output_format: str,
- input_: str,
- document: nodes.document,
- optargs: _OptArgs,
-) -> str:
+def format(output_format: str,
+ input_: str,
+ document: nodes.document,
+ optargs: _OptArgs,
+ ) -> str:
formatter = _output_formatters[output_format]
return formatter(input_, document, optargs)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.