Skip to content
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

rpc: fix 0-ady functions raising an exception #134

Closed
Closed
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
7 changes: 4 additions & 3 deletions src/p4p/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,14 @@ def _wrapMethod(K, V):
if S.varargs is not None or keywords is not None:
raise TypeError("vararg not supported for proxy method %s" % K)

if len(S.args) != len(S.defaults):
args, defaults = ([] if v is None else v for v in (S.args, S.defaults))
Copy link
Member

@mdavidsaver mdavidsaver Jan 16, 2024

Choose a reason for hiding this comment

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

Do you mean for this line to do something like the following?

args, defaults = S.args or [], S.defaults or []

Copy link
Author

Choose a reason for hiding this comment

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

Yes, but I generally don't use the or syntax to handle None because it also brakes on falsely values.

Copy link
Member

Choose a reason for hiding this comment

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

For reference, I understand the concern about loose type comparison rules. In this instance, S comes from the builtin inspect module, which I think can be relied on not to change radically. So I think the or [] is a reasonable abbreviation.

if len(args) != len(defaults):
raise TypeError("proxy method %s must specify types for all arguments" % K)

try:
NT = NTURI(zip(S.args, S.defaults))
NT = NTURI(zip(args, defaults))
except Exception as e:
raise TypeError("%s : failed to build method from %s, %s" % (e, S.args, S.defaults))
raise TypeError("%s : failed to build method from %s, %s" % (e, args, defaults))

@wraps(V)
def mcall(self, *args, **kws):
Expand Down