Skip to content

Commit

Permalink
ENT-5549: Fix issues found when type-hinting
Browse files Browse the repository at this point in the history
* Card ID: ENT-5549

- Stop shadowing module callable in cpuinfo.py
- Add abstract _parse method to BaseCpuInfo
  • Loading branch information
m-horky committed Mar 27, 2023
1 parent c24da73 commit bdb6a07
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/subscription_manager/cp_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ def get_keycloak_auth_cp(self, token) -> connection.UEPConnection:
uep: connection.UEPConnection = self.get_no_auth_cp()

if not uep.has_capability("keycloak_auth"):
# FIXME This error class should be instantiated
raise TokenAuthUnsupportedException

# FIXME: make this more reliable
Expand Down
11 changes: 7 additions & 4 deletions src/subscription_manager/cpuinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,12 @@ def fact_sluggify_item(item_tuple: Iterable[str]) -> Tuple[str, str]:
return (newkey, item_tuple[1])


# FIXME Argument shadows variaable name from outer scope
def split_key_value_generator(file_contents: str, line_splitter: Callable) -> Iterator[List[str]]:
def split_key_value_generator(
file_contents: str,
splitter: Callable[[str], Optional[List[str]]],
) -> Iterator[List[str]]:
for line in file_contents.splitlines():
parts: List[str] = line_splitter(line)
parts: List[str] = splitter(line)
if parts:
yield parts

Expand Down Expand Up @@ -360,7 +362,8 @@ def from_proc_cpuinfo_string(cls: type, proc_cpuinfo_string: str):

return cpu_info

# FIXME Implement _parse function doing `pass` or raising NotImplementedError
def _parse(self, cpuinfo_data: str) -> None:
raise NotImplementedError()


class Aarch64CpuInfo(BaseCpuInfo):
Expand Down
13 changes: 7 additions & 6 deletions src/subscription_manager/productid.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import logging
import os

from typing import Callable, Dict, List, Literal, Optional, Union
from typing import Callable, Dict, List, Literal, Optional, Tuple, Union

# for labelCompare
import rpm
Expand Down Expand Up @@ -111,8 +111,6 @@ def __fn(self) -> str:
class ComparableMixin:
"""Needs compare_keys to be implemented."""

# FIXME self.compare_keys should be defined here, raising NotImplementedError

def _compare(self, keys: List, method: Callable) -> Union[Literal[NotImplemented], bool]:
return method(keys[0], keys[1]) if keys else NotImplemented

Expand All @@ -134,6 +132,9 @@ def __le__(self, other):
def __ge__(self, other):
return self._compare(self.compare_keys(other), lambda s, o: s >= o)

def compare_keys(self, other):
raise NotImplementedError()


class RpmVersion:
"""Represent the epoch, version, release of a rpm style version.
Expand Down Expand Up @@ -234,8 +235,8 @@ class ComparableProduct(ComparableMixin):
def __init__(self, product):
self.product = product

def compare_keys(self, other):
"""Create a a tuple of RpmVersion objects.
def compare_keys(self, other) -> Optional[Tuple[RpmVersion, RpmVersion]]:
"""Create a tuple of RpmVersion objects.
Create a RpmVersion using the product's version attribute
as the 'version' attribute for a rpm label tuple. We let the
Expand Down Expand Up @@ -269,7 +270,7 @@ def __init__(self, product_cert):

# keys used to compare certificate. For now, just the keys for the
# Product.version. This could include say, certificate serial or issue date
def compare_keys(self, other):
def compare_keys(self, other) -> Optional[Tuple[RpmVersion, RpmVersion]]:
return self.comp_product.compare_keys(other.comp_product)


Expand Down
2 changes: 1 addition & 1 deletion src/subscription_manager/repofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Repo(dict):
}

def __init__(self, repo_id: str, existing_values: List = None):
# FIXME Missing super() call
super().__init__()
if HAS_DEB822 is True:
self.PROPERTIES["arches"] = (1, None)

Expand Down
5 changes: 2 additions & 3 deletions src/subscription_manager/repolib.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,7 @@ def get_consumer_auth_cp(self) -> "UEPConnection":
self.uep = self.cp_provider.get_consumer_auth_cp()
return self.uep

def perform(self) -> Union["RepoActionReport", Literal[0]]:
# FIXME return None instead of 0
def perform(self) -> Optional["RepoActionReport"]:
# the [rhsm] manage_repos can be overridden to disable generation of the
# redhat.repo file:
if not self.manage_repos:
Expand All @@ -429,7 +428,7 @@ def perform(self) -> Union["RepoActionReport", Literal[0]]:
if repo_file.exists():
log.info("Removing %s due to manage_repos configuration." % repo_file.path)
RepoActionInvoker.delete_repo_file()
return 0
return None

repo_pairs = []
for repo_class, server_val_repo_class in get_repo_file_classes():
Expand Down

0 comments on commit bdb6a07

Please sign in to comment.