Re: Forward References

2023-09-03 Thread MRAB via Python-list
On 2023-09-03 21:43, Jonathan Gossage via Python-list wrote: I am attempting to use forward references in my program and I am failing. This also does not work with the older way of putting the name of a class as a string. Here is some sample code: from __future__ import annotations from

Forward References

2023-09-03 Thread Jonathan Gossage via Python-list
I am attempting to use forward references in my program and I am failing. This also does not work with the older way of putting the name of a class as a string. Here is some sample code: from __future__ import annotations from dataclasses import dataclass from typing import TypeAlias ColorDef

Re: Inheritance and forward references (prototypes)

2009-06-22 Thread Lorenzo Di Gregorio
On 21 Jun., 22:51, Scott David Daniels wrote: > LorenzoDiGregoriowrote: > > On 21 Jun., 01:54, Dave Angel wrote: > >> ... > >> class B(object): > >>     def __init__(self,test=None): > >>         if test==None: > >>             test = A() > >>         self.obj =() > >>         return > > ... > >

Re: Inheritance and forward references (prototypes)

2009-06-22 Thread Bruno Desthuilliers
Dave Angel a écrit : (snip Default arguments of class methods are evaluated during the definition of the class Default arguments of functions are eval'd during the execution of the def statement. The fact that you use a def statement within a class statement's body is totally orthogonal -

Re: Inheritance and forward references (prototypes)

2009-06-22 Thread Bruno Desthuilliers
Piet van Oostrum a écrit : Steven D'Aprano (SD) wrote: (snip) SD> # A.__base__ = DebugA ## Uncomment this line for debugging. A.__base__ = DebugA TypeError: readonly attribute Make that: A.__bases__ = DebugA, or even better (readability-wise): A.__bases__ = (DebugA,) Just the sam

Re: Inheritance and forward references (prototypes)

2009-06-21 Thread Scott David Daniels
Lorenzo Di Gregorio wrote: On 21 Jun., 01:54, Dave Angel wrote: ... class B(object): def __init__(self,test=None): if test==None: test = A() self.obj =() return ... I had also thought of using "None" (or whatever else) as a marker but I was curious to fi

Re: Inheritance and forward references (prototypes)

2009-06-21 Thread Lie Ryan
Lorenzo Di Gregorio wrote: > I had also thought of using "None" (or whatever else) as a marker but > I was curious to find out whether there are better ways to supply an > object with standard values as a default argument. > In this sense, I was looking for problems ;-) > > Of course the observati

Re: Inheritance and forward references (prototypes)

2009-06-21 Thread Lorenzo Di Gregorio
On 21 Jun., 01:54, Dave Angel wrote: > LorenzoDiGregoriowrote: > > On Jun 20, 8:43 pm, Dave Angel wrote: > > >>LorenzoDiGregoriowrote: > > >>> Hi, > > >>> I'm wondering what would be the preferred way to solve the following > >>> forward reference problem: > > >>>

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Dave Angel
Lorenzo Di Gregorio wrote: On Jun 20, 8:43 pm, Dave Angel wrote: Lorenzo Di Gregorio wrote: Hi, I'm wondering what would be the preferred way to solve the following forward reference problem: --- class BaseA(object): def __init__(

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Rhodri James
On Sat, 20 Jun 2009 21:26:56 +0100, Lorenzo Di Gregorio wrote: Thank you for your help: I'm working on a rather large source, but I think I have isolated the problem now. This listing generates an error: --- class BaseA(object): def __init__(se

Inheritance and forward references (prototypes)

2009-06-20 Thread Xavier Ho
Arg, forgot to post to the mailing list again. -_- On a smaller issue, don't you need to do: class DebugA(BaseA): def __init__(self): BaseA.__init__(self) return As in, explicitly call the __init__ function when you initalise DebugA, since DebugA extends BaseA? I'm just gett

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Lorenzo Di Gregorio
On Jun 20, 8:43 pm, Dave Angel wrote: > Lorenzo Di Gregorio wrote: > > Hi, > > > I'm wondering what would be the preferred way to solve the following > > forward reference problem: > > > --- > > class BaseA(object): > >     def __init__(self): > >         return

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Piet van Oostrum
> Steven D'Aprano (SD) wrote: >SD> Lorenzo Di Gregorio wrote: >>> Hi, >>> >>> I'm wondering what would be the preferred way to solve the following >>> forward reference problem: >SD> You don't actually explain what is the problem. Fortunately, I'm good at >SD> guessing, and I think I can gu

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Dave Angel
Lorenzo Di Gregorio wrote: Hi, I'm wondering what would be the preferred way to solve the following forward reference problem: --- class BaseA(object): def __init__(self): return class DebugA(BaseA): def __init__(self): return # here

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Steven D'Aprano
Lorenzo Di Gregorio wrote: > Hi, > > I'm wondering what would be the preferred way to solve the following > forward reference problem: You don't actually explain what is the problem. Fortunately, I'm good at guessing, and I think I can guess what your problem is (see below): >

Inheritance and forward references (prototypes)

2009-06-20 Thread Lorenzo Di Gregorio
Hi, I'm wondering what would be the preferred way to solve the following forward reference problem: --- class BaseA(object): def __init__(self): return class DebugA(BaseA): def __init__(self): return # here I would have a prototype of