Skip to content

feat: add a System type alias for the system arguments - #127

Merged
proxi merged 2 commits into
mainfrom
proxi/system-type-alias
Dec 1, 2026
Merged

proxi merged 2 commits into
mainfrom
proxi/system-type-alias

Conversation

@proxi

@proxi proxi commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

First step towards mypy --disallow-untyped-defs: say what system really accepts.

The system arguments have accepted a redis-py client or pipeline as well as a registered name since 6026462 (2015), and the docstrings say "string, Redis instance, or Pipeline instance". The annotations said str, so type checkers rejected the documented usage.

  • Adds System = str | Redis to bitmapist. A pipeline is covered, since Pipeline subclasses Redis.
  • Uses it for the 11 parameters that were annotated system: str (get_redis, mark_event, unmark_event, mark_unique, unmark_unique, get_event_names, delete_all_events, delete_temporary_bitop_keys, and three event class methods).
  • Adds test_system_accepts_client_and_pipeline: passing a client or a pipeline had no test.

No runtime change, apart from redis.client.Redis now being imported at runtime (the alias needs it; redis was imported already).

Not in this PR: the system parameters that have no annotation yet (most event classes, bitmapist.cohort). They get System when those modules are typed.

mypy passes in the project env and with the pre-commit hook's setup. I could not run the test suite locally (no Redis backend), so the new test is verified by CI only.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XGjgWiXoieBLCLiXckPSe9

The system arguments have accepted a redis-py client or pipeline as well
as a registered name since 6026462 (2015), and the docstrings say so,
but the annotations said 'str'. Type checkers rejected the documented
usage.

Add 'System = str | Redis | Pipeline' and use it for the 11 parameters
that were annotated 'system: str'. No runtime change.

Passing a client or a pipeline had no test, so add one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XGjgWiXoieBLCLiXckPSe9
@proxi proxi added the 🚢 Ship PR requires passing checks before merge, but no independent human review. label Dec 1, 2026
@proxi
proxi marked this pull request as ready for review December 1, 2026 12:28

@doistbot doistbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, clean typing step: System = str | Redis | Pipeline now matches what the system parameters have actually accepted since 2015, and it's applied consistently across the 11 annotated parameters, with a new test covering the previously untested client/pipeline usage. No inline issues were flagged; the only open item is CI confirmation of the new test since it couldn't run locally without a Redis backend.

I also left one optional follow-up note in the details below.

Optional follow-up note (1)
  • P3 bitmapist/init.py:100: Pipeline is a subclass of Redis in redis-py, so type checkers collapse Redis | Pipeline to Redis; the extra member doesn't widen what System accepts. The comment above already documents that pipelines are supported, so this can just be System: TypeAlias = str | Redis.

Share Feedback • Review Logs • Trace

Pipeline subclasses Redis, so listing it added nothing to what the
alias accepts. Pipeline goes back to a type-checking-only import.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XGjgWiXoieBLCLiXckPSe9
@proxi

proxi commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

This comment was posted by Claude on Janusz's behalf, as part of addressing the doistbot review.

Pipeline is a subclass of Redis in redis-py, so type checkers collapse Redis | Pipeline to Redis; the extra member doesn't widen what System accepts. [...] this can just be System: TypeAlias = str | Redis.

Changed in 805afc4: the alias is now str | Redis, the comment above it says a pipeline is a client too, and Pipeline is back to a type-checking-only import. mypy still accepts system=client.pipeline(), and the new test covers that case at runtime.

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

Labels

🚢 Ship PR requires passing checks before merge, but no independent human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants