Ways to do Typing #132
Closed
Moritz-Schmidt
started this conversation in
Ideas
Replies: 3 comments 9 replies
-
|
What about typing inside out? So we use strict typing everywhere we can inside the library but do not rely on heavy typing at the outside interfaces, like data classes? Much like an API, where you have to separate the typing into a definition file (swagger/openapi) |
Beta Was this translation helpful? Give feedback.
9 replies
-
|
@Moritz-Schmidt can we help you somehow? |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
we merged the changes from @Moritz-Schmidt to main. I will close this discussion. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
There are multiple ways to type this library.
1. Mashumaro (or other serialization/deserialization library)
@erwindouna started implementing mashumaro models in his rewrite. These could be used to add typing to the HTTP API responses and the return types of the PyTado functions.
This has the drawback that it would probably break backwards compatibility since the functions will return a dataclass instead of a dict. This may be avoided by either implementing functions like
__getitem__so the dataclass also acts like a dict (however I'm not sure if this will work properly) or by using mashumaro just for validation and still returning a dict.2. TypedDict
The Models mentioned above could also be converted to TypedDict's which would be great for backwards compatibility but not as nice for readability and validation.
Personally I'd favour Mashumaro since the Models already mostly exist. I think for backwards compatibility returning dicts in the Tado Class in interface.py would be good. The new methods should return mashumaru objects.
What are other opinions on this? I can start working on typing once we decided how it should be done.
Beta Was this translation helpful? Give feedback.
All reactions