You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This syntax is preferred over Optional and Union in newer versions of Python.
This PR also replaces several type annotations from typing module with native types, and a few other modernizations.
🔄 Types of changes
Bug fix (backwards compatible)
Modernization
PR Type
Enhancement
Description
Replace Optional and Union with PEP 604 union syntax (|)
Move Callable import from typing to collections.abc
Replace typing.List with native list type annotation
Remove unused imports and clean up type hints across codebase
Diagram Walkthrough
flowchart LR
A["typing.Optional<br/>typing.Union"] -->|"Replace with"| B["PEP 604<br/>Union Syntax"]
C["typing.Callable"] -->|"Move to"| D["collections.abc"]
E["typing.List"] -->|"Replace with"| F["Native list"]
B --> G["Modernized<br/>Type Hints"]
D --> G
F --> G
Objective: To create a detailed and reliable record of critical system actions for security analysis and compliance.
Status: No new logging: The PR primarily updates type hints and signatures without introducing or modifying logging of critical actions, so it neither adds nor clearly omits required audit trails.
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful degradation
Status: Error context: Type hint refactors do not change behavior, but no additional edge-case handling or contextual error improvements were added alongside signature changes.
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive information like PII, PHI, or cardholder data.
Status: No logging change: The PR introduces no new logging and thus does not demonstrate adherence to structured, sensitive-data-safe logging in modified paths.
Referred Code
returnf"{host}:{port}"defis_connectable(port: int, host: str|None="localhost") ->bool:
"""Tries to connect to the server at port to see if it is running. Args: port: port number host: hostname or IP """socket_=Nonetry:
socket_=socket.create_connection((host, port), 1)
result=Trueexcept_is_connectable_exceptions:
result=Falsefinally:
ifsocket_:
try:
socket_.shutdown(socket.SHUT_RDWR)
exceptException:
... (clipped10lines)
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent vulnerabilities
Status: Validation unchanged: Changes are to type annotations and defaults (e.g., optional parameters) without added input validation or sanitization logic; security posture appears unchanged but not enhanced.
Referred Code
defset_geolocation_override(
self,
coordinates: GeolocationCoordinates|None=None,
error: GeolocationPositionError|None=None,
contexts: list[str] |None=None,
user_contexts: list[str] |None=None,
) ->None:
"""Set geolocation override for the given contexts or user contexts. Args: coordinates: Geolocation coordinates to emulate, or None. error: Geolocation error to emulate, or None. contexts: List of browsing context IDs to apply the override to. user_contexts: List of user context IDs to apply the override to. Raises: ValueError: If both coordinates and error are provided, or if both contexts and user_contexts are provided, or if neither contexts nor user_contexts are provided. """
... (clipped130lines)
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
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.
User description
🔗 Related Issues
#15697
💥 What does this PR do?
This PR improves Python type hints to use union types that are available in Python 3.10+:
This syntax is preferred over
OptionalandUnionin newer versions of Python.This PR also replaces several type annotations from
typingmodule with native types, and a few other modernizations.🔄 Types of changes
PR Type
Enhancement
Description
Replace
OptionalandUnionwith PEP 604 union syntax (|)Move
Callableimport fromtypingtocollections.abcReplace
typing.Listwith nativelisttype annotationRemove unused imports and clean up type hints across codebase
Diagram Walkthrough
File Walkthrough
20 files
Replace Optional/Union with PEP 604 syntaxModernize exception class type hintsUpdate WebDriver type hints to PEP 604Modernize RelativeBy class type hintsUpdate storage module type annotationsModernize emulation module type hintsUpdate input module with PEP 604 syntaxMove Callable import and modernize type hintsUpdate script module type annotationsModernize CDP generator type hintsUpdate ClientConfig type hintsModernize Firefox options type hintsUpdate authenticator type annotationsModernize action builder type hintsUpdate print options type hintsModernize pointer actions type hintsUpdate utility functions type hintsModernize Chromium options type hintsUpdate wheel input type annotationsModernize browser module type hints44 files