{"id":1047,"date":"2009-07-25T10:17:12","date_gmt":"2009-07-25T09:17:12","guid":{"rendered":"http:\/\/fiber-space.de\/wordpress\/?p=1047"},"modified":"2009-07-25T10:22:30","modified_gmt":"2009-07-25T09:22:30","slug":"four-things-id-change-in-python-and-a-little-more","status":"publish","type":"post","link":"http:\/\/fiber-space.de\/wordpress\/2009\/07\/25\/four-things-id-change-in-python-and-a-little-more\/","title":{"rendered":"Four things I&#8217;d change in Python &#8211; and a little more"},"content":{"rendered":"<h3>1. Import system<\/h3>\n<p>Replace the flat module cache by a set of ModuleTree objects rooted in nodes living on the PYTHONPATH. Apply relative path semantics by default and treat absolute paths as special cases. Internal paths which are used in import statements or for traversing ModuleTree objects and external ones ( file-system, zip-files, URLs etc. ) are related through<em> representations<\/em> of internal paths [1]. Representations shall be user definable. For ModuleTree objects custom import semantics may be defined. This replaces &#8220;import hooks&#8221; and provides similar functionality in a much safer and object oriented manner.  Further effects: no physical module is imported twice for two different import paths; each module can be used as a script no matter how the path is written. No changes to the language syntax.<\/p>\n<p>[1] What I mean here is a representation of a path algebra in systems which can be considered as the &#8220;environment&#8221; of Python. This sounds more grandiose than it actually is.<\/p>\n<h3>2. Decorators everywhere<\/h3>\n<p>This basically reflects my interest in improving Jython compliance with Java and lifting Jython classes to Java classes turning Java classes into Jython class proxies &#8211; everything at runtime. This doesn&#8217;t work without specifying Java interfaces in Jython. Those consist of two parts: type signatures + annotations. For functions and classes this works in Python without much hassle. With Python 3.0 style function annotations one can even remove a decorator for type signatures. It doesn&#8217;t work for members though. In Java you can write<\/p>\n<pre lang=\"java\">public class CusomerId {\r\n    @Id\r\n    @Column(name = \"CustId\", nullable = false)\r\n    private Integer cust_id;\r\n}<\/pre>\n<p>In Python I want to write similarly<\/p>\n<pre lang=\"python\">class CusomerId:\r\n    @Id\r\n    @Column(name = \"CustId\", nullable = False)\r\n    cust_id = jproperty(\"private int\")<\/pre>\n<p>which translates into<\/p>\n<pre lang=\"python\">class CusomerId:\r\n    cust_id = Id(Column(name=\"CustId\", nullable=False)(jproperty(\"private int\")))<\/pre>\n<p>This requires that assignment statements ( grammatically expr_stmt&#8217;s ) may be decorated, not just functions and classes.<\/p>\n<h3>3. A new opcode for code monitoring<\/h3>\n<p>I know Ned Batchelders <a href=\"http:\/\/nedbatchelder.com\/code\/coverage\/\">coverage<\/a> tool and I have written one by myself using EasyExtend. EasyExtends is more powerful in that it doesn&#8217;t only provide the simplest type of coverage namely <em>statement coverage<\/em>. However it uses source code weaving which might affect functionality in a highly reflective language. It would be far better to introduce a new opcode which is weaved into Pythons bytecode and acts as a sensor. The weaving can be activated using a command line option.  The overall achievement is improved code monitoring. This solution might also be applied to improve debuggers by setting breakpoints within expressions.<\/p>\n<h3>4. Function annotation and the nonlocal statement backports<\/h3>\n<p>I wish to see function argument annotations and the nonlocal statement in Python 2.x.<\/p>\n<h3>Other things<\/h3>\n<p>Admittedly I felt a little depression after the huge disappointment which was Python 3. Instead of a bright future it looked much like a minor legacy transformation which essentially missed the point of relevant trends in language design which are marked by concurrency orientation and unification of declarative dataflow and OO in frameworks + languages like WPF\/Silverlight, Flex and JavaFX. The best thing which can be said about Python 3 is that it didn&#8217;t turn into a running gag and actually shipped code.<\/p>\n<p>However there are lots of positive news and much progress in many other areas. At many fronts Python performance is targeted: PyPy, Unladen Swallow, Psyco 2, Cython, Shedskin. Package distribution and deployment is addressed just like renovation of the standard library. With PyPy, Unladen Swallow, Jython and IronPython Python becomes or is already GIL free and fit for multicore. The one improvement I&#8217;m personally most pleased about is that of Jython. Aside from my eternal pets ( Trail + EasyExtend ) I enjoy exploring the Javaverse, which is incredibly rich, from the Jython + scripting angle with some promising first results, new challenges and also some disappointments. I actually expect the next 600 Python web frameworks of interest will not be written in CPython anymore but in Jython and IronPython using Java\/.Net components. When will we see a <em>Jython Enterprise Framework<\/em> on the JVM which will be as powerful as Spring but as lightweight as Pylons?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Import system Replace the flat module cache by a set of ModuleTree objects rooted in nodes living on the PYTHONPATH. Apply relative path semantics by default and treat absolute paths as special cases. Internal paths which are used in &hellip; <a href=\"http:\/\/fiber-space.de\/wordpress\/2009\/07\/25\/four-things-id-change-in-python-and-a-little-more\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/posts\/1047"}],"collection":[{"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/comments?post=1047"}],"version-history":[{"count":11,"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/posts\/1047\/revisions"}],"predecessor-version":[{"id":1058,"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/posts\/1047\/revisions\/1058"}],"wp:attachment":[{"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/media?parent=1047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/categories?post=1047"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/tags?post=1047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}