Skip to content

refactor: modernize utils.py with type hints and remove legacy Py2 code#551

Open
ayushshukla1807 wants to merge 1 commit into
hatnote:masterfrom
ayushshukla1807:refactor/modernize-utils-typing
Open

refactor: modernize utils.py with type hints and remove legacy Py2 code#551
ayushshukla1807 wants to merge 1 commit into
hatnote:masterfrom
ayushshukla1807:refactor/modernize-utils-typing

Conversation

@ayushshukla1807
Copy link
Copy Markdown

This PR modernizes the utils.py module to align with modern Python 3 standards (Python 3.9+ syntax).

Changes:

  • Added comprehensive type hints across all functions using from __future__ import annotations.
  • Replaced legacy six and urllib imports with standard Python 3 equivalents.
  • Removed Python 2 compatibility boilerplate (unicode, basestring checks).
  • Standardised function signatures and return types for better IDE support and static analysis.

This refactor reduces technical debt and prepares the utility layer for future enhancements.

@lgelauff
Copy link
Copy Markdown
Collaborator

lgelauff commented May 2, 2026

i see no downsides. possible odd one out is encode_value_to_bytes when it would deal with non-strings

@ayushshukla1807
Copy link
Copy Markdown
Author

For encode_value_to_bytes, it's a safety catch for cases where the input might be an integer or a non-string object that needs to be normalized before processing. Python 3 is much less forgiving than Py2 about implicit conversions, so I'd rather have the check there than a crash in production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants