-
Notifications
You must be signed in to change notification settings - Fork 226
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
Switch to mypy #247
Switch to mypy #247
Conversation
Current status:
(also ran it on cc @tmbo @wochinge FYI. There might be some thing we'd want to fix before 2.0 final release, but maybe non-blocking |
forms: List[Union[Text, Dict]] | ||
|
||
|
||
class ActionCall(TypedDict): |
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.
these type definitions need proper review + docstrings
@@ -213,17 +214,18 @@ def entity_is_desired( | |||
""" | |||
|
|||
# slot name is equal to the entity type | |||
other_slot_equals_entity = other_slot == other_slot_mapping.get("entity") | |||
entity_type = other_slot_mapping.get("entity") | |||
other_slot_equals_entity = other_slot == entity_type |
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 part of a small refactoring done in 4dec28a
@@ -567,7 +578,10 @@ async def _validate_if_required( | |||
if utils.is_coroutine_action(self.validate): | |||
return await self.validate(dispatcher, tracker, domain) | |||
else: | |||
return self.validate(dispatcher, tracker, domain) | |||
# see https://github.com/python/mypy/issues/5206 |
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 we have to do this a lot in rasa, we might consider contributing to mypy to support useful type guards (I honestly don't know how hard it would be, but it could be worth it)
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.
yes this sounds like a good idea 👍 maybe something for someone from the team to contribute?
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.
yes definitely. I will keep this as a note for now, and if this comes back I'll mention it (in backend eng meeting for instance)
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.
looks great, excited to replace pytype 💀 😂
from typing_extensions import TypedDict | ||
|
||
|
||
class TrackerState(TypedDict): |
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.
should we rather use pythons new data classes? (and a backport for 3.6 https://pypi.org/project/dataclasses/)
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 think that could be better indeed, but I do not know enough about the specifics of the tracker state / action call:
- would renaming the method
from_dict()
tofrom_dataclass()
be acceptable? - is the type definition I made here valid? (I marked some elements required, before they were optional)
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.
after thinking a bit more about it, I'm not sure that we would benefit from the dataclass here (vs keeping the TypedDict). And if we wanted to do this it might change the public API of the SDK. For instance, instead of calling custom action with plain dicts, we would call them with dataclasses. And I'm not sure it's worth the trouble. WDYT?
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.
ok that sounds reasonable, let's stick with the typeddicts 👍
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.
looks great - amazing push for better tooling 🚀
from typing_extensions import TypedDict | ||
|
||
|
||
class TrackerState(TypedDict): |
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.
ok that sounds reasonable, let's stick with the typeddicts 👍
Proposed changes:
pytype
it took 35s; now it seems to take 2s withmypy
Status (please check what you already did):
black
(please check Readme for instructions)