Closed bdraco closed 11 months ago
Seems reasonable! how can I reproduce?
I only saw it because it came up in the py-spy watching Home Assistant request for an enphase envoy. It shows up in a callgrind as well using cProfile.
Added a micro benchmark above
Yep, smart change. 👍 For review I
grep
'ed this and ensured that you've applied this to all thecast
cases consistently.An alternative here would be to remove the cast and use a
type: ignore
, should we consider that instead as a simpler alternative? (Or not, also okay?)
Happy to do either as its really a matter of preference.
I'm used to guarding with if TYPE_CHECKING
since thats what Home Assistant prefers for these cases, but some projects prefer ignores.
but some projects prefer ignores.
I do think this repo also prefers ignores over casting.
I'm unsure why cast
added to this line but it's worth to use type: ignore
instead at there.
Thanks
Summary
Guard casting type subscripting with TYPE_CHECKING to avoid runtime construction each time
_receive_event
is called which is unexpectedly expensiveChecklist