mypy: Enable strict mode

This is the same as what we were doing.

Change-Id: Id7061bf410931001eaa8a2eb4a242fb146054d0e
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane
2025-06-27 18:14:32 +01:00
parent 49bbd096cb
commit 33968f15ce
5 changed files with 27 additions and 37 deletions

View File

@@ -18,13 +18,13 @@ repos:
files: .*\.(yaml|yml)$
exclude: '^zuul.d/.*$'
- repo: https://github.com/PyCQA/doc8
rev: v1.1.2
rev: v2.0.0
hooks:
- id: doc8
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.8
rev: v0.12.1
hooks:
- id: ruff
- id: ruff-check
args: ['--fix', '--unsafe-fixes']
- id: ruff-format
- repo: https://opendev.org/openstack/hacking
@@ -35,7 +35,7 @@ repos:
- flake8-import-order~=0.18.2
exclude: '^(doc|releasenotes|tools)/.*$'
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0
rev: v1.16.1
hooks:
- id: mypy
additional_dependencies:

View File

@@ -338,11 +338,13 @@ class BaseAPI:
:returns: list of resource dicts
"""
items = self.list(path)
if isinstance(items, dict):
resp = self.list(path)
if isinstance(resp, dict):
# strip off the enclosing dict
key = list(items.keys())[0]
items = items[key]
key = list(resp.keys())[0]
items = resp[key]
else:
items = resp
ret = []
for o in items:

View File

@@ -134,7 +134,7 @@ class OSC_Config(config.OpenStackConfig): # type: ignore
default_domain = config.get('default_domain', None)
if (
identity_version == '3'
and not auth_type.startswith('v2')
and (auth_type and not auth_type.startswith('v2'))
and default_domain
):
# NOTE(stevemar): If PROJECT_DOMAIN_ID or PROJECT_DOMAIN_NAME is

View File

@@ -59,19 +59,22 @@ def log_level_from_string(level_string: str) -> int:
def log_level_from_config(config: collections.abc.Mapping[str, ty.Any]) -> int:
# Check the command line option
verbose_level = config.get('verbose_level')
verbose_level_from_config = config.get('verbose_level')
if config.get('debug', False):
verbose_level = 3
if verbose_level == 0:
verbose_level = 'error'
elif verbose_level == 1:
# If a command line option has not been specified, check the
# configuration file
verbose_level = config.get('log_level', 'warning')
elif verbose_level == 2:
verbose_level = 'info'
else:
verbose_level = 'debug'
verbose_level_from_config = 3
match verbose_level_from_config:
case 0:
verbose_level = 'error'
case 1:
# If a command line option has not been specified, check the
# configuration file
verbose_level = config.get('log_level', 'warning')
case 2:
verbose_level = 'info'
case _:
verbose_level = 'debug'
return log_level_from_string(verbose_level)

View File

@@ -39,22 +39,7 @@ packages = [
[tool.mypy]
show_column_numbers = true
show_error_context = true
ignore_missing_imports = true
follow_imports = "normal"
check_untyped_defs = true
warn_unused_ignores = true
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
strict = true
# keep this in-sync with 'mypy.exclude' in '.pre-commit-config.yaml'
exclude = '''
(?x)(