Skip to content

Report offending input in parametrized module error messages - #1103

Open
jaewonyun1234 wants to merge 1 commit into
pasqal-io:developfrom
jaewonyun1234:parametrized-module-error-messages
Open

jaewonyun1234 wants to merge 1 commit into
pasqal-io:developfrom
jaewonyun1234:parametrized-module-error-messages

Conversation

@jaewonyun1234

Copy link
Copy Markdown
Contributor

Hi @a-corni, @HGSilveri,

Following on from #1095, #1097, #1098 and #1102, this covers the parametrized module: 5 messages, 3 in variable.py and 2 in paramobj.py.

The two in paramobj.py are the same message raised from _to_dict and _to_abstract_repr. Both now name the method that couldn't be serialized, e.g. got 'Register.rotated'.

I left the Serialization of calls to parametrized objects is not supported pair unchanged. Calling a parametrized object already warns at that line, and the warning includes the same object, so repeating it in the error adds nothing.

Partially addresses #1057.

Error messages that only stated a rule now also report the value that
broke it.

Covers 5 messages: 3 in variable.py, where three of the four checks in
Variable.__post_init__ did not say what was given, and 2 in paramobj.py,
which now name the method that could not be serialized.

The two errors raised for calls to parametrized objects are left
unchanged: ParamObj.__call__ already warns at the call site and the
warning carries the same object, so repeating it adds nothing.

Existing assertions that stopped before the reported value are extended
to the end of the message.
Comment on lines +49 to +50
"Variable's 'name' has to be of type 'str', not "
f"{type(self.name)}."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe is it worth returning the input that failed ?

Suggested change
"Variable's 'name' has to be of type 'str', not "
f"{type(self.name)}."
"Variable's 'name' has to be of type 'str', not "
f"{type(self.name)} (got {self.name!r})."

Comment on lines +56 to +57
"Variable's 'size' has to be of type 'int', not "
f"{type(self.size)}."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well

Suggested change
"Variable's 'size' has to be of type 'int', not "
f"{type(self.size)}."
"Variable's 'size' has to be of type 'int', not "
f"{type(self.size)} (got {self.size!r})."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants