-
-
Notifications
You must be signed in to change notification settings - Fork 801
keyword-only arguments as required Option #270
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #270 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 242 242
Lines 4508 4509 +1
=========================================
+ Hits 4508 4509 +1
Continue to review full report at Codecov.
|
| name: str, | ||
| default: Any = inspect.Parameter.empty, | ||
| annotation: Any = inspect.Parameter.empty, | ||
| kind: inspect._ParameterKind = inspect.Parameter.POSITIONAL_OR_KEYWORD, |
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.
accessing inspect._ParameterKind is ugly a bit, but the type name is _ParameterKind
https://github.com/python/typeshed/blob/a690a14c820238ca7a64cd502343d6b5a649e731/stdlib/inspect.pyi#L125-L134
| elif param.default == Required or param.default == param.empty: | ||
| required = True | ||
| parameter_info = ArgumentInfo() | ||
| if param.kind == inspect.Parameter.KEYWORD_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.
Where should I write the test?
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.
Ideally, there would be a tutorial file in docs_src demonstrating the behavior. And then a test for that file in tests/test_tutorial/. Then reference the file in the markdown documentation with a brief explanation.
Sometimes there are tricky edge cases that don't fit into tutorials. In that case, you can add some tests in the top level of the tests/ directory.
|
@podhmo do you need some help on this PR? I really feel like this feature would be game breaker! |
|
@tiangolo What is missing in this PR so that it can be accepted? How could I help making it complete? |
|
Oh, sorry for late response, the missing part is tests. |
ryangalamb
left a comment
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.
As pointed out earlier, tests are the main thing blocking this right now.
FWIW, this is a breaking change (existing CLIs that use keyword-only arguments will change behavior), but I think this is useful enough to justify a breaking change.
Let me know if you have any more questions about how/where to add tests.
| elif param.default == Required or param.default == param.empty: | ||
| required = True | ||
| parameter_info = ArgumentInfo() | ||
| if param.kind == inspect.Parameter.KEYWORD_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.
Ideally, there would be a tutorial file in docs_src demonstrating the behavior. And then a test for that file in tests/test_tutorial/. Then reference the file in the markdown documentation with a brief explanation.
Sometimes there are tricky edge cases that don't fit into tutorials. In that case, you can add some tests in the top level of the tests/ directory.
|
Thank you for the comments, but sorry, I've lost the motivation. So, feel free to reopen or reuse the code in new pull request. |
|
Sounds good, thanks for responding and sharing your code/time! |
supports #269