-
Notifications
You must be signed in to change notification settings - Fork 22
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
Adopt sp-repo-review #89
Conversation
docs/user_guide/application.md
Outdated
schema = """ | ||
$id: http://myapplication.org/my-method | ||
version: 1 | ||
title: My Method Executed | ||
description: My method was executed one time. | ||
properties: | ||
msg: | ||
title: Message | ||
type: string | ||
""" | ||
|
||
self.eventlogger.register_event_schema( | ||
schema=schema | ||
) |
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.
The indent here was intentional, since it's part of the method from the preview code chunk.
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.
Fixed
docs/user_guide/application.md
Outdated
def my_method(self): | ||
# Do something | ||
... | ||
# Emit event telling listeners that this event happened. | ||
self.eventlogger.emit(schema_id="myapplication.org/my-method", data={"msg": "Hello, world!"}) | ||
# Do something else... | ||
... |
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.
Same here. This indent is intentional.
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.
Hmm, this was auto-formatted by blacken-docs, maybe we need to skip this file.
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.
Fixed by skipping
Thanks, @blink1073!
Thanks for pointing this out. I added this logic to catch invalid function at runtime and raise a clear error, since 1) it's possible (and not uncommon) to define a listener/modifier function after a live instance of this class has been created and 2) it's way too easy to define an invalid function. 😅 We lose this by relying on (static) type checker's right? There is no way to validate a function signature when it's defined after the start of runtime? |
Actually, here's a thought. If the parameters are non-string, we use |
Looking at this again, I don't follow what the issue is. The typing you added looks great to me. Why does the |
I couldn't use Here's an illustration: In [1]: async def listener_signature_str_ann(
...: logger: "EventLogger", schema_id: "str", data: "dict"
...: ) -> "None":
...: """An interface for a listener."""
...: ...
...:
In [2]: async def listener_signature(logger: object, schema_id: str, data: dict) -> None:
...: """An interface for a listener."""
...: ...
...:
In [3]: import inspect
In [4]: inspect.signature(listener_signature)
Out[4]: <Signature (logger: object, schema_id: str, data: dict) -> None>
In [5]: inspect.signature(listener_signature_str_ann)
Out[5]: <Signature (logger: 'EventLogger', schema_id: 'str', data: 'dict') -> 'None'>
In [10]: inspect.signature(listener_signature_str_ann).parameters['logger'].annotation
Out[10]: 'EventLogger'
In [11]: inspect.signature(listener_signature).parameters['logger'].annotation
Out[11]: object |
In #88 I added support for an annotated string, but it only works for |
Oh, I see. Yeah, you're right. Let's drop the Thank you for doing this work! |
@Zsailer heads up, I dropped the use of
inspect.signature
since it doesn't mix well withmypy
whenfrom __future__ import annotations
is used. Now that we're embracing typing, the type checker should be the one enforcing the signature.