Centralize http binding matching and omit empty payloads#503
Conversation
7f3d7df to
fb8963a
Compare
This changes the way members are classified to use a separate binding matcher. This lets us use the match statement rather than if-else chains and ensures we're minimizing the number of times we have to iterate over the member list. This also adds the ability to select whether a payload should be omitted if nothing is bound to it.
fb8963a to
9a6d18b
Compare
| self.response_status = response_status | ||
| found_body = False | ||
| found_payload = False | ||
| self.bindings = [Binding.BODY] * len(struct.members) |
There was a problem hiding this comment.
Is there we're a reason we're initializing this list here if we're going to swap things out below? Is there a benefit to not just initialize it all at once?
There was a problem hiding this comment.
The order of the members in the dictionary isn't the same as the modeled index order, so we can't just append and expect the order to be right. I've got some ideas on how to change schemas so the member order is represented in the dict though. Perhaps I should put that up, it'll reduce the amount of generated code too.
| self.has_body = found_body | ||
| self.has_payload = found_payload | ||
|
|
||
| def should_write_body(self, omit_empty_payload: bool) -> bool: |
There was a problem hiding this comment.
nit; We may want to potentially make this a keyword only arg? Calling should_write_body(True) is kind of confusing when the parameter is indicating the opposite. I see we're aliasing the value to a parameter with the same name though in actual usage.
This changes the way members are classified to use a separate binding matcher. This lets us use the match statement rather than if-else chains and ensures we're minimizing the number of times we have to iterate over the member list.
This also adds the ability to select whether a payload should be omitted if nothing is bound to it.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.