473,626 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PEP 318: Can't we all just get along?

For what it's worth, I wrote the original PEP 318. I probably wasn't
qualified, but I just wanted a nice simple way to declare class methods
without having to repeat the function name. After submitting it to BDFL
for approval, more work was needed and the discussion of PEP 318 on
python-dev increased rapidly. It was evident that I was in over my head,
so I asked more someone more experienced to take over.

I guess others had bigger plans for my proposal that I had planned. It
has turned into the "solution" to many problems: type checking (both
arguments and returned values), metaclasses, metadata, interfaces,
function attributes, etc.). Unfortunately, in the process, this simple
request for syntactical sugar has turned into a monstrosity. In my
opinion, none of the proposed syntaxes really seem Pythonic. This PEP
just seems to be trying to solve too many problems.

Bear with me, but I'd like to propose one more syntax that is simple,
easy for newbies to understand, and nowhere near as powerful as the
current PEP's syntax. However, it doesn't add incoherent, arbitrary
syntax either.

def classmethod foo(x, y, z):
pass

That's it. One "decorator" that is a callable object that takes a
method as it's only argument. No expressions, lists, tuples, etc. Just
one callable object. Ok, if you absolutely must have more than one.

def classmethod synchronized foo(x, y, z):
pass

Once again, no expressions. I know that this isn't going to solve
everyone's type-checking, metadata, and function attribute problems, but
let's face it, using this PEP for all of those things just creates ugly
syntax. There must be more Pythonic ways to do those things in their
own PEPs.

--
Kevin Smith
Ke*********@sas .com
Jul 18 '05 #1
38 2573
Kevin Smith wrote:
For what it's worth, I wrote the original PEP 318. I probably wasn't
qualified, but I just wanted a nice simple way to declare class methods
without having to repeat the function name. After submitting it to BDFL
for approval, more work was needed and the discussion of PEP 318 on
python-dev increased rapidly. It was evident that I was in over my head,
so I asked more someone more experienced to take over.

I guess others had bigger plans for my proposal that I had planned. It
has turned into the "solution" to many problems: type checking (both
arguments and returned values), metaclasses, metadata, interfaces,
function attributes, etc.). Unfortunately, in the process, this simple
request for syntactical sugar has turned into a monstrosity. In my
opinion, none of the proposed syntaxes really seem Pythonic. This PEP
just seems to be trying to solve too many problems.

Bear with me, but I'd like to propose one more syntax that is simple,
easy for newbies to understand, and nowhere near as powerful as the
current PEP's syntax. However, it doesn't add incoherent, arbitrary
syntax either.

def classmethod foo(x, y, z):
pass

That's it. One "decorator" that is a callable object that takes a
method as it's only argument. No expressions, lists, tuples, etc. Just
one callable object. Ok, if you absolutely must have more than one.

def classmethod synchronized foo(x, y, z):
pass

Once again, no expressions. I know that this isn't going to solve
everyone's type-checking, metadata, and function attribute problems, but
let's face it, using this PEP for all of those things just creates ugly
syntax. There must be more Pythonic ways to do those things in their
own PEPs.


Nope. That's using static declarations. We're a dynamically typed
language as much as possible. Isn't there something that doesn't
require any additional grammar words to identify classmethods and
staticmethods? Isn't there something, inherent in the way static,
class, and instance methods 'look' naturally, that would tell us what
they are?

Jul 18 '05 #2
Paul Morrow wrote:
Kevin Smith wrote:
def classmethod foo(x, y, z):
pass

That's it. One "decorator" that is a callable object that takes a
method as it's only argument. No expressions, lists, tuples, etc.
Just one callable object.


Nope. That's using static declarations. We're a dynamically typed
language as much as possible. Isn't there something that doesn't
require any additional grammar words to identify classmethods and
staticmethods?


It looks to me as though Kevin is not suggesting keywords, but
callables. In other words he would consider this valid, provided
my_own_decorato r was a callable.

def my_own_decorato r foo(x, y, z):
pass
-Peter
Jul 18 '05 #3
Peter Hansen wrote:
Paul Morrow wrote:
Kevin Smith wrote:
def classmethod foo(x, y, z):
pass

That's it. One "decorator" that is a callable object that takes a
method as it's only argument. No expressions, lists, tuples, etc.
Just one callable object.

Nope. That's using static declarations. We're a dynamically typed
language as much as possible. Isn't there something that doesn't
require any additional grammar words to identify classmethods and
staticmethods?

It looks to me as though Kevin is not suggesting keywords, but
callables. In other words he would consider this valid, provided
my_own_decorato r was a callable.

def my_own_decorato r foo(x, y, z):
pass
-Peter


Oh, sorry, I wasn't reading that closely enough. Hmmmm... it's an
interesting idea. It's not ugly...

First though, I still believe that we should exploit existing
conventions (recommended coding practices) as a way of getting 'free'
declarations for class, static, and instance methods (e.g. methods whose
first param is 'self' are instance methods, etc.). That feels very
pythonic to me, just as we use naming conventions to distinguish public,
private, and semi-private methods.

But I think that, where we want to provide additional info about a
method, and there are no conventions to take advantage of, Kevin's
suggestion does have some appeal.

Questions (for Kevin):

1. Would

def deco1 foo(a, b, c): pass

be the same as (just syntactic sugar for)

def foo(a, b, c): pass
foo = deco1(foo)

or would it mean something else?

2. Would

def deco1 deco2 foo(a, b, c): pass

be the same as

def foo(a, b, c): pass
foo = deco1(deco2(foo ))

or

def foo(a, b, c): pass
foo = deco2(deco1(foo ))
3. Would there be any restrictions on what a decorator could *do* to the
method it was passed? e.g. Could it change:

* the method's name (which could of course affect the method's
visibility: public|private| semi-private)?
* whether the method was a static, class, or instance method?
* the method's signature (formal parameter names, parameter order,
defaults values)?
Jul 18 '05 #4
In article <20************ ********@braebu rn.themorgue.or g>,
Kevin Smith <Ke*********@sa s.com> wrote:

Bear with me, but I'd like to propose one more syntax that is simple,
easy for newbies to understand, and nowhere near as powerful as the
current PEP's syntax. However, it doesn't add incoherent, arbitrary
syntax either.

def classmethod foo(x, y, z):
pass

That's it. One "decorator" that is a callable object that takes a
method as it's only argument. No expressions, lists, tuples, etc. Just
one callable object. Ok, if you absolutely must have more than one.

def classmethod synchronized foo(x, y, z):
pass

Once again, no expressions. I know that this isn't going to solve
everyone's type-checking, metadata, and function attribute problems, but
let's face it, using this PEP for all of those things just creates ugly
syntax. There must be more Pythonic ways to do those things in their
own PEPs.


Kevin,

+1 for this idea.

I completely agree that the original PEP-318 proposed a simple and
reasonable idea, and I too have been much dismayed by all that seems to
have been grafted onto it since. This latest idea of yours certainly
sounds a lot more reasonable than anything else I've seen so far. It
solves the original well-defined problem cleanly, and probably solves
some of the other proposed uses too.

I would even go so far as to say: Go ahead and restrict it to at most
one callable object. If someone really wants to define a flaming hot
crossed synchronized blue classmethod foo, they can bloody well define a
callable object that has the (in)appropriate behaviour.

I hope that perhaps cooler heads (such as yours) will prevail, and keep
Python's syntax and semantics relatively neat and tidy. We don't need
the One PEP to Rule Them All, in the Land of Python where the shadows --
so far -- do not lie.

-M, "one more PEP out of you, mister, and you're history!" ;)

--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
Jul 18 '05 #5
Michael J. Fromberger wrote:
In article <20************ ********@braebu rn.themorgue.or g>,
Kevin Smith <Ke*********@sa s.com> wrote:
Bear with me, but I'd like to propose one more syntax that is simple,
easy for newbies to understand, and nowhere near as powerful as the
current PEP's syntax. However, it doesn't add incoherent, arbitrary
syntax either.

def classmethod foo(x, y, z):
pass

That's it. One "decorator" that is a callable object that takes a
method as it's only argument. No expressions, lists, tuples, etc. Just
one callable object. Ok, if you absolutely must have more than one.

def classmethod synchronized foo(x, y, z):
pass

Once again, no expressions. I know that this isn't going to solve
everyone's type-checking, metadata, and function attribute problems, but
let's face it, using this PEP for all of those things just creates ugly
syntax. There must be more Pythonic ways to do those things in their
own PEPs.

Kevin,

+1 for this idea.


I posted the same thing to python-dev (although it took a week for the
post to appear) and some guy said -infinity or something smart like that.
I think it is simpler to use keywords for classmethod and staticmethod
at least. Those are builtin features of python, just like they are
builtins for java (which has keywords for its builtins like static,
abstract, interface, etc.).
I propose this *in addition* to whatever decorator syntax we add. We
shouldn't consider staticmethod and classmethod as decorators.
Jul 18 '05 #6
Kevin Smith wrote:
For what it's worth, I wrote the original PEP 318. I probably wasn't
qualified, but I just wanted a nice simple way to declare class methods
without having to repeat the function name. After submitting it to BDFL
for approval, more work was needed and the discussion of PEP 318 on
python-dev increased rapidly. It was evident that I was in over my head,
so I asked more someone more experienced to take over.

I guess others had bigger plans for my proposal that I had planned. It
has turned into the "solution" to many problems: type checking (both
arguments and returned values), metaclasses, metadata, interfaces,
function attributes, etc.). Unfortunately, in the process, this simple
request for syntactical sugar has turned into a monstrosity. In my
opinion, none of the proposed syntaxes really seem Pythonic. This PEP
just seems to be trying to solve too many problems.

Bear with me, but I'd like to propose one more syntax that is simple,
easy for newbies to understand, and nowhere near as powerful as the
current PEP's syntax. However, it doesn't add incoherent, arbitrary
syntax either.

def classmethod foo(x, y, z):
pass

That's it. One "decorator" that is a callable object that takes a
method as it's only argument. No expressions, lists, tuples, etc. Just
one callable object.
+2 for me.

Ok, if you absolutely must have more than one.
def classmethod synchronized foo(x, y, z):
pass


No. If you want more than one, provide your own decorator, ie :

def synchronizedCla ssmethod(method ):
return synchronized(cl assmethod(metho d))

def synchronizedCla ssmethod foo(x, y, z):
pass

My 2 eurocents
Bruno

Jul 18 '05 #7
On Tue, 17 Aug 2004 21:13:47 -0400,
Paul Morrow <pm****@yahoo.c om> wrote:
First though, I still believe that we should exploit existing
conventions (recommended coding practices) as a way of getting 'free'
declarations for class, static, and instance methods (e.g. methods
whose first param is 'self' are instance methods, etc.). That feels
very pythonic to me, just as we use naming conventions to distinguish
public, private, and semi-private methods.


I don't understand how assigning semantic significance to a "recommende d
coding practice" is Pythonic.

In the face of ambiguity, refuse to guess.

Explicit is better than implicit.

I think that the idea that started this thread is just right:

def decorator function( arguments ): pass

is exactly equivalent to

def function( arguments ): pass
decorator( function )

Note that:

- the decorator is right next to the function name
- the decorator is outside the code of the function
- there are no new keywords or punctuation
- it's dynamic, flexible, and extensible

It's also abusable, but that's the nature of a language as dynamic as
Python.

Regards,
Dan

--
Dan Sommers
<http://www.tombstoneze ro.net/dan/>
Never play leapfrog with a unicorn.
Jul 18 '05 #8
Dan Sommers wrote:
On Tue, 17 Aug 2004 21:13:47 -0400,
Paul Morrow <pm****@yahoo.c om> wrote:

First though, I still believe that we should exploit existing
conventions (recommended coding practices) as a way of getting 'free'
declaration s for class, static, and instance methods (e.g. methods
whose first param is 'self' are instance methods, etc.). That feels
very pythonic to me, just as we use naming conventions to distinguish
public, private, and semi-private methods.

I don't understand how assigning semantic significance to a "recommende d
coding practice" is Pythonic.

In the face of ambiguity, refuse to guess.

Explicit is better than implicit.


Good conventions prevent ambiguity.

class Foo:
def method1(self, a, b): pass # clearly an instance method
def method2(cls, a, b): pass # clearly a class method
def method3(a, b): pass # clearly a static method
When declarations conflict with conventions, it makes us wonder what the
author really intended.

def staticmethod setX(self, x):
self.x = x

I think that the idea that started this thread is just right:


You're right, this thread is about decorators, not about more
opportunities for dynamic typing. I just wanted to remind us that
decorators are a lot like static typing, which isn't terribly pythonic.

Jul 18 '05 #9
In <ma************ *************** ***********@pyt hon.org> Paul Morrow
wrote:
Peter Hansen wrote:
Questions (for Kevin):
1. Would

def deco1 foo(a, b, c): pass

be the same as (just syntactic sugar for)

def foo(a, b, c): pass
foo = deco1(foo)

or would it mean something else?


Sorry, I guess I should have put the equivalent current Python code in
my first post. The example above is exactly what I meant.

2. Would

def deco1 deco2 foo(a, b, c): pass

be the same as

def foo(a, b, c): pass
foo = deco1(deco2(foo ))

or

def foo(a, b, c): pass
foo = deco2(deco1(foo ))
I would choose the first option since it's easier to transform the
string "deco1 deco2 foo" to "deco1(deco2(fo o))" while I'm reading it (i.
e. it fits my head :) ).

3. Would there be any restrictions on what a decorator could *do* to
the method it was passed? e.g. Could it change:

* the method's name (which could of course affect the method's
visibility: public|private| semi-private)?
Nope, beginners wouldn't understand it immediately. That's just too
magical.
* whether the method was a static, class, or instance method?
Yes.
* the method's signature (formal parameter names, parameter order,
defaults values)?


I guess, in theory, it could since the object returned by the
"decorator" (I really hate that term) could return a completely
different object, but I wouldn't suggest it.

--
Kevin Smith
Ke*********@sas .com
Jul 18 '05 #10

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

Similar topics

68
4335
by: Marco Bubke | last post by:
Hi I have read some mail on the dev mailing list about PEP 318 and find the new Syntax really ugly. def foo(x, y): pass I call this foo(1, 2), this isn't really intuitive to me! Also I don't like the brackets.
3
1284
by: PF | last post by:
Hello, I'm pleased to see activity on this topic as it pains me to write "classmethod" two pages of code after the method definition. However I find the decorators to obfuscate the syntax and lessen the expressivity (ie. they restrain what can be done). All these problems come from the fact that the execution of the "foo=staticmethod(foo)" must be delayed after the execution of the "def" statement because it must act on the function...
45
2564
by: Edward K. Ream | last post by:
Hello all, First of all, my present state of mind re pep 318 is one of sheepish confusion. I suspect pep 318 will not affect Leo significantly, but I am most surprised that an apparently controversial feature is being added without a notice, say, in comp.lang.python.announce. I say sheepish, because everyone knows that one should make sure new proposals don't bite you. Still, I would have thought that there were other ways of keeping...
3
1140
by: Hallvard B Furuseth | last post by:
....and opinions:-) I don't understand some of the arguments in pep-318 (version 1.19), or what the current syntax has to do with some of the design goals mentioned there. Could someone explain? > Design Goals > > The new syntax should > (...)
0
2338
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and Methods Version: $Revision: 1.34 $ Last-Modified: $Date: 2004/09/03 09:32:50 $ Author: Kevin D. Smith, Jim Jewett, Skip Montanaro, Anthony Baxter
0
8192
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8696
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8358
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6119
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4195
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.