Skip to content
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

Enable union-attr mypy check and fix issues #10942

Merged
merged 23 commits into from
Mar 3, 2022
Merged

Conversation

ancalita
Copy link
Member

@ancalita ancalita commented Feb 23, 2022

Proposed changes:

Status (please check what you already did):

  • added some tests for the functionality
  • updated the documentation
  • updated the changelog (please check changelog for instructions)
  • reformat files using black (please check Readme for instructions)

@ancalita ancalita requested review from wochinge and m-vdb February 25, 2022 12:37
@ancalita ancalita marked this pull request as ready for review February 25, 2022 12:37
@ancalita ancalita requested a review from a team February 25, 2022 12:37
@ancalita ancalita requested a review from a team as a code owner February 25, 2022 12:37
@ancalita ancalita requested review from dakshvar22 and removed request for a team February 25, 2022 12:37
@ancalita
Copy link
Member Author

There are 6 errors left unfixed:

rasa/shared/core/domain.py:1499: error: Item "bool" of "Union[bool, List[Any]]" has no attribute "__iter__" (not iterable)  [union-attr]
rasa/shared/core/training_data/visualization.py:345: error: Item "UserUttered" of "Union[ActionExecuted, UserUttered]" has no attribute "action_name"  [union-attr]
rasa/engine/validation.py:454: error: Item "None" of "Optional[ParameterInfo]" has no attribute "type_annotation"  [union-attr]
rasa/nlu/classifiers/sklearn_intent_classifier.py:243: error: Item "None" of "Optional[Any]" has no attribute "predict_proba"  [union-attr]
rasa/core/agent.py:453: error: Item "None" of "Optional[MessageProcessor]" has no attribute "log_message"  [union-attr]
rasa/core/test.py:874: error: Item "None" of "Optional[MessageProcessor]" has no attribute "parse_message"  [union-attr]

The first one appears in a domain method that will be removed once the domain loading tech debt PR gets merged.
The other 5 I found difficult to fix - so I think it's best to ignore them with the no-qa comment? Unless there are other suggestions?

Copy link
Collaborator

@m-vdb m-vdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐞

rasa/core/actions/action.py Outdated Show resolved Hide resolved
rasa/core/actions/action.py Outdated Show resolved Hide resolved
rasa/core/actions/forms.py Outdated Show resolved Hide resolved
rasa/core/actions/forms.py Outdated Show resolved Hide resolved
rasa/core/agent.py Outdated Show resolved Hide resolved
rasa/shared/nlu/training_data/loading.py Outdated Show resolved Hide resolved
rasa/utils/tensorflow/rasa_layers.py Outdated Show resolved Hide resolved
rasa/utils/tensorflow/temp_keras_modules.py Outdated Show resolved Hide resolved
rasa/validator.py Outdated Show resolved Hide resolved
rasa/validator.py Outdated Show resolved Hide resolved
@m-vdb
Copy link
Collaborator

m-vdb commented Feb 28, 2022

for the other errors you mentioned:

rasa/shared/core/domain.py:1499: error: Item "bool" of "Union[bool, List[Any]]" has no attribute "iter" (not iterable) [union-attr]

Is there a way to fix the type definition of self.intent_properties? It's not accurate. Maybe with a TypedDict?

rasa/shared/core/training_data/visualization.py:345: error: Item "UserUttered" of "Union[ActionExecuted, UserUttered]" has no attribute "action_name" [union-attr]

I think it's because mypy cannot pickup the type of o_cleaned[i]. Have you tried defining a variable, e.g. o = o_cleaned[i] to see if mypy picks it up properly?

rasa/engine/validation.py:454: error: Item "None" of "Optional[ParameterInfo]" has no attribute "type_annotation" [union-attr]

this seems like a bug actually, because not needs_passed_to_kwargs is in fact not has_kwargs or required_type is not None, so it means that required_type can actually be None 🤔

rasa/nlu/classifiers/sklearn_intent_classifier.py:243: error: Item "None" of "Optional[Any]" has no attribute "predict_proba" [union-attr]

self.clf type is not accurate, but that's not what's causing the issue. That's weird. Does reveal_type() reveal anything?

rasa/core/agent.py:453: error: Item "None" of "Optional[MessageProcessor]" has no attribute "log_message" [union-attr]

what happens if you do a if self.processor check before?

rasa/core/test.py:874: error: Item "None" of "Optional[MessageProcessor]" has no attribute "parse_message" [union-attr]

should we raise an internal error line 826 if processor is not defined?

@dakshvar22 dakshvar22 removed their request for review February 28, 2022 16:34
@ancalita
Copy link
Member Author

ancalita commented Mar 1, 2022

for the other errors you mentioned:

@m-vdb I've managed to implement feedback for a few of them, but have got 2 left that cannot fix:

rasa/nlu/classifiers/sklearn_intent_classifier.py:243: error: Item "None" of "Optional[Any]" has no attribute "predict_proba" [union-attr]
self.clf type is not accurate, but that's not what's causing the issue. That's weird. Does reveal_type() reveal anything?

I used reveal_type and mypy didn't show anything 😕

rasa/core/agent.py:453: error: Item "None" of "Optional[MessageProcessor]" has no attribute "log_message" [union-attr]
what happens if you do a if self.processor check before?

I thought of this, but didn't know what to return, since it expects a DialogueStateTracker instance. Instantiate an empty one with the sender id from the user message?

@m-vdb
Copy link
Collaborator

m-vdb commented Mar 1, 2022

for the last two:

  • the first one is very weird. Maybe it's because self.clf can be None, but the type is not accurate (check the init method). It should be clf: Optional["sklearn.model_selection.GridSearchCV"] = None,.
  • this one seems to be the same "agent_must_be_ready" issue. I think you can ignore it

@ancalita ancalita requested review from m-vdb and removed request for wochinge March 2, 2022 14:07
Copy link
Collaborator

@m-vdb m-vdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 🎉 I've left a couple of more minor comments, but it's ready to merge!

rasa/shared/core/generator.py Outdated Show resolved Hide resolved
@ancalita ancalita enabled auto-merge (squash) March 3, 2022 15:40
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2022

🚀 A preview of the docs have been deployed at the following URL: https://10942--rasahq-docs-rasa-v2.netlify.app/docs/rasa

@ancalita ancalita merged commit ec8de9b into main Mar 3, 2022
@ancalita ancalita deleted the 9096/mypy-union-attr branch March 3, 2022 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable mypy union-attr error code
2 participants