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
Type stubs for tqdm library #8235
Conversation
This comment has been minimized.
This comment has been minimized.
It's fine to use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Thanks for the PR! We'll take a full look when the tests are passing (feel free to ask if you need a hand with any of them).
Please don't make unrelated changes to CONTRIBUTING.md
in this PR, though. If you think that needs to be changed, please do that in its own PR. It'll make for a very confusing git history otherwise.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
If the implementation breaks LSP by having an incompatible override, the best thing to do is to mimic the implementation exactly and add a |
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: ignite (https://github.com/pytorch/ignite)
+ ignite/contrib/handlers/tqdm_logger.py:141: error: Incompatible types in assignment (expression has type "tqdm[<nothing>]", variable has type "None") [assignment]
optuna (https://github.com/optuna/optuna)
+ optuna/progress_bar.py:57: error: Need type annotation for "_progress_bar"
+ optuna/progress_bar.py:67: error: Argument 1 to "format_interval" of "tqdm" has incompatible type "Optional[float]"; expected "float"
+ optuna/integration/_lightgbm_tuner/optimize.py:622: error: Need type annotation for "pbar"
rclip (https://github.com/yurijmikhalevich/rclip)
- rclip/main.py:8: error: Cannot find implementation or library stub for module named "tqdm"
pyppeteer (https://github.com/pyppeteer/pyppeteer)
+ pyppeteer/chromium_downloader.py:92: error: Need type annotation for "process_bar"
+ pyppeteer/chromium_downloader.py:94: error: Argument "file" to "tqdm" has incompatible type "Optional[str]"; expected "Optional[SupportsWrite[str]]"
|
1 similar comment
Diff from mypy_primer, showing the effect of this PR on open source code: ignite (https://github.com/pytorch/ignite)
+ ignite/contrib/handlers/tqdm_logger.py:141: error: Incompatible types in assignment (expression has type "tqdm[<nothing>]", variable has type "None") [assignment]
optuna (https://github.com/optuna/optuna)
+ optuna/progress_bar.py:57: error: Need type annotation for "_progress_bar"
+ optuna/progress_bar.py:67: error: Argument 1 to "format_interval" of "tqdm" has incompatible type "Optional[float]"; expected "float"
+ optuna/integration/_lightgbm_tuner/optimize.py:622: error: Need type annotation for "pbar"
rclip (https://github.com/yurijmikhalevich/rclip)
- rclip/main.py:8: error: Cannot find implementation or library stub for module named "tqdm"
pyppeteer (https://github.com/pyppeteer/pyppeteer)
+ pyppeteer/chromium_downloader.py:92: error: Need type annotation for "process_bar"
+ pyppeteer/chromium_downloader.py:94: error: Argument "file" to "tqdm" has incompatible type "Optional[str]"; expected "Optional[SupportsWrite[str]]"
|
Diff from mypy_primer, showing the effect of this PR on open source code: ignite (https://github.com/pytorch/ignite)
+ ignite/contrib/handlers/tqdm_logger.py:141: error: Incompatible types in assignment (expression has type "tqdm[Any]", variable has type "None") [assignment]
optuna (https://github.com/optuna/optuna)
+ optuna/progress_bar.py:57: error: Need type annotation for "_progress_bar"
+ optuna/progress_bar.py:67: error: Argument 1 to "format_interval" of "tqdm" has incompatible type "Optional[float]"; expected "float"
rclip (https://github.com/yurijmikhalevich/rclip)
- rclip/main.py:8: error: Cannot find implementation or library stub for module named "tqdm"
pyppeteer (https://github.com/pyppeteer/pyppeteer)
+ pyppeteer/chromium_downloader.py:94: error: Argument "file" to "tqdm" has incompatible type "Optional[str]"; expected "Optional[SupportsWrite[str]]"
|
(I might need to iterate a little bit to tackle these primer errors) |
Diff from mypy_primer, showing the effect of this PR on open source code: ignite (https://github.com/pytorch/ignite)
+ ignite/contrib/handlers/tqdm_logger.py:141: error: Incompatible types in assignment (expression has type "tqdm[Any]", variable has type "None") [assignment]
optuna (https://github.com/optuna/optuna)
+ optuna/progress_bar.py:67: error: Argument 1 to "format_interval" of "tqdm" has incompatible type "Optional[float]"; expected "float"
rclip (https://github.com/yurijmikhalevich/rclip)
- rclip/main.py:8: error: Cannot find implementation or library stub for module named "tqdm"
pyppeteer (https://github.com/pyppeteer/pyppeteer)
+ pyppeteer/chromium_downloader.py:94: error: Argument "file" to "tqdm" has incompatible type "Optional[str]"; expected "Optional[SupportsWrite[str]]"
|
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.
Awesome, thanks for your patience! The remaining mypy_primer hits all look like true positives to me (except the pyppeteer
one, which I can't make head or tail of... but you can't catch them all ¯\_(ツ)_/¯
)
Weird, https://github.com/pyppeteer/pyppeteer/blob/f98f9030d3d40dc629bf08f93672f05caf8dfb0e/pyppeteer/chromium_downloader.py#L94 doesn't have a |
Yeah, I have no idea. Weirdly, the default branch for |
There's a hardcoded revision: https://github.com/hauntsaninja/mypy_primer/blob/d91de1f533963a41d362531147c2ff407c286433/mypy_primer.py#L1431 This is the version it's checking: https://github.com/pyppeteer/pyppeteer/blob/2d27bfdf9b6d0df32e5ebe869b057409042417a8/pyppeteer/chromium_downloader.py#L94 |
Hmm, seems like primer's been hardcoded to that revision for 2 years now. I wonder if |
python/typeshed#8235 (comment) It's not clear from the comment why this was hardcoded. Let's use this PR to figure out whether we can drop the pin.
Awesome to see this go in! Thanks a lot @AlexWaygood for making contributing so smooth and welcoming! |
python/typeshed#8235 (comment) It's not clear from the comment why this was hardcoded.
@AlexWaygood Thanks for your work, that really cool to finally have typings for it. with logging_redirect_tqdm():
pass
|
@alkatar21 thanks! I've filed #8251. |
And, merged (thanks for the quick review @srittau!). A new release should be shortly auto-uploaded to PyPI by the typeshed bots :) |
While tqdm is very popular, it is not only not typed, but strips the types of sequences it receives due to the way it works.
This should resolve the issue for most users.
An issue to add type hints to tqdm has been around since 2016, but hasn't seen any progress.