Commit graph

76 commits

Author SHA1 Message Date
Berker Peksag 2708578736
bpo-11572: Make minor improvements to copy module (GH-8208)
* When doing getattr lookups with a default of "None", it now
  uses an "is" comparison against None which is more correct
* Removed outdated code

Patch by Brandon Rhodes.
2018-07-09 23:14:54 +03:00
Serhiy Storchaka 818e18dd94 Issue #26167: Minimized overhead in copy.copy() and copy.deepcopy().
Optimized copying and deepcopying bytearrays, NotImplemented, slices,
short lists, tuples, dicts, sets.
2016-03-06 14:56:57 +02:00
Serhiy Storchaka 0a20bbf669 Issue #26202: copy.deepcopy() now correctly copies range() objects with
non-atomic attributes.
2016-01-28 21:43:35 +02:00
Serhiy Storchaka b63015b01a Issue #25718: Fixed copying object with state with boolean value is false. 2015-11-30 17:35:40 +02:00
Serhiy Storchaka cbbec1c53f Issue #25718: Fixed copying object with state with boolean value is false. 2015-11-30 17:20:02 +02:00
Serhiy Storchaka 32af7549a7 Issue #20289: The copy module now uses pickle protocol 4 (PEP 3154) and
supports copying of instances of classes whose __new__ method takes
keyword-only arguments.
2015-03-24 18:06:42 +02:00
Benjamin Peterson 4ce5f3f203 improve idioms (closes #20642)
Patch by Claudiu Popa.
2014-05-03 20:22:00 -04:00
Antoine Pitrou dc9215f882 Issue #20791: copy.copy() now doesn't make a copy when the input is a bytes object. Initial patch by Peter Otten. 2014-02-27 22:14:31 +01:00
Alexandre Vassalotti 5c1c3b4f19 Issue #11480: Fixed copy.copy to work with classes with custom metaclasses.
Patch by Daniel Urban.
2013-12-01 13:25:26 -08:00
Sandro Tosi 4dc9c84ed9 #11572: improvements to copy module tests along with removal of old test suite 2011-08-05 23:05:35 +02:00
Benjamin Peterson e90ec366fb don't memoize objects that are their own copies (closes #12422)
Patch mostly by Alex Gaynor.
2011-06-27 16:22:46 -05:00
Antoine Pitrou d6399d2d19 Fix running the copy module from the command-line (however use{ful,less} it may be). 2010-09-04 17:46:44 +00:00
Antoine Pitrou 3941a8fece Issue #1100562: Fix deep-copying of objects derived from the list and dict types.
Patch by Michele Orrù and Björn Lindqvist.
2010-09-04 17:40:21 +00:00
Antoine Pitrou 1fc0d2b364 Merged revisions 76571 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r76571 | antoine.pitrou | 2009-11-28 16:55:58 +0100 (sam., 28 nov. 2009) | 3 lines

  Issue #1515: Enable use of deepcopy() with instance methods.  Patch by Robert Collins.
........
2009-11-28 15:58:27 +00:00
Antoine Pitrou 6e61006cc2 Merged revisions 72669 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r72669 | antoine.pitrou | 2009-05-15 18:54:52 +0200 (ven., 15 mai 2009) | 3 lines

  Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
........
2009-05-15 17:04:50 +00:00
Alexandre Vassalotti 1f2ba4b6da Rename the repr module to reprlib.
Merged revisions 63357 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r63357 | alexandre.vassalotti | 2008-05-16 02:58:49 -0400 (Fri, 16 May 2008) | 2 lines

  Changed references to the reprlib module to use its new name.
........
2008-05-16 07:12:44 +00:00
Alexandre Vassalotti f7fa63dd55 Rename copy_reg module to copyreg.
Updated documentation.
Merged revisions 63042 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r63042 | alexandre.vassalotti | 2008-05-11 04:25:28 -0400 (Sun, 11 May 2008) | 5 lines

  Added module stub for copy_reg renaming in 3.0.
  Renamed copy_reg to copyreg in the standard library, to avoid
  spurious warnings and ease later merging to py3k branch. Public
  documentation remains intact.
........
2008-05-11 08:55:36 +00:00
Christian Heimes cc47b05fe5 Merged revisions 61834,61841-61842,61851-61853,61863-61864,61869-61870,61874,61889 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r61834 | raymond.hettinger | 2008-03-24 07:07:49 +0100 (Mon, 24 Mar 2008) | 1 line

  Tighten documentation for Random.triangular.
........
  r61841 | raymond.hettinger | 2008-03-24 09:17:39 +0100 (Mon, 24 Mar 2008) | 1 line

  Issue 2460: Make Ellipsis objects copyable.
........
  r61842 | georg.brandl | 2008-03-24 10:34:34 +0100 (Mon, 24 Mar 2008) | 2 lines

  #1700821: add a note to audioop docs about signedness of sample formats.
........
  r61851 | christian.heimes | 2008-03-24 20:57:42 +0100 (Mon, 24 Mar 2008) | 1 line

  Added quick hack for bzr
........
  r61852 | christian.heimes | 2008-03-24 20:58:17 +0100 (Mon, 24 Mar 2008) | 1 line

  Added quick hack for bzr
........
  r61853 | amaury.forgeotdarc | 2008-03-24 22:04:10 +0100 (Mon, 24 Mar 2008) | 4 lines

  Issue2469: Correct a typo I introduced at r61793: compilation error with UCS4 builds.

  All buildbots compile with UCS2...
........
  r61863 | neal.norwitz | 2008-03-25 05:17:38 +0100 (Tue, 25 Mar 2008) | 2 lines

  Fix a bunch of UnboundLocalErrors when the tests fail.
........
  r61864 | neal.norwitz | 2008-03-25 05:18:18 +0100 (Tue, 25 Mar 2008) | 2 lines

  Try to fix a bunch of compiler warnings on Win64.
........
  r61869 | neal.norwitz | 2008-03-25 07:35:10 +0100 (Tue, 25 Mar 2008) | 3 lines

  Don't try to close a non-open file.
  Don't let file removal cause the test to fail.
........
  r61870 | neal.norwitz | 2008-03-25 08:00:39 +0100 (Tue, 25 Mar 2008) | 7 lines

  Try to get this test to be more stable:
   * disable gc during the test run because we are spawning objects and there
     was an exception when calling Popen.__del__
   * Always set an alarm handler so the process doesn't exit if the test fails
     (should probably add assertions on the value of hndl_called in more places)
   * Using a negative time causes Linux to treat it as zero, so disable that test.
........
  r61874 | gregory.p.smith | 2008-03-25 08:31:28 +0100 (Tue, 25 Mar 2008) | 2 lines

  Use a 32-bit unsigned int here, a long is not needed.
........
  r61889 | georg.brandl | 2008-03-25 12:59:51 +0100 (Tue, 25 Mar 2008) | 2 lines

  Move declarations to block start.
........
2008-03-25 14:56:36 +00:00
Guido van Rossum 98297ee781 Merging the py3k-pep3137 branch back into the py3k branch.
No detailed change log; just check out the change log for the py3k-pep3137
branch.  The most obvious changes:

  - str8 renamed to bytes (PyString at the C level);
  - bytes renamed to buffer (PyBytes at the C level);
  - PyString and PyUnicode are no longer compatible.

I.e. we now have an immutable bytes type and a mutable bytes type.

The behavior of PyString was modified quite a bit, to make it more
bytes-like.  Some changes are still on the to-do list.
2007-11-06 21:34:58 +00:00
Guido van Rossum 1325790b93 Merged revisions 55795-55816 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk

........
  r55797 | neal.norwitz | 2007-06-07 00:00:57 -0700 (Thu, 07 Jun 2007) | 3 lines

  Get rid of some remnants of classic classes.  types.ClassType == type.
  Also get rid of almost all uses of the types module and use the builtin name.
........
  r55798 | neal.norwitz | 2007-06-07 00:12:36 -0700 (Thu, 07 Jun 2007) | 1 line

  Remove a use of types, verify commit hook works
........
  r55809 | guido.van.rossum | 2007-06-07 11:11:29 -0700 (Thu, 07 Jun 2007) | 2 lines

  Fix syntax error introduced by Neal in last checkin.
........
2007-06-07 23:15:56 +00:00
Walter Dörwald 756f139b97 Register a dispatcher for str8. (This makes test_copy.py pass again.)
Make registeration of str dispatcher unconditional.
2007-06-07 13:11:04 +00:00
Guido van Rossum 805365ee39 Merged revisions 55007-55179 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk

........
  r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines

  Use the new print syntax, at least.
........
  r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line

  remove old cruftiness
........
  r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line

  make this work with the new Python
........
  r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line

  Get asdl code gen working with Python 2.3.  Should continue to work with 3.0
........
  r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line

  Verify checkins to p3yk (sic) branch go to 3000 list.
........
  r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line

  Fix this test so it runs again by importing warnings_test properly.
........
  r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines

  So long xrange.  range() now supports values that are outside
  -sys.maxint to sys.maxint.  floats raise a TypeError.

  This has been sitting for a long time.  It probably has some problems and
  needs cleanup.  Objects/rangeobject.c now uses 4-space indents since
  it is almost completely new.
........
  r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines

  Fix two tests that were previously depending on significant spaces
  at the end of a line (and before that on Python 2.x print behavior
  that has no exact equivalent in 3.0).
........
2007-05-07 22:24:25 +00:00
Guido van Rossum ef87d6ed94 Rip out all the u"..." literals and calls to unicode(). 2007-05-02 19:09:54 +00:00
Neal Norwitz b69b2e59f6 Remove duplicate refs to int from int/long unification presumably. (There might be more refs like these.) 2007-02-27 03:41:04 +00:00
Guido van Rossum cc2b016125 - PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
and .keys(), .items(), .values() return dict views.

The dict views aren't fully functional yet; in particular, they can't
be compared to sets yet.  but they are useful as "iterator wells".

There are still 27 failing unit tests; I expect that many of these
have fairly trivial fixes, but there are so many, I could use help.
2007-02-11 06:12:03 +00:00
Guido van Rossum be19ed77dd Fix most trivially-findable print statements.
There's one major and one minor category still unfixed:
doctests are the major category (and I hope to be able to augment the
refactoring tool to refactor bona fide doctests soon);
other code generating print statements in strings is the minor category.

(Oh, and I don't know if the compiler package works.)
2007-02-09 05:37:30 +00:00
Guido van Rossum e2a383d062 Rip out 'long' and 'L'-suffixed integer literals.
(Rough first cut.)
2007-01-15 16:59:06 +00:00
Guido van Rossum 65810fee5e SF patch 1495675: Remove types.InstanceType and new.instance
(Collin Winter)
2006-05-26 19:12:38 +00:00
Tim Peters d6e7e73ff8 Whitespace normalization. 2006-02-26 04:21:50 +00:00
Guido van Rossum 1968ad32cd - Patch 1433928:
- The copy module now "copies" function objects (as atomic objects).
  - dict.__getitem__ now looks for a __missing__ hook before raising
    KeyError.
  - Added a new type, defaultdict, to the collections module.
    This uses the new __missing__ hook behavior added to dict (see above).
2006-02-25 22:38:04 +00:00
Raymond Hettinger f9d88ab39e SF bug #1219361 Fix typo 2005-06-13 01:10:15 +00:00
Martin v. Löwis e2713becd8 Build with --disable-unicode again. Fixes #1158607.
Will backport to 2.4.
2005-03-08 15:03:08 +00:00
Raymond Hettinger f715366f23 Reduce the usage of the types module. 2005-02-07 14:16:21 +00:00
Raymond Hettinger f0e3569a28 Refactor the copy dispatcher code in copy.py. Simplifies and shortens
the code by grouping common cases together.
2004-03-08 05:59:33 +00:00
Martin v. Löwis ba8f5ff76c Copy builtin functions as atomic. Fixes #746304. Will backport to 2.2. 2003-06-14 07:10:06 +00:00
Guido van Rossum 99d2c251df SF patch 707900, fixing bug 702858, by Steven Taschuk.
Copying a new-style class that had a reference to itself didn't work.
(The same thing worked fine for old-style classes.)
2003-06-13 19:28:47 +00:00
Guido van Rossum 68468eba63 Get rid of many apply() calls. 2003-02-27 20:14:51 +00:00
Tim Peters f2715e0764 Whitespace normalization. 2003-02-19 02:35:07 +00:00
Guido van Rossum 9c9cf41a01 Remove now unused _better_reduce. 2003-02-19 01:20:40 +00:00
Guido van Rossum e690883ccf Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again. 2003-02-19 01:19:28 +00:00
Guido van Rossum 1dca482dbd Somehow, copy() of a classic class object was handled
atomically, but deepcopy() didn't support this at all.
I don't see any reason for this, so I'm adding ClassType
to the set of types that are deep-copied atomically.
2003-02-07 17:53:23 +00:00
Guido van Rossum c06e3acc73 Add support for copy_reg.dispatch_table.
Rewrote copy() and deepcopy() without avoidable try/except statements;
getattr(x, name, None) or dict.get() are much faster than try/except.
2003-02-07 17:30:18 +00:00
Guido van Rossum 5aac4e6312 Move _better_reduce from copy.py to copy_reg.py, and also use it in
pickle.py, where it makes save_newobj() unnecessary.  Tests pass.
2003-02-06 22:57:00 +00:00
Guido van Rossum 85233bf746 Fix a bug in the way __getnewargs__ was handled. 2003-02-06 21:25:12 +00:00
Guido van Rossum c755758906 Support all the new stuff supported by the new pickle code:
- subclasses of list or dict
- __reduce__ returning a 4-tuple or 5-tuple
- slots
2003-02-06 19:53:22 +00:00
Guido van Rossum 90e05b0e25 Support __reduce__ returning a 4-tuple or 5-tuple. 2003-02-06 18:18:23 +00:00
Martin v. Löwis 71b755646a Support copying booleans. Fixes #668925. 2003-01-16 10:40:00 +00:00
Guido van Rossum 611546005b Make sure that *any* object whose id() is used as a memo key is kept
alive in the memo.  This fixes SF bug 592567.
2002-08-12 20:20:08 +00:00
Guido van Rossum 11ade1ddc0 SF patch 560794 (Greg Chapman): deepcopy can't handle custom
metaclasses.

This is essentially the same problem as that reported in bug 494904
for pickle: deepcopy should treat instances of custom metaclasses the
same way it treats instances of type 'type'.

Bugfix candidate.
2002-06-10 21:10:27 +00:00
Guido van Rossum 3e3583c345 Fix from SF patch 565085: copy._reduction doesn't __setstate__.
Straightforward fix.  Will backport to 2.2.  If there's ever a new 2.1
release, this could be backported there too (since it's an issue with
anything that's got both a __reduce__ and a __setstate__).
2002-06-06 17:41:20 +00:00