From 1d7f4079ce955702a5cdc415d04814ea27f7aa70 Mon Sep 17 00:00:00 2001 From: "Gary Kwong [:gkw]" Date: Sat, 20 Jul 2024 00:02:23 -0700 Subject: [PATCH] Define __slots__ for class properties and enforce method overrides using the overrides package --- pyproject.toml | 1 + startrepo/common.py | 8 ++++++-- startrepo/devices/oneplus3t.py | 8 ++++++-- startrepo/devices/oneplus6t.py | 8 ++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6e964ed..4087e53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,7 @@ test = [ 'coverage ~= 7.6.0; python_version >= "3.11"', 'coverage[toml] ~= 7.6.0; python_version <= "3.10"', "mypy ~= 1.10.1", + "overrides ~= 7.7.0", "pylint ~= 3.2.5", 'pyright==1.1.372; platform_system == "Linux"', "pytest ~= 8.2.2", diff --git a/startrepo/common.py b/startrepo/common.py index 30ad7aa..3ffd1fc 100644 --- a/startrepo/common.py +++ b/startrepo/common.py @@ -4,20 +4,24 @@ from typing import TYPE_CHECKING +from overrides import EnforceOverrides + if TYPE_CHECKING: from typing_extensions import Self # Directly import from typing on Python 3.11+ -# class LOSDeviceError(Exception): +# class LOSDeviceError(Exception, EnforceOverrides): # """Error class unique to LOSDevice objects.""" -class LOSDevice: +class LOSDevice(EnforceOverrides): """A device that supports Lineage OS. :param new_type: This is a new type for LOSDevice """ + __slots__ = ("new_type",) + def __init__(self, new_type: str) -> None: """Initialize the LOSDevice.""" self.new_type = new_type diff --git a/startrepo/devices/oneplus3t.py b/startrepo/devices/oneplus3t.py index 9ec9028..621a3b7 100644 --- a/startrepo/devices/oneplus3t.py +++ b/startrepo/devices/oneplus3t.py @@ -2,13 +2,15 @@ from __future__ import annotations +from overrides import EnforceOverrides + from startrepo.common import LOSDevice -# class OP3TError(Exception): +# class OP3TError(LOSDeviceError, EnforceOverrides): # """Error class unique to OP3T objects.""" -class OP3T(LOSDevice): +class OP3T(LOSDevice, EnforceOverrides): """OnePlus 3T object.""" def __init__(self) -> None: @@ -16,11 +18,13 @@ def __init__(self) -> None: super().__init__("") # @classmethod + # @override # def main(cls) -> None: # """OP3T main method. # """ # @staticmethod + # @override # def create() -> None: # """Build a shell. # """ diff --git a/startrepo/devices/oneplus6t.py b/startrepo/devices/oneplus6t.py index 8b7fd4f..28d1ea3 100644 --- a/startrepo/devices/oneplus6t.py +++ b/startrepo/devices/oneplus6t.py @@ -2,13 +2,15 @@ from __future__ import annotations +from overrides import EnforceOverrides + from startrepo.common import LOSDevice -# class OP6TError(Exception): +# class OP6TError(LOSDeviceError, EnforceOverrides): # """Error class unique to OP6T objects.""" -class OP6T(LOSDevice): +class OP6T(LOSDevice, EnforceOverrides): """OnePlus 6T object.""" def __init__(self) -> None: @@ -16,11 +18,13 @@ def __init__(self) -> None: super().__init__("") # @classmethod + # @override # def main(cls) -> None: # """OP6T main method. # """ # @staticmethod + # @override # def create() -> None: # """Build a shell. # """