Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The solution of this problem is trivial and is left as an exercise for the reader.


devel / comp.lang.python / Re: Advantages of Default Factory in Dataclasses

SubjectAuthor
o Re: Advantages of Default Factory in DataclassesPaul Bryan

1
Re: Advantages of Default Factory in Dataclasses

<mailman.104.1637519123.19479.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16146&group=comp.lang.python#16146

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: pbr...@anode.ca (Paul Bryan)
Newsgroups: comp.lang.python
Subject: Re: Advantages of Default Factory in Dataclasses
Date: Sun, 21 Nov 2021 10:25:23 -0800
Lines: 27
Message-ID: <mailman.104.1637519123.19479.python-list@python.org>
References: <CADrxXXksfD+nxVT0pPyHjX6jtkqfKDYvyTf11P7eT+Bbtbu81A@mail.gmail.com>
<4765df8e2335cee6e90bd737c5cebed113696d23.camel@anode.ca>
<CADrxXXmA6gSxN_XLVLY2EpAoaVZ4nP97QfVCMCXLUreSGi67aA@mail.gmail.com>
<050b83f489b6e110cee739812b753f399b8cfb6f.camel@anode.ca>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 7nJj15d7Os8ENnX6aq7DyQO4iNVoRkj0qQjPiuiGOOTw==
Return-Path: <pbryan@anode.ca>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=anode.ca header.i=@anode.ca header.b=cc1bZkIw;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.023
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'sun,': 0.07; 'cc:addr
:python-list': 0.09; 'question:': 0.09; 'though.': 0.09; '7:17':
0.16; 'cc:name:python': 0.16; 'dict': 0.16; 'initialize': 0.16;
'instance': 0.16; 'janhangeer': 0.16; 'received:10.202': 0.16;
'received:10.202.2': 0.16; 'received:internal': 0.16;
'received:messagingengine.com': 0.16; 'wrote:': 0.16; '16,': 0.19;
'tue,': 0.19; 'cc:addr:python.org': 0.20; 'returns': 0.22; 'code':
0.23; 'cc:2**0': 0.25; 'example,': 0.28; 'header:User-Agent:1':
0.30; 'deep': 0.31; 'default': 0.31; 'question': 0.32; "i'm":
0.33; 'header:In-Reply-To:1': 0.34; 'received:66': 0.35; 'using':
0.37; 'class': 0.37; 'advantage': 0.40; 'copy.': 0.40; 'want':
0.40; 'copy': 0.63; 'your': 0.64; 'look': 0.65; 'created.': 0.69;
'2021': 0.71; 'skip:f 20': 0.75; 'field': 0.78; 'paul': 0.81;
'attribute': 0.84; 'bryan': 0.84; 'factory': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anode.ca; h=
message-id:subject:from:to:cc:date:in-reply-to:references
:content-type:mime-version; s=fm2; bh=FEZxicwxTBmPhyffhZxRuwd7ZY
KmP/ojY2x7dgEFwlk=; b=cc1bZkIwEgGpBC52Ib93UNc3kd37Mz3o5QXEDtvMNK
Iy+RW1hA2B99hJ1WcfKfJ8zlSNNnuWo52rBI2+Su82QAQE9hdSe2X2/ti4kT0h9K
vh4nMpZ3G93tVZx0t8C8LpqKjKSFN3VmpEKfAD1smXP4zENNlP1CKzLg/lFZMdDH
FiC9FCRqIo4i8br3J1bzDpBk9xHdkEKoaphii3EUfgmbhtOHFzED6T6VqeqO0IIW
MCGaFF2HBEhMYwVrAnYMU5BNTtjzBv7TxZvfhEIXju/NmfSLYFxauptTi7GjEjT3
RHuZXKcDny74JjFVLGwyT98cKuj1yCZgw4M7gXZZd0+w==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:content-type:date:from:in-reply-to
:message-id:mime-version:references:subject:to:x-me-proxy
:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=FEZxic
wxTBmPhyffhZxRuwd7ZYKmP/ojY2x7dgEFwlk=; b=kUMyz4R62QZEzHcaEJkBD7
SgvBYigCVCPqAMGrRMUrcH+eAgsKU/V07E1K3+ygR8ytSrsmgY+7YDb6YMqdSvQc
uQqeoNXRvB67490bH6lkA+yNAn5v29QvFTRhuVSJvJ665YNRPY9NaomZN5k3fvp7
ZE+8f2EkGW5f5ZeTM2Y/vwexMkxJSopasJ4CRyXD5IaY+mr3rso/X4bYBn6ZUQaS
nTrT0emYhmPFbasrdg0gFTFi+Rot950lu8KL0KqeAHaZLSTCaDbf+tw/qN1wFvWN
WF0om6PUkRz36hKGvt5Osd29q8T9rKq/ddun4aTBZ5tYVdCZAeAv3zxw0vQW1Lkg
==
X-ME-Sender: <xms:EI-aYRwMMx2TTmXPWBAn80VCMc6KrI5JIefAGGfv2R_XAuBNLkJ0Lw>
<xme:EI-aYRRsYwWs589HLCNuPgeOSGkI85FoBfuwEss-i_diF6wW5mlgt3HVO10LHsxH0
I3yFUd2PEFInzPKsyQ>
X-ME-Received: <xmr:EI-aYbVUP5CIp7i1dVDdTEHixeWIe3wS_yViKLayPZrHg6R6TrPUtEpFNhgjsuytsznlaQyObFaVEW4UnyU7xJdNfuvPi2hvXq-xfw>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrgedvgdduudehucetufdoteggodetrfdotf
fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen
uceurghilhhouhhtmecufedttdenucenucfjughrpefkuffhvfffjghftggfggesrgdtre
ertderjeenucfhrhhomheprfgruhhluceurhihrghnuceophgsrhihrghnsegrnhhouggv
rdgtrgeqnecuggftrfgrthhtvghrnhepvddtteeikefhteelgfdvffeigeetkeekveefge
eigfetieejueelhfefheekieegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm
pehmrghilhhfrhhomhepphgsrhihrghnsegrnhhouggvrdgtrg
X-ME-Proxy: <xmx:EI-aYTgb0aKrVH41Y0IuH0zupm6zvnXjU1Ez8dBGRZFLdhthfS3yAQ>
<xmx:EI-aYTCrYBXG_rjPqLnXD4jARwMMmIG9h649MQk2pRs5GG1HZ-1jyQ>
<xmx:EI-aYcKfHOWCMR15OYIldB8Jtfc9f8oBmm21Dcy2ZXrgAHOkSSNDNw>
<xmx:EI-aYWpzPL_EXj3IGQdR0u17qOazZQ_UAy2wLjsaIXNj7IbuJyYUgQ>
In-Reply-To: <CADrxXXmA6gSxN_XLVLY2EpAoaVZ4nP97QfVCMCXLUreSGi67aA@mail.gmail.com>
User-Agent: Evolution 3.42.1
X-Content-Filtered-By: Mailman/MimeDel 2.1.37
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.37
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <050b83f489b6e110cee739812b753f399b8cfb6f.camel@anode.ca>
X-Mailman-Original-References: <CADrxXXksfD+nxVT0pPyHjX6jtkqfKDYvyTf11P7eT+Bbtbu81A@mail.gmail.com>
<4765df8e2335cee6e90bd737c5cebed113696d23.camel@anode.ca>
<CADrxXXmA6gSxN_XLVLY2EpAoaVZ4nP97QfVCMCXLUreSGi67aA@mail.gmail.com>
 by: Paul Bryan - Sun, 21 Nov 2021 18:25 UTC

On Sun, 2021-11-21 at 21:51 +0400, Abdur-Rahmaan Janhangeer wrote:
>
> On Tue, Nov 16, 2021 at 7:17 PM Paul Bryan <pbryan@anode.ca> wrote:
> > On Tue, 2021-11-16 at 17:04 +0400, Abdur-Rahmaan Janhangeer wrote:
> >
> > > A simple question: why do we need field(default_factory ) in
> > > dataclasses?
> >
> >
> > To initialize a default value when a new instance of the dataclass
> > is created. For example, if you want a field to default to a dict.
> > A new dict is created for each instance of the dataclass created.
> >
>
>
> Why not have an attribute which returns a deep copy of a dict?

You can certainly write a default factory to return a deep copy. I'm
not understanding your question about the attribute though. Attribute
in what object? What might the code look like using an attribute?

> Like the only advantage of default factory is copying whatever we
> specify? 

The advantage of the default factory is that it can generate a value at
the time a data class is initialized.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor