Skip to content

Commit

Permalink
Increase mypy dependency (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia1243 authored Nov 15, 2023
1 parent 8b4aed8 commit b18c7d8
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 22 deletions.
12 changes: 6 additions & 6 deletions kubemarine/admission.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os
import uuid
import re
from typing import Dict, Any, List, Optional
from typing import Dict, Any, List, Optional, Union

import ruamel.yaml
import yaml
Expand Down Expand Up @@ -899,22 +899,22 @@ def get_labels_to_ensure_profile(inventory: dict, profile: str) -> Dict[str, str
def label_namespace_pss(cluster: KubernetesCluster, manage_type: str) -> None:
first_control_plane = cluster.nodes["control-plane"].get_first_member()
# set/delete labels on predifined plugins namsespaces
for namespace, profile in builtin.get_namespace_to_necessary_pss_profiles(cluster).items():
for ns_name, profile in builtin.get_namespace_to_necessary_pss_profiles(cluster).items():
target_labels = get_labels_to_ensure_profile(cluster.inventory, profile)
if manage_type in ["apply", "install"] and target_labels:
cluster.log.debug(f"Set PSS labels for profile {profile} on namespace {namespace}")
cluster.log.debug(f"Set PSS labels for profile {profile} on namespace {ns_name}")
command = "kubectl label ns {namespace} {lk}={lv} --overwrite"

else: # manage_type == "delete" or default labels are not necessary
cluster.log.debug(f"Delete PSS labels from namespace {namespace}")
cluster.log.debug(f"Delete PSS labels from namespace {ns_name}")
command = "kubectl label ns {namespace} {lk}- || true"
target_labels = _get_default_labels(profile)

for lk, lv in target_labels.items():
first_control_plane.sudo(command.format(namespace=namespace, lk=lk, lv=lv))
first_control_plane.sudo(command.format(namespace=ns_name, lk=lk, lv=lv))

procedure_config = cluster.procedure_inventory["pss"]
namespaces = procedure_config.get("namespaces")
namespaces: List[Union[str, Dict[str, dict]]] = procedure_config.get("namespaces")
# get the list of namespaces that should be labeled then set/delete labels
if namespaces:
default_modes = {}
Expand Down
2 changes: 1 addition & 1 deletion kubemarine/core/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import os
from typing import Dict, List

import fabric # type: ignore[import]
import fabric # type: ignore[import-untyped]

from kubemarine.core import static

Expand Down
4 changes: 2 additions & 2 deletions kubemarine/core/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from types import TracebackType
from typing import Tuple, List, Dict, Callable, Any, Optional, Union, OrderedDict, TypeVar, Type, Mapping, Iterable

import fabric # type: ignore[import]
import fabric.transfer # type: ignore[import]
import fabric # type: ignore[import-untyped]
import fabric.transfer # type: ignore[import-untyped]

from concurrent.futures.thread import ThreadPoolExecutor

Expand Down
2 changes: 1 addition & 1 deletion kubemarine/core/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import sys
from abc import ABC, abstractmethod

from pygelf import gelf, GelfTcpHandler, GelfUdpHandler, GelfTlsHandler, GelfHttpHandler # type: ignore[import]
from pygelf import gelf, GelfTcpHandler, GelfUdpHandler, GelfTlsHandler, GelfHttpHandler # type: ignore[import-untyped]

from copy import deepcopy
from typing import Any, List, Optional, cast, Dict, Union
Expand Down
18 changes: 12 additions & 6 deletions kubemarine/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import time
import tarfile

from typing import Tuple, Callable, List, TextIO, cast, Union, TypeVar, Dict
from typing import Tuple, Callable, List, TextIO, cast, Union, TypeVar, Dict, Sequence

import yaml
import ruamel.yaml
Expand All @@ -40,9 +40,15 @@
_T_contra = TypeVar("_T_contra", contravariant=True)


class SupportsDunderLT(Protocol[_T_contra]):
class SupportsAllComparisons(Protocol[_T_contra]):
def __lt__(self, __other: _T_contra) -> bool: ...

def __gt__(self, __other: _T_contra) -> bool: ...

def __le__(self, __other: _T_contra) -> bool: ...

def __ge__(self, __other: _T_contra) -> bool: ...


def do_fail(message: str = '', reason: Exception = None, hint: str = '', logger: log.EnhancedLogger = None) -> None:

Expand Down Expand Up @@ -381,7 +387,7 @@ def yaml_structure_preserver() -> ruamel.yaml.YAML:
return ruamel_yaml


def is_sorted(l: list, key: Callable = None) -> bool:
def is_sorted(l: Sequence[str], key: Callable[[str], SupportsAllComparisons] = None) -> bool:
"""
Check that the specified list is sorted.
Expand All @@ -394,7 +400,7 @@ def is_sorted(l: list, key: Callable = None) -> bool:
return all(key(l[i]) <= key(l[i + 1]) for i in range(len(l) - 1))


def map_sorted(map_: CommentedMap, key: Callable[[str], SupportsDunderLT] = None) -> CommentedMap:
def map_sorted(map_: CommentedMap, key: Callable[[str], SupportsAllComparisons] = None) -> CommentedMap:
"""
Check that the specified CommentedMap is sorted, or create new sorted map from it otherwise.
Expand All @@ -406,14 +412,14 @@ def map_sorted(map_: CommentedMap, key: Callable[[str], SupportsDunderLT] = None
_key = key
else:
_key = lambda x: x
map_keys = list(map_)
map_keys: List[str] = list(map_)
if not is_sorted(map_keys, key=_key):
map_ = CommentedMap(sorted(map_.items(), key=lambda item: _key(item[0])))

return map_


def insert_map_sorted(map_: CommentedMap, k: str, v: object, key: Callable = None) -> None:
def insert_map_sorted(map_: CommentedMap, k: str, v: object, key: Callable[[str], SupportsAllComparisons] = None) -> None:
"""
Insert new item to the CommentedMap or update the value for the existing key.
The map should be already sorted.
Expand Down
2 changes: 1 addition & 1 deletion kubemarine/core/yaml_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from deepmerge import Merger # type: ignore[import]
from deepmerge import Merger # type: ignore[import-untyped]


def is_list_extends(nxt: list) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion kubemarine/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from copy import deepcopy
from typing import List, Dict, Union, Any, Optional, Mapping, Iterable, IO, Tuple, cast

import fabric # type: ignore[import]
import fabric # type: ignore[import-untyped]
import invoke

from kubemarine import system, procedures
Expand Down
2 changes: 1 addition & 1 deletion kubemarine/procedures/check_paas.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from kubemarine.kubernetes.deployment import Deployment
from kubemarine.kubernetes.object import KubernetesObject
from kubemarine.coredns import generate_configmap
from deepdiff import DeepDiff # type: ignore[import]
from deepdiff import DeepDiff # type: ignore[import-untyped]


def services_status(cluster: KubernetesCluster, service_type: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion kubemarine/resources/scripts/check_url_availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
if major_version == 3:
import urllib.request as urllib
else:
import urllib2 as urllib # type: ignore[import, no-redef]
import urllib2 as urllib # type: ignore[import-not-found, no-redef]

try:
source = sys.argv[1]
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ requires-python = ">=3.7"
[project.optional-dependencies]
ansible = ["ansible==7.0.*"]
mypy = [
"mypy==1.3.*",
"mypy==1.7.*",
"types-PyYAML==6.*",
"types-invoke==1.*",
"types-toml==0.*",
Expand Down Expand Up @@ -102,7 +102,7 @@ warn_unreachable = true
# strict typing checks
check_untyped_defs = true
strict_equality = true
strict_concatenate = true
extra_checks = true
disallow_subclassing_any = true
disallow_untyped_decorators = true
disallow_incomplete_defs = true
Expand Down

0 comments on commit b18c7d8

Please sign in to comment.