You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/04/16 10:37:05 UTC
[GitHub] [airflow] ashb opened a new pull request #8398: Allow "falsey"
default arguments in CLI Parser
ashb opened a new pull request #8398: Allow "falsey" default arguments in CLI Parser
URL: https://github.com/apache/airflow/pull/8398
In #8219 we noticed that we couldn't set a `default=0` because of the
`and v` check. The "add_argument" function in python avoid this by using
**kwargs, but we want type checking so can't directly use the same
there.
This uses the same pattern that configparser does to allow falsey (0,
False) and even `None` as valid values, distinct from not being passed.
---
Make sure to mark the boxes below before creating PR: [x]
- [x] Description above provides context of the change
- [x] Unit tests coverage for changes (not needed for documentation changes)
- [x] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
- [x] Relevant documentation is updated including usage instructions.
- [x] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
---
In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] ashb merged pull request #8398: Allow "falsey" default
arguments in CLI Parser
Posted by GitBox <gi...@apache.org>.
ashb merged pull request #8398: Allow "falsey" default arguments in CLI Parser
URL: https://github.com/apache/airflow/pull/8398
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] kaxil commented on a change in pull request #8398: Allow
"falsey" default arguments in CLI Parser
Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #8398: Allow "falsey" default arguments in CLI Parser
URL: https://github.com/apache/airflow/pull/8398#discussion_r409471814
##########
File path: airflow/cli/cli_parser.py
##########
@@ -73,21 +73,25 @@ def error(self, message):
self.exit(2, f'\n{self.prog} command error: {message}, see help above.\n')
+# Used in Arg to enable `None' as a distinct value from "not passed"
+_UNSET = object()
+
+
class Arg:
"""Class to keep information about command line argument"""
- # pylint: disable=redefined-builtin
- def __init__(self, flags=None, help=None, action=None, default=None, nargs=None,
- type=None, choices=None, required=None, metavar=None):
+ # pylint: disable=redefined-builtin,unused-argument
+ def __init__(self, flags=_UNSET, help=_UNSET, action=_UNSET, default=_UNSET, nargs=_UNSET, type=_UNSET,
+ choices=_UNSET, required=_UNSET, metavar=_UNSET):
self.flags = flags
- self.help = help
- self.action = action
- self.default = default
- self.nargs = nargs
- self.type = type
- self.choices = choices
- self.required = required
- self.metavar = metavar
- # pylint: enable=redefined-builtin
+ self.kwargs = {}
+ for k, v in locals().items():
+ if v is _UNSET:
+ continue
+ if k in ("self", "flags"):
+ continue
+
+ self.kwargs[k] = v
+ # pylint: enable=redefined-builtin,unused-argument
Review comment:
Can we add a test for this, e.g adding a new argument with a false default
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] ashb commented on issue #8398: Allow "falsey" default
arguments in CLI Parser
Posted by GitBox <gi...@apache.org>.
ashb commented on issue #8398: Allow "falsey" default arguments in CLI Parser
URL: https://github.com/apache/airflow/pull/8398#issuecomment-614750849
Bored waiting for travis to run the K8s tests for a cli change.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] kaxil commented on issue #8398: Allow "falsey" default
arguments in CLI Parser
Posted by GitBox <gi...@apache.org>.
kaxil commented on issue #8398: Allow "falsey" default arguments in CLI Parser
URL: https://github.com/apache/airflow/pull/8398#issuecomment-614629905
One of the tests failed but might be just a flaky test:
``|
FAILED tests/jobs/test_local_task_job.py::TestLocalTaskJob::test_mark_failure_on_failure_callback
= 1 failed, 2594 passed, 46 skipped, 4 xpassed, 6 warnings in 1267.93s (0:21:07) =
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] ashb commented on a change in pull request #8398: Allow
"falsey" default arguments in CLI Parser
Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #8398: Allow "falsey" default arguments in CLI Parser
URL: https://github.com/apache/airflow/pull/8398#discussion_r409521499
##########
File path: airflow/cli/cli_parser.py
##########
@@ -73,21 +73,25 @@ def error(self, message):
self.exit(2, f'\n{self.prog} command error: {message}, see help above.\n')
+# Used in Arg to enable `None' as a distinct value from "not passed"
+_UNSET = object()
+
+
class Arg:
"""Class to keep information about command line argument"""
- # pylint: disable=redefined-builtin
- def __init__(self, flags=None, help=None, action=None, default=None, nargs=None,
- type=None, choices=None, required=None, metavar=None):
+ # pylint: disable=redefined-builtin,unused-argument
+ def __init__(self, flags=_UNSET, help=_UNSET, action=_UNSET, default=_UNSET, nargs=_UNSET, type=_UNSET,
+ choices=_UNSET, required=_UNSET, metavar=_UNSET):
self.flags = flags
- self.help = help
- self.action = action
- self.default = default
- self.nargs = nargs
- self.type = type
- self.choices = choices
- self.required = required
- self.metavar = metavar
- # pylint: enable=redefined-builtin
+ self.kwargs = {}
+ for k, v in locals().items():
+ if v is _UNSET:
+ continue
+ if k in ("self", "flags"):
+ continue
+
+ self.kwargs[k] = v
+ # pylint: enable=redefined-builtin,unused-argument
Review comment:
Done.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] ashb commented on a change in pull request #8398: Allow
"falsey" default arguments in CLI Parser
Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #8398: Allow "falsey" default arguments in CLI Parser
URL: https://github.com/apache/airflow/pull/8398#discussion_r409478020
##########
File path: airflow/cli/cli_parser.py
##########
@@ -73,21 +73,25 @@ def error(self, message):
self.exit(2, f'\n{self.prog} command error: {message}, see help above.\n')
+# Used in Arg to enable `None' as a distinct value from "not passed"
+_UNSET = object()
+
+
class Arg:
"""Class to keep information about command line argument"""
- # pylint: disable=redefined-builtin
- def __init__(self, flags=None, help=None, action=None, default=None, nargs=None,
- type=None, choices=None, required=None, metavar=None):
+ # pylint: disable=redefined-builtin,unused-argument
+ def __init__(self, flags=_UNSET, help=_UNSET, action=_UNSET, default=_UNSET, nargs=_UNSET, type=_UNSET,
+ choices=_UNSET, required=_UNSET, metavar=_UNSET):
self.flags = flags
- self.help = help
- self.action = action
- self.default = default
- self.nargs = nargs
- self.type = type
- self.choices = choices
- self.required = required
- self.metavar = metavar
- # pylint: enable=redefined-builtin
+ self.kwargs = {}
+ for k, v in locals().items():
+ if v is _UNSET:
+ continue
+ if k in ("self", "flags"):
+ continue
+
+ self.kwargs[k] = v
+ # pylint: enable=redefined-builtin,unused-argument
Review comment:
Good call.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] ashb commented on issue #8398: Allow "falsey" default
arguments in CLI Parser
Posted by GitBox <gi...@apache.org>.
ashb commented on issue #8398: Allow "falsey" default arguments in CLI Parser
URL: https://github.com/apache/airflow/pull/8398#issuecomment-614664656
Flakey test addressed (hopefully) in #8405
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services