summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2023-03-13 21:42:05 (GMT)
committerGitHub <noreply@github.com>2023-03-13 21:42:05 (GMT)
commitd97757f793ea53dda3cc6882b4a92d3e921b17c9 (patch)
treea5bc4852eaa2d04af37975ae1f1f9b13c4757ece
parent71e37d907905b0504c5bb7b25681adeea2157492 (diff)
downloadcpython-d97757f793ea53dda3cc6882b4a92d3e921b17c9.zip
cpython-d97757f793ea53dda3cc6882b4a92d3e921b17c9.tar.gz
cpython-d97757f793ea53dda3cc6882b4a92d3e921b17c9.tar.bz2
gh-102069: Fix `__weakref__` descriptor generation for custom dataclasses (#102075)
-rw-r--r--Lib/dataclasses.py3
-rw-r--r--Lib/test/test_dataclasses.py15
-rw-r--r--Misc/NEWS.d/next/Library/2023-02-20-16-47-56.gh-issue-102069.FS7f1j.rst1
3 files changed, 15 insertions, 4 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 7c3285c..82b08fc 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -1189,6 +1189,9 @@ def _add_slots(cls, is_frozen, weakref_slot):
# Remove __dict__ itself.
cls_dict.pop('__dict__', None)
+ # Clear existing `__weakref__` descriptor, it belongs to a previous type:
+ cls_dict.pop('__weakref__', None) # gh-102069
+
# And finally create the class.
qualname = getattr(cls, '__qualname__', None)
cls = type(cls)(cls.__name__, cls.__bases__, cls_dict)
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py
index 46d4e0f..46f3304 100644
--- a/Lib/test/test_dataclasses.py
+++ b/Lib/test/test_dataclasses.py
@@ -3175,6 +3175,8 @@ class TestSlots(unittest.TestCase):
with self.assertRaisesRegex(TypeError,
"cannot create weak reference"):
weakref.ref(a)
+ with self.assertRaises(AttributeError):
+ a.__weakref__
def test_slots_weakref(self):
@dataclass(slots=True, weakref_slot=True)
@@ -3183,7 +3185,9 @@ class TestSlots(unittest.TestCase):
self.assertIn("__weakref__", A.__slots__)
a = A(1)
- weakref.ref(a)
+ a_ref = weakref.ref(a)
+
+ self.assertIs(a.__weakref__, a_ref)
def test_slots_weakref_base_str(self):
class Base:
@@ -3249,7 +3253,8 @@ class TestSlots(unittest.TestCase):
self.assertIn("__weakref__", Base.__slots__)
self.assertNotIn("__weakref__", A.__slots__)
a = A(1)
- weakref.ref(a)
+ a_ref = weakref.ref(a)
+ self.assertIs(a.__weakref__, a_ref)
def test_weakref_slot_subclass_no_weakref_slot(self):
@dataclass(slots=True, weakref_slot=True)
@@ -3265,7 +3270,8 @@ class TestSlots(unittest.TestCase):
self.assertIn("__weakref__", Base.__slots__)
self.assertNotIn("__weakref__", A.__slots__)
a = A(1)
- weakref.ref(a)
+ a_ref = weakref.ref(a)
+ self.assertIs(a.__weakref__, a_ref)
def test_weakref_slot_normal_base_weakref_slot(self):
class Base:
@@ -3280,7 +3286,8 @@ class TestSlots(unittest.TestCase):
self.assertIn("__weakref__", Base.__slots__)
self.assertNotIn("__weakref__", A.__slots__)
a = A(1)
- weakref.ref(a)
+ a_ref = weakref.ref(a)
+ self.assertIs(a.__weakref__, a_ref)
class TestDescriptors(unittest.TestCase):
diff --git a/Misc/NEWS.d/next/Library/2023-02-20-16-47-56.gh-issue-102069.FS7f1j.rst b/Misc/NEWS.d/next/Library/2023-02-20-16-47-56.gh-issue-102069.FS7f1j.rst
new file mode 100644
index 0000000..04c87e5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-02-20-16-47-56.gh-issue-102069.FS7f1j.rst
@@ -0,0 +1 @@
+Fix ``__weakref__`` descriptor generation for custom dataclasses.
unknown_no_errorcode'>bug_unknown_no_errorcode Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.
summaryrefslogtreecommitdiffstats
path: root/doc/FindExec.3
blob: 0e225e9fd6ed7991e324d4596988ea0d911b9ef6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'\"
'\" Copyright (c) 1995-1996 Sun Microsystems, Inc.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\" 
.so man.macros
.TH Tcl_FindExecutable 3 8.1 Tcl "Tcl Library Procedures"
.BS
.SH NAME
Tcl_FindExecutable, Tcl_GetNameOfExecutable \- identify or return the name of the binary file containing the application
.SH SYNOPSIS
.nf
\fB#include <tcl.h>\fR
.sp
void
\fBTcl_FindExecutable\fR(\fIargv0\fR)
.sp
const char *
\fBTcl_GetNameOfExecutable\fR()
.SH ARGUMENTS
.AS char *argv0
.AP char *argv0 in
The first command-line argument to the program, which gives the
application's name.
.BE

.SH DESCRIPTION
.PP
The \fBTcl_FindExecutable\fR procedure computes the full path name of
the executable file from which the application was invoked and saves
it for Tcl's internal use.
The executable's path name is needed for several purposes in
Tcl.  For example, it is needed on some platforms in the
implementation of the \fBload\fR command.
It is also returned by the \fBinfo nameofexecutable\fR command.
.PP
On UNIX platforms this procedure is typically invoked as the very
first thing in the application's main program;  it must be passed
\fIargv[0]\fR as its argument.  It is important not to change the
working directory before the invocation.
\fBTcl_FindExecutable\fR uses \fIargv0\fR
along with the \fBPATH\fR environment variable to find the
application's executable, if possible.  If it fails to find
the binary, then future calls to \fBinfo nameofexecutable\fR
will return an empty string.
.PP
\fBTcl_GetNameOfExecutable\fR simply returns a pointer to the
internal full path name of the executable file as computed by
\fBTcl_FindExecutable\fR.  This procedure call is the C API
equivalent to the \fBinfo nameofexecutable\fR command.  NULL
is returned if the internal full path name has not been
computed or unknown.

.SH KEYWORDS
binary, executable file