Add mypy tox env
Add a "mypy" tox environment which runs mypy type checking against Cinder code. Taken from Stephen Finucane's Nova work at https://review.opendev.org/#/c/676208/ Added "show_error_codes" and "pretty" options. Generates an html report in ./mypy-report/ This adds stubs for oslo.i18n, so that _() calls are annotated as intended. It may be possible to do this with less .pyi files carried along here. Change-Id: I2589d22c1f16f2e177d34730a520591743c0c1e3
This commit is contained in:
parent
2ce35aa94b
commit
6e53c264b6
1
.gitignore
vendored
1
.gitignore
vendored
@ -27,6 +27,7 @@ instances
|
||||
keeper
|
||||
keys
|
||||
local_settings.py
|
||||
mypy-report
|
||||
tools/lintstack.head.py
|
||||
tools/pylint_exceptions
|
||||
tags
|
||||
|
8
cinder/tests/stubs/oslo_i18n/__init__.pyi
Normal file
8
cinder/tests/stubs/oslo_i18n/__init__.pyi
Normal file
@ -0,0 +1,8 @@
|
||||
# Stubs for oslo_i18n (Python 3)
|
||||
#
|
||||
# NOTE: This dynamically typed stub was automatically generated by stubgen.
|
||||
|
||||
from ._factory import *
|
||||
from ._gettextutils import *
|
||||
from ._lazy import *
|
||||
from ._translate import *
|
24
cinder/tests/stubs/oslo_i18n/_factory.pyi
Normal file
24
cinder/tests/stubs/oslo_i18n/_factory.pyi
Normal file
@ -0,0 +1,24 @@
|
||||
# Stubs for oslo_i18n._factory (Python 3)
|
||||
#
|
||||
# NOTE: This dynamically typed stub was automatically generated by stubgen.
|
||||
|
||||
from typing import Any, Optional
|
||||
|
||||
class TranslatorFactory:
|
||||
domain: Any = ...
|
||||
localedir: Any = ...
|
||||
def __init__(self, domain: Any, localedir: Optional[Any] = ...) -> None: ...
|
||||
@property
|
||||
def primary(self) -> ty.Callable[str]: ...
|
||||
@property
|
||||
def contextual_form(self): ...
|
||||
@property
|
||||
def plural_form(self): ...
|
||||
@property
|
||||
def log_info(self): ...
|
||||
@property
|
||||
def log_warning(self): ...
|
||||
@property
|
||||
def log_error(self): ...
|
||||
@property
|
||||
def log_critical(self): ...
|
8
cinder/tests/stubs/oslo_i18n/_gettextutils.pyi
Normal file
8
cinder/tests/stubs/oslo_i18n/_gettextutils.pyi
Normal file
@ -0,0 +1,8 @@
|
||||
# Stubs for oslo_i18n._gettextutils (Python 3)
|
||||
#
|
||||
# NOTE: This dynamically typed stub was automatically generated by stubgen.
|
||||
|
||||
from typing import Any
|
||||
|
||||
def install(domain: Any) -> None: ...
|
||||
def get_available_languages(domain: Any): ...
|
4
cinder/tests/stubs/oslo_i18n/_i18n.pyi
Normal file
4
cinder/tests/stubs/oslo_i18n/_i18n.pyi
Normal file
@ -0,0 +1,4 @@
|
||||
# Stubs for oslo_i18n._i18n (Python 3)
|
||||
#
|
||||
# NOTE: This dynamically typed stub was automatically generated by stubgen.
|
||||
|
5
cinder/tests/stubs/oslo_i18n/_lazy.pyi
Normal file
5
cinder/tests/stubs/oslo_i18n/_lazy.pyi
Normal file
@ -0,0 +1,5 @@
|
||||
# Stubs for oslo_i18n._lazy (Python 3)
|
||||
#
|
||||
# NOTE: This dynamically typed stub was automatically generated by stubgen.
|
||||
|
||||
def enable_lazy(enable: bool = ...) -> None: ...
|
7
cinder/tests/stubs/oslo_i18n/_locale.pyi
Normal file
7
cinder/tests/stubs/oslo_i18n/_locale.pyi
Normal file
@ -0,0 +1,7 @@
|
||||
# Stubs for oslo_i18n._locale (Python 3)
|
||||
#
|
||||
# NOTE: This dynamically typed stub was automatically generated by stubgen.
|
||||
|
||||
from typing import Any
|
||||
|
||||
def get_locale_dir_variable_name(domain: Any): ...
|
16
cinder/tests/stubs/oslo_i18n/_message.pyi
Normal file
16
cinder/tests/stubs/oslo_i18n/_message.pyi
Normal file
@ -0,0 +1,16 @@
|
||||
# Stubs for oslo_i18n._message (Python 3)
|
||||
#
|
||||
# NOTE: This dynamically typed stub was automatically generated by stubgen.
|
||||
|
||||
import six
|
||||
from typing import Any, Optional
|
||||
|
||||
CONTEXT_SEPARATOR: str
|
||||
LOG: Any
|
||||
|
||||
class Message(six.text_type):
|
||||
def __new__(cls, msgid: Any, msgtext: Optional[Any] = ..., params: Optional[Any] = ..., domain: str = ..., has_contextual_form: bool = ..., has_plural_form: bool = ..., *args: Any): ...
|
||||
def translation(self, desired_locale: Optional[Any] = ...): ...
|
||||
def __mod__(self, other: Any): ...
|
||||
def __add__(self, other: Any) -> None: ...
|
||||
def __radd__(self, other: Any): ...
|
7
cinder/tests/stubs/oslo_i18n/_translate.pyi
Normal file
7
cinder/tests/stubs/oslo_i18n/_translate.pyi
Normal file
@ -0,0 +1,7 @@
|
||||
# Stubs for oslo_i18n._translate (Python 3)
|
||||
#
|
||||
# NOTE: This dynamically typed stub was automatically generated by stubgen.
|
||||
|
||||
from typing import Any, Optional
|
||||
|
||||
def translate(obj: Any, desired_locale: Optional[Any] = ...): ...
|
29
cinder/tests/stubs/oslo_i18n/fixture.pyi
Normal file
29
cinder/tests/stubs/oslo_i18n/fixture.pyi
Normal file
@ -0,0 +1,29 @@
|
||||
# Stubs for oslo_i18n.fixture (Python 3)
|
||||
#
|
||||
# NOTE: This dynamically typed stub was automatically generated by stubgen.
|
||||
|
||||
import fixtures
|
||||
import gettext
|
||||
from typing import Any, Optional
|
||||
|
||||
class Translation(fixtures.Fixture):
|
||||
domain: Any = ...
|
||||
def __init__(self, domain: str = ...) -> None: ...
|
||||
def lazy(self, msg: Any): ...
|
||||
def immediate(self, msg: Any): ...
|
||||
|
||||
class ToggleLazy(fixtures.Fixture):
|
||||
def __init__(self, enabled: Any) -> None: ...
|
||||
def setUp(self) -> None: ...
|
||||
|
||||
class _PrefixTranslator(gettext.NullTranslations):
|
||||
prefix: Any = ...
|
||||
def __init__(self, fp: Optional[Any] = ..., prefix: str = ...) -> None: ...
|
||||
def gettext(self, message: Any): ...
|
||||
def ugettext(self, message: Any): ...
|
||||
|
||||
class PrefixLazyTranslation(fixtures.Fixture):
|
||||
languages: Any = ...
|
||||
locale: Any = ...
|
||||
def __init__(self, languages: Optional[Any] = ..., locale: Optional[Any] = ...) -> None: ...
|
||||
def setUp(self): ...
|
12
cinder/tests/stubs/oslo_i18n/log.pyi
Normal file
12
cinder/tests/stubs/oslo_i18n/log.pyi
Normal file
@ -0,0 +1,12 @@
|
||||
# Stubs for oslo_i18n.log (Python 3)
|
||||
#
|
||||
# NOTE: This dynamically typed stub was automatically generated by stubgen.
|
||||
|
||||
from logging import handlers
|
||||
from typing import Any, Optional
|
||||
|
||||
class TranslationHandler(handlers.MemoryHandler):
|
||||
locale: Any = ...
|
||||
def __init__(self, locale: Optional[Any] = ..., target: Optional[Any] = ...) -> None: ...
|
||||
def setFormatter(self, fmt: Any) -> None: ...
|
||||
def emit(self, record: Any) -> None: ...
|
@ -52,6 +52,7 @@ Mako==1.0.7
|
||||
MarkupSafe==1.1.0
|
||||
mock==2.0.0
|
||||
msgpack==0.5.6
|
||||
mypy==0.761
|
||||
netaddr==0.7.19
|
||||
netifaces==0.10.7
|
||||
networkx==2.1.0
|
||||
|
3
mypy-files.txt
Normal file
3
mypy-files.txt
Normal file
@ -0,0 +1,3 @@
|
||||
cinder/i18n.py
|
||||
cinder/manager.py
|
||||
cinder/volume/__init__.py
|
12
setup.cfg
12
setup.cfg
@ -117,3 +117,15 @@ storpool =
|
||||
datera =
|
||||
dfs-sdk>=1.2.25 # Apache-2.0
|
||||
|
||||
|
||||
[mypy]
|
||||
show_column_numbers = true
|
||||
show_error_context = true
|
||||
ignore_missing_imports = true
|
||||
follow_imports = skip
|
||||
incremental = true
|
||||
check_untyped_defs = true
|
||||
warn_unused_ignores = true
|
||||
show_error_codes = true
|
||||
pretty = true
|
||||
html_report = mypy-report
|
||||
|
@ -23,3 +23,5 @@ bandit==1.6.0 # Apache-2.0
|
||||
doc8>=0.6.0 # Apache-2.0
|
||||
reno>=3.1.0 # Apache-2.0
|
||||
Pygments>=2.2.0 # BSD license
|
||||
|
||||
mypy>=0.761 # MIT
|
||||
|
24
tools/mypywrap.sh
Normal file
24
tools/mypywrap.sh
Normal file
@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# A wrapper around mypy that allows us to specify what files to run 'mypy' type
|
||||
# checks on. Intended to be invoked via tox:
|
||||
#
|
||||
# tox -e mypy
|
||||
#
|
||||
# Eventually this should go away once we have either converted everything or
|
||||
# converted enough and ignored [1] the rest.
|
||||
#
|
||||
# [1] http://mypy.readthedocs.io/en/latest/config_file.html#per-module-flags
|
||||
|
||||
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
export MYPYPATH=$ROOT_DIR/../cinder/tests/stubs/
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
# if no arguments provided, use the standard converted lists
|
||||
lines=$(grep -v '#' $ROOT_DIR/../mypy-files.txt)
|
||||
python -m mypy ${lines[@]}
|
||||
else
|
||||
# else test what the user asked us to
|
||||
python -m mypy $@
|
||||
fi
|
Loading…
Reference in New Issue
Block a user