Skip to content

Commit 6c41020

Browse files
Jean THOMASwhitequark
authored andcommitted
docs: lang: fix build with PYTHONWARNINGS=error after Sphinx update.
Backported from 556faea
1 parent 0ac941a commit 6c41020

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/lang.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ Specifying a shape with a range is convenient for counters, indexes, and all oth
172172

173173
Python ranges are *exclusive* or *half-open*, meaning they do not contain their ``.stop`` element. Because of this, values with shapes cast from a ``range(stop)`` where ``stop`` is a power of 2 are not wide enough to represent ``stop`` itself:
174174

175+
.. doctest::
176+
:hide:
177+
178+
>>> import warnings
179+
>>> _warning_filters_backup = warnings.catch_warnings()
180+
>>> _warning_filters_backup.__enter__() # have to do this horrific hack to make it work with `PYTHONWARNINGS=error` :(
181+
>>> warnings.simplefilter("default", SyntaxWarning)
182+
175183
.. doctest::
176184

177185
>>> fencepost = C(256, range(256))
@@ -182,6 +190,11 @@ Specifying a shape with a range is convenient for counters, indexes, and all oth
182190
>>> fencepost.value
183191
0
184192

193+
.. doctest::
194+
:hide:
195+
196+
>>> _warning_filters_backup.__exit__()
197+
185198
Amaranth detects uses of :class:`Const` and :class:`Signal` that invoke such an off-by-one error, and emits a diagnostic message.
186199

187200
.. note::
@@ -677,6 +690,14 @@ Python expression Amaranth expression (boolean operands)
677690

678691
When applied to Amaranth boolean values, the ``~`` operator computes negation, and when applied to Python boolean values, the ``not`` operator also computes negation. However, the ``~`` operator applied to Python boolean values produces an unexpected result:
679692

693+
.. doctest::
694+
:hide:
695+
696+
>>> import warnings
697+
>>> _warning_filters_backup = warnings.catch_warnings()
698+
>>> _warning_filters_backup.__enter__() # have to do this horrific hack to make it work with `PYTHONWARNINGS=error` :(
699+
>>> warnings.simplefilter("ignore", DeprecationWarning)
700+
680701
.. doctest::
681702

682703
>>> ~False
@@ -695,6 +716,11 @@ Python expression Amaranth expression (boolean operands)
695716
>>> ~use_stb | stb # WRONG! MSB of 2-bit wide OR expression is always 1
696717
(| (const 2'sd-2) (sig stb))
697718

719+
.. doctest::
720+
:hide:
721+
722+
>>> _warning_filters_backup.__exit__()
723+
698724
Amaranth automatically detects some cases of misuse of ``~`` and emits a detailed diagnostic message.
699725

700726
.. TODO: this isn't quite reliable, #380

0 commit comments

Comments
 (0)