Skip to content

Commit

Permalink
Define __slots__ for class properties and enforce method overrides us…
Browse files Browse the repository at this point in the history
…ing the overrides package
  • Loading branch information
nth10sd committed Jul 20, 2024
1 parent 564a614 commit 1d7f407
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions startrepo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions startrepo/devices/oneplus3t.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@

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:
"""Initialize the OP3T."""
super().__init__("")

# @classmethod
# @override
# def main(cls) -> None:
# """OP3T main method.
# """

# @staticmethod
# @override
# def create() -> None:
# """Build a shell.
# """
8 changes: 6 additions & 2 deletions startrepo/devices/oneplus6t.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@

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:
"""Initialize the OP6T."""
super().__init__("")

# @classmethod
# @override
# def main(cls) -> None:
# """OP6T main method.
# """

# @staticmethod
# @override
# def create() -> None:
# """Build a shell.
# """

0 comments on commit 1d7f407

Please sign in to comment.