SF.net SVN: docutils:[9842 ] trunk/docutils

aa-turner--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9842
          http://sourceforge.net/p/docutils/code/9842
Author:   aa-turner
Date:     2024-08-01 22:41:27 +0000 (Thu, 01 Aug 2024)
Log Message:
-----------
Enable the perflint linter in Ruff

Modified Paths:
--------------
    trunk/docutils/.ruff.toml
    trunk/docutils/docutils/nodes.py
    trunk/docutils/docutils/parsers/rst/states.py
    trunk/docutils/docutils/transforms/frontmatter.py
    trunk/docutils/docutils/transforms/references.py
    trunk/docutils/docutils/utils/__init__.py
    trunk/docutils/docutils/utils/math/math2html.py
    trunk/docutils/docutils/writers/html4css1/__init__.py
    trunk/docutils/test/test_parsers/test_rst/test_TableParser.py
    trunk/docutils/tools/buildhtml.py

Modified: trunk/docutils/.ruff.toml
===================================================================
--- trunk/docutils/.ruff.toml	2024-08-01 22:27:19 UTC (rev 9841)
+++ trunk/docutils/.ruff.toml	2024-08-01 22:41:27 UTC (rev 9842)
@@ -18,6 +18,7 @@
     "INP",  # flake8-no-pep420
     "INT",  # flake8-gettext
     "LOG",  # flake8-logging
+    "PERF", # perflint
     "PGH",  # pygrep-hooks
     "PIE",  # flake8-pie
     "PT",   # flake8-pytest
@@ -37,6 +38,9 @@
     # whitespace around the operators with the lowest priority(ies).
     # Use your own judgment; …"
 
+    "PERF203",  # ``try``-``except`` within a loop incurs performance overhead
+    # Needs more thought.
+
     "PT009",  # Use a regular assert instead of unittest-style
     "PT027",  # Use pytest.raises instead of unittest-style
     # We still use unittest.

Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py	2024-08-01 22:27:19 UTC (rev 9841)
+++ trunk/docutils/docutils/nodes.py	2024-08-01 22:41:27 UTC (rev 9842)
@@ -776,10 +776,10 @@
                    [child.astext() for child in self.children])
 
     def non_default_attributes(self) -> dict[str, Any]:
-        atts = {}
-        for key, value in self.attributes.items():
-            if self.is_not_default(key):
-                atts[key] = value
+        atts = {
+            key: value for key, value in self.attributes.items()
+            if self.is_not_default(key)
+        }
         return atts
 
     def attlist(self) -> list[tuple[str, Any]]:

Modified: trunk/docutils/docutils/parsers/rst/states.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/states.py	2024-08-01 22:27:19 UTC (rev 9841)
+++ trunk/docutils/docutils/parsers/rst/states.py	2024-08-01 22:41:27 UTC (rev 9842)
@@ -2889,9 +2889,10 @@
                     text = parts[0].rstrip()
                     textnode = nodes.Text(text)
                     node_list[-1] += textnode
-                    for part in parts[1:]:
-                        node_list.append(
-                            nodes.classifier(unescape(part, True), part))
+                    node_list += [
+                        nodes.classifier(unescape(part, True), part)
+                        for part in parts[1:]
+                    ]
             else:
                 node_list[-1] += node
         return node_list, messages

Modified: trunk/docutils/docutils/transforms/frontmatter.py
===================================================================
--- trunk/docutils/docutils/transforms/frontmatter.py	2024-08-01 22:27:19 UTC (rev 9841)
+++ trunk/docutils/docutils/transforms/frontmatter.py	2024-08-01 22:41:27 UTC (rev 9842)
@@ -418,9 +418,10 @@
         nodelist = []
         if len(docinfo) != 0:
             nodelist.append(docinfo)
-        for name in ('dedication', 'abstract'):
-            if topics[name]:
-                nodelist.append(topics[name])
+        if topics['dedication']:
+            nodelist.append(topics['dedication'])
+        if topics['abstract']:
+            nodelist.append(topics['abstract'])
         return nodelist
 
     def check_empty_biblio_field(self, field, name) -> bool:

Modified: trunk/docutils/docutils/transforms/references.py
===================================================================
--- trunk/docutils/docutils/transforms/references.py	2024-08-01 22:27:19 UTC (rev 9841)
+++ trunk/docutils/docutils/transforms/references.py	2024-08-01 22:41:27 UTC (rev 9842)
@@ -113,14 +113,15 @@
     default_priority = 440
 
     def apply(self) -> None:
-        anonymous_refs = []
-        anonymous_targets = []
-        for node in self.document.findall(nodes.reference):
-            if node.get('anonymous'):
-                anonymous_refs.append(node)
-        for node in self.document.findall(nodes.target):
-            if node.get('anonymous'):
-                anonymous_targets.append(node)
+        anonymous_refs = [
+            node for node
+            in self.document.findall(nodes.reference)
+            if node.get('anonymous')]
+        anonymous_targets = [
+            node for node
+            in self.document.findall(nodes.target)
+            if node.get('anonymous')
+        ]
         if len(anonymous_refs) != len(anonymous_targets):
             msg = self.document.reporter.error(
                   'Anonymous hyperlink mismatch: %s references but %s '

Modified: trunk/docutils/docutils/utils/__init__.py
===================================================================
--- trunk/docutils/docutils/utils/__init__.py	2024-08-01 22:27:19 UTC (rev 9841)
+++ trunk/docutils/docutils/utils/__init__.py	2024-08-01 22:41:27 UTC (rev 9842)
@@ -725,10 +725,11 @@
     subtags = list(tag.split('_'))
     base_tag = (subtags.pop(0),)
     # find all combinations of subtags
-    taglist = []
-    for n in range(len(subtags), 0, -1):
-        for tags in itertools.combinations(subtags, n):
-            taglist.append('-'.join(base_tag+tags))
+    taglist = [
+        '-'.join(base_tag + tags)
+        for n in range(len(subtags), 0, -1)
+        for tags in itertools.combinations(subtags, n)
+    ]
     taglist += base_tag
     return taglist
 

Modified: trunk/docutils/docutils/utils/math/math2html.py
===================================================================
--- trunk/docutils/docutils/utils/math/math2html.py	2024-08-01 22:27:19 UTC (rev 9841)
+++ trunk/docutils/docutils/utils/math/math2html.py	2024-08-01 22:41:27 UTC (rev 9842)
@@ -991,10 +991,8 @@
 
     def gethtml(self, container):
         "Return the HTML code"
-        result = []
         html = ContentsOutput.gethtml(self, container)
-        for line in html:
-            result.append(self.filter(line))
+        result = [self.filter(line) for line in html]
         return result
 
     def filter(self, line):

Modified: trunk/docutils/docutils/writers/html4css1/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/html4css1/__init__.py	2024-08-01 22:27:19 UTC (rev 9841)
+++ trunk/docutils/docutils/writers/html4css1/__init__.py	2024-08-01 22:41:27 UTC (rev 9842)
@@ -932,10 +932,10 @@
     """
 
     def visit_list_item(self, node):
-        children = []
-        for child in node.children:
-            if not isinstance(child, nodes.Invisible):
-                children.append(child)
+        children = [
+            child for child in node.children
+            if not isinstance(child, nodes.Invisible)
+        ]
         if (children and isinstance(children[0], nodes.paragraph)
             and (isinstance(children[-1], nodes.bullet_list)
                  or isinstance(children[-1], nodes.enumerated_list))):

Modified: trunk/docutils/test/test_parsers/test_rst/test_TableParser.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_TableParser.py	2024-08-01 22:27:19 UTC (rev 9841)
+++ trunk/docutils/test/test_parsers/test_rst/test_TableParser.py	2024-08-01 22:41:27 UTC (rev 9842)
@@ -23,7 +23,7 @@
 class GridTableParserTestCase(unittest.TestCase):
     def test_parse_table(self):
         parser = tableparser.GridTableParser()
-        for name, cases in totest.items():
+        for cases in totest.values():
             for case in cases:
                 case_input, case_table, _case_expected = case
                 lines_input = StringList(string2lines(case_input), 'test data')

Modified: trunk/docutils/tools/buildhtml.py
===================================================================
--- trunk/docutils/tools/buildhtml.py	2024-08-01 22:27:19 UTC (rev 9841)
+++ trunk/docutils/tools/buildhtml.py	2024-08-01 22:41:27 UTC (rev 9842)
@@ -201,7 +201,7 @@
         """
         with warnings.catch_warnings():
             warnings.filterwarnings('ignore', category=DeprecationWarning)
-            for name, publisher in self.publishers.items():
+            for publisher in self.publishers.values():
                 option_parser = OptionParser(
                     components=publisher.components, read_config_files=True,
                     usage=usage, description=description)

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.