-
Notifications
You must be signed in to change notification settings - Fork 148
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
Add type hints to sygnal/utils.py
#276
Conversation
@@ -65,7 +71,7 @@ def glob_to_regex(glob): | |||
return re.compile(r"\A" + res + r"\Z", re.IGNORECASE) | |||
|
|||
|
|||
def _reject_invalid_json(val): | |||
def _reject_invalid_json(val: 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.
Could also use NoReturn
here, but I don't think there's any practical benefit to doing so.
sygnal/utils.py
Outdated
return f"[{self.extra['request_id']}] {msg}", kwargs | ||
|
||
|
||
def glob_to_regex(glob): | ||
def glob_to_regex(glob: str) -> Union[Pattern, Pattern[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.
I don't understand the return type here---why can't we just say it returns a Pattern[str]
in all cases?
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.
I nicked this from somewhere and now I can't remember where, but I think you are correct we can use the narrower case. I will change this.
|
||
async def twisted_sleep(delay, twisted_reactor): | ||
|
||
async def twisted_sleep(delay: float, twisted_reactor: "SygnalReactor") -> 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 fine as it is, but I wanted to mention a couple of alternatives here. One be to write twisted_reactor: IReactorTime
and only import IReactorTime
; a second would be to move SygnalReactor
into a new file, say sygnal/types.py
.
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.
Great, I appreciate knowing alternative solutions, it really helps to have more tools in my arsenal.
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.
I'm happy if mypy is!
As the title states.