473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PEP-318, billion-and-first syntax proposal



As soon as one of these syntax discussions go on long enough, I start to
think that, whatever the problem ,it should be solved by thunks (search
python dev if you need to know what a thunk is) or something thunk-like.
It's a personal weakness, I suppose. In that vein, here's my entry into
the Great Decorator Debate 2004.

def NAME as EXPRESSION:
BLOCK

BLOCK is executed in a separate namespace *before* EXPRESSION is
evaluated. EXPRESSION is then evaluated in BLOCK's namespace. This is
probably best illustrated with an example or three:

class C:

# The standard staticmethod example. It works reasonably well
for this, but is
# a bit wordier than some examples. It's clear what's happening
though.

def foo as staticmethod(body):
def body(x, y):
#...

# This method generalized nicely to properties, which I like.

def bar as property(getbar, setbar, None, doc):
doc = "That crazy bar property!"
def getbar(self):
#....
def setbar(self, value):
#....

# It's pretty good for the nasty long decorators and arg list case.

def bar as OBJCDecorator("@#%$@#^",
SomeOtherDecorator("asdfasf", body)):
def body(a_long_argument_list, with_long_arg_name, _etc.):
#....

This syntax is by no means perfect; it's a little wordy in the simple
case for one thing. But it's more obvious what's happening in this
syntax than in any of the others that I've seen which I think is a big
plus.

It also generalizes well to the hypothetical Python 3000 with optional
type checking, since the signature can be placed on the user visible
'foo' instead of on the pre-transform body:

def foo(int, int)->int as staticmethod(body):
def body(x, y):
#...

Enjoy,

-tim

Jul 18 '05 #1
0 968

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

59
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
72
by: Raymond Hettinger | last post by:
Peter Norvig's creative thinking triggered renewed interest in PEP 289. That led to a number of contributors helping to re-work the pep details into a form that has been well received on the...
20
by: Micah Elliott | last post by:
Please read/comment/vote. This circulated as a pre-PEP proposal submitted to c.l.py on August 10, but has changed quite a bit since then. I'm reposting this since it is now "Open (under...
77
by: Ben Finney | last post by:
Howdy all, PEP 354: Enumerations in Python has been accepted as a draft PEP. The current version can be viewed online: <URL:http://www.python.org/peps/pep-0354.html> Here is the...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.