Enable mypy for pep8 tox target

No significant changes; put some hints where mypy got confused.

Co-Authored-By: Miro Tomaska <mtomaska@redhat.com>
Change-Id: I285d7bfffd9349467b24d8f078847d77a5b47cbe
This commit is contained in:
Miro Tomaska
2024-05-15 12:49:32 -04:00
committed by Ihar Hrachyshka
parent 20bb2de4cf
commit 3f59155eff
14 changed files with 55 additions and 18 deletions

13
mypy.ini Normal file
View File

@@ -0,0 +1,13 @@
# Config file options: https://mypy.readthedocs.io/en/stable/config_file.html
[mypy]
incremental = True
pretty = True
show_error_context = True
show_column_numbers = True
warn_unused_ignores = True
# remove gradually as progress is made
disable_error_code = import-untyped,var-annotated,import-not-found
# honor excludes by not following there through imports
follow_imports = silent

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import typing
from neutron_lib.api import converters
from neutron_lib.db import constants
@@ -25,7 +27,7 @@ DESCRIPTION = 'The agent management extension.'
UPDATED_TIMESTAMP = '2013-02-03T10:00:00-00:00'
RESOURCE_NAME = ALIAS
COLLECTION_NAME = ALIAS + 's'
RESOURCE_ATTRIBUTE_MAP = {
RESOURCE_ATTRIBUTE_MAP: dict[str, typing.Any] = {
COLLECTION_NAME: {
'id': {'allow_post': False, 'allow_put': False,
'validate': {'type:uuid': None},

View File

@@ -26,8 +26,10 @@ is_sort_key = {'is_sort_key': True}
agents_collection = agent.RESOURCE_ATTRIBUTE_MAP[agent.COLLECTION_NAME]
RESOURCE_ATTRIBUTE_MAP = {
agent.COLLECTION_NAME: {
k: {**v, **is_sort_key} for k, v in agents_collection.items() if
k != "configurations"}
k: {**v, **is_sort_key}
for k, v in agents_collection.items()
if k != "configurations"
}
}
SUB_RESOURCE_ATTRIBUTE_MAP = {}
ACTION_MAP = {}

View File

@@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import typing
from neutron_lib.api import converters
from neutron_lib.api.definitions import network
from neutron_lib.api.definitions import port
@@ -108,7 +110,7 @@ _PARENT = {
'collection_name': POLICIES,
'member_name': POLICY
}
SUB_RESOURCE_ATTRIBUTE_MAP = {
SUB_RESOURCE_ATTRIBUTE_MAP: dict[str, typing.Any] = {
BANDWIDTH_LIMIT_RULES: {
'parent': _PARENT,
'parameters': dict(

View File

@@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import typing
from neutron_lib.api import converters
from neutron_lib.api.definitions import provider_net
from neutron_lib.api.definitions import subnet
@@ -35,7 +37,7 @@ DESCRIPTION = 'Segments extension.'
UPDATED_TIMESTAMP = '2016-02-24T17:00:00-00:00'
RESOURCE_NAME = 'segment'
COLLECTION_NAME = RESOURCE_NAME + 's'
RESOURCE_ATTRIBUTE_MAP = {
RESOURCE_ATTRIBUTE_MAP: dict[str, typing.Any] = {
COLLECTION_NAME: {
'id': {
'allow_post': False,

View File

@@ -14,6 +14,7 @@
# under the License.
import abc
import typing
from neutron_lib._i18n import _
from neutron_lib import constants
@@ -183,7 +184,7 @@ class APIExtensionDescriptor(ExtensionDescriptor):
If extension implementations need to override the default behavior of
this class they can override the respective method directly.
"""
api_definition = _UNSET
api_definition: typing.Union[constants.Sentinel, object] = _UNSET
@classmethod
def _assert_api_definition(cls, attr=None):

View File

@@ -161,7 +161,7 @@ class ContextBaseWithSession(ContextBase):
_TransactionConstraint = collections.namedtuple(
'TransactionConstraint', ['if_revision_match', 'resource', 'resource_id'])
'_TransactionConstraint', ['if_revision_match', 'resource', 'resource_id'])
class Context(ContextBaseWithSession):

View File

@@ -116,4 +116,5 @@ try:
pass
except AttributeError:
# SQLAlchemy < 2.0
BASEV2 = declarative.declarative_base(cls=NeutronBaseV2)
BASEV2 = declarative.declarative_base( # type: ignore[misc]
cls=NeutronBaseV2)

View File

@@ -12,6 +12,8 @@
import importlib.util
import os
import types
import typing
from neutron_lib.api import definitions
from neutron_lib.api.definitions import base
@@ -74,10 +76,10 @@ ASSERT_FUNCTIONS = {
class DefinitionBaseTestCase(test_base.BaseTestCase):
extension_module = None
extension_resources = ()
extension_subresources = ()
extension_attributes = ()
extension_module: typing.Optional[types.ModuleType] = None
extension_resources: tuple[str, ...] = ()
extension_subresources: tuple[str, ...] = ()
extension_attributes: tuple[str, ...] = ()
def setUp(self):
super().setUp()

View File

@@ -19,6 +19,6 @@ from neutron_lib.tests.unit.api.definitions import base
class AgentDefinitionTestCase(base.DefinitionBaseTestCase):
extension_module = agent
extension_resources = (agent.COLLECTION_NAME,)
extension_attributes = ('topic', 'agent_type', 'created_at',
'configurations', 'heartbeat_timestamp',
'binary', 'started_at', 'host', 'alive',)
extension_attributes: tuple[str, ...] = (
'topic', 'agent_type', 'created_at', 'configurations',
'heartbeat_timestamp', 'binary', 'started_at', 'host', 'alive',)

View File

@@ -18,4 +18,6 @@ from neutron_lib.tests.unit.api.definitions import test_agent as base
class AgentResourcesSyncedDefinitionTestCase(base.AgentDefinitionTestCase):
extension_module = agent_resources_synced
extension_attributes = (agent_resources_synced.RESOURCES_SYNCED,)
extension_attributes: tuple[str, ...] = (
agent_resources_synced.RESOURCES_SYNCED,
)

View File

@@ -32,7 +32,8 @@ try:
pass
except AttributeError:
# SQLAlchemy < 2.0
ModelBaseV2 = declarative.declarative_base(cls=models.ModelBase)
ModelBaseV2 = declarative.declarative_base( # type: ignore[misc]
cls=models.ModelBase)
class FakePort(ModelBaseV2):

View File

@@ -23,7 +23,7 @@ def reset():
del NOTIFICATIONS[:]
FakeMessage = collections.namedtuple('Message',
FakeMessage = collections.namedtuple('FakeMessage',
['publisher_id', 'priority',
'event_type', 'payload'])

View File

@@ -20,13 +20,22 @@ allowlist_externals = bash
commands =
stestr run {posargs}
[testenv:mypy]
deps = {[testenv:pep8]deps}
commands =
mypy --config-file ./mypy.ini neutron_lib
[testenv:pep8]
deps =
{[testenv]deps}
mypy==1.13.0
commands =
flake8
bash {toxinidir}/tools/check_samples.sh
bash {toxinidir}/tools/check_unit_test_structure.sh
bash ./tools/coding-checks.sh --pylint '{posargs}'
{[testenv:bandit]commands}
{[testenv:mypy]commands}
[testenv:releasenotes]
deps =