-
Notifications
You must be signed in to change notification settings - Fork 336
Fix a couple type annotations in the RootConfig
/Config
#18409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a couple type annotations in the RootConfig
/Config
#18409
Conversation
@@ -1047,7 +1047,7 @@ def get_instance(self, key: str) -> str: | |||
return self._get_instance(key) | |||
|
|||
|
|||
def read_file(file_path: Any, config_path: Iterable[str]) -> str: | |||
def read_file(file_path: Any, config_path: StrSequence) -> str: |
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.
Updated because error: Argument 2 to "ConfigError" has incompatible type "Iterable[str]"; expected "Union[tuple[str, ...], list[str], None]" [arg-type]
(ConfigError
is used below)
Updating this also catches a few mistakes in our codebase.
@@ -445,7 +445,7 @@ def invoke_all( | |||
return res | |||
|
|||
@classmethod | |||
def invoke_all_static(cls, func_name: str, *args: Any, **kwargs: any) -> None: |
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.
This is a typo. any
isn't a valid type (correct type is Any
)
I assume this wasn't caught because it's defined correctly in the stub file _base.pyi
synapse/synapse/config/_base.pyi
Line 133 in ae877aa
def invoke_all_static(cls, func_name: str, *args: Any, **kwargs: Any) -> None: ... |
See #18409 (comment) > The constructor accepts `Optional[RootConfig]` but the attribute is not > optional `root: RootConfig` and we don't default it when not passed in. We > either need to a) assert is not `None` or b) adjust the function signature > to not allow `Optional`
@@ -170,7 +170,7 @@ class Config: | |||
|
|||
section: ClassVar[str] | |||
|
|||
def __init__(self, root_config: "RootConfig" = None): | |||
def __init__(self, root_config: "RootConfig"): |
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.
Our code assumes this isn't Optional
everywhere. And we always pass it in as far as I can tell. The only place we didn't do this was in the tests but I've updated all of them to pass in a RootConfig
.
synapse/config/_base.pyi
also assumes it isn't Optional
:
synapse/synapse/config/_base.pyi
Lines 179 to 180 in ae877aa
class Config: | |
root: RootConfig |
@@ -0,0 +1 @@ | |||
Fix a couple type annotations in the `RootConfig`/`Config`. |
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.
Complement CI failures are unrelated to this PR and tracked by matrix-org/complement#775
Thanks for the review @erikjohnston 🐝 |
Fix a couple type annotations in the
RootConfig
/Config
. Discovered while cribbing this code for another project.It's really sucks that
mypy
type checking doesn't catch this. I assume this is because we also have asynapse/config/_base.pyi
that overrides all of this. Still unclear to me why theIterable[str]
vsStrSequence
issue wasn't caught as that's whatConfigError
expects.Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.(run the linters)