class A:
def __init__(self):
self.version = "old"
def new_init(obj):
obj.version = "new"
A.__init__ = new_init
assert A().version == "new"
In issue #766 Glyph requested the support of the popular attrs package.
When I started working on it I realized that there was a big issue with the way classes are currently implemented.
The following code fails on the version currently on line at brython.info:
class A:
def __init__(self):
self.version = "old"
def new_init(obj):
obj.version = "new"
A.__init__ = new_init
assert A().version == "new"
In the current implementation, classes are represented by two Javascript objects :
- the "class dictionary" : a Javascript object with all the attributes and methods defined in the class
- the "factory function" : the function used to create instances
Currently, the Javascript object used for the class A is the "factory function". Setting A.__init__ changes the attribute __init__ of the class dictionary, but not the factory function itself...
Instead of trying workarounds, I have decided to change the whole class implementation. I have done it in the branch "rewrite_classes" of the Github repo. I don't think that calling it a "major rewriting" is an overstatement : 57 files changed, 8,189 additions and 9,084 deletions.
I also made more Python-compliant how user-defined classes are created using metaclasses, how class instances are created using the metaclass __call__ method. I have learned quite a few things on my way...
The version in this branch "rewrite_classes" is not running correctly : it passes all the tests and runs all the demos in the gallery.
Error at Object._b_.AttributeError (eval at $make_exc (py_exceptions.js:417), <anonymous>:41:15) at $JSObjectDict.__getattribute__ (js_objects.js:317) at Object.$B.$getattr (py_builtin_functions.js:875) at Object.$B.$call (py_utils.js:736) at show1 (eval at run_py (py_import.js:253), <anonymous>:203:32) at eval (eval at run_script (py2js.js:7944), <anonymous>:16:97) at run_script (py2js.js:7944) at callback (py2js.js:7886) at Object.load_scripts [as _load_scripts] (py2js.js:7922) at _run_scripts (py2js.js:8295) at brython (py2js.js:8155) at onload (console.html?lang=fr:65)
On Tuesday, 13 February 2018 06:50:40 UTC-4, Pierre Quentel wrote:In issue #766 Glyph requested the support of the popular attrs package.
When I started working on it I realized that there was a big issue with the way classes are currently implemented.
The following code fails on the version currently on line at brython.info:
class A:
def __init__(self):
self.version = "old"
def new_init(obj):
obj.version = "new"
A.__init__ = new_init
assert A().version == "new"
In the current implementation, classes are represented by two Javascript objects :
- the "class dictionary" : a Javascript object with all the attributes and methods defined in the class
- the "factory function" : the function used to create instances
Currently, the Javascript object used for the class A is the "factory function". Setting A.__init__ changes the attribute __init__ of the class dictionary, but not the factory function itself...
Instead of trying workarounds, I have decided to change the whole class implementation. I have done it in the branch "rewrite_classes" of the Github repo. I don't think that calling it a "major rewriting" is an overstatement : 57 files changed, 8,189 additions and 9,084 deletions.
I also made more Python-compliant how user-defined classes are created using metaclasses, how class instances are created using the metaclass __call__ method. I have learned quite a few things on my way...
The version in this branch "rewrite_classes" is not running correctly : it passes all the tests and runs all the demos in the gallery.I assume you meant to write "now" instead of "not".
And, if so, I need help to test things out.I've tried to get that branch but something has obviously gone wrong as neither the editor nor the console load and I cannot run the turtle demos (which was the first thing I tried)To get the branch, I did the following:> git checkout --track upstream/rewrite_classes
Switched to a new branch 'rewrite_classes'Branch rewrite_classes set up to track remote branch rewrite_classes from upstream.> git branchfix/master/turtle709fix/master/turtle739master* rewrite_classes> git statusOn branch rewrite_classesYour branch is up-to-date with 'upstream/rewrite_classes'.
Le mardi 13 février 2018 16:20:37 UTC+1, André a écrit :
On Tuesday, 13 February 2018 06:50:40 UTC-4, Pierre Quentel wrote:...
The version in this branch "rewrite_classes" is not running correctly : it passes all the tests and runs all the demos in the gallery.I assume you meant to write "now" instead of "not".
Oops. When I was young, in the 80's, we would have called that a "laspus révélateur"...
And, if so, I need help to test things out.I've tried to get that branch but something has obviously gone wrong as neither the editor nor the console load and I cannot run the turtle demos (which was the first thing I tried)To get the branch, I did the following:> git checkout --track upstream/rewrite_classes
Switched to a new branch 'rewrite_classes'Branch rewrite_classes set up to track remote branch rewrite_classes from upstream.> git branchfix/master/turtle709fix/master/turtle739master* rewrite_classes> git statusOn branch rewrite_classesYour branch is up-to-date with 'upstream/rewrite_classes'.
Since I'm hopeless at git, I just made a fresh clone of the repository, switched to the "rewrite_classes" branch and started the server, all the tests pass and the console loads without errors. The most likely is that *I* am doing something wrong, but I don't know what.
On Tuesday, 13 February 2018 15:16:57 UTC-4, Pierre Quentel wrote:
Le mardi 13 février 2018 16:20:37 UTC+1, André a écrit :
On Tuesday, 13 February 2018 06:50:40 UTC-4, Pierre Quentel wrote:...
The version in this branch "rewrite_classes" is not running correctly : it passes all the tests and runs all the demos in the gallery.I assume you meant to write "now" instead of "not".
Oops. When I was young, in the 80's, we would have called that a "laspus révélateur"..."lapsus", sûrement ;-)
I think that *I* am hopeless at git...I just made a fresh clone of the repository, switched to the "rewrite_classes" branch and started the server. The console did load properly.. (Yay!)However ... if I attempt to run the very first turtle demo, I get the following:Traceback (most recent call last):module _collections line 475field_names=tuple(map(str,field_names))module python_script line 38traceback.print_exc()module line 1import turtlemodule turtle line 1375import inspectmodule inspect line 34import impmodule imp line 30import tokenizemodule tokenize line 94class TokenInfo(collections. namedtuple('TokenInfo','type string start end line')):module _collections line 475field_names=tuple(map(str,field_names))NameError: name 'map' is not definedSo ... progress of sorts, but something is definitely wrong here.André
--
You received this message because you are subscribed to a topic in the Google Groups "brython" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/brython/Puefct6H9GQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to brython+unsubscribe@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/9afb209b-7290-4589-a03f-78474e6ca324%40googlegroups.com.