Add overloads to 'wrap_text' for better type hinting
Explanation of changes
Adds the following overloads to base_analysis.wrap_text
:
@overload
def wrap_text(
text: str, width: int = 35, replace_whitespace: bool = True, **kwargs
) -> str: ...
@overload
def wrap_text(
text: None, width: int = 35, replace_whitespace: bool = True, **kwargs
) -> None: ...
I've also taken the liberty of adding type hints for the other arguments, while I was at it.
Motivation of changes
At OrangeQS, we use this function quite extensively in our analyses. However, it has been giving us issues with our type checker, since the returned message can be None
(which is not accepted by subsequent parts of our code). This MR fixes this by overloading the function with multiple signatures.
I'm only tackling a single function in this MR. I can imagine this being part of a larger rewrite of many functions (lots of functions in base_analysis
have either poor or nonexistent typechecking). If this cannot get merged pending such a larger rewrite, feel free to close this MR again - we'll keep on using ignore statements for our type checking issues until then. If mini-MRs like this one are okay, I might open a sporadic MR here and there in the future with similar fixes.
Merge checklist
See also merge request guidelines
-
Merge request has been reviewed (in-depth by a knowledgeable contributor), and is approved by a project maintainer. -
New code is covered by unit tests (or N/A). -
New code is documented and docstrings use numpydoc format (or N/A). -
New functionality: considered making private instead of extending public API (or N/A). -
Public API changed: added @deprecated
(or N/A). -
Newly added/adjusted documentation and docstrings render properly (or N/A). -
Pipeline fix or dependency update: post in #software-for-developers
channel to mergemain
back in or update local packages (or N/A). -
Tested on hardware (or N/A). -
CHANGELOG.md
andAUTHORS.md
have been updated (or N/A). -
Windows tests in CI pipeline pass (manually triggered by maintainers before merging). - Maintainers do not hit Auto-merge, we need to actively check as manual tests do not block pipeline
For reference, the issues workflow is described in the contribution guidelines.