You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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?
Protocols seem like a good fit for this solution, but a union is fine as well. I don't think there is anything in typeshed we could or should do about this, though (unless this is a common pattern).
Activity
srittau commentedon Feb 11, 2019
Protocols seem like a good fit for this solution, but a union is fine as well. I don't think there is anything in typeshed we could or should do about this, though (unless this is a common pattern).