Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/nmigen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 031a9e261607
Choose a base ref
...
head repository: m-labs/nmigen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3c07d8d52cef
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Jan 1, 2019

  1. hdl.rec: include record name in error message.

    whitequark committed Jan 1, 2019
    Copy the full SHA
    3c07d8d View commit details
Showing with 16 additions and 3 deletions.
  1. +6 −2 nmigen/hdl/rec.py
  2. +10 −1 nmigen/test/test_hdl_rec.py
8 changes: 6 additions & 2 deletions nmigen/hdl/rec.py
Original file line number Diff line number Diff line change
@@ -93,8 +93,12 @@ def __getitem__(self, name):
try:
return self.fields[name]
except KeyError:
raise NameError("Record does not have a field '{}'. Did you mean one of: {}?"
.format(name, ", ".join(self.fields))) from None
if self.name is None:
reference = "Unnamed record"
else:
reference = "Record '{}'".format(self.name)
raise NameError("{} does not have a field '{}'. Did you mean one of: {}?"
.format(reference, name, ", ".join(self.fields))) from None

def shape(self):
return sum(len(f) for f in self.fields.values()), False
11 changes: 10 additions & 1 deletion nmigen/test/test_hdl_rec.py
Original file line number Diff line number Diff line change
@@ -85,5 +85,14 @@ def test_wrong_field(self):
("ack", 1),
])
with self.assertRaises(NameError,
msg="Record does not have a field 'en'. Did you mean one of: stb, ack?"):
msg="Record 'r' does not have a field 'en'. Did you mean one of: stb, ack?"):
r.en

def test_wrong_field_unnamed(self):
r = [Record([
("stb", 1),
("ack", 1),
])][0]
with self.assertRaises(NameError,
msg="Unnamed record does not have a field 'en'. Did you mean one of: stb, ack?"):
r.en