-
-
Notifications
You must be signed in to change notification settings - Fork 2
Enhancement | Issue #21 | OPT-2 | Implement typed argument casting #307
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
base: master
Are you sure you want to change the base?
Enhancement | Issue #21 | OPT-2 | Implement typed argument casting #307
Conversation
WalkthroughA new casting utility module was introduced to convert string values to Python primitive types, and its functionality was integrated into configuration loading and argument parsing. Existing and new tests were updated or created to verify that values are now cast to appropriate types (booleans, integers, floats) instead of remaining as strings. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ConfigLoader
participant _casting
User->>ConfigLoader: load()
ConfigLoader->>_casting: cast_value(str_value)
_casting-->>ConfigLoader: casted_value
ConfigLoader-->>User: config_dict with casted values
sequenceDiagram
participant User
participant ArgParser
participant _casting
User->>ArgParser: parse_task_args(input_args)
ArgParser->>_casting: cast_value(arg)
_casting-->>ArgParser: casted_arg
ArgParser-->>User: args, kwargs (with casted values)
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Pull Request Test Coverage Report for Build 15472282000Details
💛 - Coveralls |
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.
Actionable comments posted: 3
🧹 Nitpick comments (1)
leverage/_casting.py (1)
1-8
: Consider adding more comprehensive docstring and imports.The module could benefit from a more detailed docstring explaining the casting strategy and potential edge cases.
""" -Value casting utilities. +Value casting utilities for converting string values to Python primitives. + +This module provides functions to safely cast string values to boolean, integer, +and float types, falling back to the original string if casting fails. """ -from typing import Any +from typing import Any, Union import yaml
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
leverage/_casting.py
(1 hunks)leverage/_parsing.py
(2 hunks)leverage/conf.py
(2 hunks)tests/test__parsing.py
(1 hunks)tests/test_casting.py
(1 hunks)tests/test_conf.py
(1 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
tests/test__parsing.py
[refactor] 35-35: Redundant comparison - expected != expected
(R0124)
[refactor] 36-36: Redundant comparison - received != received
(R0124)
tests/test_casting.py
[refactor] 1-1: Useless option value for '--disable', 'print-statement' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'parameter-unpacking' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'unpacking-in-except' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'old-raise-syntax' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'backtick' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'import-star-module-level' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'apply-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'basestring-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'buffer-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'cmp-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'coerce-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'execfile-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'file-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'long-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'raw_input-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'reduce-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'standarderror-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'unicode-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'xrange-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'coerce-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'delslice-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'getslice-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'setslice-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'no-absolute-import' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'old-division' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-iter-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-view-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'next-method-called' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'metaclass-assignment' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'indexing-exception' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'raising-string' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'reload-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'oct-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'hex-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'nonzero-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'cmp-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'input-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'round-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'intern-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'unichr-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'map-builtin-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'zip-builtin-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'range-builtin-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'filter-builtin-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'using-cmp-argument' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'div-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'idiv-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'rdiv-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'exception-message-attribute' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'invalid-str-codec' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'sys-max-int' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'bad-python3-import' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-string-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-str-translate-call' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-itertools-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-types-field' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'next-method-defined' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-items-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-keys-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-values-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-operator-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-urllib-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'xreadlines-attribute' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-sys-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'exception-escape' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'comprehension-escape' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
🪛 GitHub Actions: Tests | Lint w/ Black
tests/test__parsing.py
[error] 1-1: Prettier formatting check failed. Run 'black --write' to fix code style issues in this file.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: integration_tests_cli_refarch (3.9.15, 1.3.5-0.2.0)
🔇 Additional comments (15)
tests/test_conf.py (1)
35-35
:❓ Verification inconclusive
Verify boolean casting behavior aligns with expectations.
Similar to
MFA_ENABLED
, the test now expectsTrue
instead of"true"
forDEBUG
. Ensure this type change is compatible with all code that consumes this configuration value.
🏁 Script executed:
#!/bin/bash # Description: Search for usages of DEBUG to verify impact of type change # Search for DEBUG usage patterns rg -A 3 -B 3 "DEBUG"Length of output: 3767
🏁 Script executed:
#!/bin/bash # Locate configuration files find . -type f | grep -E '/conf.*\.py$' || echo "no conf file"Length of output: 130
🏁 Script executed:
#!/bin/bash # Show definitions of MFA_ENABLED and DEBUG in leverage/conf.py rg -n -C5 'MFA_ENABLED' leverage/conf.py rg -n -C5 'DEBUG' leverage/conf.pyLength of output: 75
🏁 Script executed:
#!/bin/bash # Show file leverage/conf.py with line numbers cat -n leverage/conf.pyLength of output: 2295
ACTION REQUIRED: Confirm Boolean Casting Impact on
DEBUG
Consumption
The test now asserts"DEBUG": True
(Python bool) instead of the string"true"
. Before merging, please verify that every consumer of theDEBUG
config value handles a boolean rather than a string:• leverage/conf.py → uses
cast_value(val)
to convert"true"
→True
.
• Search codebase forconfig["DEBUG"]
or.get("DEBUG")
to ensure it’s not compared against strings.
• Inleverage/logger.py
, log‐level selection is driven by click'sstate.verbosity
, not thisDEBUG
key—no direct impact there.
• Any other places that read the raw env var (e.g., manualos.getenv("DEBUG")
checks) must expect a bool now.Please review and update any string comparisons or downstream logic accordingly.
leverage/conf.py (2)
9-9
: Import looks good.Clean import of the casting functionality.
61-61
: Casting integration implemented correctly.The casting is applied appropriately to environment variable values. However, consider the performance impact if there are many environment variables, as each value now goes through the casting pipeline.
Note: The TODO comment on line 39 about returning an Env object for type casting utilities is now partially addressed by this implementation, though it still uses a dictionary.
leverage/_parsing.py (3)
5-5
: Import looks good.Clean import of the casting functionality.
45-45
: Casting applied correctly to positional arguments.The casting ensures that positional arguments are converted to appropriate types rather than remaining as strings.
52-52
: Casting applied correctly to keyword arguments.The casting ensures that keyword argument values are converted to appropriate types rather than remaining as strings.
tests/test__parsing.py (5)
11-11
: LGTM: Proper casting verification for positional arguments.The test case correctly expects integer and float casting instead of string values, aligning with the new casting functionality.
13-16
: LGTM: Comprehensive keyword argument casting tests.The test properly verifies that boolean and integer values are cast while preserving string values that shouldn't be cast.
18-28
: Excellent edge case coverage for casting functionality.The comprehensive test cases cover:
- Scientific notation (
1e10
)- Special float values (
inf
,nan
)- Leading zeros (
007
,0123
)- Boolean variations in different cases
- Mixed keyword argument types
This ensures robust validation of the casting implementation.
34-38
: Correct NaN handling implementation.The element-wise comparison with special NaN handling is the proper approach since
NaN != NaN
evaluates toTrue
in Python. The static analysis warning about redundant comparisons is a false positive in this context.🧰 Tools
🪛 Pylint (3.3.7)
[refactor] 35-35: Redundant comparison - expected != expected
(R0124)
[refactor] 36-36: Redundant comparison - received != received
(R0124)
1-61
:❓ Verification inconclusive
Fix code formatting to resolve pipeline failure.
The Black formatter requires formatting fixes.
🏁 Script executed:
#!/bin/bash # Description: Apply Black formatting to fix the pipeline failure # Expected: File will be reformatted according to Black standards black --check tests/test__parsing.py || echo "Formatting needed" black --write tests/test__parsing.pyLength of output: 314
Formatting Check Required
Black could not be executed in this environment, so we’re unable to verify the formatting automatically. Please ensure that
tests/test__parsing.py
is formatted according to Black’s rules to fix the pipeline failure. For example:pip install black black tests/test__parsing.py
🧰 Tools
🪛 Pylint (3.3.7)
[refactor] 1-1: Useless option value for '--disable', 'print-statement' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'parameter-unpacking' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'unpacking-in-except' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'old-raise-syntax' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'backtick' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'import-star-module-level' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'apply-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'basestring-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'buffer-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'cmp-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'coerce-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'execfile-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'file-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'long-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'raw_input-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'reduce-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'standarderror-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'unicode-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'xrange-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'coerce-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'delslice-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'getslice-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'setslice-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'no-absolute-import' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'old-division' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-iter-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-view-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'next-method-called' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'metaclass-assignment' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'indexing-exception' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'raising-string' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'reload-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'oct-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'hex-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'nonzero-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'cmp-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'input-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'round-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'intern-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'unichr-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'map-builtin-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'zip-builtin-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'range-builtin-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'filter-builtin-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'using-cmp-argument' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'div-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'idiv-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'rdiv-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'exception-message-attribute' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'invalid-str-codec' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'sys-max-int' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'bad-python3-import' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-string-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-str-translate-call' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-itertools-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-types-field' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'next-method-defined' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-items-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-keys-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-values-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-operator-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-urllib-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'xreadlines-attribute' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-sys-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'exception-escape' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'comprehension-escape' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 35-35: Redundant comparison - expected != expected
(R0124)
[refactor] 36-36: Redundant comparison - received != received
(R0124)
🪛 GitHub Actions: Tests | Lint w/ Black
[error] 1-1: Prettier formatting check failed. Run 'black --write' to fix code style issues in this file.
tests/test_casting.py (4)
1-6
: Clean imports and setup.Proper imports for the testing framework and the casting module being tested.
🧰 Tools
🪛 Pylint (3.3.7)
[refactor] 1-1: Useless option value for '--disable', 'print-statement' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'parameter-unpacking' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'unpacking-in-except' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'old-raise-syntax' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'backtick' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'import-star-module-level' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'apply-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'basestring-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'buffer-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'cmp-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'coerce-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'execfile-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'file-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'long-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'raw_input-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'reduce-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'standarderror-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'unicode-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'xrange-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'coerce-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'delslice-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'getslice-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'setslice-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'no-absolute-import' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'old-division' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-iter-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-view-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'next-method-called' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'metaclass-assignment' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'indexing-exception' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'raising-string' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'reload-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'oct-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'hex-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'nonzero-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'cmp-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'input-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'round-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'intern-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'unichr-builtin' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'map-builtin-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'zip-builtin-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'range-builtin-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'filter-builtin-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'using-cmp-argument' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'div-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'idiv-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'rdiv-method' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'exception-message-attribute' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'invalid-str-codec' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'sys-max-int' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'bad-python3-import' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-string-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-str-translate-call' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-itertools-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-types-field' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'next-method-defined' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-items-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-keys-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'dict-values-not-iterating' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-operator-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-urllib-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'xreadlines-attribute' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'deprecated-sys-function' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'exception-escape' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
[refactor] 1-1: Useless option value for '--disable', 'comprehension-escape' was removed from pylint, see pylint-dev/pylint#4942.
(R0022)
8-23
: Comprehensive parametrized test data for cast_value.Excellent coverage including:
- Boolean values (
"true"
,"False"
)- Integers with edge cases (
"-2"
,"007"
,"0123"
)- Floats with scientific notation (
"1e3"
)- Special values (
"inf"
,"nan"
)- Non-convertible strings (
"foo"
)This ensures thorough validation of the casting logic.
24-30
: Proper NaN handling in assertions.Using
math.isnan()
for NaN comparisons is the correct approach, avoiding the pitfall of direct NaN equality checks.
32-38
: Good coverage of helper functions.The tests verify both successful conversions and fallback behavior when conversion isn't possible, ensuring the helper functions work as expected.
def as_bool(value: str) -> Any: | ||
"""Return the boolean representation of ``value`` if possible.""" | ||
try: | ||
parsed = yaml.safe_load(value) | ||
if isinstance(parsed, bool): | ||
return parsed | ||
except yaml.YAMLError: | ||
pass | ||
return value |
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.
Security concern: yaml.safe_load can parse more than just booleans.
Using yaml.safe_load
for boolean parsing is risky as it can interpret various YAML constructs beyond simple boolean values. This could lead to unexpected behavior or security issues.
Consider using a more explicit boolean parsing approach:
-def as_bool(value: str) -> Any:
- """Return the boolean representation of ``value`` if possible."""
- try:
- parsed = yaml.safe_load(value)
- if isinstance(parsed, bool):
- return parsed
- except yaml.YAMLError:
- pass
- return value
+def as_bool(value: str) -> Any:
+ """Return the boolean representation of ``value`` if possible."""
+ lower_value = value.lower().strip()
+ if lower_value in ('true', 'yes', '1', 'on'):
+ return True
+ elif lower_value in ('false', 'no', '0', 'off'):
+ return False
+ return value
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
def as_bool(value: str) -> Any: | |
"""Return the boolean representation of ``value`` if possible.""" | |
try: | |
parsed = yaml.safe_load(value) | |
if isinstance(parsed, bool): | |
return parsed | |
except yaml.YAMLError: | |
pass | |
return value | |
def as_bool(value: str) -> Any: | |
"""Return the boolean representation of ``value`` if possible.""" | |
lower_value = value.lower().strip() | |
if lower_value in ('true', 'yes', '1', 'on'): | |
return True | |
elif lower_value in ('false', 'no', '0', 'off'): | |
return False | |
return value |
🤖 Prompt for AI Agents
In leverage/_casting.py around lines 10 to 18, the use of yaml.safe_load to
parse booleans is insecure because it can interpret complex YAML structures
beyond simple booleans. Replace yaml.safe_load with a more explicit boolean
parsing method that only recognizes specific string values like "true", "false",
"yes", "no" (case-insensitive) and returns the corresponding boolean, otherwise
return the original value.
def cast_value(value: str) -> Any: | ||
"""Try to cast ``value`` to bool, int or float using the helper functions | ||
:func:`as_bool`, :func:`as_int` and :func:`as_float`. | ||
Args: | ||
value (str): Value to cast. | ||
Returns: | ||
Any: The value converted to its apparent type or the original string. | ||
""" | ||
value = as_bool(value) | ||
if isinstance(value, str): | ||
value = as_int(value) | ||
if isinstance(value, str): | ||
value = as_float(value) | ||
|
||
return value |
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.
🛠️ Refactor suggestion
Add input validation and improve type safety.
The function accepts str
type but doesn't validate the input. Also, the casting order could cause issues where numeric strings like "123.0" are cast as integers instead of floats.
def cast_value(value: str) -> Any:
- """Try to cast ``value`` to bool, int or float using the helper functions
- :func:`as_bool`, :func:`as_int` and :func:`as_float`.
-
- Args:
- value (str): Value to cast.
-
- Returns:
- Any: The value converted to its apparent type or the original string.
- """
+ """Try to cast ``value`` to bool, int or float using the helper functions
+ :func:`as_bool`, :func:`as_int` and :func:`as_float`.
+
+ Args:
+ value (str): Value to cast.
+
+ Returns:
+ Any: The value converted to its apparent type or the original string.
+ """
+ if not isinstance(value, str):
+ return value
+
value = as_bool(value)
if isinstance(value, str):
+ # Try float before int to handle decimal numbers correctly
+ temp_float = as_float(value)
+ if not isinstance(temp_float, str):
+ # Check if it's actually an integer value
+ if temp_float.is_integer():
+ return int(temp_float)
+ return temp_float
value = as_int(value)
- if isinstance(value, str):
- value = as_float(value)
return value
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
def cast_value(value: str) -> Any: | |
"""Try to cast ``value`` to bool, int or float using the helper functions | |
:func:`as_bool`, :func:`as_int` and :func:`as_float`. | |
Args: | |
value (str): Value to cast. | |
Returns: | |
Any: The value converted to its apparent type or the original string. | |
""" | |
value = as_bool(value) | |
if isinstance(value, str): | |
value = as_int(value) | |
if isinstance(value, str): | |
value = as_float(value) | |
return value | |
def cast_value(value: str) -> Any: | |
"""Try to cast ``value`` to bool, int or float using the helper functions | |
:func:`as_bool`, :func:`as_int` and :func:`as_float`. | |
Args: | |
value (str): Value to cast. | |
Returns: | |
Any: The value converted to its apparent type or the original string. | |
""" | |
if not isinstance(value, str): | |
return value | |
value = as_bool(value) | |
if isinstance(value, str): | |
# Try float before int to handle decimal numbers correctly | |
temp_float = as_float(value) | |
if not isinstance(temp_float, str): | |
# Check if it's actually an integer value | |
if temp_float.is_integer(): | |
return int(temp_float) | |
return temp_float | |
value = as_int(value) | |
return value |
🤖 Prompt for AI Agents
In leverage/_casting.py around lines 37 to 53, add input validation to ensure
the input is a string before processing to improve type safety. Adjust the
casting order to first attempt casting to float, then int, and finally bool, to
correctly handle numeric strings like "123.0" without prematurely casting them
as integers. Update the function to raise a TypeError if the input is not a
string.
@@ -30,9 +30,9 @@ | |||
True, | |||
{ | |||
"PROJECT": "foobar", | |||
"MFA_ENABLED": "true", | |||
"MFA_ENABLED": True, |
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.
💡 Verification agent
🧩 Analysis chain
Verify boolean casting behavior aligns with expectations.
The test now expects True
instead of "true"
for MFA_ENABLED
. This change aligns with the new casting functionality, but ensure this behavioral change is intentional and won't break downstream code that expects string values.
🏁 Script executed:
#!/bin/bash
# Description: Search for usages of MFA_ENABLED to verify impact of type change
# Search for MFA_ENABLED usage patterns
rg -A 3 -B 3 "MFA_ENABLED"
Length of output: 2238
Ensure consistent boolean conversion for MFA_ENABLED across modules.
Tests in tests/test_conf.py
now expect native booleans, but downstream code still treats MFA_ENABLED
as a string:
tests/test_modules/test_credentials.py
fixture uses"MFA_ENABLED": "true"
instead ofTrue
.leverage/container.py
doesself.env_conf.get("MFA_ENABLED", "false") == "true"
and has a# TODO: Convert values to bool upon loading
.leverage/modules/credentials.py
assignsconfig_values["mfa_enabled"]
directly from the raw string returned byenv_config.get("MFA_ENABLED", "false")
.
Please update these places to use the new casting logic (returning booleans) and adjust the corresponding tests to expect True
/False
.
🤖 Prompt for AI Agents
In tests/test_conf.py at line 33, the MFA_ENABLED value is changed to a boolean
True, but related code in tests/test_modules/test_credentials.py,
leverage/container.py, and leverage/modules/credentials.py still treat
MFA_ENABLED as a string. Update these files to consistently use boolean values
for MFA_ENABLED by applying the new casting logic that converts environment
variables to booleans, and modify their tests to expect True/False instead of
"true"/"false" strings.
Summary
Testing
pytest tests/test__parsing.py tests/test_conf.py tests/test_casting.py -q
pytest -q
https://chatgpt.com/codex/tasks/task_e_6841c005a738832fba0a8e5381fda35d
Summary by CodeRabbit