Skip to content

Improve thread pool process#12

Open
hima1701 wants to merge 12 commits intoKludex:mainfrom
hima1701:main
Open

Improve thread pool process#12
hima1701 wants to merge 12 commits intoKludex:mainfrom
hima1701:main

Conversation

@hima1701
Copy link
Copy Markdown

@hima1701 hima1701 commented Dec 23, 2024

Description

This PR intends to rectify the pool process through which files are being checked and dumped for type checking using mypy api.

Changes

Promypy dump command :

Exception files :
Previously implemented pool process was not handling timeout errors returned by mypy api. The issue for timeout was because of deeply nested objects . Hence we had to classify those files as exception files so it doesn't fail silently. This is one of the important scenarios to be handled as when verifying JSON payloads, this highlights the exception files which failed type checking.

Processed files :
Introduce set of processed files as we filter out files that failed due to an exception in promypy api. Modify the way we loop in the list of files with that of as_completed futures. Previously there was a mismatch in the error that is being matched with that of filename.

Promypy check command :
Introduce the same pool process to check the files which are passed to mypy api.

Both dump and check have been improvised to handle exceptions and fix the mismatch when processing the result of the pool.

There are also some version which are bumped in the process of updating libraries used .

@hima1701 hima1701 marked this pull request as ready for review December 23, 2024 23:02
@hima1701
Copy link
Copy Markdown
Author

@Kludex This is an amazing pre-commit hook which has helped reduce the typing issues. I have made some improvements which makes it efficient by handling exceptions . Please take a look and review . Thank you!

Copy link
Copy Markdown
Owner

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

I'm happy to accept any PR that is self-contained.

Comment thread promypy/main.py Outdated
Comment thread promypy/main.py
Comment on lines +142 to +145
print(
"promypy failed with exit status code 2. Please raise this issue with the developer."
)
print("Error details: ", api_result)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

What developer? 🤔

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Was added as log to debug incase there is a timeout to reach out to whoever is maintaining the pre-commit hook.

Comment thread .pre-commit-config.yaml
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can we open a different PR for this?

Comment thread promypy/main.py
directory: str = ".",
mypy_args: Optional[str] = None,
timeout: int = 10,
timeout: int = 30,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why the default changed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

mypy was too slow to process even the simplest nested files. Since there were huge number of files which were resulting in timeout exception, we had to change the default instead of passing as an arg.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is this that slow on the latest mypy releases?

But you can pass a different timeout for your use case.

Comment thread promypy/main.py
if filename not in files_to_ignore:
output.append(line)
except TimeoutError: # pragma: no cover
progress.console.print("TimeoutError")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can we speed up the tool instead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That could be something done if they are going to continue using promypy for type checking purposes. This PR is just to have these changes on master in order to avoid using the forked repo.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This seems a bit selfish. The license is MIT, you are free to fork, and publish under a different PyPI domain, as long as you don't remove the license.

@Kludex
Copy link
Copy Markdown
Owner

Kludex commented Dec 26, 2024

Is Deliverect using this?

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
@hima1701
Copy link
Copy Markdown
Author

Is Deliverect using this?

Yes, currently they are.

@Kludex
Copy link
Copy Markdown
Owner

Kludex commented Jan 6, 2025

The tests are not passing.

PR welcome to drop Python 3.7, or maybe you can just fix the problem on the pipeline?


I'm not willing to accept this PR as is. I'd prefer to have minimal PRs. This PR introduces opinionated behavior changes without previous discussion.

That said, I'm happy to continue reviewing PRs if you are willing to open small PRs, with tests.

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