Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

619 move to pyright #632

Merged
merged 25 commits into from
Nov 21, 2024
Merged

619 move to pyright #632

merged 25 commits into from
Nov 21, 2024

Conversation

stan-dot
Copy link
Contributor

@stan-dot stan-dot commented Sep 11, 2024

Move to pyright simplifies the setup and gives more precise feedback on the code quality

@stan-dot stan-dot added documentation Improvements or additions to documentation dependencies Pull requests that update a dependency file python Pull requests that update Python code dev-environment Issues for improving the developer environment/experience labels Sep 11, 2024
@stan-dot stan-dot self-assigned this Sep 11, 2024
@stan-dot stan-dot linked an issue Sep 11, 2024 that may be closed by this pull request
@stan-dot
Copy link
Contributor Author

stan-dot commented Oct 4, 2024

@callumforrester please let me know your thoughts

@callumforrester
Copy link
Contributor

@stan-dot I like where this is going, thanks

@stan-dot
Copy link
Contributor Author

ok will try to finish this today

@stan-dot stan-dot force-pushed the 619-move-to-pyright branch from 48371ac to d28365e Compare October 11, 2024 09:34
@stan-dot
Copy link
Contributor Author

simmotor has float and has that in the tests as well - but the Ophyd type is this: value : object, optional The initial value. Default is 0. which pyright reads as int.

adding an ignore line pending ophyd choosing a side here

@stan-dot
Copy link
Contributor Author

task_worker complains - because run_engine is not typed 😢

@stan-dot
Copy link
Contributor Author

DeviceStatus in devices.py complains that the DeviceStatus (imported from ophyd ❗ ) does not support the bluesky Status protocol

@stan-dot
Copy link
Contributor Author

still one issue with the stomp instantiation from the CLI - what's your opinion @callumforrester ?

@stan-dot stan-dot marked this pull request as ready for review October 11, 2024 09:59
@stan-dot
Copy link
Contributor Author

src/blueapi/service/interface.py Outdated Show resolved Hide resolved
src/blueapi/service/runner.py Outdated Show resolved Hide resolved
src/blueapi/startup/simmotor.py Show resolved Hide resolved
src/blueapi/utils/__init__.py Show resolved Hide resolved
src/blueapi/worker/task_worker.py Outdated Show resolved Hide resolved
src/blueapi/worker/task_worker.py Show resolved Hide resolved
tests/unit_tests/worker/devices.py Show resolved Hide resolved
@callumforrester
Copy link
Contributor

@stan-dot: Maybe we should make the password a secret in a separate PR, in order to deal with the errors. It is not essential to adopting pyright.

@stan-dot
Copy link
Contributor Author

stan-dot commented Oct 14, 2024

I'd agree with you, @callumforrester had this difference was between a 200 lines PR and 1k lines PR. it's 100 +- lines at the moment so easy to review. :( The errors are from pyright, so it makes sense to make this as a change

Maybe we should make the password a secret in a separate PR

this soft maybe does not feel honest as we both know you'd abosolutely not allow for this to go in the same PR, so please skip the pleasantries and just tell me to raise an issue and make a PR...

@callumforrester
Copy link
Contributor

For the record it was a genuine maybe, I agree that those changes are tangentially related. I read them during review and decided not to contest them unless they caused problems. I am unable to commit the time to help you debug the error right now so I'm leaving it up to you whether you want to put time into debugging on your own or make an issue and defer until later. I am happy with either resolution.

@stan-dot
Copy link
Contributor Author

  /workspaces/blueapi/src/blueapi/startup/simmotor.py:41:9 - error: Method "set" overrides class "SynAxis" in an incompatible manner
    Return type mismatch: base method returns type "MoveStatus", override returns type "Status"
      "Status" is not assignable to "MoveStatus" (reportIncompatibleMethodOverride)
  /workspaces/blueapi/src/blueapi/startup/simmotor.py:70:14 - error: "MoveStatus" is not defined (reportUndefinedVariable)
  /workspaces/blueapi/src/blueapi/startup/simmotor.py:93:36 - error: "MoveStatus" is not defined (reportUndefinedVariable)
  /workspaces/blueapi/src/blueapi/startup/simmotor.py:94:16 - error: "MoveStatus" is not defined (reportUndefinedVariable)
/workspaces/blueapi/src/blueapi/worker/task_worker.py
  /workspaces/blueapi/src/blueapi/worker/task_worker.py:99:54 - error: Argument of type "LoggingPropertyMachine | ProxyString | str" cannot be assigned to parameter "bluesky_state" of type "RawRunEngineState" in function "from_bluesky_state"
    Type "LoggingPropertyMachine | ProxyString | str" is not assignable to type "RawRunEngineState"
      Type "str" is not assignable to type "RawRunEngineState"
        Type "str" is not assignable to type "type[ProxyString]"
        Type "str" is not assignable to type "type[str]"
        Type "str" is not assignable to type "type[PropertyMachine]" (reportArgumentType)
/workspaces/blueapi/tests/unit_tests/worker/devices.py
  /workspaces/blueapi/tests/unit_tests/worker/devices.py:43:9 - error: Method "set" overrides class "Movable" in an incompatible manner
    Return type mismatch: base method returns type "Status", override returns type "Status"
      "Status" is incompatible with protocol "Status"
        "exception" is an incompatible type
          Type "(timeout: Unknown | None = None) -> (StatusTimeoutError | Exception | type[Exception] | None)" is not assignable to type "(timeout: float | None = 0) -> (BaseException | None)"
            Function return type "StatusTimeoutError | Exception | type[Exception] | None" is incompatible with type "BaseException | None"
        "bluesky.protocols.Status" is not assignable to "ophyd.status.Status"
        "bluesky.protocols.Status" is not assignable to "ophyd.status.Status" (reportIncompatibleMethodOverride)
  /workspaces/blueapi/tests/unit_tests/worker/devices.py:45:16 - error: Type "AdditionalUpdateStatus" is not assignable to return type "Status"
    "AdditionalUpdateStatus" is not assignable to "Status" (reportReturnType)
7 errors, 0 warnings, 0 informations 

those are the errors, they are all grounded in the chaos around ophyd-vs-ophyd-async bluesky protocol import (SynAxis and worker devices cases), as well as with State tracking - EngineState and the application specific state, and the unexpected super_state_machine import - not maintained, afaik vendored in into Bluesky.

either those are solved in a different PR or this PR is merged with 'ignore' flags.

@callumforrester
Copy link
Contributor

@stan-dot I am okay with ignore flags on ophyd (not ophyd-async) devices, this problem is probably related to bluesky/bluesky#1809

@stan-dot stan-dot force-pushed the 619-move-to-pyright branch from 53dc1ad to 5850a02 Compare October 16, 2024 13:22
@stan-dot
Copy link
Contributor Author

any idea why are the tests taking forever @callumforrester ?

@callumforrester
Copy link
Contributor

callumforrester commented Oct 17, 2024

No although all bets are off while main is broken...
They may have been queued, we can only run up to 20 in the org at once

@stan-dot stan-dot force-pushed the 619-move-to-pyright branch from 9165f13 to 02f8738 Compare November 18, 2024 13:17
@stan-dot
Copy link
Contributor Author

re: versions - I heard the reconciled version set is worked on atm

Copy link
Contributor

@DiamondJoseph DiamondJoseph left a comment

Choose a reason for hiding this comment

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

Just needs the tests fixed- I think the fixture is now returning the wrong object: it may have previously been returning the right object of the wrong type?

exporter in conftest

@stan-dot
Copy link
Contributor Author

stan-dot commented Nov 20, 2024

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: assert list[bluesky.protocols.Movable] == list[blueapi.core.context.BlueskyContext._reference.<locals>.Reference]
  
  Full diff:
  - list[blueapi.core.context.BlueskyContext._reference.<locals>.Reference]
  + list[bluesky.protocols.Movable]

some tests still not updated wrt the dependencies change?

this plus the run engine which was just copy pasted from bluesky but there the structure changed

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

Attention: Patch coverage is 83.87097% with 5 lines in your changes missing coverage. Please review.

Project coverage is 92.17%. Comparing base (a4e881d) to head (e3d3302).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/blueapi/worker/task_worker.py 58.33% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #632      +/-   ##
==========================================
- Coverage   92.27%   92.17%   -0.10%     
==========================================
  Files          35       35              
  Lines        1800     1803       +3     
==========================================
+ Hits         1661     1662       +1     
- Misses        139      141       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@DiamondJoseph DiamondJoseph merged commit 86c5905 into main Nov 21, 2024
28 of 29 checks passed
@DiamondJoseph DiamondJoseph deleted the 619-move-to-pyright branch November 21, 2024 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file dev-environment Issues for improving the developer environment/experience documentation Improvements or additions to documentation python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move to pyright
3 participants