Skip to content

Python 2.x compatibility #23

@sphh

Description

@sphh

Hi Mike,

Some time ago, I had the same problem as @zlite. My solution does keep the same functionality in Python 3.x, but is compatible with 2.x;

There is only one change in PyCmdMessenger.py and the diff is:

@@ -116,7 +116,7 @@
                               "?":self._recv_bool,
                               "g":self._recv_guess}
 
-    def send(self,cmd,*args,arg_formats=None):
+    def send(self,cmd,*args,**kwargs):
         """
         Send a command (which may or may not have associated arguments) to an
         arduino using the CmdMessage protocol.  The command and any parameters
@@ -127,6 +127,10 @@
         arg_formats supercedes formats specified on initialization.
         """
 
+        arg_formats = kwargs.pop('arg_formats', None)
+        if kwargs:
+            raise TypeError("'send()' got unexpected keyword arguments: {}".format(', '.join(kwargs.keys())))
+
         # Turn the command into an integer.
         try:
             command_as_int = self._cmd_name_to_int[cmd]

Maybe the setup.py must also be changed.

I don't know if you want to incorporate it into you code. I can understand it if you don't want to keep backward compatibility. Maybe you just want to add a comment what has to be changed for Python 2.x?

Best wishes,
Stephan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions