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

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9961
          http://sourceforge.net/p/docutils/code/9961
Author:   milde
Date:     2024-10-21 21:47:17 +0000 (Mon, 21 Oct 2024)
Log Message:
-----------
Store attribute values with datatype "yesorno" as `bool` values.

Use `bool` instead of `int` to store values of "yesorno" attributes in
Python doctree element instances.
This is the "natural" choice for "yesorno" and restores consistency
with the validating function `nodes.validate_yesorno()`.

In XML and pseudoxml output, the value is serialized as "0" or "1"
for backwards compatibility.

Modified Paths:
--------------
    trunk/docutils/docs/ref/doctree.rst
    trunk/docutils/docutils/nodes.py
    trunk/docutils/docutils/parsers/rst/directives/tables.py
    trunk/docutils/docutils/parsers/rst/states.py

Modified: trunk/docutils/docs/ref/doctree.rst
===================================================================
--- trunk/docutils/docs/ref/doctree.rst	2024-10-21 20:48:53 UTC (rev 9960)
+++ trunk/docutils/docs/ref/doctree.rst	2024-10-21 21:47:17 UTC (rev 9961)
@@ -4102,7 +4102,7 @@
     Resolves to NMTOKEN_.
   | Used in the anonymous_, colsep_, ltrim_, rtrim_, rowsep_,
     and `stub`_ attributes.
-    Python data type: ``int``.
+    Python data type: ``bool``.
 
 __ ../index.html#introductory-tutorial-material-for-end-users
 

Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py	2024-10-21 20:48:53 UTC (rev 9960)
+++ trunk/docutils/docutils/nodes.py	2024-10-21 21:47:17 UTC (rev 9961)
@@ -3205,7 +3205,14 @@
     return [whitespace_normalize_name(name) for name in value]
 
 
-def validate_yesorno(value: bool | Literal['0', '1']) -> bool:
+def validate_yesorno(value: str | int | bool) -> bool:
+    """Validate a `%yesorno`__ (flag) value.
+
+    The string literal "0" evaluates to ``False``, all other
+    values are converterd with `bool()`.
+
+    __ https://docutils.sourceforge.io/docs/ref/doctree.html#yesorno
+    """
     if value == "0":
         return False
     return bool(value)

Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/tables.py	2024-10-21 20:48:53 UTC (rev 9960)
+++ trunk/docutils/docutils/parsers/rst/directives/tables.py	2024-10-21 21:47:17 UTC (rev 9961)
@@ -501,7 +501,7 @@
             if col_width is not None:
                 colspec.attributes['colwidth'] = col_width
             if stub_columns:
-                colspec.attributes['stub'] = 1
+                colspec.attributes['stub'] = True
                 stub_columns -= 1
             tgroup += colspec
         rows = []

Modified: trunk/docutils/docutils/parsers/rst/states.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/states.py	2024-10-21 20:48:53 UTC (rev 9960)
+++ trunk/docutils/docutils/parsers/rst/states.py	2024-10-21 21:47:17 UTC (rev 9961)
@@ -861,7 +861,7 @@
             elif target and (aliastype == 'uri'):
                 reference['refuri'] = alias
             else:
-                reference['anonymous'] = 1
+                reference['anonymous'] = True
         else:
             if target:
                 target['names'].append(refname)
@@ -929,7 +929,7 @@
                     reference_node = nodes.reference(
                         '|%s%s' % (subref_text, endstring), '')
                     if endstring[-2:] == '__':
-                        reference_node['anonymous'] = 1
+                        reference_node['anonymous'] = True
                     else:
                         reference_node['refname'] = normalize_name(subref_text)
                         self.document.note_refname(reference_node)
@@ -980,7 +980,7 @@
             name=whitespace_normalize_name(referencename))
         referencenode[0].rawsource = referencename
         if anonymous:
-            referencenode['anonymous'] = 1
+            referencenode['anonymous'] = True
         else:
             referencenode['refname'] = refname
             self.document.note_refname(referencenode)
@@ -1807,7 +1807,7 @@
         for colwidth in colwidths:
             colspec = nodes.colspec(colwidth=colwidth)
             if stub_columns:
-                colspec.attributes['stub'] = 1
+                colspec.attributes['stub'] = True
                 stub_columns -= 1
             tgroup += colspec
         if headrows:
@@ -2021,7 +2021,7 @@
         else:                       # anonymous target
             if refuri:
                 target['refuri'] = refuri
-            target['anonymous'] = 1
+            target['anonymous'] = True
             self.document.note_anonymous_target(target)
 
     def substitution_def(self, match):

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
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.