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

Apply type casting & remove empty kwarg for Command #108

Merged
merged 4 commits into from
May 23, 2024

Conversation

nkvuong
Copy link
Contributor

@nkvuong nkvuong commented May 23, 2024

Currently, all kwargs are passed into App.command as str. Empty kwarg is passed as empty string.

In this PR, we remove any empty kwarg, and apply casting based on the kwarg annotation for primitive types

Copy link

codecov bot commented May 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.05%. Comparing base (2b75d24) to head (cc89c55).
Report is 3 commits behind head on main.

Current head cc89c55 differs from pull request most recent head 73c601f

Please upload reports for the commit 73c601f to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #108      +/-   ##
==========================================
+ Coverage   78.78%   79.05%   +0.27%     
==========================================
  Files          14       14              
  Lines        1499     1509      +10     
  Branches      269      272       +3     
==========================================
+ Hits         1181     1193      +12     
+ Misses        230      229       -1     
+ Partials       88       87       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@nfx nfx left a comment

Choose a reason for hiding this comment

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

lgtm

@nfx nfx merged commit cb16357 into databrickslabs:main May 23, 2024
10 of 11 checks passed
nfx added a commit that referenced this pull request May 23, 2024
* Applied type casting & remove empty kwarg for Command ([#108](#108)). A new method, `get_argument_type`, has been added to the `Command` class in the `cli.py` file to determine the type of a given argument name based on the function's signature. The `_route` method has been updated to remove any empty keyword arguments from the `kwargs` dictionary, and apply type casting based on the argument type using the `get_argument_type` method. This ensures that the `kwargs` passed into `App.command` are correctly typed and eliminates any empty keyword arguments, which were previously passed as empty strings. In the test file for the command-line interface, the `foo` command's keyword arguments have been updated to include `age` (int), `salary` (float), `is_customer` (bool), and `address` (str) types, with the `name` argument remaining and a default value for `address`. The `test_commands` and `test_injects_prompts` functions have been updated accordingly. These changes aim to improve the input validation and type safety of the `App.command` method.
@nfx nfx mentioned this pull request May 23, 2024
nfx added a commit that referenced this pull request May 23, 2024
* Applied type casting & remove empty kwarg for Command
([#108](#108)). A new
method, `get_argument_type`, has been added to the `Command` class in
the `cli.py` file to determine the type of a given argument name based
on the function's signature. The `_route` method has been updated to
remove any empty keyword arguments from the `kwargs` dictionary, and
apply type casting based on the argument type using the
`get_argument_type` method. This ensures that the `kwargs` passed into
`App.command` are correctly typed and eliminates any empty keyword
arguments, which were previously passed as empty strings. In the test
file for the command-line interface, the `foo` command's keyword
arguments have been updated to include `age` (int), `salary` (float),
`is_customer` (bool), and `address` (str) types, with the `name`
argument remaining and a default value for `address`. The
`test_commands` and `test_injects_prompts` functions have been updated
accordingly. These changes aim to improve the input validation and type
safety of the `App.command` method.
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