Skip to content

Commit d17801c

Browse files
committed
[GR-68498] Undo the magic-iter.py benchmark change and document why it was how it was
1 parent bbee3b5 commit d17801c

File tree

1 file changed

+13
-2
lines changed
  • graalpython/com.oracle.graal.python.benchmarks/python/micro

1 file changed

+13
-2
lines changed

graalpython/com.oracle.graal.python.benchmarks/python/micro/magic-iter.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,19 @@
3838
# SOFTWARE.
3939

4040
class CustomIterator:
41+
# Even though this is worse for our generated code, it is increasingly
42+
# common, because the typing PEP explicitly has an example like this:
43+
# https://peps.python.org/pep-0526/#class-and-instance-variable-annotations
44+
#
45+
# While that is a historical document, it is a) still widely referenced and
46+
# b) at the time of writing this comment latest spec still has a similar
47+
# example where a variable is initialized with a default on the class level
48+
# and the __init__ method only conditionally overrides the default *and
49+
# otherwise keeps it on the class* making self.FOO accesses polymorphic:
50+
# https://typing.python.org/en/latest/spec/class-compat.html#classvar
51+
pos = 0
52+
4153
def __init__(self, obj):
42-
self.pos = 0
4354
self.__obj = obj
4455

4556
def __iter__(self):
@@ -70,7 +81,7 @@ def count(num):
7081
val0 = next(it)
7182
val1 = next(it)
7283
val2 = next(it)
73-
84+
7485
return (val0, val1, val2)
7586

7687

0 commit comments

Comments
 (0)