-
Notifications
You must be signed in to change notification settings - Fork 235
Open
Labels
discussionsNeed more discussion before taking further actionsNeed more discussion before taking further actions
Description
Motivation
In PyGMT, most parameters default to False (for boolean-only parameters) or None (for non-boolean parameters), which means the parameters are not given and should not be used in building the CLI option string. We usually need to check if a parameter is given, like below
if value is not False: # For boolean-only parameters
...
if value is not None: # For non-boolean parameters
...
if value is not None and value is not False: # A more general check
...This repetitive pattern:
- Reduces code readability
- Makes maintenance harder [Sometimes we may incorrectly use
if value is not Nonewhenvalueis a boolean type] - Makes the intent less clear to new contributors
Solution
Introduced a new is_given() helper function to simplify parameter validation across PyGMT and refactored existing code to use it consistently.
def is_given(value: Any) -> bool:
return value is not None and value is not FalseThen we should
- replace
x is not None/x is not False/x is not None and x is not Falsewithis_given(x). - replace
x is None or x is Falsetonot is_given(x)
This is just an internal change and doesn't break any existing behavior.
Comments?
Metadata
Metadata
Assignees
Labels
discussionsNeed more discussion before taking further actionsNeed more discussion before taking further actions