Constructor call in the same class?

K

Karsten Wutzke

What's wrong with:

class Enum(RootFragment):
__jpaTypes = {
# complete!
'CascadeType': Enum("javax.persistence.CascadeType"),
'DiscriminatorType':
Enum("javax.persistence.DiscriminatorType"),
'EnumType': Enum("javax.persistence.EnumType"),
'FetchType': Enum("javax.persistence.FetchType"),
'FlushModeType': Enum("javax.persistence.FlushModeType"),
'GenerationType': Enum("javax.persistence.GenerationType"),
'InheritanceType': Enum("javax.persistence.InheritanceType"),
'LockModeType': Enum("javax.persistence.LockModeType"),
'PersistenceContextType':
Enum("javax.persistence.PersistenceContextType"),
'TemporalType': Enum("javax.persistence.TemporalType"),
}

# constructor
def __init__(self, package, modifiers, name, superInterfaces = [],
annotations = [], innerClasses = [], properties = [],
methods = []):
RootFragment.__init__(self, packageName, modifiers, "enum",
name, superInterfaces, annotations, innerClasses, properties, methods)


?

I get

'CascadeType': Enum("javax.persistence.CascadeType"),

NameError: name 'Enum' is not defined

What's wrong with calling a constructor in a dict initializer? How do
I solve this?

Karsten
 
T

Thomas Jollans

What's wrong with:

class Enum(RootFragment):
__jpaTypes = {
# complete!
'CascadeType': Enum("javax.persistence.CascadeType"),
'DiscriminatorType':
Enum("javax.persistence.DiscriminatorType"),
'EnumType': Enum("javax.persistence.EnumType"),
'FetchType': Enum("javax.persistence.FetchType"),
'FlushModeType': Enum("javax.persistence.FlushModeType"),
'GenerationType': Enum("javax.persistence.GenerationType"),
'InheritanceType': Enum("javax.persistence.InheritanceType"),
'LockModeType': Enum("javax.persistence.LockModeType"),
'PersistenceContextType':
Enum("javax.persistence.PersistenceContextType"),
'TemporalType': Enum("javax.persistence.TemporalType"),
}

# constructor
def __init__(self, package, modifiers, name, superInterfaces = [],
annotations = [], innerClasses = [], properties = [],
methods = []):
RootFragment.__init__(self, packageName, modifiers, "enum",
name, superInterfaces, annotations, innerClasses, properties, methods)


?

I get

'CascadeType': Enum("javax.persistence.CascadeType"),

NameError: name 'Enum' is not defined

well, within the class statement, it's not defined. So you can't call
Enum yet.

You have to create your dict somewhere else. You can either set it from
outside:

class Enum(RootFragment):
...

Enum._jpaTypes = { ... }


Or, do exactly the same thing, but within a class method:

class Enum(bla):
@classmethod
def contruct_jpatypes(cls):
cls.__jpaTypes = { ... }

Enum.construct_jpatypes()
 
K

Karsten Wutzke

You have to create your dict somewhere else. You can either set it from
outside:

class Enum(RootFragment):
    ...

Enum._jpaTypes = { ... }

THANKS for the quick help.

Karsten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top