lucasheld / uptime-kuma-api

A Python wrapper for the Uptime Kuma Socket.IO API
https://uptime-kuma-api.readthedocs.io
MIT License
252 stars 19 forks source link

Clean up code and implement best practices #27

Closed Vinalti closed 1 year ago

Vinalti commented 1 year ago

Proposed changes

  1. type(a) == list replaced with isinstance(a, list)

    That ensures that an inherited class of list is also recognized as list

  2. a_dict['key'] replaced with a_dict.get('key')

    If the key doesn't exists the method .get("key") will return None instead of raising an exception

  3. annotation -> list replaced by more accurate -> list[dict]

    Simple best practice for TypeHints

lucasheld commented 1 year ago

This module should be compatible with python 3.6. list[dict] is not supported in this version:

...
    def get_monitors(self) -> list[dict]:
TypeError: 'type' object is not subscriptable
Vinalti commented 1 year ago

Oh ok I see then I think that we should :

from __future__ import annotation

or

from Typing import List

#and use
List[dict]
lucasheld commented 1 year ago

Hmm, I noticed that Python 3.6 is end-of-life. Then I think we can just drop support for this version and add

from __future__ import annotations

With this import list[dict] is supported in Python 3.7 (PEP 563).

lucasheld commented 1 year ago

Thank you!