server
server copied to clipboard
[chore] mypy for helpers/audio.py
- In line 1483 I changed from
playertoplayer.player_id- is that correct? - In line 96 the asyncio.Task needs a type hint I don't know yet
Besides:
It is a lot of "assert foo is not None" etc - is that ok?
I'm not able to check for MusicProvider without the if TYPE_CHECKING due to a circular import otherwise. Could we make that cleaner?
I'm not able to check for MusicProvider without the if TYPE_CHECKING due to a circular import otherwise. Could we make that cleaner?
Yeah, i have been staring at that a couple of times as well and i couldn't come up with a clean solution. We can make it easier if we let the "get_provider" simply always return a provider and raise otherwise.
Maybe @Jc2k has some ideas ?
If it's abnormal for get_provider to fail, let's make it raise. Otherwise if it's reasonable to fail, leaving it as optional means eventually mypy will force all get_provider users to consider that possibility (there isn't a way to signal "you must handle this exception").
Not a fan of if TYPE_CHECKING but can't think of a way around it.
I left the "if TYPE_CHECKING" in then for this specific case. Even if the function raises, I still need to check the provider type - or would you introduce a function like "get_music_provider"?
I went through all helper files now. I'm having a little trouble type hinting the dynamic routes (and maybe double check the static routes) in webserver.py, and would ask for help there.
music_assistant/helpers/webserver.py:36: error: Missing type parameters for generic type "Callable" [type-arg]
music_assistant/helpers/webserver.py:114: error: Missing type parameters for generic type "Callable" [type-arg]
music_assistant/helpers/webserver.py:125: error: Function is missing a return type annotation [no-untyped-def]
music_assistant/helpers/webserver.py:150: error: Returning Any from function declared to return "Response" [no-any-return]
Other than that I think it's not looking too bad.
I ignored the webserver.py again, such that this PR at least passes all tests. Also merged the recent changes here again.