Description
First off, big thanks to @pcorpet for adding Flask stubs in #2740. I was updating one of my packages with to new type information and noticed something that stuck out to me.
One of the patterns that my team and I like to use is to create a set of endpoints that are bound to a Flask
duck-type; basically this factory can take a flask.Flask
instance or a flask.Blueprint
instance since both support add_url_rule
.
typeshed/third_party/2and3/flask/app.pyi
Line 98 in ca62cec
I am not super familiar with typeshed practices or Flask internals but the solution I am using right now locally is to define FlaskBlueprintType = Union[flask.Flask, flask.Blueprint]
and use that. A potentially more useful solution would be to define an ABC which Flask and Blueprint either explicitly implement or simply through https://docs.python.org/3/library/abc.html#abc.ABCMeta.register. Another option is to use https://www.python.org/dev/peps/pep-0544/ but Protocols are not fully finalized yet.
Does this make sense as type information to add or am I approaching this problem the wrong way?