Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f3fc6c

Browse files
GudniNathanmiss-islington
authored andcommitted
bpo-38293: Allow shallow and deep copying of property objects (GH-16438)
Copying property objects results in a TypeError. Steps to reproduce:```>>> import copy>>> obj = property()>>> copy.copy(obj)````This affects both shallow and deep copying. My idea for a fix is to add property objects to the list of "atomic" objects in the copy module.These already include types like functions and type objects.I also added property objects to the unit tests test_copy_atomic and test_deepcopy_atomic. This is my first PR, and it's highly likely I've made some mistake, so please be kind :)https://bugs.python.org/issue38293
1 parent54cfbb2 commit9f3fc6c

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

‎Lib/copy.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def copy(x):
107107
def_copy_immutable(x):
108108
returnx
109109
fortin (type(None),int,float,bool,complex,str,tuple,
110-
bytes,frozenset,type,range,slice,
110+
bytes,frozenset,type,range,slice,property,
111111
types.BuiltinFunctionType,type(Ellipsis),type(NotImplemented),
112112
types.FunctionType,weakref.ref):
113113
d[t]=_copy_immutable
@@ -195,6 +195,7 @@ def _deepcopy_atomic(x, memo):
195195
d[types.BuiltinFunctionType]=_deepcopy_atomic
196196
d[types.FunctionType]=_deepcopy_atomic
197197
d[weakref.ref]=_deepcopy_atomic
198+
d[property]=_deepcopy_atomic
198199

199200
def_deepcopy_list(x,memo,deepcopy=deepcopy):
200201
y= []

‎Lib/test/test_copy.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class WithMetaclass(metaclass=abc.ABCMeta):
9999
42,2**100,3.14,True,False,1j,
100100
"hello","hello\u1234",f.__code__,
101101
b"world",bytes(range(256)),range(10),slice(1,10,2),
102-
NewStyle,Classic,max,WithMetaclass]
102+
NewStyle,Classic,max,WithMetaclass,property()]
103103
forxintests:
104104
self.assertIs(copy.copy(x),x)
105105

@@ -357,7 +357,7 @@ def f():
357357
pass
358358
tests= [None,42,2**100,3.14,True,False,1j,
359359
"hello","hello\u1234",f.__code__,
360-
NewStyle,Classic,max]
360+
NewStyle,Classic,max,property()]
361361
forxintests:
362362
self.assertIs(copy.deepcopy(x),x)
363363

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add:func:`copy.copy` and:func:`copy.deepcopy` support to:func:`property` objects.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp