Replies: 2 comments 1 reply
-
|
Is there any case where someone would want to customize header storage? For other request data I see more benefits in it, because someone may want to have e.g. case insensitivity or similar things that would not make sense as a default or officially supported config option... PS: I think having |
Beta Was this translation helpful? Give feedback.
-
|
Another thing I notice as I'm working on the structured header classes is that what the All the "basic" headers, using But structured headers may return For responses, this is even more inconsistent. Whether the property has a setter or deleter, and whether the setter accepts I think we should do the following:
I'm less sure about one other potential change: Raising 400 errors instead of returning I'll note that while all this sounds like a pretty disruptive refactor, I already did this extensively with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There are a bunch of things I've noticed over time that contribute to the complexity of Werkzeug's classes and functions, especially from a typing perspective.
werkzeug.datastructures.mixinscontains a bunch of immutable mixins. However, they're all marked private, and they're only used to then be mixed in to the real storage class, likeImmutableList,ImmutableDict, etc. It seems like the mixins could be merged into their concrete implementations.ImmutableListdoesn't seem necessary, as that's basically whattupleis. It's also marked private.ImmutableTypeConversionDictis never used.ImmutableDictis only used forMap.default_converters, and there seems to be no reason to do that vs annotating it asMappinginstead ofMutableMapping.Requesthas three attributesparameter_storage_class,dict_storage_class, andlist_storage_class. On the other hand, it doesn't have a way to customize the header storage class. The docs for these suggest that you may have reason to useImmutableDictinstead ofImmutableMultiDictfor some speedup, but that speed difference should have been negligible even when it was first written, and Python has only gotten faster. It would also be confusing as multi dict returns the first value first while dict would return the last value. The docs clearly say it would be a bad idea to use mutable structures for these, so that's not a reason to keep them. It's not clear why parameter and dict would have different storage classes. I'm pretty sure I also dealt with issues in the past where some use ofdict_storage_classactually needed a dict and not a multi dict, and I recall some places that didn't use the attributes either. I can't think of a good reason to customize these classes nowadays. If we wanted to accurately typeRequest, it should really be generic over these three types (and probably a few more things), making the annotations really complex if we were to go that far.A bunch of header parsing functions in
werkzeug.httptake aclsargument, and this requires a bunch of@overloadsignatures to get typing correct, and I'm not even sure it's entirely correct still. Many of these are also tied to more specific data structures, such asAccept, which also use the functions inhttp, which requires working around circular imports. I'd like to move parse/dump functions into methods on those classes instead,from_header(cls, value) -> Selfandto_header(self) -> str.Beta Was this translation helpful? Give feedback.
All reactions