-
Notifications
You must be signed in to change notification settings - Fork 169
Refactor argument handling: simplify logic by using arg_len variable #915
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: main
Are you sure you want to change the base?
Conversation
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.
Thanks @kaz2700 !
I made a couple of minor suggestions, otherwise the code looks good.
You will need to add a changelog in towncrier
format, as specified in the developer instructions , and make sure the formatting is right, by running black
on the code, as described in the formatting guide
elif len(args) == 2: | ||
elif arg_len == 2: | ||
if utils.is_string(args[0]): | ||
return self._simulate_model_string(args[0], args[1]) |
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.
return self._simulate_model_string(args[0], args[1]) | |
return self._simulate_model_string(*args) |
elif arg_len == 2: | ||
if utils.is_string(args[0]): | ||
return self._simulate_model_string(args[0], args[1]) | ||
|
||
return self._simulate_impulse_response(args[0], args[1]) |
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.
return self._simulate_impulse_response(args[0], args[1]) | |
return self._simulate_impulse_response(*args) |
return self._simulate_impulse_response(args[0], args[1]) | ||
|
||
elif len(args) == 3: | ||
elif arg_len == 3: | ||
return self._simulate_impulse_response(args[0], args[1], args[2]) |
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.
return self._simulate_impulse_response(args[0], args[1], args[2]) | |
return self._simulate_impulse_response(*args) |
Provide an overview of the implemented solution or the fix and elaborate on the modifications.
Refactored the argument handling logic in the simulation code. Introduced a variable
arg_len
to simplify the checks on the length ofargs
and reduce redundancy. The new structure first checks the length ofargs
and branches accordingly to call the appropriate simulation methods (_simulate_power_law
,_simulate_model
,_simulate_model_string
,_simulate_power_spectrum
, or_simulate_impulse_response
) based on the type and number of arguments passed.Is there a new dependency introduced by your contribution? If so, please specify.
No new dependencies have been introduced.
Any other comments?
This refactor improves the readability and maintainability of the code.