-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Support for postional only args in dynamic library api #4701
Conversation
Walk Through copilot:walkthrough |
0ec7c8b
to
a510179
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good but looking for the actual /
value should be moved to DynamicArgumentParser
from the common base class. I also need to look at tests and docs in a bit more detail later.
for arg in argspec: | ||
arg = self._validate_arg(arg) | ||
if arg == "/": | ||
positional_only = False | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ArgumentSpecParser
is a common base class for UserKeywordArgumentParser
and DynamicArgumentParser
. Checking for actual values, in this case /
, should be done in them. I believe it would be best to add new _is_positional_only_separator
method and then use it in the for arg in argspec
loop. The usage could probably be something like this (untested):
if self._is_positional_only_separator(arg):
if positional_only_separator_seen:
self._report_error(...)
spec.positional_only, spec.positional_or_named = spec.positional_or_named, []
positional_only_separator_seen = True
The positional_only_separator_seen
would need to be initialized in the same place as named_only
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this will result cleaner code. I made the changes.
@@ -165,6 +174,8 @@ def _validate_arg(self, arg): | |||
if len(arg) == 1: | |||
return arg[0] | |||
return arg | |||
if "/" in arg and len(arg) > 1: | |||
self._report_error(f'Invalid argument "{arg}".') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the idea to make /arg
invalid syntax, but this check makes using /
anywhere in the argument name invalid. That could be a good idea as well, but it's also to some extend backwards incompatible. Although the risk that this change would actually cause issues is small, it may still not be worth the effort. On the other hand, we could consider limiting argument names also otherwise, but that would require a separate issue. We can discuss all this further in Slack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy to going either way, I do not feel strongly on the matter should /arg
or a/rg
be invalid or not. Lets discuss in Slack.
In latest commit, did leave it as is, but it is easy to change once agreement is reached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! There are few minor things to be changed (for example, this shouldn't require Python 3.8) but I can take care of that myself.
Fixes #4660
summary:
copilot:summary