Skip to content

Commit

Permalink
squash! Bump mypy from 0.812 to 0.910 in /tools
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
gsnedders authored and foolip committed Mar 7, 2022
1 parent b727257 commit 6268ce9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 63 deletions.
34 changes: 16 additions & 18 deletions tools/manifest/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@
MYPY = False
if MYPY:
# MYPY is set to True when run under Mypy.
from typing import Optional
from typing import Text
from typing import Dict
from typing import Tuple
from typing import List
from typing import Union
from typing import Type
from typing import Any
from typing import Sequence
from typing import Hashable
from typing import Any, Dict, Hashable, List, Optional, Sequence, Text, Tuple, Type, Union, cast
from .manifest import Manifest
Fuzzy = Dict[Optional[Tuple[Text, Text, Text]], List[int]]
PageRanges = Dict[Text, List[int]]
Expand All @@ -31,14 +22,21 @@ class ManifestItemMeta(ABCMeta):
attribute, and otherwise behaves like an ABCMeta."""

def __new__(cls, name, bases, attrs):
# type: (Type[ManifestItemMeta], str, Tuple[ManifestItemMeta, ...], Dict[str, Any]) -> ManifestItemMeta
rv = super(ManifestItemMeta, cls).__new__(cls, name, bases, attrs)
if not isabstract(rv):
assert issubclass(rv, ManifestItem)
assert isinstance(rv.item_type, str)
item_types[rv.item_type] = rv

return rv # type: ignore
# type: (Type[ManifestItemMeta], str, Tuple[type], Dict[str, Any]) -> ManifestItemMeta
inst = super(ManifestItemMeta, cls).__new__(cls, name, bases, attrs)
if isabstract(inst):
return inst

assert issubclass(inst, ManifestItem)
if MYPY:
inst_ = cast(Type[ManifestItem], inst)
else:
inst_ = inst

assert isinstance(inst_.item_type, str)
item_types[inst_.item_type] = inst_

return inst_


class ManifestItem(metaclass=ManifestItemMeta):
Expand Down
8 changes: 4 additions & 4 deletions tools/manifest/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import platform
import subprocess
import sys

MYPY = False
if MYPY:
Expand Down Expand Up @@ -31,7 +31,7 @@ def rel_path_to_url(rel_path, url_base="/"):

def from_os_path(path):
# type: (Text) -> Text
assert os.path.sep == u"/" or platform.system() == "Windows"
assert os.path.sep == u"/" or sys.platform == "win32"
if u"/" == os.path.sep:
rv = path
else:
Expand All @@ -43,7 +43,7 @@ def from_os_path(path):

def to_os_path(path):
# type: (Text) -> Text
assert os.path.sep == u"/" or platform.system() == "Windows"
assert os.path.sep == u"/" or sys.platform == "win32"
if u"\\" in path:
raise ValueError("normalised path contains \\")
if u"/" == os.path.sep:
Expand All @@ -59,7 +59,7 @@ def gitfunc(cmd, *args):
try:
return subprocess.check_output(full_cmd, cwd=path, stderr=subprocess.STDOUT).decode('utf8')
except Exception as e:
if platform.uname()[0] == "Windows" and isinstance(e, WindowsError):
if sys.platform == "win32" and isinstance(e, WindowsError):
full_cmd[0] = u"git.bat"
return subprocess.check_output(full_cmd, cwd=path, stderr=subprocess.STDOUT).decode('utf8')
else:
Expand Down
2 changes: 2 additions & 0 deletions tools/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ warn_return_any = True
warn_unused_configs = True
warn_unused_ignores = True

show_error_codes = True

# Ignore missing or untyped libraries.

[mypy-github.*]
Expand Down
8 changes: 8 additions & 0 deletions tools/requirements_mypy.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
mypy==0.931
mypy-extensions==0.4.3
toml==0.10.2
typed-ast==1.4.3
types-atomicwrites==1.4.1
types-PyYAML==6.0.0
types-requests==2.25.11
types-setuptools==57.4.2
types-six==1.16.2
types-ujson==4.2.0
typing-extensions==3.10.0.2
54 changes: 13 additions & 41 deletions tools/tox.ini
Original file line number Diff line number Diff line change
@@ -1,52 +1,24 @@
[tox]
envlist = py36,py37,py38,py39,{py36,py37,py38,py39}-flake8,{py36,py37,py38,py39}-mypy
envlist = py36,py37,py38,py39,{py36,py37,py38,py39}-{flake8,mypy}
skipsdist=True
skip_missing_interpreters = False
skip_missing_interpreters=False

[testenv]
deps =
-r{toxinidir}/requirements_pytest.txt
-r{toxinidir}/requirements_tests.txt
!flake8-!mypy: -r{toxinidir}/requirements_pytest.txt
!flake8-!mypy: -r{toxinidir}/requirements_tests.txt
flake8: -r{toxinidir}/requirements_flake8.txt
mypy: -r{toxinidir}/requirements_mypy.txt

commands = pytest --cov=tools --cov-report=term {posargs}
changedir =
mypy: {toxinidir}/..

commands =
!flake8-!mypy: pytest --cov=tools --cov-report=term {posargs}
flake8: flake8 --append-config={toxinidir}/flake8.ini {posargs}
mypy: mypy --config-file={toxinidir}/mypy.ini tools/

passenv =
HYPOTHESIS_PROFILE
PY_COLORS
TASKCLUSTER_ROOT_URL

[testenv:py36-flake8]
deps = -rrequirements_flake8.txt
commands = flake8 --append-config={toxinidir}/flake8.ini {posargs}

[testenv:py37-flake8]
deps = -rrequirements_flake8.txt
commands = flake8 --append-config={toxinidir}/flake8.ini {posargs}

[testenv:py38-flake8]
deps = -rrequirements_flake8.txt
commands = flake8 --append-config={toxinidir}/flake8.ini {posargs}

[testenv:py39-flake8]
deps = -rrequirements_flake8.txt
commands = flake8 --append-config={toxinidir}/flake8.ini {posargs}

[testenv:py36-mypy]
deps = -rrequirements_mypy.txt
changedir = {toxinidir}/..
commands = mypy --config-file={toxinidir}/mypy.ini tools/

[testenv:py37-mypy]
deps = -rrequirements_mypy.txt
changedir = {toxinidir}/..
commands = mypy --config-file={toxinidir}/mypy.ini tools/

[testenv:py38-mypy]
deps = -rrequirements_mypy.txt
changedir = {toxinidir}/..
commands = mypy --config-file={toxinidir}/mypy.ini tools/

[testenv:py39-mypy]
deps = -rrequirements_mypy.txt
changedir = {toxinidir}/..
commands = mypy --config-file={toxinidir}/mypy.ini tools/

0 comments on commit 6268ce9

Please sign in to comment.