Closed MarcinKonowalczyk closed 1 week ago
Typing is slightly messy, but I think correct. mypy certainly seems to be happy with it. I've had to battle a bit with ImmutableTypeConversionDict
typing, but won in the end.
@davidism anything else which needs to happen here? (all good if just waiting / no-one gotten to it. just wanna make sure i'm not sitting idle on something i'm supposed to be doing here)
Since I often use this in a non-werkzeug context, I've extracted the TypeConversionDict into a single-file micro-package: https://github.com/MarcinKonowalczyk/type_conversion_dict.
I thought it relevant to post here since i've done quite a bit of test + typing work there. The get
and pop
signatures are compatible with dict
and werzeug.datastructures.TypeConversionDict
.
In that implementation i've also added a required
kwarg which I find very useful but i don't propose to add it here ( at least not in this PR/Issue. Obv feel free to add it too if you like it :)) )
Hmm, I'm starting to wonder if this is worth it. There's also popitem
, and for MultiDict
there's poplist
and popitemlist
, and there's also OrderedMultiDict
.
Nothing in Werkzeug uses MultiDict
destructively, it's either immutable, or additive-only during testing. Long term, I would like to simplify our datastructures implementation, as there is a lot of stuff we don't actually use in Werkzeug that adds complexity.
It seems like a general MultiDict
/immutable implementation would be more appropriate as a separate library. Most users probably aren't reaching for an entire WSGI library just for MultiDict
. That could also do away with Werkzeug-specific stuff like BadRequestKeyError
.
Pushed implementations of MultiDict
pop
, popitem
, poplist
, and popitemlist
, but no tests or type annotations. I mostly did it as an exercise, I'm still not convinced this should go in.
After discussing it with other maintainers, we don't want to accept the additional complexity right now, when Werkzeug itself won't use it. Thanks for working on this.
Proposed implementation of pop with type parameter on
TypeConversionDict
. Address #2883.