server icon indicating copy to clipboard operation
server copied to clipboard

[chore] mypy for helpers/audio.py

Open fmunkes opened this issue 8 months ago • 3 comments

  • In line 1483 I changed from player to player.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?

fmunkes avatar Apr 02 '25 20:04 fmunkes

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 ?

marcelveldt avatar Apr 03 '25 07:04 marcelveldt

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.

Jc2k avatar Apr 03 '25 09:04 Jc2k

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"?

fmunkes avatar Apr 03 '25 21:04 fmunkes

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.

fmunkes avatar Apr 18 '25 21:04 fmunkes

I ignored the webserver.py again, such that this PR at least passes all tests. Also merged the recent changes here again.

fmunkes avatar May 08 '25 21:05 fmunkes