Skip to content

Ticket8527 ruff pyright#4

Open
LilithCole wants to merge 4 commits intomainfrom
Ticket8527_ruff_pyright
Open

Ticket8527 ruff pyright#4
LilithCole wants to merge 4 commits intomainfrom
Ticket8527_ruff_pyright

Conversation

@LilithCole
Copy link
Copy Markdown

@LilithCole LilithCole commented Oct 18, 2024

Ruff/pyright the device generator

To review:

  • Check code
  • Check ruff/pyright
  • Check tests pass
  • Refactor "@{lewis_emulator_device_class_name}" to something that can actually be a class name, remove templates from ignore, then check that there are no massive errors aside from the obvious imports not knowing where they should be

raise NothingToCommitError(self)

def create_submodule(self, name: str, url: str, path: str) -> None:
def create_submodule(self, name: str, url: str, path: str) -> None: # pyright: ignore
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.

What was pyright unhappy with here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the overloaded class returns a "Submodule" object for that method which it can't replace with None. I couldn't see an easy way of creating a fake Submodule to be returned to nothing.

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.

Oh I see... That's not ideal overriding someone elses' class in an incompatible way like that...

I think that is pyright pointing out something we genuinely shouldn't be doing, but I guess 🤷 if you want to leave it (if you do want to fix it, I think just renaming the method where we use it to something that doesn't conflict with the base class would be sufficient)

@Tom-Willemsen
Copy link
Copy Markdown
Member

I notice the ruff.toml which preexisted in this repo is a lot less strict than our normal one, could we move them closer do you think?

It's also not using our standard reusable-workflows setup so won't actually check pyright on build server, again would it be possible to move closer to standard?

@LilithCole
Copy link
Copy Markdown
Author

didn't notice that, changing it

@GRyall GRyall force-pushed the Ticket8527_ruff_pyright branch from e7c845c to 2f3593a Compare October 23, 2024 17:00
@GRyall
Copy link
Copy Markdown
Member

GRyall commented Oct 28, 2024

when I run ruff -check on a generated device (having made no changes to the device), I get:

C:\Instrument\Apps\EPICS\support\antonpaarldens3300>%PYTHON3% -m ruff check --config=.".\..\..\..\Dev\reusable-workflows\ruff.toml"
master\system_tests\lewis_emulators\antonpaarldens3300\__init__.py:1:1: I001 [*] Import block is un-sorted or un-formatted
master\system_tests\lewis_emulators\antonpaarldens3300\device.py:1:1: I001 [*] Import block is un-sorted or un-formatted
master\system_tests\lewis_emulators\antonpaarldens3300\device.py:8:9: ANN202 Missing return type annotation for private function `_initialize_data`
master\system_tests\lewis_emulators\antonpaarldens3300\device.py:14:9: ANN202 Missing return type annotation for private function `_get_state_handlers`
master\system_tests\lewis_emulators\antonpaarldens3300\device.py:19:9: ANN202 Missing return type annotation for private function `_get_initial_state`
master\system_tests\lewis_emulators\antonpaarldens3300\device.py:22:9: ANN202 Missing return type annotation for private function `_get_transition_handlers`
master\system_tests\lewis_emulators\antonpaarldens3300\interfaces\stream_interface.py:1:1: I001 [*] Import block is un-sorted or un-formatted
master\system_tests\lewis_emulators\antonpaarldens3300\interfaces\stream_interface.py:1:52: F401 [*] `lewis.adapters.stream.Cmd` imported but unused
master\system_tests\lewis_emulators\antonpaarldens3300\interfaces\stream_interface.py:4:33: F401 [*] `lewis.utils.replies.conditional_reply` imported but unused
master\system_tests\lewis_emulators\antonpaarldens3300\interfaces\stream_interface.py:13:9: ANN204 Missing return type annotation for special method `__init__`
master\system_tests\lewis_emulators\antonpaarldens3300\interfaces\stream_interface.py:20:9: ANN201 Missing return type annotation for public function `handle_error`
master\system_tests\lewis_emulators\antonpaarldens3300\interfaces\stream_interface.py:20:28: ANN001 Missing type annotation for function argument `request`
master\system_tests\lewis_emulators\antonpaarldens3300\interfaces\stream_interface.py:20:37: ANN001 Missing type annotation for function argument `error`
master\system_tests\lewis_emulators\antonpaarldens3300\interfaces\stream_interface.py:31:9: ANN201 Missing return type annotation for public function `catch_all`
master\system_tests\lewis_emulators\antonpaarldens3300\interfaces\stream_interface.py:31:25: ANN001 Missing type annotation for function argument `command`
master\system_tests\tests\tests.py:1:1: I001 [*] Import block is un-sorted or un-formatted
master\system_tests\tests\tests.py:6:54: F401 [*] `utils.testing.skip_if_recsim` imported but unused
Found 17 errors.
[*] 7 fixable with the `--fix` option (5 hidden fixes can be enabled with the `--unsafe-fixes` option).

running ruff -format also finds results

C:\Instrument\Apps\EPICS\support\antonpaarldens3300\master>%PYTHON3% -m ruff format --config="C:\Instrument\Dev\reusable-workflows\ruff.toml"
5 files reformatted, 5 files left unchanged

C:\Instrument\Apps\EPICS\support\antonpaarldens3300\master>git diff
diff --git a/system_tests/lewis_emulators/antonpaarldens3300/__init__.py b/system_tests/lewis_emulators/antonpaarldens3300/__init__.py
index b101794..34f904c 100644
--- a/system_tests/lewis_emulators/antonpaarldens3300/__init__.py
+++ b/system_tests/lewis_emulators/antonpaarldens3300/__init__.py
@@ -2,4 +2,4 @@ from .device import SimulatedAntonpaarldens3300
 from ..lewis_versions import LEWIS_LATEST

 framework_version = LEWIS_LATEST
-__all__ = ['SimulatedAntonpaarldens3300']
+__all__ = ["SimulatedAntonpaarldens3300"]
diff --git a/system_tests/lewis_emulators/antonpaarldens3300/device.py b/system_tests/lewis_emulators/antonpaarldens3300/device.py
index 8d2682a..a32549c 100644
--- a/system_tests/lewis_emulators/antonpaarldens3300/device.py
+++ b/system_tests/lewis_emulators/antonpaarldens3300/device.py
@@ -4,7 +4,6 @@ from lewis.devices import StateMachineDevice


 class SimulatedAntonpaarldens3300(StateMachineDevice):
-
     def _initialize_data(self):
         """
         Initialize all of the device's attributes.
@@ -13,11 +12,11 @@ class SimulatedAntonpaarldens3300(StateMachineDevice):

     def _get_state_handlers(self):
         return {
-            'default': DefaultState(),
+            "default": DefaultState(),
         }

     def _get_initial_state(self):
-        return 'default'
+        return "default"

     def _get_transition_handlers(self):
         return OrderedDict([])
diff --git a/system_tests/lewis_emulators/antonpaarldens3300/interfaces/__init__.py b/system_tests/lewis_emulators/antonpaarldens3300/interfaces/__init__.py
index 6e59b3a..a4f1ff3 100644
--- a/system_tests/lewis_emulators/antonpaarldens3300/interfaces/__init__.py
+++ b/system_tests/lewis_emulators/antonpaarldens3300/interfaces/__init__.py
@@ -1,3 +1,3 @@
 from .stream_interface import Antonpaarldens3300StreamInterface

-__all__ = ['Antonpaarldens3300StreamInterface']
+__all__ = ["Antonpaarldens3300StreamInterface"]
diff --git a/system_tests/lewis_emulators/antonpaarldens3300/interfaces/stream_interface.py b/system_tests/lewis_emulators/antonpaarldens3300/interfaces/stream_interface.py
index 5b6d3d0..f239b25 100644
--- a/system_tests/lewis_emulators/antonpaarldens3300/interfaces/stream_interface.py
+++ b/system_tests/lewis_emulators/antonpaarldens3300/interfaces/stream_interface.py
@@ -6,7 +6,6 @@ from lewis.utils.replies import conditional_reply

 @has_log
 class Antonpaarldens3300StreamInterface(StreamInterface):
-
     in_terminator = "\r\n"
     out_terminator = "\r\n"

diff --git a/system_tests/tests/tests.py b/system_tests/tests/tests.py
index ccbead5..72b7e1f 100644
--- a/system_tests/tests/tests.py
+++ b/system_tests/tests/tests.py
@@ -26,6 +26,7 @@ class Antonpaarldens3300Tests(unittest.TestCase):
     """
     Tests for the _Device_ IOC.
     """
+
     def setUp(self):
         self._lewis, self._ioc = get_running_lewis_and_ioc("antonpaarldens3300", DEVICE_PREFIX)
         self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)

@GRyall GRyall self-requested a review October 28, 2024 13:38
@GRyall
Copy link
Copy Markdown
Member

GRyall commented Oct 28, 2024

Additionally, when I run pyright against a generated device, I get:

C:\Instrument\Apps\EPICS\support\antonpaarldens3300\master>%PYTHON3% -m pyright
c:\Instrument\Apps\EPICS\support\antonpaarldens3300\master\system_tests\lewis_emulators\antonpaarldens3300\interfaces\stream_interface.py
  c:\Instrument\Apps\EPICS\support\antonpaarldens3300\master\system_tests\lewis_emulators\antonpaarldens3300\interfaces\stream_interface.py:29:14 - error: Cannot access attribute "log" for class "Antonpaarldens3300StreamInterface*"
    Attribute "log" is unknown (reportAttributeAccessIssue)
c:\Instrument\Apps\EPICS\support\antonpaarldens3300\master\system_tests\tests\tests.py
  c:\Instrument\Apps\EPICS\support\antonpaarldens3300\master\system_tests\tests\tests.py:3:6 - error: Import "utils.channel_access" could not be resolved (reportMissingImports)
  c:\Instrument\Apps\EPICS\support\antonpaarldens3300\master\system_tests\tests\tests.py:4:6 - error: Import "utils.ioc_launcher" could not be resolved (reportMissingImports)
  c:\Instrument\Apps\EPICS\support\antonpaarldens3300\master\system_tests\tests\tests.py:5:6 - error: Import "utils.test_modes" could not be resolved (reportMissingImports)
  c:\Instrument\Apps\EPICS\support\antonpaarldens3300\master\system_tests\tests\tests.py:6:6 - error: Import "utils.testing" could not be resolved (reportMissingImports)
5 errors, 0 warnings, 0 informations

@Chsudeepta
Copy link
Copy Markdown

I am getting few ruff and pyright issues. Could you run it against the latest ruff configuration once please.?

@GRyall
Copy link
Copy Markdown
Member

GRyall commented Dec 2, 2024

@Chsudeepta different ones to the ones I reported?

@Chsudeepta
Copy link
Copy Markdown

@GRyall , yes, different, but similar as multiple imports couldn't be resolved.

@GRyall
Copy link
Copy Markdown
Member

GRyall commented Dec 2, 2024

@Chsudeepta did you use the ruff.toml that is distributed with the repo?

@Chsudeepta
Copy link
Copy Markdown

@GRyall These are mostly pyright issues (those that are similar to the ones you reported above). There are also a host ruff issues extracted by running the script in reusable-workflows

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