[py] raise typed WebDriver errors for BiDi wire error codes - #17952
[py] raise typed WebDriver errors for BiDi wire error codes#17952titusfortner wants to merge 2 commits into
Conversation
PR Summary by QodoRaise typed WebDriver exceptions for BiDi wire errors
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo
1.
|
|
@cgoldberg & @AutomatedTester & @navin772 can you help make sure this is the right way to do things for Python.
But, this split wasn't quite as clean as what I did for Ruby. |
🔗 Related Issues
Python counterpart of #17855, which did this for Ruby.
💥 What does this PR do?
Note that this is for the BiDi implementation generated from the schema not the code currently in use off the driver.
WebDriverException: codes the classic error handler already types keep that class, and BiDi-only codes get their own.except NoSuchElementExceptioncatches a BiDi failure and a classic one alike.🔧 Implementation Notes
ErrorCodeenum as real class statements, so they type-check, autocomplete and document like every other exception in the bindings.errorhandler's ownErrorCode/ExceptionMappingtables at generation time rather than keeping a second copy, so a class the handler retypes later follows on the next build — this is why the generator now depends on:remote.WebDriverException(unknown error,unsupported operation) get a declared subclass instead: strictly more specific, still caught by anyone catching the base.🤖 AI assistance
💡 Additional Considerations
type()behind a module__getattr__, which is what the first pass did — mypy resolves any name off such a module, so a misspelled exception name imports clean and every class narrows only totype[WebDriverException], and the classes never reach Sphinx autodoc ordir(). It also let the generated table and the runtime surface disagree:NoSuchAlertExceptionandUnableToCaptureScreenExceptionwere listed but raisedAttributeError, because those two codes resolve toNoAlertPresentExceptionandScreenshotException.selenium/common/exceptions.py— they would be public and could carry real docstrings and a hierarchy, but the list drifts from the schema on every spec bump and needs a coverage test to stay honest..pyistub next to the minted classes — cannot be made correct from the schema alone: a stub built from the name table would declare the two classes above, which do not exist, and would type the ten shared codes as distinct from their classic counterparts, breakingexceptmatching.errorhandlereither way, so the separation is organizational rather than real.🔄 Types of changes