fix various bugs found by the 'prospector' static-analysis tool

This commit is contained in:
Andrew Scheller
2016-04-07 16:12:17 +01:00
parent 4f7e1f003e
commit 72ca075668
13 changed files with 33 additions and 34 deletions

View File

@@ -9,7 +9,7 @@ str = type('')
import io
from collections import namedtuple
from ..exc import PinUnknownPi, PinMultiplePins
from ..exc import PinUnknownPi, PinMultiplePins, PinNoPins
# Some useful constants for describing pins

View File

@@ -15,7 +15,7 @@ try:
except ImportError:
from ..compat import isclose
from . import Pin, PINS_CLEANUP
from . import Pin
from ..exc import PinSetInput, PinPWMUnsupported, PinFixedPull
@@ -38,7 +38,7 @@ class MockPin(Pin):
try:
old_pin = cls._PINS[number]
except KeyError:
self = super(Pin, cls).__new__(cls)
self = super(MockPin, cls).__new__(cls)
cls._PINS[number] = self
self._number = number
self._function = 'input'

View File

@@ -16,6 +16,7 @@ from ..exc import (
PinFixedPull,
PinInvalidPull,
PinInvalidBounce,
PinInvalidState,
)
@@ -135,7 +136,7 @@ class PiGPIOPin(Pin):
if self._host == 'localhost':
return "GPIO%d" % self._number
else:
return "GPIO%d on %s:%d" % (self._host, self._port)
return "GPIO%d on %s:%d" % (self._number, self._host, self._port)
@property
def host(self):
@@ -182,7 +183,7 @@ class PiGPIOPin(Pin):
try:
self._connection.set_PWM_dutycycle(self._number, int(value * 255))
except pigpio.error:
raise PinInvalidValue('invalid state "%s" for pin %r' % (value, self))
raise PinInvalidState('invalid state "%s" for pin %r' % (value, self))
elif self.function == 'input':
raise PinSetInput('cannot set state of pin %r' % self)
else:

View File

@@ -7,8 +7,6 @@ from __future__ import (
str = type('')
from threading import Lock
import RPIO
import RPIO.PWM
from RPIO.Exceptions import InvalidChannelException
@@ -21,6 +19,8 @@ from ..exc import (
PinFixedPull,
PinInvalidPull,
PinInvalidBounce,
PinInvalidState,
PinPWMError,
)
@@ -126,7 +126,7 @@ class RPIOPin(Pin):
def _set_state(self, value):
if not 0 <= value <= 1:
raise PinInvalidValue('invalid state "%s" for pin %r' % (value, self))
raise PinInvalidState('invalid state "%s" for pin %r' % (value, self))
if self._pwm:
RPIO.PWM.clear_channel_gpio(0, self._number)
if value == 0: