Skip to content

Commit e069316

Browse files
Added a note about mutable types of named tuples
As pointed out by Cornelius Krupp, types created by the namedtuple constructor are mutable.
1 parent 51f43b7 commit e069316

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

peps/pep-0795.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ across sub-interpreters without the changes proposed by this PEP. The
268268
``n`` tuple contains a mutable dictionary and is, therefore, **not**
269269
deeply immutable and therefore not safe to share between sub-interpreters.
270270

271+
(Note that types created by ``namedtuple`` are mutable. This means that
272+
``Person`` above is mutable. Below we introduce a solution for this by
273+
way of a ``freeze()`` function. Another possibility is to provide a
274+
companion constructor for named tuples that create immutable types.)
275+
271276

272277
Sharing of Types
273278
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)