I'm writing this down as more of a general issue, I don't have anything concrete or specific to change just yet.
Background
I was recently playing around with the polars library, and I was surprised by how good the typing is. If there are any typing errors in your select query for example, the code would certainly fail at runtime. They support a lot of different operations and codepaths and it all works great with the type system (unlike pandas). That got me thinking if we can make PTB better typed, so there's more confidence that there's no runtime errors when you run your bot for the first time.
Potential area of improvement
The biggest area of improvement I see is definitely the handler (with filters) -> callback interface. For e.g. when opening echobot.py, ty gives me a bunch of typing issues in every callback, mostly because we are accessing attributes which could be None. We know they would work at runtime because we have a filter which filters them only when they are not None. The typing system does not know this.
Possible Solution?
I remember discussing this a long time ago in the dev chat, and I think at the time we could not resolve it, since it required making the Update class Generic? Or adding a bunch of type casts everywhere.
I wonder if there is now a better solution to this considering all the new typing features of recent python versions (3.11+). I'm still not that well versed in typing to come up with the best solution yet.
This is a great opportunity for a new contributor to give their ideas on how to fix this.
I'm writing this down as more of a general issue, I don't have anything concrete or specific to change just yet.
Background
I was recently playing around with the
polarslibrary, and I was surprised by how good the typing is. If there are any typing errors in your select query for example, the code would certainly fail at runtime. They support a lot of different operations and codepaths and it all works great with the type system (unlikepandas). That got me thinking if we can make PTB better typed, so there's more confidence that there's no runtime errors when you run your bot for the first time.Potential area of improvement
The biggest area of improvement I see is definitely the handler (with filters) -> callback interface. For e.g. when opening echobot.py,
tygives me a bunch of typing issues in every callback, mostly because we are accessing attributes which could beNone. We know they would work at runtime because we have a filter which filters them only when they are notNone. The typing system does not know this.Possible Solution?
I remember discussing this a long time ago in the dev chat, and I think at the time we could not resolve it, since it required making the Update class Generic? Or adding a bunch of type casts everywhere.
I wonder if there is now a better solution to this considering all the new typing features of recent python versions (3.11+). I'm still not that well versed in typing to come up with the best solution yet.
This is a great opportunity for a new contributor to give their ideas on how to fix this.