falcon icon indicating copy to clipboard operation
falcon copied to clipboard

Refactor CONSUME_MULTIPLE_SEGMENTS in BaseConverter

Open davetapley opened this issue 5 months ago • 1 comments

I was going to add types to https://github.com/falconry/falcon/blob/4910dd73ecd1b9c8cf6cae045b26ad432fa56128/falcon/routing/converters.py#L34

but as the docs give the type of value ⬇️ depend on CONSUME_MULTIPLE_SEGMENTS. https://github.com/falconry/falcon/blob/4910dd73ecd1b9c8cf6cae045b26ad432fa56128/falcon/routing/converters.py#L46-L53

This is a bit awkward because CONSUME_MULTIPLE_SEGMENTS can only be known at run time, but it's so tightly coupled to the behavior of the class it feels like it should be static.

Can I propose having two classes instead, e.g. BaseConverter and BaseConverterMultipleSegment, with value as str and list[str] respectively?

Then we could probably get rid of ⬇️ and just do an isinstance check. https://github.com/falconry/falcon/blob/4910dd73ecd1b9c8cf6cae045b26ad432fa56128/falcon/routing/converters.py#L61-L62

davetapley avatar Jan 29 '24 23:01 davetapley