Cleaned up some code duplication and python version checks#18
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors Python version compatibility checks and reduces code duplication by introducing centralized utilities. The main focus is on cleaning up repeated version checks throughout the codebase and consolidating common functionality.
- Centralized Python 3.12+ version check in a dedicated compatibility module
- Added reusable
cleanup_escapesfunction to eliminate duplicate escape sequence handling - Removed numerous inline version checks in favor of the centralized constant
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| urlpath/_compat.py | New compatibility module with centralized Python version check |
| urlpath/_utils.py | Added cleanup_escapes function and updated all exports |
| urlpath/_url.py | Replaced sys.version_info checks with IS_PY312_PLUS constant |
| urlpath/_flavour.py | Updated version check and improved type checking compatibility |
| if not TYPE_CHECKING and not IS_PY312_PLUS: | ||
| from pathlib import _PosixFlavour | ||
| else: |
There was a problem hiding this comment.
[nitpick] The conditional import logic is complex and could be simplified. Consider using a try/except ImportError pattern which would be more readable and handle the import availability directly.
| if not TYPE_CHECKING and not IS_PY312_PLUS: | |
| from pathlib import _PosixFlavour | |
| else: | |
| try: | |
| from pathlib import _PosixFlavour | |
| except ImportError: |
| result = super().joinpath(*pathsegments) | ||
| return result # type: ignore[return-value] |
There was a problem hiding this comment.
The intermediate variable assignment is unnecessary. The code can be simplified to 'return super().joinpath(*pathsegments) # type: ignore[return-value]'.
| result = super().joinpath(*pathsegments) | |
| return result # type: ignore[return-value] | |
| return super().joinpath(*pathsegments) # type: ignore[return-value] |
No description provided.