Skip to content

Correct the increment type for tqdm.update() - #16937

Open
Lushiyao5 wants to merge 2 commits into
python:mainfrom
Lushiyao5:fix-tqdm-update-increment
Open

Lushiyao5 wants to merge 2 commits into
python:mainfrom
Lushiyao5:fix-tqdm-update-increment

Conversation

@Lushiyao5

Copy link
Copy Markdown
Contributor

The standard progress bar compares the increment with zero and adds it to its counter. The current annotation accepts None, which raises TypeError on an enabled bar. The notebook implementation forwards the increment to the standard implementation and returns its result, so it also accepts floats and returns bool | None.

I verified the standard implementation with omitted, integer, float, and None arguments. A mypy check passed for the valid calls and reported only the two expected diagnostics for passing None. Both changed stubs also passed mypy.

Comment thread stubs/tqdm/tqdm/notebook.pyi Outdated

def __iter__(self) -> Iterator[_T]: ...
def update(self, n: int = 1): ... # type: ignore[override]
def update(self, n: FloatInt = 1) -> bool | None: ...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please don't use FloatInt in new code, see the comment in _typeshed/__init__.pyi.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

This branch has not been deployed

No deployments
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