Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f0e3569a
Commit
f0e3569a
authored
Mar 08, 2004
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor the copy dispatcher code in copy.py. Simplifies and shortens
the code by grouping common cases together.
parent
99842b65
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
35 deletions
+17
-35
Lib/copy.py
Lib/copy.py
+17
-35
No files found.
Lib/copy.py
View file @
f0e3569a
...
...
@@ -97,44 +97,26 @@ def copy(x):
_copy_dispatch
=
d
=
{}
def
_copy_
atomic
(
x
):
def
_copy_
immutable
(
x
):
return
x
d
[
types
.
NoneType
]
=
_copy_atomic
d
[
types
.
IntType
]
=
_copy_atomic
d
[
types
.
LongType
]
=
_copy_atomic
d
[
types
.
FloatType
]
=
_copy_atomic
d
[
types
.
BooleanType
]
=
_copy_atomic
try
:
d
[
types
.
ComplexType
]
=
_copy_atomic
except
AttributeError
:
pass
d
[
types
.
StringType
]
=
_copy_atomic
try
:
d
[
types
.
UnicodeType
]
=
_copy_atomic
except
AttributeError
:
pass
try
:
d
[
types
.
CodeType
]
=
_copy_atomic
except
AttributeError
:
pass
d
[
types
.
TypeType
]
=
_copy_atomic
d
[
types
.
XRangeType
]
=
_copy_atomic
d
[
types
.
ClassType
]
=
_copy_atomic
d
[
types
.
BuiltinFunctionType
]
=
_copy_atomic
def
_copy_list
(
x
):
return
x
[:]
d
[
types
.
ListType
]
=
_copy_list
def
_copy_tuple
(
x
):
return
x
[:]
d
[
types
.
TupleType
]
=
_copy_tuple
def
_copy_dict
(
x
):
for
t
in
(
types
.
NoneType
,
int
,
long
,
float
,
bool
,
str
,
tuple
,
frozenset
,
type
,
xrange
,
types
.
ClassType
,
types
.
BuiltinFunctionType
):
d
[
t
]
=
_copy_immutable
for
name
in
(
"ComplexType"
,
"UnicodeType"
,
"CodeType"
):
t
=
getattr
(
types
,
name
,
None
)
if
t
is
not
None
:
d
[
t
]
=
_copy_immutable
def
_copy_with_constructor
(
x
):
return
type
(
x
)(
x
)
for
t
in
(
list
,
dict
,
set
):
d
[
t
]
=
_copy_with_constructor
def
_copy_with_copy_method
(
x
):
return
x
.
copy
()
d
[
types
.
DictionaryType
]
=
_copy_dict
if
PyStringMap
is
not
None
:
d
[
PyStringMap
]
=
_copy_
dict
d
[
PyStringMap
]
=
_copy_
with_copy_method
def
_copy_inst
(
x
):
if
hasattr
(
x
,
'__copy__'
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment