Skip to content

Improve define_guard typing#205

Merged
deathaxe merged 5 commits intomasterfrom
bugfix/define_guard-typing
Feb 23, 2026
Merged

Improve define_guard typing#205
deathaxe merged 5 commits intomasterfrom
bugfix/define_guard-typing

Conversation

@FichteFoll
Copy link
Member

This required quite a bit of back and forth and I don't exactly consider the result to be readable, but at least it is correct now and it did, in fact, reveal another typing bug.

With these changes, we now pass typechecks in mypy 1.19 (which does not support Python 3.8 as defined in our pyproject.toml and thus cannot be invoked via uv, but it doesn't hurt to be future-proof).

The intention is to eventually silence a couple warnings in mypy 1.19
about missing `self` arguments in the methods annotated by
`define_guard`, but this iteration does not work.

Instead, it exposed another error in `ViewStream` that is addressed in a
later commit.

    error: Self argument missing for a non-static method (or an invalid type for self)  [misc]
It is not possible to satisfy the type signature of
`TextIOBase.readline` due to the conflict with `IOBase.readline`
returning a different type while still being an inherited class.
Instead, we claim that `ViewStream` implements the protocol (which is
semantically equivalent).
Addresses the mypy 1.19 errors that complain about the first argument of
the wrapped guard function not being `self`.

    Self argument missing for a non-static method (or an invalid type for self)

Arguably this also makes the classes easier to read.
@FichteFoll FichteFoll added this to the 2.2.0 milestone Feb 22, 2026
@deathaxe deathaxe merged commit f331b22 into master Feb 23, 2026
1 check passed
@deathaxe deathaxe deleted the bugfix/define_guard-typing branch February 23, 2026 17:14
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