From: W. Trevor King Date: Wed, 12 Jun 2013 12:52:13 +0000 (-0400) Subject: Use generators, now that Cython supports them X-Git-Tag: 0.9~1^2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=232324464d58a778ba97bb3c9dd3bbbfd2db5c5f;p=pycomedi.git Use generators, now that Cython supports them The Cython 0.15 release notes (2011-08-05) claim support for generators [1]. [1]: http://wiki.cython.org/ReleaseNotes-0.15 --- diff --git a/pycomedi/channel.pyx b/pycomedi/channel.pyx index 4b0a3c1..2151ac3 100644 --- a/pycomedi/channel.pyx +++ b/pycomedi/channel.pyx @@ -123,12 +123,8 @@ cdef class Channel (object): def ranges(self, **kwargs): "Iterate through all available ranges." - ret = [] for i in range(self.get_n_ranges()): - #yield self.subdevice(i, **kwargs) - # Generators are not supported in Cython 0.14.1 - ret.append(self.get_range(i, **kwargs)) - return ret + yield self.get_range(i, **kwargs) cdef class DigitalChannel (Channel): diff --git a/pycomedi/device.pyx b/pycomedi/device.pyx index 6b13157..420bf4a 100644 --- a/pycomedi/device.pyx +++ b/pycomedi/device.pyx @@ -295,12 +295,8 @@ cdef class Device (_DeviceHolder): def subdevices(self, **kwargs): "Iterate through all available subdevices." - ret = [] for i in range(self.get_n_subdevices()): - #yield self.subdevice(i, **kwargs) - # Generators are not supported in Cython 0.14.1 - ret.append(self.subdevice(i, **kwargs)) - return ret + yield self.subdevice(i, **kwargs) def subdevice(self, index, factory=_subdevice.Subdevice, **kwargs): return factory(device=self, index=index, **kwargs) diff --git a/pycomedi/subdevice.pyx b/pycomedi/subdevice.pyx index 582835e..14338a8 100644 --- a/pycomedi/subdevice.pyx +++ b/pycomedi/subdevice.pyx @@ -150,12 +150,8 @@ cdef class Subdevice (_SubdeviceHolder): def channels(self, **kwargs): "Iterate through all available channels." - ret = [] for i in range(self.get_n_channels()): - #yield self.channel(i, **kwargs) - # Generators are not supported in Cython 0.14.1 - ret.append(self.channel(i, **kwargs)) - return ret + yield self.channel(i, **kwargs) def channel(self, index, factory=_channel.Channel, **kwargs): "`Channel` instance for the `index`\ed channel."