Skip to content

Conversation

@rwb27
Copy link
Collaborator

@rwb27 rwb27 commented Jan 28, 2026

Previously, BaseDescriptor typed the owning object as Thing, which was a bit loose and led to some vague type hints (particularly for functional properties and actions).

I've added a second generic parameter for the owning class. This makes some of the type test code a bit more verbose, but it gets rid of a fair few type: ignore statements and also means we now detect a few type errors that were previously missed.

This is mostly tidying up, but will be useful for some PRs in the near future.

Closes #217
Closes #162

rwb27 added 5 commits January 28, 2026 16:53
Previously, BaseDescriptor typed the owning object as `Thing`, which was
a bit loose and led to some vague type hints (particularly for functional
properties and actions).

I've added a second generic parameter for the owning class. This makes some of the type test code
a bit more verbose, but it gets rid of
a fair few `type: ignore` statements
and also means we now detect a few
type errors that were previously missed.

This is mostly tidying up, but will be useful for some PRs in the near future.
This uses the new generic parameter for the descriptor's Owner to correctly type the function's `self` parameter, among other things.
This was a one-character fix: we now need the second argument when
inspecting `__orig_class__` to get the
value type.

This is only used when a descriptor is created using subscript syntax, e.g.
`prop = Property[Thing, int](default=0)`.

Happily, it was picked up in tests, and is now passing.
This now correctly uses the `Owner` type variable in `BaseDescriptor`. `mypy` picked up an inconsistency between this and `ActionDescriptor`, but oddly not on Python 3.10.
@barecheck
Copy link

barecheck bot commented Jan 28, 2026

Barecheck - Code coverage report

Total: 96.31%

Your code coverage diff: 0.01% ▴

Uncovered files and lines
FileLines
src/labthings_fastapi/actions.py162-163, 414-415, 539-540, 553, 578-579, 704, 850-851, 854, 857, 905
src/labthings_fastapi/properties.py677, 681, 704-707, 779, 798, 931

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.

Consider making BaseDescriptor generic with respect to the host class. A test in typing_tests/thing_definitions.py passes and I don't understand why.

2 participants