Skip to content

Commit 2d7fad4

Browse files
authored
Merge pull request #434 from cristi-iacob/python-codacy-fixes
python: code quality improvements
2 parents 89f19c7 + eb9fe23 commit 2d7fad4

File tree

1 file changed

+78
-2
lines changed

1 file changed

+78
-2
lines changed

bindings/python/iio.py

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,22 @@ def __str__(self):
392392
None, "Current value of this attribute.\n\ttype=str")
393393

394394
class ChannelAttr(_Attr):
395+
395396
"""Represents an attribute of a channel."""
396397

397398
def __init__(self, channel, name):
399+
"""
400+
Initializes a new instance of the ChannelAttr class.
401+
402+
parameters:
403+
channel: type=iio.Channel
404+
A valid instance of the iio.Channel class.
405+
name: type=str
406+
The channel attribute's name
407+
408+
returns: type=iio.ChannelAttr
409+
A new instance of this class
410+
"""
398411
super(ChannelAttr, self).__init__(name, _c_get_filename(channel, name.encode('ascii')).decode('ascii'))
399412
self._channel = channel
400413

@@ -407,9 +420,22 @@ def _Attr__write(self, value):
407420
_c_write_attr(self._channel, self._name_ascii, value.encode('ascii'))
408421

409422
class DeviceAttr(_Attr):
423+
410424
"""Represents an attribute of an IIO device."""
411425

412426
def __init__(self, device, name):
427+
"""
428+
Initializes a new instance of the DeviceAttr class.
429+
430+
parameters:
431+
device: type=iio.Device
432+
A valid instance of the iio.Device class.
433+
name: type=str
434+
The device attribute's name
435+
436+
returns: type=iio.DeviceAttr
437+
A new instance of this class
438+
"""
413439
super(DeviceAttr, self).__init__(name)
414440
self._device = device
415441

@@ -422,9 +448,22 @@ def _Attr__write(self, value):
422448
_d_write_attr(self._device, self._name_ascii, value.encode('ascii'))
423449

424450
class DeviceDebugAttr(DeviceAttr):
451+
425452
"""Represents a debug attribute of an IIO device."""
426453

427454
def __init__(self, device, name):
455+
"""
456+
Initializes a new instance of the DeviceDebugAttr class.
457+
458+
parameters:
459+
device: type=iio.Device
460+
A valid instance of the iio.Device class.
461+
name: type=str
462+
The device debug attribute's name
463+
464+
returns: type=iio.DeviceDebugAttr
465+
A new instance of this class
466+
"""
428467
super(DeviceDebugAttr, self).__init__(device, name)
429468

430469
def _Attr__read(self):
@@ -436,7 +475,19 @@ def _Attr__write(self, value):
436475
_d_write_debug_attr(self._device, self._name_ascii, value.encode('ascii'))
437476

438477
class Channel(object):
478+
"""Represents a channel of an IIO device."""
479+
439480
def __init__(self, _channel):
481+
"""
482+
Initializes a new instance of the Channel class.
483+
484+
parameters:
485+
_channel: type=_ChannelPtr
486+
Pointer to an IIO Channel.
487+
488+
returns: type=iio.Channel
489+
An new instance of this class
490+
"""
440491
self._channel = _channel
441492
self._attrs = { name : ChannelAttr(_channel, name) for name in \
442493
[_c_get_attr(_channel, x).decode('ascii') for x in range(0, _c_attr_count(_channel))] }
@@ -508,6 +559,7 @@ def write(self, buf, array, raw = False):
508559
None, "Configured state of the channel\n\ttype=bool")
509560

510561
class Buffer(object):
562+
511563
"""The class used for all I/O operations."""
512564

513565
def __init__(self, device, samples_count, cyclic = False):
@@ -533,7 +585,6 @@ def __init__(self, device, samples_count, cyclic = False):
533585
raise
534586
self._length = samples_count * device.sample_size
535587
self._samples_count = samples_count
536-
537588
self._ctx = device.ctx()
538589
# Holds a reference to the corresponding IIO Context. This ensures that
539590
# every iio.Buffer object is destroyed before its corresponding IIO Context.
@@ -692,9 +743,20 @@ def sample_size(self):
692743
"List of channels available with this IIO device.\n\ttype=list of iio.Channel objects")
693744

694745
class Trigger(_DeviceOrTrigger):
746+
695747
"""Contains the representation of an IIO device that can act as a trigger."""
696748

697749
def __init__(self, _device):
750+
"""
751+
Initializes a new instance of the Trigger class.
752+
753+
parameters:
754+
_device: type=iio._DevicePtr
755+
A pointer to an IIO device.
756+
757+
returns: type=iio.Trigger
758+
An new instance of this class
759+
"""
698760
super(Trigger, self).__init__(_device)
699761

700762
def _get_rate(self):
@@ -707,9 +769,22 @@ def _set_rate(self, value):
707769
"Configured frequency (in Hz) of this trigger\n\ttype=int")
708770

709771
class Device(_DeviceOrTrigger):
772+
710773
"""Contains the representation of an IIO device."""
711774

712775
def __init__(self, ctx, _device):
776+
"""
777+
Initializes a new instance of the Device class.
778+
779+
parameters:
780+
ctx: type=iio.Context
781+
A valid instance of the iio.Context class.
782+
_device: type=_DevicePtr
783+
A pointer to an IIO device.
784+
785+
returns: type=iio.Device
786+
An new instance of this class
787+
"""
713788
super(Device, self).__init__(_device)
714789
self.ctx = weakref.ref(ctx)
715790

@@ -729,6 +804,7 @@ def _get_trigger(self):
729804
"Contains the configured trigger for this IIO device.\n\ttype=iio.Trigger")
730805

731806
class Context(object):
807+
732808
"""Contains the representation of an IIO context."""
733809

734810
def __init__(self, _context=None):
@@ -850,7 +926,7 @@ def __init__(self, xmlfile):
850926
super(XMLContext, self).__init__(ctx)
851927

852928
class NetworkContext(Context):
853-
def __init__(self, hostname = None):
929+
def __init__(self, hostname=None):
854930
"""
855931
Initializes a new instance of the Context class, using the network backend of the IIO library.
856932

0 commit comments

Comments
 (0)