Skip to content

Conversation

@rwb27
Copy link
Collaborator

@rwb27 rwb27 commented Dec 8, 2025

Following the example of properties, I've added some test code that will make mypy flag issues with typing actions.

This new test currently fails, showing that the current Descriptor is not typed correctly. I will try to get this mergeable quickly, in the hope I can sneak it into v0.0.12 as a bug fix: I had hoped actions could be type checked already.

My intention is to:

  • Make ActionDescriptor inherit from BaseDescriptor (to tidy up name/title/description handling and ensure __get__ is consistent).
  • Make ActionDescriptor generic, so that it correctly describes the bound function.
  • Annotate lt.action correctly, so that it can be type checked.

@barecheck
Copy link

barecheck bot commented Dec 8, 2025

Barecheck - Code coverage report

Total: 95.03%

Your code coverage diff: 0.02% ▴

Uncovered files and lines
FileLines
src/labthings_fastapi/actions.py162-163, 414-415, 543-544, 557, 582-583, 708, 857-858, 861, 864, 912

@rwb27
Copy link
Collaborator Author

rwb27 commented Dec 8, 2025

The failures on unpinned deps are due to a change in FastAPI. This is a trivial fix but, for clarity, I'll do that in a separate PR.

@rwb27
Copy link
Collaborator Author

rwb27 commented Dec 8, 2025

@bprobert97 I thought you might like to see my typing tests expand (and, indeed, drive development). I think one of you and Julian is sufficient: I don't think this needs double review.

@julianstirling
Copy link
Contributor

Do the tests on GitHub run on the branch or the merged result? Probably best to fix the unpinned deps and then check this all passes?

@bprobert97
Copy link
Contributor

Happy with code changes once tests pass

rwb27 added 7 commits December 9, 2025 12:31
Following the example of properties, I've added some test code that will make `mypy` flag issues with typing actions.

This new test currently fails, showing that the current Descriptor is not typed correctly.
This introduces two changes:

1. actions are now properly type hinted.
2. ActionDescriptor now inherits from BaseDescriptor.

The significance of these two changes will be described at more length in the MR thread.

Inheriting from BaseDescriptor deduplicates some boilerplate, and deduplicates handling of name/title/description.

The main change is that we now use TypeVar and ParamSpec to fully describe the function being wrapped. ActionDescriptor is generic in three parameters, which allows us to pass the type of the bound function through the descriptor properly.

There was an assumption that the name of the function matches the name of the descriptor. This is now explicit.

Currently, the only fudge is that the type of the owning Thing isn't perfect. This is a limitation of BaseDescriptor, which doesn't have a generic parameter for the owning Thing.
We were creating a new subclass of ActionDescriptor each time we instantiated it in `lt.action`.
I'm fairly sure this was done because, in the past, we manipulated `__init__` or similar. That's no longer an issue.

I have added a test to make sure rewriting `self.__doc__` has the intended effect.
Removed a TODO in favour of an issue, and expanded an acronym.
Copy link
Contributor

@julianstirling julianstirling left a comment

Choose a reason for hiding this comment

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

Thanks for the rebase, tests are now passing.

@rwb27
Copy link
Collaborator Author

rwb27 commented Dec 9, 2025

I've rebased on #216 so all tests now pass.

@rwb27 rwb27 merged commit ea6b00a into main Dec 9, 2025
14 checks passed
@rwb27 rwb27 deleted the action_typing branch December 9, 2025 12:35
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.

4 participants