Browse Source

drop compatibility with python3.6 (as in PySwitchbot v0.11.0)

https://github.com/Danielhiversen/pySwitchbot/commit/590b58a43d56cb0fda3ccdf6c4506aa6ec1864ee#diff-4a04772ec76f55c7c44a96ff0eef45da07305d1e6ef7100e3a3c6d2a80f32e35R2

https://github.com/fphammerle/switchbot-mqtt/issues/55#issuecomment-955633808
Fabian Peter Hammerle 2 years ago
parent
commit
b0a6ad4925
4 changed files with 13 additions and 19 deletions
  1. 0 1
      .github/workflows/python.yml
  2. 2 0
      CHANGELOG.md
  3. 3 3
      setup.py
  4. 8 15
      switchbot_mqtt/_actors/_base.py

+ 0 - 1
.github/workflows/python.yml

@@ -34,7 +34,6 @@ jobs:
     strategy:
       matrix:
         python-version:
-        - '3.6'
         - '3.7'
         - '3.8'
         - '3.9'

+ 2 - 0
CHANGELOG.md

@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
+### Removed
+- compatibility with `python3.6`
 
 ## [2.2.0] - 2021-10-23
 ### Added

+ 3 - 3
setup.py

@@ -65,7 +65,6 @@ setuptools.setup(
         "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
         "Operating System :: POSIX :: Linux",
         # .github/workflows/python.yml
-        "Programming Language :: Python :: 3.6",
         "Programming Language :: Python :: 3.7",
         "Programming Language :: Python :: 3.8",
         "Programming Language :: Python :: 3.9",
@@ -73,8 +72,9 @@ setuptools.setup(
         "Topic :: Home Automation",
     ],
     entry_points={"console_scripts": ["switchbot-mqtt = switchbot_mqtt._cli:_main"]},
-    # variable type hints, f-strings & * to force keyword-only arguments
-    python_requires=">=3.6",
+    # >=3.6 variable type hints, f-strings & * to force keyword-only arguments
+    # >=3.7 postponed evaluation of type annotations (PEP563) & dataclass
+    python_requires=">=3.7",
     install_requires=[
         # >=1.3.0 for btle.BTLEManagementError (could be replaced with BTLEException)
         # >=0.1.0 for btle.helperExe

+ 8 - 15
switchbot_mqtt/_actors/_base.py

@@ -16,7 +16,10 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
+from __future__ import annotations  # PEP563 (default in python>=3.10)
+
 import abc
+import dataclasses
 import logging
 import queue
 import shlex
@@ -37,21 +40,11 @@ from switchbot_mqtt._utils import (
 _LOGGER = logging.getLogger(__name__)
 
 
+@dataclasses.dataclass
 class _MQTTCallbackUserdata:
-    # pylint: disable=too-few-public-methods; @dataclasses.dataclass when python_requires>=3.7
-    def __init__(
-        self,
-        *,
-        retry_count: int,
-        device_passwords: typing.Dict[str, str],
-        fetch_device_info: bool,
-    ) -> None:
-        self.retry_count = retry_count
-        self.device_passwords = device_passwords
-        self.fetch_device_info = fetch_device_info
-
-    def __eq__(self, other: object) -> bool:
-        return isinstance(other, type(self)) and vars(self) == vars(other)
+    retry_count: int
+    device_passwords: typing.Dict[str, str]
+    fetch_device_info: bool
 
 
 class _MQTTControlledActor(abc.ABC):
@@ -144,7 +137,7 @@ class _MQTTControlledActor(abc.ABC):
         userdata: _MQTTCallbackUserdata,
         topic: str,
         expected_topic_levels: typing.List[_MQTTTopicLevel],
-    ) -> typing.Optional["_MQTTControlledActor"]:
+    ) -> typing.Optional[_MQTTControlledActor]:
         try:
             mac_address = _parse_mqtt_topic(
                 topic=topic, expected_levels=expected_topic_levels