Skip to content

Conversation

@alexrudd2
Copy link
Collaborator

Caught by pyright :)

Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

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

This one seems wrong.

else ""
)
function_codes += f"<option value={function.function_code} {selected}>function code name</option>"
function_codes += f"<option value={function} {selected}>function code name</option>"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is wrong, you are now building a list of object pointers and not function codes !

selected = (
"selected"
if function.function_code == self.call_monitor.function
if function == self.call_monitor.function
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems wrong, it is a list of function codes, not object pointers.

@alexrudd2
Copy link
Collaborator Author

alexrudd2 commented Dec 9, 2025

You have to look at the surrounding context. list_function_codes() -> list[int]
Therefore function is an int.
Therefore, function.function_code does not exist, and the existing code is broken in some manner.
(It's never called in tests and has # pragma: no cover so the breakage is not detected.)

def list_function_codes(self):
"""Return list of function codes."""
return list(self.pdu_table)

for function in DecodePDU(True).list_function_codes():
selected = (
"selected"
if function.function_code == self.call_monitor.function
else ""
)
function_codes += f"<option value={function.function_code} {selected}>function code name</option>"

Perhaps something like the code below was the intention? Although I don't really see the advantage over my first code.

for function in DecodePDU(True).pdu_table.values():
    req_func, _res_func = function
     selected = (
        "selected"
         if req_func.function_code == self.call_monitor.function
          else ""
      )
      function_codes += f"<option value={req_func.function_code} {selected}>function code name</option>"

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.

3 participants