473,854 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Prothon, metaclasses, Zope [Was: A 'Python like' language]

> Hello, my name is Skip and I am metaclass-unaware. I've been programming in
Python for about ten years and I have yet to write a metaclass. At first I
thought it was just that metaclasses were new to the language, but now as
more and more people use them and proclaim their widespread benefits, I have
come to realize that through years of abuse my brain has become addicted to
classic classes.


I began using Python since version 2.2.1 and without knowing anything
about OOP, so I had the advantage of a fresh start ;) Still, I will readily
admit that I was not immediately sold to metaclasses and actually I was
kind of skeptical about them. The "Putting metaclasses to work" book
made me change my mind. At this point I have becomed so accustomed to
metaclasses that I am disturbed when I cannot use them.

Just a real life example. I started studying Zope few days ago.
Writing my first class I got caught since I was overriding a predefined Zope
method. I made a dir() and discovered that the context object in Zope
has more than four hundreds (400!) attributes. In such a situation it
is likely to override a predefined name, especially now that I am a
beginner and I have a fair chance of reimplementing (badly) something
which is already available. So, I thought: "well, this a job for a metaclass"
and in five minutes I implemented a metaclass raising an error if I was
inadvertently overriding a predefined name (except names such as __init__
and similia, of course). Everything was nice and good until the moment
I tested the metaclass on a Zope class and got a segmentation fault.

Since I don't know anything about Zope internals I can only make a guess
of what happened and I would be happy if some Zope guru here could
confirm (possibly educated) guess.

In my understanding, Zope tweaked Python classes at C level code, introducing
the concept of Extension classes. Extension classes are instances of a C coded
metaclass which does a lot of magic (for instance there are methods which
are automatically generated each time I create an extensions class);
unfortunately, this metaclass does not follow the protocol of Python 2.2+
metaclasses. This is evidently an historical accident, since Zope Extension
Classes were invented before Python 2.2[*]; the net result is that I cannot
mix Python classes with custom metaclasses and Zope Extension classes.

I have heard that this is a temporary wart and that Zope 3 will solve
this issue (I'd like to have a confirmation here). However, for the
moment, I had to come out with a non-metaclass solution.

So, I reverted my mind to the pre-metaclass functioning mode (which required
a certain effort) and I wrote a function that takes a class, looks at
its dictionary, and raises an error if the class overrides an attribute
which is already defined in the parent classes. The solution works,
but it is kind of ugly compared to the metaclass solution:

1. The metaclass can raise the error *before* the metaclass is created,
whereas the function works a posteriori, *after* the overriding is done;
if find it to be conceptually unsatisfactory, I don't want to create
a class just to throw it away. The alternative is to use a class factory,
but then I have just re-invented a metaclass with an ugly call syntax.

2. The metaclass can be inherited, so the check is automatic for all children;
on the contrary, I have to call the function by hand each time I define
a new class. This means writing twice the class name, which is error
prone if I later rename the class and I forget to update the function
call.

Whereas it is true that in most cases you can find a non-metaclass solution,
it is also true that in most case the metaclass solution is by far more
elegant than the alternative.

BTW, I wonder how Prothon would solve this problem, i.e. selectively
forbidding the overriding of names, with an easy of use/elegance
comparable to the Python metaclass solution.

Michele Simionato

[*] I would be curious to know if Guido decided to expose metaclasses in
Python since he noticed that they were already being used in real applications
such as Zope (in some hidden form), or if there was some other reason.
Jul 18 '05
27 2030
aa**@pythoncraf t.com (Aahz) wrote in message news:<c4******* ***@panix1.pani x.com>...
In article <95************ **************@ posting.google. com>,
Michele Simionato <mi************ ***@poste.it> wrote:

[...]


Michele, I just got a mailbox full error when I tried sending you
e-mail. Please fix.


It should work now. My address mi************* **@poste.it is mostly
a span recipient I don't check often. Rea addresses I check every day are
mi************* *@libero.it and mi************* **@partecs.com
M.S.
Jul 18 '05 #21
In article <95************ **************@ posting.google. com>,
Michele Simionato <mi************ ***@poste.it> wrote:
aa**@pythoncra ft.com (Aahz) wrote in message news:<c4******* ***@panix1.pani x.com>...

Michele, I just got a mailbox full error when I tried sending you
e-mail. Please fix.


It should work now. My address mi************* **@poste.it is mostly
a span recipient I don't check often. Rea addresses I check every day are
mi************ **@libero.it and mi************* **@partecs.com


Then please make those addresses readily available by sticking them in
your .sig or something. Having a non-replyable address is about as rude
as top-posting. ;-)
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

"usenet imitates usenet" --Darkhawk
Jul 18 '05 #22
Mark Hahn wrote:
You don't have to use the obj = proto() technique to create an object. The following code is identical to saying subproto = topproto() except no
__init__() will be called:

subproto = Object()
subproto.set_pr oto(topproto) # switch prototype on the fly

Does this give you the missing piece you need


Yes, it does, I think. Creating the prototype this way
is very similar to what the Python class statement does.

Greg
Jul 18 '05 #23
Mark Hahn wrote:
it is difficult to give credit to people liking tabs and


As far as top-posting, I am trying to improve, it's just hard to change my
reply style after using it for 30 years without getting any complaints
before. I feel like I'm in a twilight-zone episode.


Actually I am too. There is some interresting dynamics going on here.

Appart from that Brandon guy, I have never experienced such a reaction
before in this group. I hope it is just a fluke.
regards Max M
Jul 18 '05 #24
In article <40************ *********@dread 12.news.tele.dk >,
Max M <ma**@mxm.dk> wrote:
Mark Hahn wrote:

As far as top-posting, I am trying to improve, it's just hard to change my
reply style after using it for 30 years without getting any complaints
before. I feel like I'm in a twilight-zone episode.


Actually I am too. There is some interresting dynamics going on here.

Appart from that Brandon guy, I have never experienced such a reaction
before in this group. I hope it is just a fluke.


Mark's the first person I recall seeing who was trying to participate in
a serious discussion and also using top-posting. Also, there are a fair
number of netiquette snobs here, and when Mark actively rejected the
arguments against top-posting, people got annoyed. It was similar to
the reaction you might expect from the following exchange:

A: <spam>
B: Please don't post spam, it's not appropriate
A: Why not? Spam has a number of beneficial qualities....

I'm always surprised when I find someone who's been active on the Net for
more than a few years who isn't even aware of how much a hot-button
top-posting is in some communities.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

"usenet imitates usenet" --Darkhawk
Jul 18 '05 #25
aa**@pythoncraf t.com (Aahz) wrote in message news:<c4******* ***@panix2.pani x.com>...
In article <95************ **************@ posting.google. com>,
Michele Simionato <mi************ ***@poste.it> wrote:
My address mi************* **@poste.it is mostly
a span recipient I don't check often. Rea addresses I check every day are
mi************ **@libero.it and mi************* **@partecs.com


Then please make those addresses readily available by sticking them in
your .sig or something. Having a non-replyable address is about as rude
as top-posting. ;-)

BTW, I tried to send you a message and got this:

- These recipients of your message have been processed by the mail
server:
aa**@pythoncraf t.com; Failed; 5.1.1 (bad destination mailbox address)

Remote MTA iris2.directnic .com: SMTP diagnostic: 550 5.7.1 Mail from
smtp1.libero.it (193.70.192.51) refused (blackholed by
bl.spamcop.net) ; Blocked - see
http://www.spamcop.net/bl.shtml?193.70.192.51

So it looks like spam is taking control of our lifes and making both
of us to appear rude :-/
Michele Simionato
Jul 18 '05 #26
In article <95************ *************@p osting.google.c om>,
Michele Simionato <mi************ ***@poste.it> wrote:
aa**@pythoncra ft.com (Aahz) wrote in message news:<c4******* ***@panix2.pani x.com>...
In article <95************ **************@ posting.google. com>,
Michele Simionato <mi************ ***@poste.it> wrote:

My address mi************* **@poste.it is mostly
a span recipient I don't check often. Rea addresses I check every day are
mi********** ****@libero.it and mi************* **@partecs.com


Then please make those addresses readily available by sticking them in
your .sig or something. Having a non-replyable address is about as rude
as top-posting. ;-)


BTW, I tried to send you a message and got this:

- These recipients of your message have been processed by the mail
server:
aa**@pythoncra ft.com; Failed; 5.1.1 (bad destination mailbox address)

Remote MTA iris2.directnic .com: SMTP diagnostic: 550 5.7.1 Mail from
smtp1.libero.i t (193.70.192.51) refused (blackholed by
bl.spamcop.net ); Blocked - see
http://www.spamcop.net/bl.shtml?193.70.192.51

So it looks like spam is taking control of our lifes and making both
of us to appear rude :-/


Ick. That's odd -- I thought my DNS provider didn't do that kind of
thing, but I'm guessing they've been under such overload that they had
to. <sigh> Please forward that message with full headers to
aa****@panix.co m -- my local spam filters shouldn't trap it.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

"usenet imitates usenet" --Darkhawk
Jul 18 '05 #27
In article <c4**********@p anix3.panix.com >, Aahz wrote:

Ick. That's odd -- I thought my DNS provider didn't do that kind of
thing, but I'm guessing they've been under such overload that they had
to. <sigh> Please forward that message with full headers to
a****y@p***x.co m -- my local spam filters shouldn't trap it.


Just a few words of advice - never post your email address on Usenet unless:

a) you don't mind getting flooded with spam, or
b) you obfuscate it in some way

Especially given the context of this conversation, it made me wince when I
saw you post a secondary email address in plaintext to get around spam
problems with your primary one...

Peace,
Dave

--
..:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.
: please talk to your son or daughter about parametric polymorphism. :
Jul 18 '05 #28

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

Similar topics

0
1405
by: Mark Hahn | last post by:
I would like to announce a new interpreted object-oriented language very closely based on Python, that is Prototype-based, like Self (http://research.sun.com/research/self/language.html) instead of class-based like Python. I have named the language Prothon, short for PROtotype pyTHON. You can check it out at http://prothon.org. The prototype scheme makes object oriented computing very simple and complicated things like meta-classes...
0
1320
by: Mark Hahn | last post by:
Ben Collins and I have developed a new interpreted object-oriented language very closely based on Python, that is Prototype-based, like Self (http://research.sun.com/research/self/language.html) instead of class-based like Python. I have named the language Prothon, short for PROtotype pyTHON. You can check it out at http://prothon.org. The prototype scheme makes object oriented computing very simple and complicated things like...
145
6443
by: David MacQuigg | last post by:
Playing with Prothon today, I am fascinated by the idea of eliminating classes in Python. I'm trying to figure out what fundamental benefit there is to having classes. Is all this complexity unecessary? Here is an example of a Python class with all three types of methods (instance, static, and class methods). # Example from Ch.23, p.381-2 of Learning Python, 2nd ed. class Multi:
7
3568
by: Michele Simionato | last post by:
So far, I have not installed Prothon, nor I have experience with Io, Self or other prototype-based languages. Still, from the discussion on the mailing list, I have got the strong impression that you do not actually need to fork Python in order to implement prototypes. It seems to me that Python metaclasses + descriptors are more than powerful enough to implementing prototypes in pure Python. I wrote a module that implements part of what...
25
1851
by: Mark Hahn | last post by:
There is a new release of Prothon that I think is worth mentioning here. Prothon version 0.1.0 has changed almost beyond recognition compared to what was discussed here before. For example: the "Perl-like" symbols are gone and the "self" keyword is back, replacing the period. Prothon has gotten more "python-like", simpler, and more powerful, all at the same time. There is a new tutorial that covers Prothon completely without assuming...
49
2641
by: Mark Hahn | last post by:
As we are addressing the "warts" in Python to be fixed in Prothon, we have come upon the mutable default parameter problem. For those unfamiliar with the problem, it can be seen in this Prothon code sample where newbies expect the two function calls below to both print : def f( list= ): print list.append!(1) f() # prints
20
1824
by: Mark Hahn | last post by:
Prothon is pleased to announce another major release of the language, version 0.1.2, build 710 at http://prothon.org. This release adds many new features and demonstrates the level of maturity that Prothon has reached. The next release after this one in approximately a month will be the first release to incorporate the final set of frozen Prothon 1.0 language features and will be the Alpha release. You can see the set of features still...
0
9899
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9750
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
11024
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...
0
10362
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...
0
9510
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7076
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
5738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4550
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
3
3182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.