Clean up code and implement best practices #27

Merged
Vinalti merged 3 commits from best-practices into master 2023-05-01 18:57:55 +02:00
Vinalti commented 2023-04-28 01:27:08 +02:00 (Migrated from github.com)

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

## 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 2023-04-30 16:15:37 +02:00 (Migrated from github.com)

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
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 2023-04-30 20:17:40 +02:00 (Migrated from github.com)

Oh ok I see then I think that we should :

from __future__ import annotation

or

from Typing import List

#and use
List[dict]
Oh ok I see then I think that we should : ```py from __future__ import annotation ``` or ```py from Typing import List #and use List[dict] ```
lucasheld commented 2023-04-30 22:30:20 +02:00 (Migrated from github.com)

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).

Hmm, I noticed that [Python 3.6 is end-of-life](https://devguide.python.org/versions/). Then I think we can just drop support for this version and add ```python from __future__ import annotations ``` With this import `list[dict]` is supported in Python 3.7 ([PEP 563](https://peps.python.org/pep-0563/)).
lucasheld commented 2023-05-01 18:58:08 +02:00 (Migrated from github.com)

Thank you!

Thank you!
Sign in to join this conversation.
No description provided.