Use generators, now that Cython supports them
authorW. Trevor King <wking@tremily.us>
Wed, 12 Jun 2013 12:52:13 +0000 (08:52 -0400)
committerW. Trevor King <wking@tremily.us>
Sat, 15 Jun 2013 14:22:47 +0000 (10:22 -0400)
The Cython 0.15 release notes (2011-08-05) claim support for
generators [1].

[1]: http://wiki.cython.org/ReleaseNotes-0.15

pycomedi/channel.pyx
pycomedi/device.pyx
pycomedi/subdevice.pyx

index 4b0a3c1446695789ae7dc1d732426ef2d1ce0a9c..2151ac3a49a184f93b1062528afdaf39d3c4ff4e 100644 (file)
@@ -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):
index 6b13157093158eb0db046b4886c4e759354fced1..420bf4afbe0b22df215ab15da29742815720cb1d 100644 (file)
@@ -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)
index 582835ed91bde4fcd30e2d99b3f60cbfae404545..14338a8c2f3886b30428f1895cf510faad937f36 100644 (file)
@@ -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."