Skip to content

Bulk-replace cls.__name__ with cls.__qualname__ #1422

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 1 commit into from
Jun 27, 2024
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
2 changes: 1 addition & 1 deletion amaranth/_unused.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __del__(self):
return
if hasattr(self, "_MustUse__used") and not self._MustUse__used:
if get_linter_option(self._MustUse__context["filename"],
self._MustUse__warning.__name__, bool, True):
self._MustUse__warning.__qualname__, bool, True):
warnings.warn_explicit(
f"{self!r} created but never used", self._MustUse__warning,
**self._MustUse__context)
Expand Down
2 changes: 1 addition & 1 deletion amaranth/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def union(i, start=None):
def final(cls):
def init_subclass():
raise TypeError("Subclassing {}.{} is not supported"
.format(cls.__module__, cls.__name__))
.format(cls.__module__, cls.__qualname__))
cls.__init_subclass__ = init_subclass
return cls

Expand Down
8 changes: 4 additions & 4 deletions amaranth/build/plat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ def __init__(self):
def default_clk_constraint(self):
if self.default_clk is None:
raise AttributeError("Platform '{}' does not define a default clock"
.format(type(self).__name__))
.format(type(self).__qualname__))
return self.lookup(self.default_clk).clock

@property
def default_clk_frequency(self):
constraint = self.default_clk_constraint
if constraint is None:
raise AttributeError("Platform '{}' does not constrain its default clock"
.format(type(self).__name__))
.format(type(self).__qualname__))
return constraint.frequency

def add_file(self, filename, content):
Expand Down Expand Up @@ -173,7 +173,7 @@ def toolchain_program(self, products, name, **kwargs):
Extract bitstream for fragment ``name`` from ``products`` and download it to a target.
"""
raise NotImplementedError("Platform '{}' does not support programming"
.format(type(self).__name__))
.format(type(self).__qualname__))


class TemplatedPlatform(Platform):
Expand Down Expand Up @@ -244,7 +244,7 @@ def _extract_override(var, *, expected_type):
if issubclass(expected_type, str) and not isinstance(kwarg, str) and isinstance(kwarg, Iterable):
kwarg = " ".join(kwarg)
if not isinstance(kwarg, expected_type) and not expected_type is None:
raise TypeError(f"Override '{var}' must be a {expected_type.__name__}, not {kwarg!r}")
raise TypeError(f"Override '{var}' must be a {expected_type.__qualname__}, not {kwarg!r}")
return kwarg
else:
return jinja2.Undefined(name=var)
Expand Down
22 changes: 11 additions & 11 deletions amaranth/hdl/_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,16 @@ def __init__(self, *args, **kwargs):

def __init_subclass__(cls, **kwargs):
if cls.as_shape is ShapeCastable.as_shape:
raise TypeError(f"Class '{cls.__name__}' deriving from 'ShapeCastable' must override "
raise TypeError(f"Class '{cls.__qualname__}' deriving from 'ShapeCastable' must override "
f"the 'as_shape' method")
if cls.const is ShapeCastable.const:
raise TypeError(f"Class '{cls.__name__}' deriving from 'ShapeCastable' must override "
raise TypeError(f"Class '{cls.__qualname__}' deriving from 'ShapeCastable' must override "
f"the 'const' method")
if cls.__call__ is ShapeCastable.__call__:
raise TypeError(f"Class '{cls.__name__}' deriving from 'ShapeCastable' must override "
raise TypeError(f"Class '{cls.__qualname__}' deriving from 'ShapeCastable' must override "
f"the '__call__' method")
if cls.from_bits is ShapeCastable.from_bits:
raise TypeError(f"Class '{cls.__name__}' deriving from 'ShapeCastable' must override "
raise TypeError(f"Class '{cls.__qualname__}' deriving from 'ShapeCastable' must override "
f"the 'from_bits' method")

# The signatures and definitions of these methods are weird because they are present here for
Expand Down Expand Up @@ -1400,10 +1400,10 @@ def __init__(self, *args, **kwargs):

def __init_subclass__(cls, **kwargs):
if cls.as_value is ValueCastable.as_value:
raise TypeError(f"Class '{cls.__name__}' deriving from 'ValueCastable' must override "
raise TypeError(f"Class '{cls.__qualname__}' deriving from 'ValueCastable' must override "
"the 'as_value' method")
if cls.shape is ValueCastable.shape:
raise TypeError(f"Class '{cls.__name__}' deriving from 'ValueCastable' must override "
raise TypeError(f"Class '{cls.__qualname__}' deriving from 'ValueCastable' must override "
"the 'shape' method")

# The signatures and definitions of these methods are weird because they are present here for
Expand Down Expand Up @@ -2065,12 +2065,12 @@ def __init__(self, shape=None, *, name=None, init=None, reset=None, reset_less=F
if isinstance(orig_shape, ShapeCastable):
self._format = orig_shape.format(orig_shape(self), "")
elif isinstance(orig_shape, type) and issubclass(orig_shape, Enum):
self._format = Format.Enum(self, orig_shape, name=orig_shape.__name__)
self._format = Format.Enum(self, orig_shape, name=orig_shape.__qualname__)
else:
self._format = Format("{}", self)

if isinstance(decoder, type) and issubclass(decoder, Enum):
self._format = Format.Enum(self, decoder, name=decoder.__name__)
self._format = Format.Enum(self, decoder, name=decoder.__qualname__)

self._decoder = decoder

Expand Down Expand Up @@ -3185,7 +3185,7 @@ def __len__(self):

def __repr__(self):
pairs = [f"({k!r}, {v!r})" for k, v in self.items()]
return "{}.{}([{}])".format(type(self).__module__, type(self).__name__,
return "{}.{}([{}])".format(type(self).__module__, type(self).__qualname__,
", ".join(pairs))


Expand Down Expand Up @@ -3217,7 +3217,7 @@ def __len__(self):
return len(self._storage)

def __repr__(self):
return "{}.{}({})".format(type(self).__module__, type(self).__name__,
return "{}.{}({})".format(type(self).__module__, type(self).__qualname__,
", ".join(repr(x) for x in self))


Expand Down Expand Up @@ -3247,7 +3247,7 @@ def __lt__(self, other):
return self._intern < other._intern

def __repr__(self):
return f"<{__name__}.SignalKey {self.signal!r}>"
return f"<{__qualname__}.SignalKey {self.signal!r}>"


class SignalDict(_MappedKeyDict):
Expand Down
4 changes: 2 additions & 2 deletions amaranth/hdl/_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ def __init__(self, builder, depth):
def __getattr__(self, name):
if name in ("comb", "sync"):
raise AttributeError("'{}' object has no attribute '{}'; did you mean 'd.{}'?"
.format(type(self).__name__, name, name))
.format(type(self).__qualname__, name, name))
raise AttributeError("'{}' object has no attribute '{}'"
.format(type(self).__name__, name))
.format(type(self).__qualname__, name))


class _ModuleBuilderSubmodules:
Expand Down
4 changes: 2 additions & 2 deletions amaranth/hdl/_nir.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def traverse(net):
elif isinstance(obj, Operator):
obj = f"operator {obj.operator}"
else:
obj = f"cell {obj.__class__.__name__}"
obj = f"cell {obj.__class__.__qualname__}"
src_loc = "<unknown>:0" if src_loc is None else f"{src_loc[0]}:{src_loc[1]}"
msg.append(f" {src_loc}: {obj} bit {bit}\n")
raise CombinationalCycle("".join(msg))
Expand Down Expand Up @@ -656,7 +656,7 @@ class Operator(Cell):

The ternary operators are:

- 'm': multiplexer, first input needs to have width of 1, second and third operand need to have
- 'm': multiplexer, first input needs to have width of 1, second and third operand need to have
the same width as output; implements arg0 ? arg1 : arg2

Attributes
Expand Down
4 changes: 2 additions & 2 deletions amaranth/lib/cdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def elaborate(self, platform):
if self._max_input_delay is not None:
raise NotImplementedError("Platform '{}' does not support constraining input delay "
"for FFSynchronizer"
.format(type(platform).__name__))
.format(type(platform).__qualname__))

m = Module()
flops = [Signal(self.i.shape(), name=f"stage{index}",
Expand Down Expand Up @@ -170,7 +170,7 @@ def elaborate(self, platform):
if self._max_input_delay is not None:
raise NotImplementedError("Platform '{}' does not support constraining input delay "
"for AsyncFFSynchronizer"
.format(type(platform).__name__))
.format(type(platform).__qualname__))

m = Module()
m.domains += ClockDomain("async_ff", async_reset=True)
Expand Down
4 changes: 2 additions & 2 deletions amaranth/lib/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def __and__(self, other):
__rxor__ = __and__

def __repr__(self):
return f"{self.__class__.__name__}({self.__layout!r}, {self.__target!r})"
return f"{self.__class__.__qualname__}({self.__layout!r}, {self.__target!r})"


class Const(ValueCastable):
Expand Down Expand Up @@ -1124,7 +1124,7 @@ def __and__(self, other):
__rxor__ = __and__

def __repr__(self):
return f"{self.__class__.__name__}({self.__layout!r}, {self.__target!r})"
return f"{self.__class__.__qualname__}({self.__layout!r}, {self.__target!r})"


class _AggregateMeta(ShapeCastable, type):
Expand Down
4 changes: 2 additions & 2 deletions amaranth/lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def from_bits(cls, bits):
def format(cls, value, format_spec):
if format_spec != "":
raise ValueError(f"Format specifier {format_spec!r} is not supported for enums")
return Format.Enum(value, cls, name=cls.__name__)
return Format.Enum(value, cls, name=cls.__qualname__)


# In 3.11, Python renamed EnumMeta to EnumType. Like Python itself, we support both for
Expand Down Expand Up @@ -310,7 +310,7 @@ def __ne__(self, other):
return self.target != other.target

def __repr__(self):
return f"{type(self).__name__}({self.enum.__name__}, {self.target!r})"
return f"{type(self).__qualname__}({self.enum.__qualname__}, {self.target!r})"


class FlagView(EnumView):
Expand Down
2 changes: 1 addition & 1 deletion amaranth/lib/wiring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ def __repr__(self):
attrs = ''.join(f", {name}={value!r}"
for name, value in self.__dict__.items()
if name != "signature")
return f'<{type(self).__name__}: {self.signature}{attrs}>'
return f'<{type(self).__qualname__}: {self.signature}{attrs}>'


# To reduce API surface area `FlippedInterface` is made final. This restriction could be lifted
Expand Down
2 changes: 1 addition & 1 deletion amaranth/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _serve_yosys(modules):
rtlil_text = rtlil.convert(elaboratable, name=module_name, ports=ports)
response = {"frontend": "ilang", "source": rtlil_text}
except Exception as error:
response = {"error": f"{type(error).__name__}: {str(error)}"}
response = {"error": f"{type(error).__qualname__}: {str(error)}"}

else:
return {"error": "Unrecognized method {!r}".format(request["method"])}
Expand Down
4 changes: 2 additions & 2 deletions amaranth/vendor/_xilinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ def get_ff_sync(self, ff_sync):
elif ff_sync._max_input_delay is not None:
raise NotImplementedError("Platform '{}' does not support constraining input delay "
"for FFSynchronizer"
.format(type(self).__name__))
.format(type(self).__qualname__))
for i, o in zip((ff_sync.i, *flops), flops):
m.d[ff_sync._o_domain] += o.eq(i)
m.d.comb += ff_sync.o.eq(flops[-1])
Expand Down Expand Up @@ -1284,7 +1284,7 @@ def get_async_ff_sync(self, async_ff_sync):
elif async_ff_sync._max_input_delay is not None:
raise NotImplementedError("Platform '{}' does not support constraining input delay "
"for AsyncFFSynchronizer"
.format(type(self).__name__))
.format(type(self).__qualname__))

for i, o in zip((0, *flops_q), flops_d):
m.d.comb += o.eq(i)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_back_rtlil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,7 @@ class MyEnum(enum.Enum, shape=unsigned(2)):
attribute \generator "Amaranth"
attribute \top 1
module \top
attribute \enum_base_type "MyEnum"
attribute \enum_base_type "DetailTestCase.test_enum.<locals>.MyEnum"
attribute \enum_value_00 "A"
attribute \enum_value_01 "B"
attribute \enum_value_10 "C"
Expand Down Expand Up @@ -2052,7 +2052,7 @@ class Meow(data.Struct):
attribute \top 1
module \top
wire width 13 input 0 \sig
attribute \enum_base_type "MyEnum"
attribute \enum_base_type "DetailTestCase.test_struct.<locals>.MyEnum"
attribute \enum_value_00 "A"
attribute \enum_value_01 "B"
attribute \enum_value_10 "C"
Expand Down
10 changes: 5 additions & 5 deletions tests/test_hdl_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def from_bits(self, bits):
class ShapeCastableTestCase(FHDLTestCase):
def test_no_override(self):
with self.assertRaisesRegex(TypeError,
r"^Class 'MockShapeCastableNoOverride' deriving from 'ShapeCastable' must "
r"^Class '.+\.MockShapeCastableNoOverride' deriving from 'ShapeCastable' must "
r"override the 'as_shape' method$"):
class MockShapeCastableNoOverride(ShapeCastable):
def __init__(self):
Expand Down Expand Up @@ -509,7 +509,7 @@ def __init__(self, value):

def shape(self):
return MockConstShape()

def as_value(self):
return Const(self.value, 8)

Expand Down Expand Up @@ -1308,7 +1308,7 @@ class Color(Enum):
BLUE = 2
s = Signal(decoder=Color)
self.assertEqual(s.decoder, Color)
self.assertRepr(s._format, "(format-enum (sig s) 'Color' (1 'RED') (2 'BLUE'))")
self.assertRepr(s._format, f"(format-enum (sig s) '{Color.__qualname__}' (1 'RED') (2 'BLUE'))")

def test_enum(self):
s1 = Signal(UnsignedEnum)
Expand Down Expand Up @@ -1481,14 +1481,14 @@ def __getattr__(self, attr):
class ValueCastableTestCase(FHDLTestCase):
def test_no_override(self):
with self.assertRaisesRegex(TypeError,
r"^Class 'MockValueCastableNoOverrideAsValue' deriving from 'ValueCastable' must "
r"^Class '.+\.MockValueCastableNoOverrideAsValue' deriving from 'ValueCastable' must "
r"override the 'as_value' method$"):
class MockValueCastableNoOverrideAsValue(ValueCastable):
def __init__(self):
pass

with self.assertRaisesRegex(TypeError,
r"^Class 'MockValueCastableNoOverrideShapec' deriving from 'ValueCastable' must "
r"^Class '.+\.MockValueCastableNoOverrideShapec' deriving from 'ValueCastable' must "
r"override the 'shape' method$"):
class MockValueCastableNoOverrideShapec(ValueCastable):
def __init__(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_hdl_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -3416,15 +3416,15 @@ class MyEnum(enum.Enum, shape=unsigned(2)):
])
self.assertEqual(nl.signal_fields[s1.as_value()], {
(): SignalField(nl.signals[s1.as_value()], signed=False),
('a',): SignalField(nl.signals[s1.as_value()][0:2], signed=False, enum_name="MyEnum", enum_variants={
('a',): SignalField(nl.signals[s1.as_value()][0:2], signed=False, enum_name=MyEnum.__qualname__, enum_variants={
0: "A",
1: "B",
2: "C",
}),
('b',): SignalField(nl.signals[s1.as_value()][2:5], signed=True)
})
self.assertEqual(nl.signal_fields[s2.as_value()], {
(): SignalField(nl.signals[s2.as_value()], signed=False, enum_name="MyEnum", enum_variants={
(): SignalField(nl.signals[s2.as_value()], signed=False, enum_name=MyEnum.__qualname__, enum_variants={
0: "A",
1: "B",
2: "C",
Expand Down Expand Up @@ -3515,4 +3515,4 @@ def test_require_renamed(self):
m.submodules += DomainRenamer("test")(RequirePosedge("sync"))
with self.assertRaisesRegex(DomainRequirementFailed,
r"^Domain test has a negedge clock, but posedge clock is required by top.U\$0 at .*$"):
Fragment.get(m, None).prepare()
Fragment.get(m, None).prepare()
Loading