-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Remove setattr with kwargs from HomeServer class #8466
Remove setattr with kwargs from HomeServer class #8466
Conversation
| def inject_cache(obj, kw: dict): | ||
| # Install @cache_in_self attributes | ||
| for key, val in kw.items(): | ||
| setattr(obj, "_" + key, val) | ||
|
|
||
| obj.tls_server_context_factory = Mock() | ||
| obj.tls_client_options_factory = Mock() | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to inject cache-specific attributes, at least be explicit about it
also, deduplicated code for 2 cases down below where it needs to be injected just after creating the homeserver objects and before any branch logic
|
|
||
| inject_cache(hs, kwargs) | ||
|
|
||
| hs.datastore = datastore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
datastore=datastore was added previously, but get_datastore() is not annotated with @cache_in_self, so i'm including this here for any fucky sideeffects it might have
|
|
||
| hs.setup() | ||
| if homeserverToUse.__name__ == "TestHomeServer": | ||
| if homeserver_to_use == TestHomeServer: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless there is another class that is also exactly called TestHomeServer within the test framework, this is more idiomatic
| reactor=None, | ||
| homeserverToUse=TestHomeServer, | ||
| **kargs | ||
| homeserver_to_use: Type[HomeServer] = TestHomeServer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snake_case is more idiomatic for python
I'm not sure that accessing these directly was "wrong" -- I think it was designed to allow for this direct usage. Note that #8060 might have some info on the current implementation.
To clarify -- this PR makes it so that |
| ) | ||
|
|
||
| depname = builder.__name__[len("get_") :] | ||
| # get_attr -> _attr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could change that to this for better clarification:
| # get_attr -> _attr | |
| # get_variable() -> _variable |
Yes, and make it so that any attributes (that're later referred to) are not dynamically set inside
Yes, but seeing that in code somewhere else makes it not "vaguely apparent" that it is not a normal variable, if it's prefixed with Also, I'm trying to help a bit with enforcing an style, |
|
I'm liking these changes, but have questions about others. However, my main concern is that there's a lot going on here, and it's all happening in one commit. I think this PR would be a lot easier to review if each class of change were broken up into its own commit, or its own PR, so that discussion on each change could be compartmentalised. |
|
@anoadragon453 I could split it into; And then follow-up with B. the changes that prefix the I'd close this pull request and cherrypick the changes to a branch and PR change A, after that passes, i'd PR B, would that work? |
|
@ShadowJonathan Sounds like a solid plan, thanks! |
Change
@cache_in_selfto use_-prefixed attributes.Cleanup some misc direct-attribute usages (to
get_X()ones)Add
version_stringattribute toHomeServerFix some tests that acted wonky because of all of this.
Pull Request Checklist
EventStoretoEventWorkerStore.".code blocks.Signed-off-by: Jonathan de Jong <jonathan@automatia.nl>