-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[py] Addressing mypy type annotation errors #15928
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
base: trunk
Are you sure you want to change the base?
[py] Addressing mypy type annotation errors #15928
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
@bandophahita Thank you for the contribution! This looks good. Also, run the formatter - |
Why do we need this? What's wrong with accepting a sequence? |
Need is probably too strong of a term. It made sense to me to keep it a list since that's what Short answer; keeping the types simple prevents confusion. But in case that's an issue, I reverted the argument annotations. |
78d767c
to
926aafb
Compare
I still see a change from Sequence to list. Just leave them as a sequence unless there is a need to enforce a list. |
There are changes from Sequence to list but those are attributes. I reverted the argument annotations. |
I think I should explain the change. The problem was when referencing |
@bandophahita can you explain why we need the new class attributes? |
For sure. These are technically not NEW attributes but simply annotations for the class attributes. They dont do anything at runtime. Mypy reads them as the annotations instead of autodetecting/using what is set in the |
@@ -27,6 +27,8 @@ | |||
class WebDriver(ChromiumDriver): | |||
"""Controls the MSEdgeDriver and allows you to drive the browser.""" | |||
|
|||
service: Service |
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.
This class annotation lets mypy understand that the webdriver has an attribute service
that is an instance of Service
. The Optional[Service]
argument annotation caused mypy to believe the attribute webdriver.servce
could be None
, when in fact it never is. Mypy isn't smart enough to read the code that way.
@@ -35,6 +35,9 @@ class ChromiumService(service.Service): | |||
:param driver_path_env_key: (Optional) Environment variable to use to get the path to the driver executable. | |||
""" | |||
|
|||
_service_args: list[str] | |||
log_output: Union[None, IOBase, int, SubprocessStdAlias] |
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.
Annotation to let mypy know what log_output
attribute can be. Autodetermination wasn't smart enough to see past the argument annotation which was fine for the argument but incomplete for the attribute.
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.
There is a real possibility that the argument annotation is incomplete here too. I didn't address this. Someone more familiar with the log_output
argument should confirm it's annotation.
User description
🔗 Related Issues
addresses part of #15697
💥 What does this PR do?
Updates annotations and sets proper default objects.
🔧 Implementation Notes
💡 Additional Considerations
🔄 Types of changes
PR Type
Other
Description
Fix mypy type annotation errors across webdriver services
Change
Sequence[str]
tolist[str]
for service argumentsAdd explicit type annotations for class attributes
Update ChromiumDriver constructor parameter types
Changes walkthrough 📝
3 files
Update service_args type annotations to list[str]
Fix type annotations and add attribute declarations
Change service_args type from Sequence to list
4 files
Add explicit type annotations for options and service
Update constructor parameter types and imports
Add log_output type annotation declaration
Add explicit type annotations for attributes