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

Refactor helpers.py to Move Hard-Coded List to globals.py #5555

Closed
wants to merge 6 commits into from

Conversation

40gilad
Copy link

@40gilad 40gilad commented Aug 20, 2024

This pull request refactors the helpers.py file by moving a hard-coded list of false attributes to the globals.py file. The list, previously hard-coded in multiple locations, is now centralized in globals.py as a new global constant named _false_attributes.

Changes Made:

  • Added _false_attributes list to globals.py with the value ["0", "false", "no", "null", "none"].
  • Updated helpers.py to use the new _false_attributes variable from globals.py.

Benefits:

  • Improved Maintainability: Centralizing the list makes future updates easier and reduces duplication.
  • Enhanced Readability: Using a named constant improves code clarity and intention.

Testing:

  • Verified that the changes do not introduce any regressions or break existing functionality.
  • Please review the changes and let me know if any additional modifications are needed. Thank you!

@@ -49,3 +49,5 @@
session: SessionMixin = LocalProxy( # type: ignore[assignment]
_cv_request, "session", unbound_message=_no_req_msg
)

_false_attributes: t.List[str] = ["0", "false", "no", "null", "none"]
Copy link
Member

Choose a reason for hiding this comment

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

null and none do not make sense here, it's not something people would pass for a boolean option.

Also, this does not belong in this file. helpers.py is already he most suitable path.

But considering that it's already in two very simple utility functions, I'm not sure if it even makes much sense to extract this into a separate list (which, by the way, should be a set and not a list)

Copy link
Author

Choose a reason for hiding this comment

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

it makes better practice. its not hard coded and better to maintaine.
in addition, i aggree that none and null shouldnt be passed as boolean but you can use None as False in python (in a condition. " if None" is will evaluate to False.

@@ -49,3 +49,5 @@
session: SessionMixin = LocalProxy( # type: ignore[assignment]
_cv_request, "session", unbound_message=_no_req_msg
)

_false_attributes: list[str] = ["0", "false", "no", "null", "none"]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a unmarked behavior change, this list is more exhaustive,

This might create trouble for slightly sarcastic deployments

@davidism
Copy link
Member

I don't think this change is needed. In general, we do not accept style or refactoring PRs.

@davidism davidism closed this Aug 20, 2024
@40gilad 40gilad deleted the refactor_helpers branch August 20, 2024 15:18
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants