On Saturday 18.12.2010 18:34:57 Georg Brandl wrote:
Am 18.12.2010 12:23, schrieb Eike Welk:
Instance Creation -----------------
foo = {| a=1, b=2 |}:Foo
This should be equivalent to:
foo = Foo(a=1, b=2)
In the usual case, it should not be necessary to specify the class name:
foo = {| a=1, b=2 |}
The run-time should search for a class with a matching "__init__" method.
I'm beginning to suspect this is an elaborate trolling attempt...
Yes, it's a bit of fun. This would never get into Python anyway, but I'd like it nevertheless. (It is Ocaml's record syntax with some small tweaks.) It would be possible to realize it though. With "inspect.getfullargspec" you can see the a function's signature. There might be problems with efficiency, because you'd have to search through globals and locals repeatedly. You you could however store which class matched, somewhere in the code object. Storing this kind of information would go against Python's nature as a dynamic language, even though it would work as expected in 99% of the use cases. Oh well ... Eike