Skip to content

Commit a793b3a

Browse files
committed
[py]: document mypy config; add additional types and types dependencies
1 parent 3918220 commit a793b3a

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

py/mypy.ini

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
[mypy]
22
files = selenium
3-
ignore_missing_imports = False
3+
; warn about per-module sections in the config file that do not match any files processed.
44
warn_unused_configs = True
5+
; disallows subclassing of typing.Any.
56
disallow_subclassing_any = True
7+
; disallow usage of generic types that do not specify explicit type parameters.
68
disallow_any_generics = True
9+
; disallow calling functions without type annotations from functions that have type annotations.
710
disallow_untyped_calls = True
11+
; disallow defining functions without type annotations or with incomplete annotations.
812
disallow_untyped_defs = True
13+
; disallow defining functions with incomplete type annotations.
914
disallow_incomplete_defs = True
15+
; type-checks the interior of functions without type annotations.
1016
check_untyped_defs = True
17+
; reports an error whenever a function with type annotations is decorated with a decorator without annotations.
1118
disallow_untyped_decorators = True
19+
; changes the treatment of arguments with a default value of None by not implicitly making their type `typing.Optional`.
1220
no_implicit_optional = True
21+
; warns about casting an expression to it's inferred type.
1322
warn_redundant_casts = True
23+
; warns about unneeded `# type: ignore` comments.
1424
warn_unused_ignores = True
25+
; warns when returning a value with typing.Any from a function with a non typing.Any return type.
1526
warn_return_any = True
27+
; Shows a warning when encountering any code inferred to be unreachable after performing type analysis.
1628
warn_unreachable = True
29+
30+
[mypy-trio_websocket]
31+
; suppress error messages about imports that cannot be resolved.
32+
ignore_missing_imports = True
33+
34+
[mypy-_winreg]
35+
; suppress error messages about imports that cannot be resolved.
36+
ignore_missing_imports = True

py/selenium/webdriver/ie/service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
17+
import typing
1818
from typing import List
1919

2020
from selenium.webdriver.common import service
@@ -31,9 +31,9 @@ def __init__(
3131
self,
3232
executable_path: str = DEFAULT_EXECUTABLE_PATH,
3333
port: int = 0,
34-
host: str = None,
35-
log_level: str = None,
36-
log_file: str = None,
34+
host: typing.Optional[str] = None,
35+
log_level: typing.Optional[str] = None,
36+
log_file: typing.Optional[str] = None,
3737
):
3838
"""
3939
Creates a new instance of the Service

py/selenium/webdriver/support/expected_conditions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"""
3131

3232

33-
def title_is(title):
33+
def title_is(title: str):
3434
"""An expectation for checking the title of a page.
3535
title is the expected title, which must be an exact match
3636
returns True if the title matches, false otherwise."""
@@ -41,7 +41,7 @@ def _predicate(driver):
4141
return _predicate
4242

4343

44-
def title_contains(title):
44+
def title_contains(title: str):
4545
"""An expectation for checking that the title contains a case-sensitive
4646
substring. title is the fragment of title expected
4747
returns True when the title matches, False otherwise
@@ -66,7 +66,7 @@ def _predicate(driver):
6666
return _predicate
6767

6868

69-
def url_contains(url):
69+
def url_contains(url: str):
7070
"""An expectation for checking that the current url contains a
7171
case-sensitive substring.
7272
url is the fragment of url expected,
@@ -79,7 +79,7 @@ def _predicate(driver):
7979
return _predicate
8080

8181

82-
def url_matches(pattern):
82+
def url_matches(pattern: str):
8383
"""An expectation for checking the current url.
8484
pattern is the expected pattern, which must be an exact match
8585
returns True if the url matches, false otherwise."""
@@ -90,7 +90,7 @@ def _predicate(driver):
9090
return _predicate
9191

9292

93-
def url_to_be(url):
93+
def url_to_be(url: str):
9494
"""An expectation for checking the current url.
9595
url is the expected url, which must be an exact match
9696
returns True if the url matches, false otherwise."""
@@ -101,7 +101,7 @@ def _predicate(driver):
101101
return _predicate
102102

103103

104-
def url_changes(url):
104+
def url_changes(url: str):
105105
"""An expectation for checking the current url.
106106
url is the expected url, which must not be an exact match
107107
returns True if the url is different, false otherwise."""

py/selenium/webdriver/support/wait.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565
exceptions.append(ignored_exceptions)
6666
self._ignored_exceptions = tuple(exceptions)
6767

68-
def __repr__(self):
68+
def __repr__(self) -> str:
6969
return '<{0.__module__}.{0.__name__} (session="{1}")>'.format(type(self), self._driver.session_id)
7070

7171
def until(self, method, message: str = ""):

py/tox.ini

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ commands = sphinx-build -b html -d ../build/doctrees docs/source ../build/docs/a
1313
[testenv:mypy]
1414
skip_install = true
1515
deps =
16-
mypy
17-
lxml
18-
commands = mypy {posargs}
16+
mypy==0.982
17+
lxml==4.9.1
18+
types-urllib3==1.26.25
19+
types-certifi==2021.10.8.3
20+
trio-typing==0.7.0
21+
commands = mypy --install-types {posargs}
1922

2023

2124
[isort]

0 commit comments

Comments
 (0)