Skip to content

Ele 381 add mypy to the cli repo - step 1#837

Merged
haritamar merged 15 commits into
masterfrom
ele-381-add-mypy-to-the-cli-repo
May 21, 2023
Merged

Ele 381 add mypy to the cli repo - step 1#837
haritamar merged 15 commits into
masterfrom
ele-381-add-mypy-to-the-cli-repo

Conversation

@haritamar
Copy link
Copy Markdown
Collaborator

No description provided.

@linear
Copy link
Copy Markdown

linear Bot commented Apr 27, 2023

ELE-381 Add MyPy to the CLI repo

We use type hints extensively in our python code, but we have a lot of errors that are currently untested in the CI.

We want to add MyPy to our CI process - but that also requires fixing the existing errors we have. This is something the longer we wait with the harder it will become.

DoD:

  • MyPy is a part of our CI process.

@github-actions
Copy link
Copy Markdown
Contributor

👋 @haritamar
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in this pull request.

Comment thread mypy.ini Outdated
Comment thread mypy.ini
allow_redefinition = True

[mypy-alive_progress]
ignore_missing_imports = True
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

For every library that didn't have a "stubs" library I needed to do this (See the libs I added to dev-requirements.txt)

Comment thread elementary/monitor/api/filters/filters.py Outdated
Receives a list of strings, either JSON dumped or not, dedups and sorts it, and returns it as a comma-separated
string.
This is useful for various lists we include in slack messages (owners, subscribers, etc)
"""
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I removed prettify_json_str_set because it was confusing.
Made this function always return a string because that's the intention (it's for the owner list in slack messages)

@haritamar haritamar force-pushed the ele-381-add-mypy-to-the-cli-repo branch from 93faac8 to d3dfbf0 Compare May 17, 2023 14:37
Comment thread elementary/monitor/alerts/alerts.py
return []
result = []
for model_error_alert in model_error_alert_list:
assert isinstance(model_error_alert, ModelAlert)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How could a non ModelAlert be in this list in the first place?
Maybe we should make a check and raise an error?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The problem is that self._components_to_alerts is a dict whose value changes according to the provided key. There's no way that I can tell to make mypy understand it.
Changed to an exception though.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(may worth refactoring, but I want to avoid it for now)

Comment thread elementary/monitor/alerts/alert.py Outdated
Copy link
Copy Markdown
Contributor

@elongl elongl left a comment

Choose a reason for hiding this comment

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

I think we should perhaps use the base classes in the typings rather than cast() to the parent classes. Additionally we might use Generics for that. I'd also avoid using assert as Python recommends to only use that keyword for tests and debugging purposes.

Comment thread elementary/monitor/api/alerts/alerts.py Outdated
Comment thread elementary/monitor/api/lineage/lineage.py Outdated
@haritamar haritamar merged commit 8596f14 into master May 21, 2023
@haritamar haritamar deleted the ele-381-add-mypy-to-the-cli-repo branch May 21, 2023 09:25
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.

2 participants