Run mypy from tox

This avoids the need to duplicate our dependency list in multiple
places and allows us to take advantage of tox's dependency management
infrastructure, to ensure we always get the latest and greatest version
of a package allowed by upper-constraints.

While here, we also update versions of other pre-commit hooks and
simplify the mypy configuration, aligning it with that of other typed
oslo projects.

Change-Id: I9ca3ec0d6f2de19f52f3d4c46fcbc43f9ed3a5b4
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane
2025-12-01 13:08:33 +00:00
parent 696c3d611e
commit 0fc5e2d0e6
6 changed files with 29 additions and 57 deletions

View File

@@ -13,27 +13,14 @@ repos:
- id: debug-statements
- id: check-yaml
files: .*\.(yaml|yml)$
- repo: https://opendev.org/openstack/hacking
rev: 7.0.0
hooks:
- id: hacking
additional_dependencies: []
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.0
rev: v0.14.8
hooks:
- id: ruff-check
args: ['--fix', '--unsafe-fixes']
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.17.1
- repo: https://opendev.org/openstack/hacking
rev: 8.0.0
hooks:
- id: mypy
additional_dependencies: [
'dogpile.cache>=1.5.0',
]
# keep this in-sync with '[tool.mypy] exclude' in 'pyproject.toml'
exclude: |
(?x)(
doc/.*
| releasenotes/.*
)
- id: hacking
additional_dependencies: []

View File

@@ -104,4 +104,4 @@ class PooledMemcachedBackend(memcached_backend.MemcachedBackend):
# lets us avoid need to hack it too much
@property
def client(self) -> ClientProxy:
return ClientProxy(self.client_pool) # type: ignore
return ClientProxy(self.client_pool)

View File

@@ -459,7 +459,7 @@ def _sha1_mangle_key(key: str | bytes) -> str:
except (UnicodeError, AttributeError):
# NOTE(stevemar): if encoding fails just continue anyway.
pass
return util.sha1_mangle_key(key) # type: ignore
return util.sha1_mangle_key(key)
def function_key_generator(
@@ -472,9 +472,7 @@ def function_key_generator(
category=DeprecationWarning,
stacklevel=2,
)
return util.function_key_generator( # type: ignore
namespace, fn, to_str=to_str
)
return util.function_key_generator(namespace, fn, to_str=to_str)
def kwarg_function_key_generator(
@@ -487,9 +485,7 @@ def kwarg_function_key_generator(
category=DeprecationWarning,
stacklevel=2,
)
return util.kwarg_function_key_generator( # type: ignore
namespace, fn, to_str=to_str
)
return util.kwarg_function_key_generator(namespace, fn, to_str=to_str)
def create_region(
@@ -545,7 +541,7 @@ def configure_cache_region(
# easier / less ugly.
config_dict = _build_cache_config(conf)
region.configure_from_config( # type: ignore[no-untyped-call]
region.configure_from_config(
config_dict, f'{conf.cache.config_prefix}.'
)
@@ -697,8 +693,7 @@ def get_memoization_decorator(
expiration_time = _get_expiration_time_fn(conf, expiration_group)
memoize = region.cache_on_arguments(
should_cache_fn=should_cache,
expiration_time=expiration_time, # type: ignore
should_cache_fn=should_cache, expiration_time=expiration_time
)
# Make sure the actual "should_cache" and "expiration_time" methods are

View File

@@ -13,6 +13,7 @@
import queue
import threading
import time
from typing import Any
from unittest import mock
import testtools
@@ -24,7 +25,7 @@ from oslo_cache import exception
from oslo_cache.tests import test_cache
class _TestConnectionPool(_memcache_pool.ConnectionPool):
class _TestConnectionPool(_memcache_pool.ConnectionPool[Any]):
destroyed_value = 'destroyed'
def _create_connection(self):

View File

@@ -74,35 +74,12 @@ ignore = [
python_version = "3.10"
show_column_numbers = true
show_error_context = true
strict = true
ignore_missing_imports = true
follow_imports = "normal"
check_untyped_defs = true
warn_unused_ignores = false
warn_return_any = true
warn_unused_configs = true
warn_redundant_casts = true
strict_equality = true
disallow_untyped_decorators = true
disallow_any_generics = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
no_implicit_reexport = true
extra_checks = true
# keep this in-sync with 'mypy.exclude' in '.pre-commit-config.yaml'
exclude = '''
(?x)(
doc
| releasenotes
)
'''
exclude = '(?x)(doc | releasenotes)'
[[tool.mypy.overrides]]
module = ["oslo_cache.tests.*"]
warn_return_any = false
disallow_untyped_decorators = false
disallow_any_generics = false
disallow_subclassing_any = false
disallow_untyped_calls = false
disallow_untyped_defs = false
disallow_subclassing_any = false

14
tox.ini
View File

@@ -21,11 +21,23 @@ commands =
pifpaf -e OSLO_CACHE_TEST run {env:PIFPAF_DAEMON} {env:PIFPAF_OPTS} -- stestr run --slowest
[testenv:pep8]
skip_install = true
description =
Run style checks.
deps =
pre-commit
{[testenv:mypy]deps}
commands =
pre-commit run -a
{[testenv:mypy]commands}
[testenv:mypy]
description =
Run type checks.
deps =
{[testenv]deps}
mypy
commands =
mypy --cache-dir="{envdir}/mypy_cache" {posargs:oslo_cache}
[testenv:venv]
commands = {posargs}