Skip to content

Fix tests on 3.12 #799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 0 additions & 73 deletions amaranth/_toolchain/cxx.py

This file was deleted.

4 changes: 3 additions & 1 deletion amaranth/hdl/dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from functools import wraps
from enum import Enum
import warnings
import sys

from .._utils import flatten, bits_for
from .. import tracer
Expand Down Expand Up @@ -210,7 +211,8 @@ def _set_ctrl(self, name, data):

def _check_signed_cond(self, cond):
cond = Value.cast(cond)
if cond.shape().signed:
if sys.version_info < (3, 12, 0) and cond.shape().signed:
# TODO(py3.11): remove; ~True is a warning in 3.12+, finally!
warnings.warn("Signed values in If/Elif conditions usually result from inverting "
"Python booleans with ~, which leads to unexpected results. "
"Replace `~flag` with `not flag`. (If this is a false positive, "
Expand Down
34 changes: 18 additions & 16 deletions tests/test_hdl_dsl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# amaranth: UnusedElaboratable=no

import sys
from collections import OrderedDict

from amaranth.hdl.ast import *
Expand Down Expand Up @@ -324,27 +325,28 @@ def test_If_wide(self):
)
""")

def test_If_signed_suspicious(self):
m = Module()
with self.assertWarnsRegex(SyntaxWarning,
(r"^Signed values in If\/Elif conditions usually result from inverting Python "
if sys.version_info < (3, 12): # upstream warning in 3.12!
def test_If_signed_suspicious(self):
m = Module()
with self.assertWarnsRegex(SyntaxWarning,
r"^Signed values in If\/Elif conditions usually result from inverting Python "
r"booleans with ~, which leads to unexpected results\. Replace `~flag` with "
r"`not flag`\. \(If this is a false positive, silence this warning with "
r"`m\.If\(x\)` → `m\.If\(x\.bool\(\)\)`\.\)$")):
with m.If(~True):
pass
r"`m\.If\(x\)` → `m\.If\(x\.bool\(\)\)`\.\)$"):
with m.If(~True):
pass

def test_Elif_signed_suspicious(self):
m = Module()
with m.If(0):
pass
with self.assertWarnsRegex(SyntaxWarning,
(r"^Signed values in If\/Elif conditions usually result from inverting Python "
def test_Elif_signed_suspicious(self):
m = Module()
with m.If(0):
pass
with self.assertWarnsRegex(SyntaxWarning,
r"^Signed values in If\/Elif conditions usually result from inverting Python "
r"booleans with ~, which leads to unexpected results\. Replace `~flag` with "
r"`not flag`\. \(If this is a false positive, silence this warning with "
r"`m\.If\(x\)` → `m\.If\(x\.bool\(\)\)`\.\)$")):
with m.Elif(~True):
pass
r"`m\.If\(x\)` → `m\.If\(x\.bool\(\)\)`\.\)$"):
with m.Elif(~True):
pass

def test_if_If_Elif_Else(self):
m = Module()
Expand Down
68 changes: 0 additions & 68 deletions tests/test_toolchain_cxx.py

This file was deleted.