forbiddenfruit icon indicating copy to clipboard operation
forbiddenfruit copied to clipboard

Cursing int __iter__ silently fails.

Open 0xf0f opened this issue 6 years ago • 2 comments

>>> def int_iter(self):
	i = 0
	while i < self:
		yield i
		i += 1

		
>>> curse(int, '__iter__', int_iter)
>>> for i in 12:
	print('1231')

	
Traceback (most recent call last):
  File "<pyshell#19>", line 1, in <module>
    for i in 12:
TypeError: 'int' object is not iterable

Not sure if this is a bug or just unimplemented. Maybe raising a NotImplementedError exception would be helpful if it's the latter.

0xf0f avatar Mar 28 '19 02:03 0xf0f

Thanks for reporting! That's a good one! The handling of dunder methods was introduced quite recently (https://github.com/clarete/forbiddenfruit/pull/24) and it didn't include the __iter__ protocol. Let me know if you have any interest in suggesting a fix, I can walk you through the code! I think that'd be the fastest way to get these changes in!

clarete avatar Apr 19 '19 18:04 clarete

@clarete Is anything required for implementing __repr__, __hash__, __call__, __iter__, __next__, or other missing dunder methods than adding them to PyTypeObject._fields_ and override_dict?

alexchandel avatar Nov 19 '19 06:11 alexchandel