sgzwiz / brython

Automatically exported from code.google.com/p/brython
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

List comprehension not working with class members (attributes, methods) #59

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

class NOListComp:
 def show(self,x):
  print(x)
  return x
 def go_list(self):
  self.pair = [1,2]
  print([self.show(u) for u in self.pair])
 def cheat_list_source(self):
  self.pair = [1,2]
  pair = self.pair
  print([self.show(u) for u in pair])
 def cheat_list_both(self):
  self.pair = [1,2]
  pair = self.pair
  show = self.show
  print([show(u) for u in pair])

# fails with SyntaxError: unknown token [$] for u in $$self.pair:
NOListComp().go_list()
# fails with SyntaxError: unknown token [$]  tvar = $$self.show(u)
NOListComp().cheat_list_source()
# possible workaround
NOListComp().cheat_list_both()

What is the expected output? What do you see instead?

1
2
[1, 2]

instead fails with Syntax Error

What version of the product are you using? On what operating system?
Brython version 1.0.20130126-094636
Linux Mint 14 "Nadia"

Please provide any additional information below.
works fine in ipython Python 2.7.3 (default, Sep 26 2012, 21:53:58)

Original issue reported on code.google.com by ca...@nce.ufrj.br on 28 Jan 2013 at 10:06

GoogleCodeExporter commented 9 years ago
Ok, this will be fixed with the release of the new core modules, out soon

Original comment by pierre.q...@gmail.com on 2 Feb 2013 at 6:39

GoogleCodeExporter commented 9 years ago
Fixed in version 1.1

Original comment by pierre.q...@gmail.com on 16 Feb 2013 at 5:25