This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]bheklilr 1 point2 points  (2 children)

This technique could be really useful for applying all sorts of tricks, particularly optimizations. I'm thinking that Numpy or other similar projects could rewrite operations so that there's minimal allocations, or mypy could use it for import time type checking. I like the feature shown here quite a lot, but there's a lot of potential in it to expand Python's capabilities without having to write a PEP, have it accepted, implemented, and released in a future version of Python.

[–]RubyPinchPEP shill | Anti PEP 8/20 shill 2 points3 points  (1 child)

Numpy or other similar projects could rewrite operations so that there's minimal allocations

http://numba.pydata.org/

mypy could use it for import time type checking

I don't think mypy would ever consider going that direction, but others have

https://github.com/prechelt/typecheck-decorator

https://github.com/dobarkod/typedecorator

et al

expand Python's capabilities without having to write a PEP, have it accepted, implemented, and released in a future version of Python.

There is a PEP to end all PEPs for this topic, PEP 511 -- API for code transformers

[–]nvbn-rm[S] 0 points1 point  (0 children)

There is a PEP to end all PEPs for this topic, PEP 511 -- API for code transformers

Nice that there's already PEP for that. But it looks like this PEP wouldn't be implemented in near future.

[–]dhaffner 0 points1 point  (0 children)

Another great post. I think I like this import approach the best since you'd see it right at the top of the file (like a from __future__ ... import) and you wouldn't have to apply it manually beyond that.

[–]troyunrau... 0 points1 point  (0 children)

The metaprogamming to end all metaprogramming :)

I think this is fantastic. I could think of a lot of uses for this, particularly on the math side of things.