Merge pull request #1162 from ogayot/fix-obvious-typing-issues
Fix some typing issues reported by mypy, including potential crash when comparing snap versions
This commit is contained in:
commit
efea0c5391
|
@ -21,6 +21,7 @@ import os
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
|
@ -82,9 +83,9 @@ installed system will be mounted at /target.""")
|
||||||
|
|
||||||
class SubiquityClient(TuiApplication):
|
class SubiquityClient(TuiApplication):
|
||||||
|
|
||||||
snapd_socket_path = '/run/snapd.socket'
|
snapd_socket_path: Optional[str] = '/run/snapd.socket'
|
||||||
|
|
||||||
variant = None
|
variant: Optional[str] = None
|
||||||
cmdline = ['snap', 'run', 'subiquity']
|
cmdline = ['snap', 'run', 'subiquity']
|
||||||
dryrun_cmdline_module = 'subiquity.cmd.tui'
|
dryrun_cmdline_module = 'subiquity.cmd.tui'
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from subiquitycore.tuicontroller import (
|
from subiquitycore.tuicontroller import (
|
||||||
TuiController,
|
TuiController,
|
||||||
|
@ -28,7 +29,7 @@ class Confirm(Exception):
|
||||||
|
|
||||||
class SubiquityTuiController(TuiController):
|
class SubiquityTuiController(TuiController):
|
||||||
|
|
||||||
endpoint_name = None
|
endpoint_name: Optional[str] = None
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
super().__init__(app)
|
super().__init__(app)
|
||||||
|
|
|
@ -76,9 +76,9 @@ class SnapVersion:
|
||||||
elif self.patch < other.patch:
|
elif self.patch < other.patch:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.git_build_id is not None and other.git_build_id is None:
|
build_id_self = \
|
||||||
return True
|
float("-inf") if self.git_build_id is None else self.git_build_id
|
||||||
elif self.git_build_id is None and other.git_build_id is not None:
|
build_id_other = \
|
||||||
return False
|
float("-inf") if other.git_build_id is None else other.git_build_id
|
||||||
|
|
||||||
return self.git_build_id > other.git_build_id
|
return build_id_self > build_id_other
|
||||||
|
|
|
@ -43,3 +43,7 @@ class TestSnapVersion(unittest.TestCase):
|
||||||
# Make sure we ignore the build ID when the patch version is different
|
# Make sure we ignore the build ID when the patch version is different
|
||||||
self.assertLess(SnapVersion.from_string("21.10.2+git255.deadbeef"),
|
self.assertLess(SnapVersion.from_string("21.10.2+git255.deadbeef"),
|
||||||
SnapVersion.from_string("21.10.3+git135.deadbeef"))
|
SnapVersion.from_string("21.10.3+git135.deadbeef"))
|
||||||
|
|
||||||
|
snap_version = SnapVersion.from_string("21.10.02")
|
||||||
|
self.assertFalse(snap_version < snap_version)
|
||||||
|
self.assertFalse(snap_version > snap_version)
|
||||||
|
|
|
@ -58,7 +58,7 @@ class CheckSubscriptionError(Exception):
|
||||||
class UAInterfaceStrategy(ABC):
|
class UAInterfaceStrategy(ABC):
|
||||||
""" Strategy to query information about a UA subscription. """
|
""" Strategy to query information about a UA subscription. """
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def query_info(token: str) -> dict:
|
async def query_info(self, token: str) -> dict:
|
||||||
""" Return information about the UA subscription based on the token
|
""" Return information about the UA subscription based on the token
|
||||||
provided. """
|
provided. """
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ class UAInterface:
|
||||||
""" Return a dictionary containing the subscription information. """
|
""" Return a dictionary containing the subscription information. """
|
||||||
return await self.strategy.query_info(token)
|
return await self.strategy.query_info(token)
|
||||||
|
|
||||||
async def get_avail_services(self, token: str) -> list:
|
async def get_avail_services(self, token: str) -> List[dict]:
|
||||||
""" Return a list of available services for the subscription
|
""" Return a list of available services for the subscription
|
||||||
associated with the token provided.
|
associated with the token provided.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from typing import Any, Optional
|
||||||
|
|
||||||
import jsonschema
|
import jsonschema
|
||||||
|
|
||||||
|
@ -32,10 +33,10 @@ log = logging.getLogger("subiquity.server.controller")
|
||||||
|
|
||||||
class SubiquityController(BaseController):
|
class SubiquityController(BaseController):
|
||||||
|
|
||||||
autoinstall_key = None
|
autoinstall_key: Optional[str] = None
|
||||||
autoinstall_schema = None
|
autoinstall_schema: Any = None
|
||||||
autoinstall_default = None
|
autoinstall_default: Any = None
|
||||||
endpoint = None
|
endpoint: Optional[type] = None
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
super().__init__(app)
|
super().__init__(app)
|
||||||
|
|
|
@ -189,7 +189,7 @@ class UbuntuAdvantageView(BaseView):
|
||||||
self.remove_overlay()
|
self.remove_overlay()
|
||||||
self.show_stretchy_overlay(ContinueAnywayWidget(self))
|
self.show_stretchy_overlay(ContinueAnywayWidget(self))
|
||||||
|
|
||||||
def show_available_services(self, services: dict) -> None:
|
def show_available_services(self, services: List[dict]) -> None:
|
||||||
""" Display an overlay with the list of services that will be enabled
|
""" Display an overlay with the list of services that will be enabled
|
||||||
via Ubuntu Advantage subscription. After the user confirms, the next we
|
via Ubuntu Advantage subscription. After the user confirms, the next we
|
||||||
will quit the current view and move on. """
|
will quit the current view and move on. """
|
||||||
|
@ -199,7 +199,8 @@ class UbuntuAdvantageView(BaseView):
|
||||||
|
|
||||||
class ShowServicesWidget(Stretchy):
|
class ShowServicesWidget(Stretchy):
|
||||||
""" Widget to show the available services for UA subscription. """
|
""" Widget to show the available services for UA subscription. """
|
||||||
def __init__(self, parent: UbuntuAdvantageView, services: list):
|
def __init__(self, parent: UbuntuAdvantageView,
|
||||||
|
services: List[dict]) -> None:
|
||||||
""" Initializes the widget by including the list of services as a
|
""" Initializes the widget by including the list of services as a
|
||||||
bullet-point list. """
|
bullet-point list. """
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
log = logging.getLogger("subiquitycore.controller")
|
log = logging.getLogger("subiquitycore.controller")
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ log = logging.getLogger("subiquitycore.controller")
|
||||||
class BaseController(ABC):
|
class BaseController(ABC):
|
||||||
"""Base class for controllers."""
|
"""Base class for controllers."""
|
||||||
|
|
||||||
model_name = None
|
model_name: Optional[str] = None
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.name = type(self).__name__[:-len("Controller")]
|
self.name = type(self).__name__[:-len("Controller")]
|
||||||
|
|
|
@ -16,7 +16,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from typing import Tuple, List
|
from typing import Optional, Tuple, List
|
||||||
import apt
|
import apt
|
||||||
import apt_pkg
|
import apt_pkg
|
||||||
|
|
||||||
|
@ -117,7 +117,8 @@ class ConfigureController(SubiquityController):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def __recommended_language_packs(self, lang, env) -> List[str]:
|
async def __recommended_language_packs(self, lang, env) \
|
||||||
|
-> Optional[List[str]]:
|
||||||
""" Return a list of package names recommended by
|
""" Return a list of package names recommended by
|
||||||
check-language-support (or a fake list if in dryrun).
|
check-language-support (or a fake list if in dryrun).
|
||||||
List returned can be empty on success. None for failure.
|
List returned can be empty on success. None for failure.
|
||||||
|
|
Loading…
Reference in New Issue