Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Emotions are alien to me. I'm a scientist. -- Spock, "This Side of Paradise", stardate 3417.3


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

SubjectAuthor
o Advantages of Default Factory in DataclassesAbdur-Rahmaan Janhangeer

1
Advantages of Default Factory in Dataclasses

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: arj.pyt...@gmail.com (Abdur-Rahmaan Janhangeer)
Newsgroups: comp.lang.python
Subject: Advantages of Default Factory in Dataclasses
Date: Tue, 16 Nov 2021 17:04:05 +0400
Lines: 15
Message-ID: <mailman.25.1637067859.19479.python-list@python.org>
References: <CADrxXXksfD+nxVT0pPyHjX6jtkqfKDYvyTf11P7eT+Bbtbu81A@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de hwWqRoLdXHS0bJjO8WfXoQNYv18tve4MSHUZjETFWbpw==
Return-Path: <arj.python@gmail.com>
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=gmail.com header.i=@gmail.com header.b=H0JtPRQk;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.017
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'url-ip:140.82/16': 0.03;
'question:': 0.09; 'url:github': 0.14; 'url-ip:140/8': 0.15;
'from:addr:arj.python': 0.16; 'from:name:abdur-rahmaan
janhangeer': 0.16; 'janhangeer': 0.16; 'mauritius': 0.16;
'github': 0.17; 'to:addr:python-list': 0.20; 'list,': 0.24;
'examples': 0.25; 'url-ip:51/8': 0.26; 'blog': 0.30;
'to:name:python': 0.32; 'message-id:@mail.gmail.com': 0.32;
'appreciated.': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'cases': 0.36; 'received:209.85':
0.37; 'received:209': 0.39; 'use': 0.39; 'skip:f 20': 0.75;
'field': 0.78; 'attribute': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:from:date:message-id:subject:to;
bh=h3HHuPqGECfo/2YPVRzNIf07v+TV0q1hiWwBPxk5d/U=;
b=H0JtPRQkcW4ddu9s5A+Tq1e+fssD+LJMkWoKtVyjCsDDESXXdAtD1dcmfjCOD9438v
B7JQRdeRiTJv5MgnylyvLxt5PVexNaoPREks/ZJQFrCjmt1hLAh4k6isfxJeejpOv7J7
0Hdh1Kj6vMBOMkVC53bcWaEb6qWe6zRLkvrrOC7e2vvtdeqpX+zqIQ+0bpH26EUY/w5I
wvaSi+RQQ3droHzIc/YtDhr7n9od/4emkgR9aKff8Zpi0UQTJkm/VSY9c7/d22pk1HUA
g/2E6Ns6lV4+tVfuDzwI0wM8LCtR+nlQqjLs91GioDPwvRdhwhZa17mpptPw4mmyqd5x
foVw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
bh=h3HHuPqGECfo/2YPVRzNIf07v+TV0q1hiWwBPxk5d/U=;
b=5g1RjMUgQ239o0oCwVthJx5kW1LgzFmFVEeOm1xw5wRPBMeSB5w7fTp1s6aEaLCHzA
X7bpt1ojUqMfpEAm9SYBK4F5k0AgyG/r4lc+oDbVIV146VtXJFQevbgzpnI3ZRb6V/oW
0+juBl0Dp7D2zmsGGmjOesKnAIvpDfh9zORT7P8Wj2lqMlXqEJJeSVRlwWreiiHP0h6x
oFzXgVpNt64bKXDcha3E+u7z2285eHir67Rp+WPN2Nf71nny7vSy2Y1vyb95/wXtRTxT
5a4S8LdDY40ckgYFqzW7P1a3HZ02EeNDg31hkTrQeLdBdJorrVsUwT1L2ilc8MCrv4gj
smVg==
X-Gm-Message-State: AOAM532u7DxC7Yld6KtT6c+NwWMPYhckXqPpeo3gjmsA0vmqLtebnUVf
rFaILMCbFTOsj7hR8/W8iMgHgres8cMH9k1Km9oxYz6MRm4=
X-Google-Smtp-Source: ABdhPJy+oRoRtgKLpoeJ1i0ejLjJiK37YJmMC9Si2Potd+PmZmFR+j/M/xARhNLAU+8xE2sbntCCIgakPFCkwMlAKFk=
X-Received: by 2002:a17:90b:1d81:: with SMTP id
pf1mr38489500pjb.134.1637067857251;
Tue, 16 Nov 2021 05:04:17 -0800 (PST)
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: <CADrxXXksfD+nxVT0pPyHjX6jtkqfKDYvyTf11P7eT+Bbtbu81A@mail.gmail.com>
 by: Abdur-Rahmaan Janhan - Tue, 16 Nov 2021 13:04 UTC

Greetings list,

A simple question: why do we need field(default_factory ) in dataclasses?

Why not make that field as an attribute return a function?

Useful implementation examples / use cases appreciated.

Kind Regards,

Abdur-Rahmaan Janhangeer
about <https://compileralchemy.github.io/> | blog
<https://www.pythonkitchen.com>
github <https://github.com/Abdur-RahmaanJ>
Mauritius

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor