Skip to content

Commit 264e1c8

Browse files
committed
squash! Bump mypy from 0.812 to 0.910 in /tools
This: * Deals with changes in how mypy handles metaclasses * Prefers sys.platform == "win32" due to python/mypy#8166 and mypy not having WindowsError defined by default any more * Installs various typestubs * Rewrites tox.ini to avoid duplicating everything, and allowing new versions of Python to be easily tested (as tox -e py310-mypy will now work without further changes).
1 parent 73860f4 commit 264e1c8

5 files changed

Lines changed: 43 additions & 63 deletions

File tree

‎tools/manifest/item.py‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,7 @@
88
MYPY = False
99
if MYPY:
1010
# MYPY is set to True when run under Mypy.
11-
from typing import Optional
12-
from typing import Text
13-
from typing import Dict
14-
from typing import Tuple
15-
from typing import List
16-
from typing import Union
17-
from typing import Type
18-
from typing import Any
19-
from typing import Sequence
20-
from typing import Hashable
11+
from typing import Any, Dict, Hashable, List, Optional, Sequence, Text, Tuple, Type, Union, cast
2112
from .manifest import Manifest
2213
Fuzzy = Dict[Optional[Tuple[Text, Text, Text]], List[int]]
2314
PageRanges = Dict[Text, List[int]]
@@ -31,14 +22,21 @@ class ManifestItemMeta(ABCMeta):
3122
attribute, and otherwise behaves like an ABCMeta."""
3223

3324
def __new__(cls, name, bases, attrs):
34-
# type: (Type[ManifestItemMeta], str, Tuple[ManifestItemMeta, ...], Dict[str, Any]) -> ManifestItemMeta
35-
rv = super(ManifestItemMeta, cls).__new__(cls, name, bases, attrs)
36-
if not isabstract(rv):
37-
assert issubclass(rv, ManifestItem)
38-
assert isinstance(rv.item_type, str)
39-
item_types[rv.item_type] = rv
40-
41-
return rv # type: ignore
25+
# type: (Type[ManifestItemMeta], str, Tuple[type], Dict[str, Any]) -> ManifestItemMeta
26+
inst = super(ManifestItemMeta, cls).__new__(cls, name, bases, attrs)
27+
if isabstract(inst):
28+
return inst
29+
30+
assert issubclass(inst, ManifestItem)
31+
if MYPY:
32+
inst_ = cast(Type[ManifestItem], inst)
33+
else:
34+
inst_ = inst
35+
36+
assert isinstance(inst_.item_type, str)
37+
item_types[inst_.item_type] = inst_
38+
39+
return inst_
4240

4341

4442
class ManifestItem(metaclass=ManifestItemMeta):

‎tools/manifest/utils.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
2-
import platform
32
import subprocess
3+
import sys
44

55
MYPY = False
66
if MYPY:
@@ -31,7 +31,7 @@ def rel_path_to_url(rel_path, url_base="/"):
3131

3232
def from_os_path(path):
3333
# type: (Text) -> Text
34-
assert os.path.sep == u"/" or platform.system() == "Windows"
34+
assert os.path.sep == u"/" or sys.platform == "win32"
3535
if u"/" == os.path.sep:
3636
rv = path
3737
else:
@@ -43,7 +43,7 @@ def from_os_path(path):
4343

4444
def to_os_path(path):
4545
# type: (Text) -> Text
46-
assert os.path.sep == u"/" or platform.system() == "Windows"
46+
assert os.path.sep == u"/" or sys.platform == "win32"
4747
if u"\\" in path:
4848
raise ValueError("normalised path contains \\")
4949
if u"/" == os.path.sep:
@@ -59,7 +59,7 @@ def gitfunc(cmd, *args):
5959
try:
6060
return subprocess.check_output(full_cmd, cwd=path, stderr=subprocess.STDOUT).decode('utf8')
6161
except Exception as e:
62-
if platform.uname()[0] == "Windows" and isinstance(e, WindowsError):
62+
if sys.platform == "win32" and isinstance(e, WindowsError):
6363
full_cmd[0] = u"git.bat"
6464
return subprocess.check_output(full_cmd, cwd=path, stderr=subprocess.STDOUT).decode('utf8')
6565
else:

‎tools/mypy.ini‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ warn_return_any = True
2222
warn_unused_configs = True
2323
warn_unused_ignores = True
2424

25+
show_error_codes = True
26+
2527
# Ignore missing or untyped libraries.
2628

2729
[mypy-github.*]

‎tools/requirements_mypy.txt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
mypy==0.910
22
mypy-extensions==0.4.3
3+
toml==0.10.2
34
typed-ast==1.4.3
5+
types-atomicwrites==1.4.1
6+
types-PyYAML==6.0.0
7+
types-requests==2.25.11
8+
types-setuptools==57.4.2
9+
types-six==1.16.2
10+
types-ujson==4.2.0
11+
typing-extensions==3.10.0.2

‎tools/tox.ini‎

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,24 @@
11
[tox]
2-
envlist = py36,py37,py38,py39,{py36,py37,py38,py39}-flake8,{py36,py37,py38,py39}-mypy
2+
envlist = py36,py37,py38,py39,{py36,py37,py38,py39}-{flake8,mypy}
33
skipsdist=True
4-
skip_missing_interpreters = False
4+
skip_missing_interpreters=False
55

66
[testenv]
77
deps =
8-
-r{toxinidir}/requirements_pytest.txt
9-
-r{toxinidir}/requirements_tests.txt
8+
!flake8-!mypy: -r{toxinidir}/requirements_pytest.txt
9+
!flake8-!mypy: -r{toxinidir}/requirements_tests.txt
10+
flake8: -r{toxinidir}/requirements_flake8.txt
11+
mypy: -r{toxinidir}/requirements_mypy.txt
1012

11-
commands = pytest --cov=tools --cov-report=term {posargs}
13+
changedir =
14+
mypy: {toxinidir}/..
15+
16+
commands =
17+
!flake8-!mypy: pytest --cov=tools --cov-report=term {posargs}
18+
flake8: flake8 --append-config={toxinidir}/flake8.ini {posargs}
19+
mypy: mypy --config-file={toxinidir}/mypy.ini tools/
1220

1321
passenv =
1422
HYPOTHESIS_PROFILE
1523
PY_COLORS
1624
TASKCLUSTER_ROOT_URL
17-
18-
[testenv:py36-flake8]
19-
deps = -rrequirements_flake8.txt
20-
commands = flake8 --append-config={toxinidir}/flake8.ini {posargs}
21-
22-
[testenv:py37-flake8]
23-
deps = -rrequirements_flake8.txt
24-
commands = flake8 --append-config={toxinidir}/flake8.ini {posargs}
25-
26-
[testenv:py38-flake8]
27-
deps = -rrequirements_flake8.txt
28-
commands = flake8 --append-config={toxinidir}/flake8.ini {posargs}
29-
30-
[testenv:py39-flake8]
31-
deps = -rrequirements_flake8.txt
32-
commands = flake8 --append-config={toxinidir}/flake8.ini {posargs}
33-
34-
[testenv:py36-mypy]
35-
deps = -rrequirements_mypy.txt
36-
changedir = {toxinidir}/..
37-
commands = mypy --config-file={toxinidir}/mypy.ini tools/
38-
39-
[testenv:py37-mypy]
40-
deps = -rrequirements_mypy.txt
41-
changedir = {toxinidir}/..
42-
commands = mypy --config-file={toxinidir}/mypy.ini tools/
43-
44-
[testenv:py38-mypy]
45-
deps = -rrequirements_mypy.txt
46-
changedir = {toxinidir}/..
47-
commands = mypy --config-file={toxinidir}/mypy.ini tools/
48-
49-
[testenv:py39-mypy]
50-
deps = -rrequirements_mypy.txt
51-
changedir = {toxinidir}/..
52-
commands = mypy --config-file={toxinidir}/mypy.ini tools/

0 commit comments

Comments
 (0)