Skip to content
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

[py] Fix type hints and docstring #12067

Merged
merged 5 commits into from
May 28, 2023

Conversation

M1troll
Copy link
Contributor

@M1troll M1troll commented May 19, 2023

Hello!

Description

I found that get_attribute method in webelement in docstring says that method can return None, but type hint is only as a string. I ran into an unexpected error calling a string method on an NoneType-object.

I also saw that docstring in location_once_scrolled_into_view property of webelement contains an incorrect description of value returned when element is not visible.

Motivation and Context

This will help you avoid unexpected errors that may be caught by typecheckers (e.g. mypy).

Reproduce

You need install selenium and mypy:

pip install selenium mypy

Code example:

from selenium import webdriver
from selenium.webdriver.common.by import By

URL = "https://www.w3schools.com/css/tryit.asp?filename=trycss_display_none"

driver = webdriver.Chrome('/usr/sbin/chromedriver')
driver.get(URL)
driver.find_element(By.ID, "accept-choices").click()

hidden_element = driver.find_element(By.CLASS_NAME, "hidden")
hidden_element.get_attribute("class").strip()

Now if we run mypy . we won't see any errors:
image

But after fixing type hint, mypy will give us an error:
image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@CLAassistant
Copy link

CLAassistant commented May 19, 2023

CLA assistant check
All committers have signed the CLA.

@diemol
Copy link
Member

diemol commented May 19, 2023

I also saw that docstring in location_once_scrolled_into_view property of webelement contains an incorrect description of value returned when element is not visible.

Was this with Chrome and Firefox?

@M1troll
Copy link
Contributor Author

M1troll commented May 19, 2023

Yes, I checked it in Chrome and Firefox
If element is not visible method returns {"x": 0, "y": 0}, not None

Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @M1troll!

@codecov-commenter
Copy link

codecov-commenter commented May 19, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (f8b7a1d) 54.83% compared to head (d8a06ec) 54.83%.

❗ Current head d8a06ec differs from pull request most recent head 5f80221. Consider uploading reports for the commit 5f80221 to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #12067   +/-   ##
=======================================
  Coverage   54.83%   54.83%           
=======================================
  Files          86       86           
  Lines        5730     5730           
  Branches      233      233           
=======================================
  Hits         3142     3142           
  Misses       2355     2355           
  Partials      233      233           
Impacted Files Coverage Δ
py/selenium/webdriver/remote/webelement.py 35.59% <0.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@diemol
Copy link
Member

diemol commented May 19, 2023

Seems the linter is failing?

@M1troll
Copy link
Contributor Author

M1troll commented May 22, 2023

You're right, but locally all linters run successfully, strange..
Can we rerun this check?
image

@diemol
Copy link
Member

diemol commented May 22, 2023

Not sure what the difference is, but the command used is TOXENV=linting-check tox -c py/tox.ini

@M1troll
Copy link
Contributor Author

M1troll commented May 22, 2023

With this command everything passing too 🥲

image

@diemol
Copy link
Member

diemol commented May 22, 2023

I can see the same error, I started an environment in GitPod:

I also checked out the PR locally and got the same:

image

@M1troll M1troll force-pushed the fix-type-hints-and-docstring branch from a7cade1 to ebebacc Compare May 26, 2023 11:42
@M1troll
Copy link
Contributor Author

M1troll commented May 26, 2023

@diemol
It looks like I found reason for the fall of linters - docformatter moved part of docstring to line above.
Can you approval workflow to run actions?

@M1troll
Copy link
Contributor Author

M1troll commented May 27, 2023

@diemol
Linters have been passed 🎉

Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @M1troll!

@diemol diemol merged commit e92987a into SeleniumHQ:trunk May 28, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants