[py] Fix return type hint for alert_is_present#16975
[py] Fix return type hint for alert_is_present#16975cgoldberg merged 3 commits intoSeleniumHQ:trunkfrom
alert_is_present#16975Conversation
|
Thank you, @nemowang2003 for this code suggestion. The support packages contain example code that many users find helpful, but they do not necessarily represent After reviewing the change, unless it is a critical fix or a feature that is needed for Selenium We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks. |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||||||||||
PR Code Suggestions ✨No code suggestions found for the PR. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a type hint issue in the Python bindings' expected conditions module. The return type of alert_is_present() is changed from Alert | bool to Alert | Literal[False] to enable proper static type inference when used with WebDriverWait.until().
Changes:
- Updated the return type annotation for
alert_is_present()fromAlert | booltoAlert | Literal[False]
cgoldberg
left a comment
There was a problem hiding this comment.
Thanks... good catch.
I just updated your branch so the docstring matches the return type.
--------- Co-authored-by: Corey Goldberg <[email protected]>
--------- Co-authored-by: Corey Goldberg <[email protected]>
User description
[py] Fix return type hint for
alert_is_present🔗 Related Issues
💥 What does this PR do?
Updates the return type hint for
expected_conditions.alert_is_present.Previously,
alert_is_presentwas typed as returningAlert | bool.This union type prevented static type checkers from correctly inferring the return type asAlertwhen the method is successfully used insideWebDriverWait.until().🔧 Implementation Notes
💡 Additional Considerations
🔄 Types of changes
PR Type
Bug fix
Description
Fix return type hint for
alert_is_presentfromAlert | booltoAlert | Literal[False]Enables static type checkers to correctly infer
Alertreturn type inWebDriverWait.until()Improves type safety and IDE autocompletion for alert handling
Diagram Walkthrough
File Walkthrough
expected_conditions.py
Update alert_is_present return type annotationpy/selenium/webdriver/support/expected_conditions.py
alert_is_present()fromCallable[[WebDriver], Alert | bool]toCallable[[WebDriver], Alert |Literal[False]]Literal[False]instead ofgeneric
boolfor the failure caseAlertwhen used withWebDriverWait.until()