Skip to content

ModbusTcpClient constructor BC break between 3.6.9 and 3.7.0 #2283

Closed as not planned
@rtek

Description

@rtek

The ModbusTcpClient had a signature change between 3.6 and 3.7 for the port parameter.

see
https://github.com/pymodbus-dev/pymodbus/blob/v3.6.9/pymodbus/client/tcp.py#L61

 def __init__(
        self,
        host: str,
        port: int = 502,
        framer: Framer = Framer.SOCKET,
        source_address: tuple[str, int] | None = None,
        **kwargs: Any,
    ) -> None:

vs
https://github.com/pymodbus-dev/pymodbus/blob/v3.7.0/pymodbus/client/tcp.py#L61

 def __init__(  # pylint: disable=too-many-arguments
        self,
        host: str,
        framer: FramerType = FramerType.SOCKET,
        port: int = 502,
        name: str = "comm",
        source_address: tuple[str, int] | None = None,
        reconnect_delay: float = 0.1,
        reconnect_delay_max: float = 300,
        timeout: float = 3,
        retries: int = 3,
        on_connect_callback: Callable[[bool], None] | None = None,
    ) -> None:

This results in the following error if using positional arguments for port.

Traceback (most recent call last):
  File "main.py", line 13, in <module>
    client = ModbusTcpClient('localhost', 5502)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../pymodbus/client/tcp.py", line 158, in __init__
    super().__init__(framer, retries)
  File "../pymodbus/client/base.py", line 190, in __init__
    self.framer: ModbusFramer = FRAMER_NAME_TO_CLASS.get(
                                ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'str' object is not callable

Reverting to 3.6.9 or using kwargs resolves the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions