Repository navigation
Conversation
| def __getattr__(self, name: str) -> Any: | ||
| return getattr(self._server, name) | ||
|
|
||
| def __setattr__(self, name: str, value: Any) -> None: |
There was a problem hiding this comment.
I see the motivation behind of this change, but I think this change raises some questions:
- This will cause the setting of the main httpserver in an "incompatible" way as it will override a value which was set before.
So the code
baked.no_handler_status_code = 404Won't tell us that it has propagated the setting to the main httpserver and thereby affected all the requests sent to the server.
You can argue that the other expect_request and expect_oneshot_request and others also update the main serve but these are rather extending the list of the expected requests, not overriding them.
- I don't like the
__setattr__implementation, I think this could be done with a property specifically with setters and getters (so we turn the attribute to a property first, then we can customize the setter here to update the parent server as well).
What do you think?
There was a problem hiding this comment.
Your example is right: with this PR, setting the value on the baked proxy changes the parent too, so the later request returns 404 rather than 500.
The original problem was that the proxy could report 404 while the actual server still returned 500. The current fix goes too far in the other direction by silently making public assignments affect the shared server.
A small prototype with an explicit getter/setter has the same global effect. Both objects use the same server URL, so changing the implementation to properties alone doesn't settle which object should own the setting.
I agree the blanket __setattr__ should go. For its replacement, would you prefer selected properties documented as shared settings, or read-only properties that reject assignment and require configuring the parent explicitly? Per-proxy response settings would need separate request scoping rather than a setter forwarding to the shared server.
I'll hold the code changes while we settle that contract.
There was a problem hiding this comment.
I think a read-only property would be a good choice here. So the proxy (made by bake()) would reject setting this value as this would have no effect at all. When getting the value it could return the one from the main server.
I'd still keep the current attribute in the scope only.
Assigning
no_handler_status_codeon a baked proxy can leave it reporting a value that does not match the real server's responses. Expose that setting as an explicit read-only property instead: reads reflect the parent's current value, while assignment and deletion raiseAttributeError.Configure
httpserver.no_handler_status_codedirectly when changing the shared server. Sibling and chained proxies then read the updated setting, including its reset afterclear(). This is limited to that one attribute; other assignment behavior remains unchanged.Validation:
make cov,make precommit,make mypyandmake docpass;bake.pyhas 100% coverage. Optional warning-as-error docs still have the same 61 baseline warnings.Linux and Windows execution remain for CI.