diff options
author | Chris Liechti <cliechti@gmx.net> | 2016-04-22 21:31:09 +0200 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2016-04-22 21:31:09 +0200 |
commit | bf9e318d9bb59abe75c4f77d3126382fac3a2d94 (patch) | |
tree | 985e7dba8a85a7e3c1a3f9d144c75f51b5ccbc57 | |
parent | 1182a3bc478364717098ba03daa958099a5236c9 (diff) | |
download | pyserial-git-bf9e318d9bb59abe75c4f77d3126382fac3a2d94.tar.gz |
serialutil: creating a Serial object with an integer argument causes error, fixes #84
- raise an explicit TypeError especially as previous versions did support
integers, which is no longer allowed
-rw-r--r-- | serial/serialutil.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/serial/serialutil.py b/serial/serialutil.py index 3bf30f5..80416ea 100644 --- a/serial/serialutil.py +++ b/serial/serialutil.py @@ -28,6 +28,11 @@ try: except (NameError, AttributeError): unicode = str # for Python 3, pylint: disable=redefined-builtin,invalid-name +try: + basestr +except (NameError, AttributeError): + basestr = (str,) # for Python 3, pylint: disable=redefined-builtin,invalid-name + # "for byte in data" fails for python3 as it returns ints instead of bytes def iterbytes(b): @@ -188,18 +193,17 @@ class SerialBase(io.RawIOBase): def port(self): """\ Get the current port setting. The value that was passed on init or using - setPort() is passed back. See also the attribute portstr which contains - the name of the port as a string. + setPort() is passed back. """ return self._port @port.setter def port(self, port): """\ - Change the port. The attribute portstr is set to a string that - contains the name of the port. + Change the port. """ - + if port is not None and not isinstance(port, basestr): + raise ValueError('"port" must be None or a string, not {}'.format(type(port))) was_open = self.is_open if was_open: self.close() |