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

Add typing to utils #139

Merged
merged 12 commits into from
Apr 4, 2024
Merged

Add typing to utils #139

merged 12 commits into from
Apr 4, 2024

Conversation

dstansby
Copy link
Contributor

Because apparently I type for fun now?

Copy link
Owner

@Cadair Cadair left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I would not be adverse to eventually having full typing support in parfive I think it would make some things easier to reason with.

Apart from the runtime aioftp issue, my comments are mainly my inexperience with typing and my general frustration at what feels like weird work arounds.

parfive/utils.py Outdated
from pathlib import Path
from itertools import count
from concurrent.futures import ThreadPoolExecutor

import aioftp
Copy link
Owner

Choose a reason for hiding this comment

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

aioftp is an optional dependency which currently should only be needed if you try to download a file with an ftp:/ scheme. I think this would break that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I've put this import under a TYPE_CHECKING guard so it's only imported when type checking.

parfive/utils.py Outdated
@@ -159,47 +162,50 @@ def sha256sum(filename):


class MultiPartDownloadError(Exception):
def __init__(self, response):
def __init__(self, response: requests.Response) -> None:
Copy link
Owner

Choose a reason for hiding this comment

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

<rant> requiring you explicitly type -> None on __init__ seems very silly as you can't actually return anything even if you wanted to </rant>

parfive/utils.py Outdated
"""
Given a path generate a unique filename.
"""
path = pathlib.Path(path)
path_ = pathlib.Path(path)
Copy link
Owner

Choose a reason for hiding this comment

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

🙄 I find this mypy error particularly frustrating. It seems very antithetical to writing clean Python code. Especially here where you are effectively doing runtime type validation.

For my own education: is there a way to persuade mypy to allow explicit type casting like this? or is any change of type an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think any change in type is an error 😢 . I'll just put a type ignore comment after it, I agree that this is a bit of a pain. Edit: turns out this doesn't matter until/if mypy is set to strict, so I just undid these variable renaming changes.

@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

Attention: Patch coverage is 96.15385% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 90.20%. Comparing base (3b049c5) to head (e8e09f8).
Report is 5 commits behind head on main.

❗ Current head e8e09f8 differs from pull request most recent head 4471513. Consider uploading reports for the commit 4471513 to get more accurate results

Files Patch % Lines
parfive/utils.py 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #139      +/-   ##
==========================================
- Coverage   90.23%   90.20%   -0.04%     
==========================================
  Files           5        5              
  Lines         635      643       +8     
==========================================
+ Hits          573      580       +7     
- Misses         62       63       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Cadair
Copy link
Owner

Cadair commented Oct 20, 2023

Other than the fact that the mypy ci is angry it looks good.

@Cadair Cadair merged commit d49ed03 into Cadair:main Apr 4, 2024
9 of 11 checks passed
@dstansby dstansby deleted the type-utils branch April 4, 2024 17:41
@Cadair Cadair added the misc Small internal changes or updates label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
misc Small internal changes or updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants