-
Notifications
You must be signed in to change notification settings - Fork 167
refactor(all): modernize codebase with python 3.11 features #1812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
danceratopz
commented
Jun 27, 2025
felix314159
reviewed
Jun 27, 2025
felix314159
reviewed
Jun 27, 2025
Replace bound patterns with Python 3.11+ type for cleaner, more idiomatic type hints in method returns. Keeps for Generic classes that need type constraints. This improves type safety and reduces boilerplate code.
Replace manual string slicing patterns with Python 3.9+ removeprefix/removesuffix methods for cleaner, more readable code that explicitly shows intent to remove specific prefixes or suffixes.
Add slots to dataclasses that don't have class variable access conflicts. Optimizes memory usage and attribute access speed for Trie, Case, and TestInfo classes that are frequently instantiated during test execution.
Replace isinstance chains with Python 3.10+ match-case syntax for better readability and more idiomatic pattern matching in trie encoding functions.
Replace Enum classes with string values with Python 3.11+ StrEnum for better type safety, cleaner string conversion, and more explicit string enumeration semantics in test configuration and execution contexts.
Replace `Union[X, Y]` with `X | Y` syntax for cleaner type annotations. Applied to type aliases, function signatures, and complex type definitions for improved readability and reduced import dependencies. Python 3.10+ feature - more concise and intuitive union syntax.
Additional conversions of `Union[X, Y]` to `X < /dev/null | Y` in logging and test modules for consistent modern type annotation syntax.
- Add `safe_docker_exec` wrapper for Docker command construction - Implement `safe_solc_command` for compiler argument validation - Add `safe_t8n_args` for transition tool parameter security - Use `LiteralString` type hints to prevent command injection - Validate file paths, EVM versions, and numeric parameters
337e02e
to
6b24bcb
Compare
marioevz
approved these changes
Jun 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks!
I've added the coverage_missed
and rebased, so CI should pass now.
6b24bcb
to
62b8269
Compare
Remove safe_docker_exec and safe_docker_command functions that added verbosity without providing meaningful security validation. These wrappers were flagged in PR review as unnecessary noise. Revert to inline Docker command construction for better readability while preserving valuable security wrappers in other modules.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
scope:fw
Scope: Framework (evm|tools|forks|pytest)
scope:tests
Scope: Changes EL client test cases in `./tests`
type:refactor
Type: Refactor
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.
🗒️ Description
This PR modernizes the EEST codebase to leverage Python 3.11+ language features (and some neglected 3.10 features) for improved performance, readability, type safety, and security.
🔧 Python 3.11+ Specific Features
1. TypeVar → Self Pattern (7 instances)
Benefits: Eliminates boilerplate
TypeVar
declarations, improves type safety, and makes method signatures cleaner and more intuitive.Replace
TypeVar
bound patterns withSelf
type for cleaner method signatures:2. String removeprefix/removesuffix (6 instances)
Benefits: More readable and explicit about intent, slightly more performant (avoids
len()
calculations), and reduces potential off-by-one errors in manual slicing.Replace manual string slicing with explicit prefix/suffix removal:
3. dataclass slots=True Optimization (3 instances)
Benefits: Reduces memory footprint (up to 40% less memory per instance), faster attribute access, and prevents accidental dynamic attribute assignment.
Add memory-efficient slots to high-frequency dataclasses:
4. Enum → StrEnum (4 enum classes)
Benefits: Better type safety for string-based enums, cleaner string conversion without
.value
, and more explicit semantics for enums that represent string constants.Convert string-based enums for better type safety:
5. LiteralString for Security (3 critical areas)
Benefits: Prevents command injection vulnerabilities, enhances static analysis for security-sensitive code, and provides compile-time validation of subprocess arguments.
Secure subprocess command construction with LiteralString validation:
🔄 Other Modern Python Improvements Applied
isinstance → match-case (2 functions, Python 3.10+)
Benefits: More readable pattern matching, better performance for complex type checking, and enables exhaustiveness checking for better maintainability.
Convert type checking chains to pattern matching:
Union type syntax modernization (25+ instances, Python 3.10+)
Benefits: More concise and readable type annotations, reduced import dependencies, and more intuitive union syntax.
Convert Union types to modern pipe syntax:
📊 Summary Stats
🔗 Related Issues or PRs
Follow-up to:
✅ Checklist
tox
checks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:uvx --with=tox-uv tox -e lint,typecheck,spellcheck,markdownlint
type(scope):
.