Skip to content

fix: correct type annotations for alive_bar and alive_it#311

Closed
daniel7an wants to merge 1 commit intorsalmei:mainfrom
daniel7an:fix/issue-306-typing
Closed

fix: correct type annotations for alive_bar and alive_it#311
daniel7an wants to merge 1 commit intorsalmei:mainfrom
daniel7an:fix/issue-306-typing

Conversation

@daniel7an
Copy link
Copy Markdown

Fixes #306

Problem

  • alive_bar had no return type annotation, showing up as Any to type checkers
  • alive_it returned Iterable[T], hiding the bar handle methods (.text(), .title(), etc.) from type checkers

Changes

  • alive_bar now returns AbstractContextManager[__AliveBarHandle], so type checkers know the with statement yields a proper bar handle with text, title, pause, current, monitor, rate, eta, elapsed, and receipt attributes
  • alive_it now returns __AliveBarIteratorAdapter[T] instead of Iterable[T], so code like progress.text('...') type-checks correctly while still being recognized as iterable
  • Added type annotations on __AliveBarIteratorAdapter for the proxied bar handle attributes
  • Added Iterator[T] return type to __iter__
  • Made __AliveBarIteratorAdapter properly Generic[T]

Example

# Before: progress.text() would be a type error
progress = alive_it(my_items)
for item in progress:
    progress.text(item.name)  # now type-checks correctly

- alive_bar now returns AbstractContextManager[__AliveBarHandle] instead of untyped
- alive_it now returns __AliveBarIteratorAdapter[T] instead of Iterable[T], exposing
  bar handle attributes (text, title, current, monitor, rate, eta, elapsed)
- __AliveBarIteratorAdapter.__iter__ now has proper Iterator[T] return type
- Make __AliveBarIteratorAdapter properly Generic[T]

Fixes #306
@rsalmei
Copy link
Copy Markdown
Owner

rsalmei commented Feb 10, 2026

Thanks a lot! That’s fantastic, @daniel7an 👍

@daniel7an daniel7an closed this by deleting the head repository Mar 11, 2026
@rsalmei
Copy link
Copy Markdown
Owner

rsalmei commented Mar 18, 2026

Oh, sorry, I haven’t merged it yet, @daniel7an. My local repository is quite messed up because I was testing some changes. But I did intend to merge it sometime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3.3.0 typing is incorrect for both alive_bar and alive_it

2 participants