[py] Fix type annotation error and raise clearer error message by Paresh-0007 · Pull Request #16174 · SeleniumHQ/selenium
Conversation
User description
🔗 Related Issues
Partially addresses #15697
💥 What does this PR do?
Fixes specific mypy type annotation errors in:
selenium/webdriver/common/virtual_authenticator.py- Now raises a KeyError if
rpIdis missing inCredential.from_dict, ensuringrp_idis always a string.
- Now raises a KeyError if
selenium/webdriver/remote/errorhandler.py- Added type checks before calling
.geton possibly-None values, so.getis only used on dictionaries.
- Added type checks before calling
🔧 Implementation Notes
- Used
isinstance(value, dict)before using.getto resolve mypy union-attr errors. - Updated
from_dictto requirerpIdand raise a clear error if missing, as discussed in project guidelines.
💡 Additional Considerations
- This is my first PR to Selenium—happy to make any changes or improvements!
- No new tests or docs needed as this is a type annotation/mypy error fix only.
- Will again work on same issue of got time from my college schedule but i'm feeling proud by contributing to this repo. Thanks !
🔄 Types of changes
- Cleanup (formatting, renaming)
PR Type
Other
Description
-
Fix mypy type annotation errors in virtual authenticator
-
Add type checks before dictionary operations in error handler
-
Ensure required
rpIdfield validation with clear error message
Diagram Walkthrough
flowchart LR
A["Type annotation errors"] --> B["Add type checks"]
B --> C["Fix virtual_authenticator.py"]
B --> D["Fix errorhandler.py"]
C --> E["Validate rpId field"]
D --> F["Check dict before .get()"]
File Walkthrough
| Relevant files | |||||
|---|---|---|---|---|---|
| Bug fix |
|
PR Reviewer Guide 🔍
Here are some key observations to aid the review process:
| ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪ |
| 🧪 No relevant tests |
| 🔒 No security concerns identified |
⚡ Recommended focus areas for reviewBackward Compatibility
rpId from optional to required and raising KeyError may break existing callers that relied on missing rpId. Verify callers and upstream data always include rpId, or consider a more descriptive exception type. |
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| Possible issue |
✅
| Medium |
Enforce rpId string typeValidate the type of py/selenium/webdriver/common/virtual_authenticator.py [183-185] if "rpId" not in data:
raise KeyError("Missing required field 'rpId' in credential data.")
-rp_id = data["rpId"]
+rp_id_raw = data["rpId"]
+if not isinstance(rp_id_raw, str):
+ raise TypeError("Field 'rpId' must be a string.")
+rp_id = rp_id_raw
Suggestion importance[1-10]: 6__ Why: The suggestion correctly identifies that | Low | |
| ||
@olleolleolle hello sir
its my first contribution in selenium , please ignore any mistakes if found and also let me know if u have any feedback on me.
cgoldberg
changed the title
Fix type annotation errors in virtual_authenticator.py and errorhandl…
[py] Fix type annotation error and raise clearer error message
Type Annotation Improvements
@cgoldberg @navin772, I have incorporated the changes as you have said
@Paresh-0007 Yes, you can run ./scripts/format.sh, it will run the linter.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This was referenced
Oct 2, 2025This was referenced
Oct 27, 2025This was referenced
Dec 9, 2025This was referenced
Dec 16, 2025This was referenced
Jan 19, 2026This was referenced
Feb 16, 2026This was referenced
Feb 23, 2026This 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