Conversation
- Replace custom type aliases from the `toolbox_python.collection_types` module with standard library types like `list[str]`, `Collection[Any]`, and `Dict[Any, Any]`. - Simplify `is_value_of_type()` and `assert_value_of_type()` function overloads by using `Collection[type]` to handle multiple input sequences. - Relocate the `log_levels` type literal to `output.py` module to better align with its usage in output formatting. - Add explicit `Callable` type hints to function aliases within the `checkers.py` module for improved type clarity. - Update the `Defaults()` class docstring to include a dedicated methods section documenting the `.get()` method. - Refactor the `flatten()` function and the `list_columns()` function to use standard collection types and remove redundant `@overload` definitions. - Improve type checking logic in the `checkers.py` module to handle generic collections of types more robustly.
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request standardizes type hints across the codebase by transitioning from custom type aliases (defined in collection_types.py) to standard Python typing constructs like Collection[Any], list[str], and dict[Any, Any]. The changes improve compatibility with modern static analysis tools and reduce internal coupling by eliminating numerous imports from the collection_types module.
Key changes include:
- Replacing custom type aliases with standard library types (
Collection,list,dict,Union,Literal) - Simplifying function overloads by consolidating type parameters
- Relocating the
log_levelsconstant fromcollection_types.pytooutput.py
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/toolbox_python/strings.py | Replaced str_list, str_list_tuple aliases with list[str] and Union[list[str], tuple[str, ...]] |
| src/toolbox_python/retry.py | Updated __all__ to list[str], added documentation for type variable and exception type alias |
| src/toolbox_python/output.py | Relocated log_levels constant, removed custom collection type imports, simplified list_columns by removing overloads |
| src/toolbox_python/lists.py | Changed return types from custom aliases to list[Any], refined input types to Collection[Collection[Any]] |
| src/toolbox_python/generators.py | Updated __all__ type hint from str_list to list[str] |
| src/toolbox_python/dictionaries.py | Replaced dict_any and dict_str_any with explicit dict[Any, Any] and dict[str, Any] |
| src/toolbox_python/defaults.py | Updated __all__ type hint, added Methods section to class docstring, changed internal list type |
| src/toolbox_python/collection_types.py | Removed log_levels constant (relocated to output.py) |
| src/toolbox_python/checkers.py | Simplified overloads by consolidating to Collection[type], updated all type hints from custom aliases to standard types, added explicit Callable annotations to function aliases |
| src/toolbox_python/bools.py | Updated __all__ type hint from str_list to list[str] |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When accessing and formatting the type in the error message. This line should be `msg += f"Must be '{check_type.__name__}'"` to be consistent with line 647 in `assert_value_of_type()` and to produce cleaner error messages that show just the type name (e.g., `'int'`) rather than the full type object representation (e.g., `<class 'int'>`).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 Overview
This pull request implements a comprehensive standardisation of type hints across the entire codebase, transitioning from custom type aliases to standard Python typing constructs. By leveraging
collections.abc.Collectionand explicit generic types likelist[str], the project achieves better compatibility with modern static analysis tools and improves overall code clarity. Additionally, this PR simplifies complex function overloads, relocates constants to more appropriate modules, and enhances documentation for core classes.🛠️ Type Hint and Import Standardisation
Transition to Standard Library Types
checkers.py: Replace customany_collectionandstr_collectionaliases withCollection[Any]andCollection[str]to align with standard Python protocolsbools.py: Updatestrtobool()to uselist[str]for internal truthy and falsy value trackingcollection_types.py: Remove redundant type aliases and relocate thelog_levelsliteral to theoutput.pymodule where it is primarily utiliseddefaults.py: Standardise the__all__export list and internal validation lists to use the nativelist[str]typedictionaries.py: Refactordict_reverse_keys_and_values()to use explicitdict[Any, Any]anddict[str, Any]type hintslists.py: Updateflatten()andflat_list()to return standardlist[Any]instead of custom list aliasesstrings.py: Replacestr_list_tuplewithUnion[list[str], tuple[str, ...]]in string membership functions for better transparencyDependency Cleanup
toolbox_python.collection_typesacross all modules, reducing internal coupling and simplifying the dependency graphCallable[..., bool]andCallable[..., None]type annotations to function aliases incheckers.pyto ensure they are correctly recognised by type checkers⚙️ Function Logic and Overload Simplification
Streamlined Type Checking
is_value_of_type(): Simplify the function signature by usingUnion[type, Collection[type]], allowing for a more robust handling of both single types and collections of typesis_all_values_of_type(): Reduce the number of@overloaddefinitions by consolidating input types intoCollection[Any]andCollection[type]assert_value_of_type(): Refactor assertion logic to match the simplified checking patterns, ensuring consistent behaviour across the validation suitecheck_typeto atupleby using a more directnot isinstance(check_type, type)check, which correctly handles all non-type iterablesEnhanced Output and List Utilities
list_columns(): Remove redundant@overloaddeclarations and useLiteral[True, False]for theprint_outputparameter to provide clearer intent to the callerflatten(): Refine the input type toCollection[Collection[Any]]to more accurately represent the expected nested structure and remove unnecessarytype: ignorecomments📖 Documentation and Metadata Improvements
Class and Method Documentation
Defaults(): Update the class docstring to include a dedicated "Methods" section, explicitly documenting the.get(),._validate_value_and_default(), and._validate_type()methodsretry(): Add descriptive docstrings for the_exceptionstype alias and theRTypeVarto improve maintainability of the retry logicModule Exports
__all__: Ensure all modules have their__all__lists correctly typed aslist[str]and include newly relocated constants likelog_levelsinoutput.py