Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-05 Thread Pieter van Oostrum
Chris Angelico writes: > On Tue, Nov 5, 2019 at 5:43 PM dieter wrote: >> I suppose that "isinstance" (at least under Python 2) does not >> behave exactly as stated in PEP 3119. Instead, "isinstance" >> first directly checks for the instance to be an instance of the >> class *AND ONLY IF THIS FAI

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-05 Thread Rhodri James
On 04/11/2019 22:23, Peter J. Holzer wrote: On 2019-11-04 14:54:23 +, Rhodri James wrote: On 04/11/2019 14:33, Veek M wrote: __metaclass__ = whatever; # is python2.x syntax But not Python3: see PEP 3115 Doesn't "X is python2.x syntax" imply "X is not python3 syntax"? Not necessarily,

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Chris Angelico
On Tue, Nov 5, 2019 at 5:43 PM dieter wrote: > I suppose that "isinstance" (at least under Python 2) does not > behave exactly as stated in PEP 3119. Instead, "isinstance" > first directly checks for the instance to be an instance of the > class *AND ONLY IF THIS FAILS* calls the class' "__instanc

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread dieter
in "True" also for other cases. > 1. Why do I get True whenever i tuple the > isinstance(f, (Bar, Foo)) > (and why don't the print's run) > > The docs say that you can feed it a tuple and that the results are OR'd > > > The form using a tupl

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Peter J. Holzer
On 2019-11-04 14:54:23 +, Rhodri James wrote: > On 04/11/2019 14:33, Veek M wrote: > > __metaclass__ = whatever; # is python2.x syntax > > But not Python3: see PEP 3115 Doesn't "X is python2.x syntax" imply "X is not python3 syntax"? hp -- _ | Peter J. Holzer| Story must ma

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Rhodri James
On 04/11/2019 14:33, Veek M wrote: Aha. You're trying to fix up the metaclass after the fact, which is not the right way to do it. If you change the class definitions to: __metaclass__ = whatever; # is python2.x syntax But not Python3: see PEP 3115 then you get the prints from MyMeta.__i

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Veek M
> > Aha. You're trying to fix up the metaclass after the fact, which is not > the right way to do it. If you change the class definitions to: > __metaclass__ = whatever; # is python2.x syntax > then you get the prints from MyMeta.__instancecheck__(). The > isinstance() still returns True, tho

Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Rhodri James
On 04/11/2019 11:30, Veek M wrote: 1. Why do I get True whenever i tuple the isinstance(f, (Bar, Foo)) (and why don't the print's run) I'm not very familiar with metaclasses, but I can answer the second part of your question. The docs say that you can feed it a tuple and t

__instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Veek M
B) or ... (etc.). - which implies that the metaclasses are called for each class? class MyzMeta(type): def __instancecheck__(cls, other): print('MyzzMeta', other) return 0 class MyMeta(MyzMeta, object): def __instancecheck__(cls, other): prin

Re: Metaclasses and classproperties

2019-09-10 Thread Eko palypse
Thank you for your thoughts. I'm trying to migrating en existing python2 api, which has been build using boost::python with pure python3 code. All of the py2 classes do have these additional properties names and values. You are right, using dict(Ordinal.__members__) for names could have been used

Re: Metaclasses and classproperties

2019-09-10 Thread Peter Otten
Eko palypse wrote: > I'm fairly new when it comes to metaclass programming and therefore the > question whether the following makes sense or not. > > The goal is to have two additional class properties which return a > dictionary name:class_attribute and value:class_attribute for an IntEnum > cla

Metaclasses and classproperties

2019-09-10 Thread Eko palypse
I'm fairly new when it comes to metaclass programming and therefore the question whether the following makes sense or not. The goal is to have two additional class properties which return a dictionary name:class_attribute and value:class_attribute for an IntEnum class and after reading about it I

Re: Metaclasses - magic functions

2016-12-23 Thread Mr. Wrobel
W dniu 23.12.2016 o 15:14, Ian Kelly pisze: (...) cls.added_in_init = 'test' Man, you are awsome genius! Finally somebody was able to explain me what is the power of __new__ and difference between __init__ !!! So what I wanted to achieve was adding some new attributes to the class ins

Re: Metaclasses - magic functions

2016-12-23 Thread Ian Kelly
On Fri, Dec 23, 2016 at 5:14 AM, Mr. Wrobel wrote: > Hi,thanx for answers, let's imagine that we want to add one class attribute > for newly created classess with using __init__ in metaclass, here's an > example: > > #!/usr/bin/env python > > class MetaClass(type): > # __init__ manipulation: >

Re: Metaclasses - magic functions

2016-12-23 Thread Mr. Wrobel
wise I use `__init__`. Likewise, if I'm using `__new__` then I do all my configuration in `__new__` unless I have a really good reason not to (such as making it easier for subclasses to modify/skip `__init__`). As far as metaclasses go... the only time I recall writing an `__init__` for a metac

Re: Metaclasses - magic functions

2016-12-20 Thread Ethan Furman
g `__new__` then I do all my configuration in `__new__` unless I have a really good reason not to (such as making it easier for subclasses to modify/skip `__init__`). As far as metaclasses go... the only time I recall writing an `__init__` for a metaclass was to strip off the extra arguments so

Re: Metaclasses - magic functions

2016-12-20 Thread Ethan Furman
On 12/20/2016 03:26 PM, Ian Kelly wrote: ... The latter is interesting mostly because it allows you to set the __slots__ or do something interesting with the __prepare__ hook (although the only interesting thing I've ever seen done with __prepare__ is to use an OrderedDict to preserve the the de

Re: Metaclasses - magic functions

2016-12-20 Thread Ben Finney
"Mr. Wrobel" writes: > Quick question, can anybody tell me when to use __init__ instead of > __new__ in meta programming? Use ‘__new__’ to do the work of *creating* one instance from nothing; allocating the storage, determining the type, etc. — anything that will be *the same* for every instance

Re: Metaclasses - magic functions

2016-12-20 Thread Ian Kelly
On Tue, Dec 20, 2016 at 2:04 PM, Mr. Wrobel wrote: > Hi, > > Quick question, can anybody tell me when to use __init__ instead of __new__ > in meta programming? > > I see that __new__ can be used mostly when I want to manipulate with class > variables that are stored into dictionary. > > But when t

Metaclasses - magic functions

2016-12-20 Thread Mr. Wrobel
Hi, Quick question, can anybody tell me when to use __init__ instead of __new__ in meta programming? I see that __new__ can be used mostly when I want to manipulate with class variables that are stored into dictionary. But when to use __init__? Any example? Thanx, M -- https://mail.python.

Re: name lookup failure using metaclasses with unittests

2013-04-12 Thread Terry Jan Reedy
to post-process the class, it seems that metaclasses are simply not the right tool. Using a post-processing object as a metaclass or decorator necessarily requires predefinition. Such objects are usually used more than once. For one-off postprocessing, I probably would not bother. At the moment, t

Re: name lookup failure using metaclasses with unittests

2013-04-12 Thread Ulrich Eckhardt
it can be instantiated when you > define the class. I don't like the approach to define the code to post-process a class before defining the class. It's a bit like top-posting, it messes up the reading order. Since I really intend to post-process the class, it seems that metaclasses

Re: name lookup failure using metaclasses with unittests

2013-04-11 Thread Arnaud Delobelle
On 11 April 2013 07:43, Ulrich Eckhardt wrote: > The second question that came up was if there is a way to keep a metaclass > defined inside the class or if the only way is to provide it externally. Yes, using metaclasses! I wouldn't recommend it though. Here's a proof of

Re: name lookup failure using metaclasses with unittests

2013-04-11 Thread Steven D'Aprano
ng back, I have a hack in mind that involves > creating a baseclass which in turn provides a metaclass that invokes a > specific function to post-initialize the class, similar to the way > Python 2 does it automatically, but I'm wondering if there isn't > anything better. See

Re: name lookup failure using metaclasses with unittests

2013-04-11 Thread Ulrich Eckhardt
Am 10.04.2013 11:52, schrieb Peter Otten: It looks like this particular invocation relies on class attribute and function __name__ being identical. Please file a bug report. http://bugs.python.org/issue17696 Uli -- http://mail.python.org/mailman/listinfo/python-list

Re: name lookup failure using metaclasses with unittests

2013-04-11 Thread Ulrich Eckhardt
Python 3, it fails to detect any test case at all! My guess is that the unittest library was changed to use metaclasses itself in order to detect classes derived from unittest.TestCase. Therefore, overriding the metaclass breaks test case discovery. My question in that context is how do I extend

Re: name lookup failure using metaclasses with unittests

2013-04-10 Thread Peter Otten
)]) File "/usr/lib/python2.7/unittest/case.py", line 191, in __init__ (self.__class__, methodName)) ValueError: no such test method in : test_2 It looks like this particular invocation relies on class attribute and function __name__ being identical. Please file a bug report. &g

name lookup failure using metaclasses with unittests

2013-04-10 Thread Ulrich Eckhardt
whether I discovered a bug. Now, concerning Python 3, it fails to detect any test case at all! My guess is that the unittest library was changed to use metaclasses itself in order to detect classes derived from unittest.TestCase. Therefore, overriding the metaclass breaks test case discovery

Re: Trying to learn about metaclasses

2011-07-30 Thread Steven D'Aprano
like 1+1 has very little power (it just adds two numbers), classes have more power, metaclasses more again, and exec even more still. Power can be used for good things, but it can also be used for bad. I consider metaclasses to be about equal in power to decorators, but more obscure and l

Re: Trying to learn about metaclasses

2011-07-30 Thread bruno.desthuilli...@gmail.com
On 25 juil, 17:36, "Steven W. Orr" wrote: > I have been doing a lot of reading. I'm starting to get it. I think it's > really cool as well as dangerous, Dangerous ??? Why so ? Is there anything "dangerous" in a constructor or an initialiser ??? A metaclass is just a class, and a class is just an

Re: Trying to learn about metaclasses

2011-07-26 Thread Thomas Jollans
On 26/07/11 04:44, Victor Khangulov wrote: > Hi Steven, > > I too am just learning about metaclasses in Python and I found the > example you posted to be excellent. > > I played around with it and noticed that the issue seems to be the > double-underscore in front of the

Re: Trying to learn about metaclasses

2011-07-25 Thread Victor Khangulov
Hi Steven, I too am just learning about metaclasses in Python and I found the example you posted to be excellent. I played around with it and noticed that the issue seems to be the double-underscore in front of the fields (cls.__fields = {}). If you change this parameter to use the single

Re: Trying to learn about metaclasses

2011-07-25 Thread Chris Kaynor
or key, value in ns.items(): >if isinstance(value, Field): >cls._fields[key] = value > > class Enforcer(object): ># attach the metaclass >__metaclass__ = EnforcerMeta > >def __setattr__(self, key, value): >if key in self._fields: >

Re: Trying to learn about metaclasses

2011-07-25 Thread Karim
Very good. Karim On 07/25/2011 05:46 PM, jfine wrote: Hi I gave a tutorial at this year's EuroPython that covered metaclasses. You can get the tutorial materials from a link on: http://ep2011.europython.eu/conference/talks/objects-and-classes-in-python-and-javascript Jonathan --

Re: Trying to learn about metaclasses

2011-07-25 Thread Peter Otten
Steven W. Orr wrote: > I have been doing a lot of reading. I'm starting to get it. I think it's > really cool as well as dangerous, but I plan on being respectful of the > construct. I found a web page that I found quite readable. > > http://cleverdevil.org/computing/78/ > > So, I tried to run t

Re: Trying to learn about metaclasses

2011-07-25 Thread jfine
Hi I gave a tutorial at this year's EuroPython that covered metaclasses. You can get the tutorial materials from a link on: http://ep2011.europython.eu/conference/talks/objects-and-classes-in-python-and-javascript Jonathan -- http://mail.python.org/mailman/listinfo/python-list

Trying to learn about metaclasses

2011-07-25 Thread Steven W. Orr
I have been doing a lot of reading. I'm starting to get it. I think it's really cool as well as dangerous, but I plan on being respectful of the construct. I found a web page that I found quite readable. http://cleverdevil.org/computing/78/ So, I tried to run the example code (below), and I ge

Re: Closures in metaclasses

2011-02-18 Thread zambr123
Hi there, We are currently looking for someone who has ideally several years coding experience, and who is familar with Network coding and the Python language. The project revolves around emulation and a chat based system, altough the vast majority of the project is focused on the chat based

Re: Closures in metaclasses

2010-01-21 Thread Arnaud Delobelle
Falcolas writes: > On Jan 21, 12:10 pm, Arnaud Delobelle wrote: [...] >> Or you could override __getattr__ >> >> -- >> Arnaud > > I tried overriding __getattr__ and got an error at runtime (the > instance did not have xyz key, etc), and the Tag dict is not > modifiable (granted, I tried Tag.__di

Re: Closures in metaclasses

2010-01-21 Thread Falcolas
On Jan 21, 1:55 pm, Peter Otten <__pete...@web.de> wrote: > Falcolas wrote: > > I tried overriding __getattr__ and got an error at runtime (the > > You can either move __getattr__() into the metaclass or instantiate the > class. I prefer the latter. > > Both approaches in one example: > > >>> class

Re: Closures in metaclasses

2010-01-21 Thread Peter Otten
Falcolas wrote: > I tried overriding __getattr__ and got an error at runtime (the You can either move __getattr__() into the metaclass or instantiate the class. I prefer the latter. Both approaches in one example: >>> class Tag: ... class __metaclass__(type): ... def __getattr_

Re: Closures in metaclasses

2010-01-21 Thread Falcolas
On Jan 21, 12:10 pm, Arnaud Delobelle wrote: > On Jan 21, 6:37 pm, Falcolas wrote: > > > On Jan 21, 11:24 am, Arnaud Delobelle wrote: > > > It was the easiest way I found to add a lot of static methods to the > > Tag class without writing each one out. __getattr__ was not working > > for this ap

Re: Closures in metaclasses

2010-01-21 Thread Arnaud Delobelle
On Jan 21, 6:37 pm, Falcolas wrote: > On Jan 21, 11:24 am, Arnaud Delobelle wrote: > > > > > > > Falcolas writes: > > > I'm running into an issue with closures in metaclasses - that is, if I > > > create a function with a closure in a metacla

Re: Closures in metaclasses

2010-01-21 Thread Falcolas
On Jan 21, 11:24 am, Arnaud Delobelle wrote: > Falcolas writes: > > I'm running into an issue with closures in metaclasses - that is, if I > > create a function with a closure in a metaclass, the closure appears > > to be lost when I access the final class. I end up g

Re: Closures in metaclasses

2010-01-21 Thread Arnaud Delobelle
Falcolas writes: > I'm running into an issue with closures in metaclasses - that is, if I > create a function with a closure in a metaclass, the closure appears > to be lost when I access the final class. I end up getting the text > 'param' instead of the actual tags I

Closures in metaclasses

2010-01-21 Thread Falcolas
I'm running into an issue with closures in metaclasses - that is, if I create a function with a closure in a metaclass, the closure appears to be lost when I access the final class. I end up getting the text 'param' instead of the actual tags I am expecting: ALL_TAGS = ['

Metaclasses Demystified

2009-06-10 Thread Boris Arloff
Hi, I have been studying python metaclasses for a few days now and I believe that slowly but surely I am grasping the subject.  The best article I have found on this is "Metaclass Demystified", by J. LaCour, Python Magazine, July 2008 (http://cleverdevil.org/computing/78/). I repl

Re: design question, metaclasses?

2009-04-14 Thread Piet van Oostrum
p = Base.DerivedGroup(format2.Group) # useful >>> >>> Could anyone please offer a comment, is this an appropriate use of >>> metaclassing, or is there maybe an easier/better alternative? >DD> I don't fully understand metaclasses, but I think I have convince

Re: design question, metaclasses?

2009-04-12 Thread Aaron Brady
On Apr 12, 4:53 pm, Darren Dale wrote: > On Apr 12, 4:50 pm, Kay Schluehr wrote: > > > > > On 11 Apr., 20:15, Darren Dale wrote: > > > > I am working on a project that provides a high level interface to hdf5 > > > files by implementing a thin wrapper around h5py. > > > I would like to > > > gene

Re: design question, metaclasses?

2009-04-12 Thread Darren Dale
On Apr 12, 4:50 pm, Kay Schluehr wrote: > On 11 Apr., 20:15, Darren Dale wrote: > > > I am working on a project that provides a high level interface to hdf5 > > files by implementing a thin wrapper around h5py. > > I would like to > > generalize the project so the same API can be used with other

Re: design question, metaclasses?

2009-04-12 Thread Kay Schluehr
On 11 Apr., 20:15, Darren Dale wrote: > I am working on a project that provides a high level interface to hdf5 > files by implementing a thin wrapper around h5py. > I would like to > generalize the project so the same API can be used with other formats, > like netcdf or ascii files. The format sp

Re: design question, metaclasses?

2009-04-12 Thread Darren Dale
On Apr 12, 3:23 pm, Aaron Brady wrote: > On Apr 12, 1:30 pm, Darren Dale wrote: > > > > > On Apr 11, 2:15 pm, Darren Dale wrote: > > _ > > > > format1.Group # implementation of group in format1 > > > format2.Group # ... > > > Base.DerivedGroup # base implementation of DerivedGroup, not directly

Re: design question, metaclasses?

2009-04-12 Thread Aaron Brady
On Apr 12, 1:30 pm, Darren Dale wrote: > On Apr 11, 2:15 pm, Darren Dale wrote: > > _ > > > format1.Group # implementation of group in format1 > > format2.Group # ... > > Base.DerivedGroup # base implementation of DerivedGroup, not directly > > useful > > format1.DerivedGroup = Base.DerivedGroup(

Re: design question, metaclasses?

2009-04-12 Thread Darren Dale
t directly > useful > format1.DerivedGroup = Base.DerivedGroup(format1.Group) # useful > format2.DerivedGroup = Base.DerivedGroup(format2.Group) # useful > > Could anyone please offer a comment, is this an appropriate use of > metaclassing, or is there maybe an easier/better alternative? I don&

design question, metaclasses?

2009-04-11 Thread Darren Dale
I am working on a project that provides a high level interface to hdf5 files by implementing a thin wrapper around h5py. I would like to generalize the project so the same API can be used with other formats, like netcdf or ascii files. The format specific code exists in File, Group and Dataset clas

Re: Is there a way to ask a class what its metaclasses are ?

2009-02-23 Thread Terry Reedy
Barak, Ron wrote: When I try the following (to see the types of the classes involved): #!/usr/bin/env python import wx from Debug import _line as line class CopyAndPaste(object): def __init__(self, *args, **kwargs): super(CopyAndPaste, self).__init__(*args, **kwargs) pr

Re: Is there a way to ask a class what its metaclasses are ?

2009-02-23 Thread Gabriel Genellina
mo09.py Traceback (most recent call > last): > File "./failover_pickle_demo09.py", line 321, in > class ListControlMeta(wx.Frame, CopyAndPaste): > TypeError: Error when calling the metaclass bases > metaclass conflict: the metaclass of a derived class must be a > (

RE: Is there a way to ask a class what its metaclasses are ?

2009-02-23 Thread Barak, Ron
> -Original Message- > From: ch...@rebertia.com [mailto:ch...@rebertia.com] On > Behalf Of Chris Rebert > Sent: Sunday, February 22, 2009 22:12 > To: Barak, Ron > Cc: python-list@python.org > Subject: Re: Is there a way to ask a class what its metaclasses are ? >

Re: Is there a way to ask a class what its metaclasses are ?

2009-02-22 Thread Chris Rebert
On Sun, Feb 22, 2009 at 5:14 AM, Barak, Ron wrote: > Hi Chris, Is there a way to ask a class what its metaclasses are ? > (e.g., how to ask wx.Frame what it's metaclass is) Of course. A metaclass is the type of a class, so it's just type(wx.Frame). Cheers, Chris -- Follow

Is there a way to ask a class what its metaclasses are ?

2009-02-22 Thread Barak, Ron
e it's listing below). > > Could you have a look at the CopyAndPaste class, and see if > something in its construction strikes you as susspicious ? > > > > Thanks, > > Ron. > > > > $ cat ./CopyAndPaste.py > > #!/usr/bin/env python > > > &g

Re: loading modules, metaclasses, chicken & eggs

2008-11-12 Thread Aaron Brady
On Nov 12, 3:01 pm, sandro <[EMAIL PROTECTED]> wrote: > Aaron Brady wrote: > > On Nov 12, 9:38 am, sandro <[EMAIL PROTECTED] wrote: > >> Hi, > >> Is there a way to solve this? I'd like ro force a reload of the > >> metaclass after 'debug'  has been loaded and debug.DBG set to True, > >> but that do

Re: loading modules, metaclasses, chicken & eggs

2008-11-12 Thread sandro
Aaron Brady wrote: > On Nov 12, 9:38 am, sandro <[EMAIL PROTECTED] wrote: >> Hi, >> Is there a way to solve this? I'd like ro force a reload of the >> metaclass after 'debug'  has been loaded and debug.DBG set to True, >> but that doesn't seem to happen... >> >> Any hints? >> >> sandro >> *:-) >>

Re: loading modules, metaclasses, chicken & eggs

2008-11-12 Thread Aaron Brady
On Nov 12, 9:38 am, sandro <[EMAIL PROTECTED]> wrote: > Hi, > Is there a way to solve this? I'd like ro force a reload of the > metaclass after 'debug'  has been loaded and debug.DBG set to True, > but that doesn't seem to happen... > > Any hints? > > sandro > *:-) > > sqlkit:  http://sqlkit.argoli

loading modules, metaclasses, chicken & eggs

2008-11-12 Thread sandro
Hi, I had two packages working fine toghether: debug and sqlkit. Debug provides a metaclass just for debuggging purposes to sqlkit (to log methods following a recipe on ASPN. It worked very well, just logging depending on the value of a module variable in debug module. That means module debug a

Re: metaclasses

2008-03-04 Thread castironpi
On Mar 4, 12:51 am, Gerard Flanagan <[EMAIL PROTECTED]> wrote: > On Mar 4, 6:31 am, [EMAIL PROTECTED] wrote: > > > > > > > On Mar 3, 10:01 pm, Benjamin <[EMAIL PROTECTED]> wrote: > > > > On Mar 3, 7:12 pm, [EMAIL PROTECTED] wrote: > > > >

Re: metaclasses

2008-03-03 Thread Gerard Flanagan
On Mar 4, 6:31 am, [EMAIL PROTECTED] wrote: > On Mar 3, 10:01 pm, Benjamin <[EMAIL PROTECTED]> wrote: > > > > > On Mar 3, 7:12 pm, [EMAIL PROTECTED] wrote: > > > > What are metaclasses? > > > Depends on whether you want to be confused or not. If you do,

Re: metaclasses

2008-03-03 Thread castironpi
On Mar 3, 10:01 pm, Benjamin <[EMAIL PROTECTED]> wrote: > On Mar 3, 7:12 pm, [EMAIL PROTECTED] wrote: > > > What are metaclasses? > > Depends on whether you want to be confused or not. If you do, look at > this old but still head bursting > essay:http://www.pyt

Re: metaclasses

2008-03-03 Thread Benjamin
On Mar 3, 7:12 pm, [EMAIL PROTECTED] wrote: > What are metaclasses? Depends on whether you want to be confused or not. If you do, look at this old but still head bursting essay: http://www.python.org/doc/essays/metaclasses/. Basically, the metaclass of a (new-style) class is responsible

Re: metaclasses

2008-03-03 Thread castironpi
On Mar 3, 8:22 pm, "Daniel Fetchinson" <[EMAIL PROTECTED]> wrote: > > What are metaclasses? > > http://www.google.com/search?q=python+metaclass > > HTH, > Daniel Not satisfied. http://en.wikipedia.org/wiki/Metaclass#Python_example That's a limitation

Re: metaclasses

2008-03-03 Thread Daniel Fetchinson
> What are metaclasses? http://www.google.com/search?q=python+metaclass HTH, Daniel -- http://mail.python.org/mailman/listinfo/python-list

metaclasses

2008-03-03 Thread castironpi
What are metaclasses? -- http://mail.python.org/mailman/listinfo/python-list

Re: metaclasses: timestamping instances

2007-09-03 Thread Gabriel Genellina
En Mon, 03 Sep 2007 07:39:05 -0300, km <[EMAIL PROTECTED]> escribi�: > But why does it show varied difference in the time between a and b > instance creations when __metaclass__ hook is used and when not used in > class Y ? I dont understand that point ! What do you expect from a._created, b.

Re: metaclasses: timestamping instances

2007-09-03 Thread km
Hi, But why does it show varied difference in the time between a and b instance creations when __metaclass__ hook is used and when not used in class Y ? I dont understand that point ! KM On 9/1/07, Michele Simionato <[EMAIL PROTECTED]> wrote: > > On Sep 1, 6:07 pm, Steve Holden <[EMAIL PROTECTE

Re: metaclasses: timestamping instances

2007-09-01 Thread Michele Simionato
On Sep 1, 6:07 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > > Debugging with Wing IDE and examining the classes at a breakpoint shows > this to be true (even after Y's __metaclass__ assignment is commented out): > > >>> X.__metaclass__ > > >>> Y.__metaclass__ > > >>> For the benefit of the

Re: metaclasses: timestamping instances

2007-09-01 Thread Steve Holden
km wrote: > Hi all, > > I have extended a prototype idea from Alex Martelli's resource on > metaclasses regarding time stamping of instances. > > > import time > class Meta(type): > start = time.time() > def __call__(cls, *args, **kw): >

metaclasses: timestamping instances

2007-09-01 Thread km
Hi all, I have extended a prototype idea from Alex Martelli's resource on metaclasses regarding time stamping of instances. import time class Meta(type): start = time.time() def __call__(cls, *args, **kw): print 'Meta start time %e'%cls.start x =

Re: metaclasses and performance

2007-06-21 Thread Mirko Dziadzka
Lenard Lindstrom <[EMAIL PROTECTED]> wrote: > I don't know if C asserts are active in release Python, but for > new-style classes one thing that happens during attribute lookup is that > an object's class is asserted to be an instance of type. Thank's for the explanation. My Linux distribution

Re: metaclasses and performance

2007-06-19 Thread Lenard Lindstrom
Mirko Dziadzka wrote: > Hi all > > I'm playing around with metaclasses and noticed, that there is small > but mesurable a performance difference in the code shown below. With a > more complex example I get a 5 percent performance penalty for using a > metaclass. Until

metaclasses and performance

2007-06-19 Thread Mirko Dziadzka
Hi all I'm playing around with metaclasses and noticed, that there is small but mesurable a performance difference in the code shown below. With a more complex example I get a 5 percent performance penalty for using a metaclass. Until today I assumed, that a metaclass has no performance i

Re: __dict__s and types and maybe metaclasses...

2007-05-02 Thread Alex Martelli
class M -- execute: ic = M("ic", bases, D) the body always creates a dictionary -- you can't override that with metaclasses. Maybe some deep bytecode hacks might work, but I have some doubts in the matter (not given it much thought, tho). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: __dict__s and types and maybe metaclasses...

2007-05-02 Thread Steven Bethard
Adam Atlas wrote: > Suppose I want to create a type (i.e. a new-style class via the usual > `class blah(...)` mechanism) but, during the process of creating the > type, I want to replace its __dict__ If I understand you right, what you want is something like:: class MyDict(object):

Re: __dict__s and types and maybe metaclasses...

2007-05-02 Thread Adam Atlas
On May 2, 5:24 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > I think that most people accomplish this by: > > class blah: > __initial_values={'a': 123, 'b': 456} > > def __init__(self): > self.__dict__.update(self.__initialvalues) That's not really what I'm talking about... I'm talk

Re: __dict__s and types and maybe metaclasses...

2007-05-02 Thread Larry Bates
t is, I have `class > blah(...): a = 123; b = 456; ...`, and I want to substitute my own > dict subclass which will thus receive __setitem__(a, 123), > __setitem__(b, 456), and so on. > > Is this possible? Maybe with metaclasses? I've experimented with them > a bit, but I

__dict__s and types and maybe metaclasses...

2007-05-02 Thread Adam Atlas
; b = 456; ...`, and I want to substitute my own dict subclass which will thus receive __setitem__(a, 123), __setitem__(b, 456), and so on. Is this possible? Maybe with metaclasses? I've experimented with them a bit, but I haven't found any setup that works. -- http://mail.python.o

Re: Putting Metaclasses to Work

2007-03-12 Thread Michele Simionato
On Mar 11, 7:31 pm, "Alan Isaac" <[EMAIL PROTECTED]> wrote: > Forman's book is out of print. > Is there a good substitute? > > Thanks, > Alan Isaac The book is about a non-standard implementation of C++ featuring metaclasses. It it not that relevant if you are

Putting Metaclasses to Work

2007-03-11 Thread Alan Isaac
Forman's book is out of print. Is there a good substitute? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: Automatic reloading, metaclasses, and pickle

2007-02-28 Thread andrewfelch
On Feb 27, 6:47 pm, "Ziga Seilnacht" <[EMAIL PROTECTED]> wrote: > Andrew Felch wrote: > > Thanks for checking. I think I narrowed the problem down to > > inheritance. I inherit from list or some other container first: > > > class PointList( list, AutoReloader ): > > def PrintHi1(self): > >

Re: Automatic reloading, metaclasses, and pickle

2007-02-27 Thread andrewfelch
On Feb 27, 3:47 pm, "Ziga Seilnacht" <[EMAIL PROTECTED]> wrote: > Andrew Felch wrote: > > Thanks for checking. I think I narrowed the problem down to > > inheritance. I inherit from list or some other container first: > > > class PointList( list, AutoReloader ): > > def PrintHi1(self): > >

Re: Automatic reloading, metaclasses, and pickle

2007-02-27 Thread Ziga Seilnacht
Andrew Felch wrote: > Thanks for checking. I think I narrowed the problem down to > inheritance. I inherit from list or some other container first: > > class PointList( list, AutoReloader ): > def PrintHi1(self): > print "Hi2" > > class MyPrintingClass( AutoReloader ): > def Prin

Re: Automatic reloading, metaclasses, and pickle

2007-02-27 Thread andrewfelch
On Feb 27, 3:23 pm, "Ziga Seilnacht" <[EMAIL PROTECTED]> wrote: > Andrew Felch wrote: > > I pasted the code into mine and replaced the old. It seems not to > > work for either unpickled objects or new objects. I add methods to a > > class that inherits from AutoReloader and reload the module, but

Re: Automatic reloading, metaclasses, and pickle

2007-02-27 Thread Ziga Seilnacht
Andrew Felch wrote: > I pasted the code into mine and replaced the old. It seems not to > work for either unpickled objects or new objects. I add methods to a > class that inherits from AutoReloader and reload the module, but the > new methods are not callable on the old objects. Man! It seems

Re: Automatic reloading, metaclasses, and pickle

2007-02-27 Thread andrewfelch
On Feb 27, 5:30 pm, "Ziga Seilnacht" <[EMAIL PROTECTED]> wrote: > Andrew Felch wrote: > > > Thanks Ziga. I use pickle protocol 2 and binary file types with the > > command: "cPickle.dump(obj, file, 2)" > > > I did your suggestion, i commented out the "__call__" function of > > MetaInstanceTracker

Re: Automatic reloading, metaclasses, and pickle

2007-02-27 Thread Ziga Seilnacht
Andrew Felch wrote: > > Thanks Ziga. I use pickle protocol 2 and binary file types with the > command: "cPickle.dump(obj, file, 2)" > > I did your suggestion, i commented out the "__call__" function of > MetaInstanceTracker and copied the text to the __new__ function of > AutoReloader (code append

Re: Automatic reloading, metaclasses, and pickle

2007-02-27 Thread andrewfelch
ss > > > ... then the changes don't affect the unpickled object. If I unpickle > > the object again, of course the changes take effect. > > > My friend that loves Smalltalk is laughing at me. I thought I had the > > upperhand when I discovered the metaclasses

Re: Automatic reloading, metaclasses, and pickle

2007-02-27 Thread Ziga Seilnacht
es take effect. > > My friend that loves Smalltalk is laughing at me. I thought I had the > upperhand when I discovered the metaclasses but now I am not sure what > to do. I really don't want to have to unpickle again, I'm processing > video and it can take a long time. >

Automatic reloading, metaclasses, and pickle

2007-02-27 Thread andrewfelch
pperhand when I discovered the metaclasses but now I am not sure what to do. I really don't want to have to unpickle again, I'm processing video and it can take a long time. By the way, I used to avoid all of these problems by never making classes, and always building complex structures

Re: metaclasses (beginner question)

2007-02-22 Thread James Stroud
Peter Otten wrote: > You determine the factory Python uses to > make a class by adding > > __metaclass__ = factory > > to the class body, so you'll probably end with something like > > class ProducerHandlerType(type): > # your code > > class A: > __metaclass__ = ProducerHandlerType >

Re: metaclasses (beginner question)

2007-02-21 Thread Laszlo Nagy
> Without looking into the details -- the (subclass of) type is meant to be > the class of the class, or the other way round, your normal classes are > instances of (a subclass of) type. You determine the factory Python uses to > make a class by adding > > __metaclass__ = factory > > to the class

Re: metaclasses (beginner question)

2007-02-21 Thread Peter Otten
Laszlo Nagy wrote: > I would like to create a hierarchy classes, where the leaves have a > special attribute called "producer_id". In addition, I would like to > have a function that can give me back the class assigned to any > producer_id value. I tried to implement this with a metaclass, but I >

metaclasses (beginner question)

2007-02-21 Thread Laszlo Nagy
Hello, I would like to create a hierarchy classes, where the leaves have a special attribute called "producer_id". In addition, I would like to have a function that can give me back the class assigned to any producer_id value. I tried to implement this with a metaclass, but I failed. Pleas

  1   2   >