Questions tagged [metaclass]

In object-oriented programming, a metaclass is a class whose instances are classes. Just as an ordinary class defines the behavior of certain objects, a metaclass defines the behavior of certain classes and their instances. Not all object-oriented programming languages support metaclasses.

1179 questions
0
votes
0 answers

How can I get the metaclass of a class in Delphi 7?

I want to raise an exception like that if an object is missing from the context object attribute list: //****************************************************************************** EMissingContextObject = class…
The Bitman
  • 1,279
  • 1
  • 11
  • 25
0
votes
1 answer

Metaclass issue with the ftp class

I would like to obtain the metaclass of some Matlab built-in classes, and I have a problem with the @ftp class : the class is seen by which but not by the metaclass system: >> which('ftp') /usr/local/MATLAB/R2016a/toolbox/matlab/iofun/@ftp/ftp.m %…
Ratbert
  • 5,463
  • 2
  • 18
  • 37
0
votes
1 answer

How is one meant to use the collections.abc classes with multiple inheritance?

I'm having an issue where I want to use the mixin methods from collections.abc.MutableSequence, but I also have to inherit from something else. class Thing(urwid.Pile, collections.abc.MutableSequence): ... I end up with TypeError: metaclass…
dwf
  • 3,503
  • 1
  • 20
  • 25
0
votes
4 answers

Python : how to prevent a class variable that is a function to be understood as a method?

I am currently implementing a django app, for this I try to use a syntax that is consistent with Django's... So here is what I am trying : class Blablabla(Model): #this contains Blablabla's options class Meta: sort_key = lambda e:…
sebpiq
  • 7,540
  • 9
  • 52
  • 69
0
votes
1 answer

Cannot replace static method

I'm trying to replace a static method at runtime using MetaClass. class MyClass { private static String getString() { 'Hello' } String testString MyClass() { testString = getString() …
m0skit0
  • 25,268
  • 11
  • 79
  • 127
0
votes
3 answers

python: manipulating __dict__ of the class

(All in ActivePython 3.1.2) I tried to change the class (rather than instance) attributes. The __dict__ of the metaclass seemed like the perfect solution. But when I tried to modify, I got: TypeError: 'dict_proxy' object does not support item…
max
  • 49,282
  • 56
  • 208
  • 355
0
votes
1 answer

Python 2.7 - Is this a valid use of __metaclass__?

The problem is as follows. There's a Base class that will be extended by several classes which may also be extended. All these classes need to initialize certain class variables. By the nature of the problem, the initialization should be incremental…
Eduardo
  • 1,235
  • 16
  • 27
0
votes
0 answers

Is the class Object in Java a metaclass?

In Java, the class Object acts as the root for all the other classes that are created. Every new class inherits from Object, so can be Object considered the Metaclass of Java? I suppose there is just one Metaclass in Java, not like Smalltalk or…
David
  • 165
  • 1
  • 8
0
votes
1 answer

Metaclass Singletons Not Working

I've tried recently to add a singleton to my project, but it doesn't act like I'd think it would. The code looks somewhat like this: main/main.py class main(metaclass=Singleton): def __init__(self): .... def Action(self): …
John M
  • 1
  • 4
0
votes
1 answer

Subclass Django ModelBase (metaclass for Django models)

I want some of my Django models to have an "owner" property. I may need to change or augment the logic later, and the logic is reused across many classes. So I'd like to just inherit from an Owned class that lets me store the user who created the…
Max Heiber
  • 14,346
  • 12
  • 59
  • 97
0
votes
1 answer

__getattribute__ function to return object value from another class

I have a base class which has 2 attributes which itself are from another class. See the code below class Base(object): def __init__(self, obj1, obj2): self.obj1 = obj1 self.obj2 = obj2 def __getattribute__(self, name): …
Anurag Sharma
  • 4,839
  • 13
  • 59
  • 101
0
votes
3 answers

How do I override base class methods in Python conditionally on whether they exist?

I have a classes BasicEvidenceTarget and SchedulableSoma. Sometimes I inherit from SchedulableSoma, BasicEvidenceTarget, sometimes I inherit from SchedulableSoma alone. When I inherit from SchedulableSoma, BasicEvidenceTarget, I want…
Neil G
  • 32,138
  • 39
  • 156
  • 257
0
votes
1 answer

In which sequence does method call work in groovy?

I am using groovy 2.3.8 I am trying to figure out how method calls work in groovy. Specifically if we have a Java class hierarchy each having a metaClass like below class A { } A.metaClass.hello = { "hello superclass" } class B extends A…
Aseem Bansal
  • 6,722
  • 13
  • 46
  • 84
0
votes
0 answers

Dynamically create multiple sub-classes with dynamically named reference

I have a module (myMod.py) with an Object baseObj with a few methods class baseObj(object): .... def doThing(self): ...... I need to create many subclasss, normal way to do this would be: class Foo(baseObl): pass class…
0
votes
0 answers

Python - Class Factory

I'm using classes to design network conversations, I have this code: class Conversation(object): __metaclass__ = ABCMeta def __init__(self, received=0, sent=0): self.sent = sent self.received = received def…
ori
  • 369
  • 2
  • 6
  • 17