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
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
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
> > ...
> >
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 -
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
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
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
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:
>
> >>>
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__(
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
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
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
> 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
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
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):
>
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
16 matches
Mail list logo