Commit Graph

69 Commits

Author SHA1 Message Date
Raymond Hettinger bf7a266074 Fixup repr for dict_proxy objects. 2011-06-30 00:44:36 +01:00
Victor Stinner e363ec1057 (Merge 3.1) Issue #9756: When calling a method descriptor or a slot wrapper
descriptor, the check of the object type doesn't read the __class__ attribute
anymore.  Fix a crash if a class override its __class__ attribute (e.g. a proxy
of the str type).
2011-05-01 23:43:37 +02:00
Benjamin Peterson 4c5bc4d7f8 remove unused last argument to property_copy 2010-06-28 02:58:25 +00:00
Antoine Pitrou c83ea137d7 Untabify C files. Will watch buildbots. 2010-05-09 14:46:46 +00:00
Benjamin Peterson 97a57ec048 rewrite for style, clarify, and comments
Also, use the hasattr() like scheme of allowing BaseException exceptions through.
2009-10-22 02:50:38 +00:00
Benjamin Peterson 3c67afa714 whitespace 2009-10-22 02:26:47 +00:00
Georg Brandl cecdc9c0e0 Remove unused variable. 2009-05-05 09:20:52 +00:00
R. David Murray 7ba8e1cbfd Fix issue 5890: (property subclass shadows __doc__ string) by inserting
the __doc__ into the subclass instance __dict__.  The fix refactors
property_copy to call property_init in such a way that the __doc__
logic is re-executed correctly when getter_doc is 1, thus simplifying
property_copy.
2009-05-04 22:16:24 +00:00
Benjamin Peterson 01c6e6fb35 many more types to initialize (I had to expose some of them) 2009-04-18 22:15:26 +00:00
Gregory P. Smith dd96db63f6 This reverts r63675 based on the discussion in this thread:
http://mail.python.org/pipermail/python-dev/2008-June/079988.html

Python 2.6 should stick with PyString_* in its codebase.  The PyBytes_* names
in the spirit of 3.0 are available via a #define only.  See the email thread.
2008-06-09 04:58:54 +00:00
Christian Heimes 593daf545b Renamed PyString to PyBytes 2008-05-26 12:51:38 +00:00
Neal Norwitz fddc469876 Prevent namespace pollution, add static for internal functions 2008-04-15 03:46:21 +00:00
Amaury Forgeot d'Arc 60d6c7f0cc Issue #2115: __slot__ attributes setting was 10x slower.
Also correct a possible crash using ABCs.

This change is exactly the same as an optimisation
done 5 years ago, but on slot *access*:
http://svn.python.org/view?view=rev&rev=28297
2008-02-15 21:22:45 +00:00
Neal Norwitz 59a65facf2 Fix refleak 2007-12-31 23:48:47 +00:00
Christian Heimes 90e10e79ea Fixed bug #1620: New @spam.getter property syntax modifies the property in place.
I added also the feature that a @prop.getter decorator does not overwrite the doc string of the property if it was given as an argument to property().
2007-12-14 02:35:23 +00:00
Andrew M. Kuchling abfe45368c Re-word sentence 2007-11-12 01:25:21 +00:00
Christian Heimes 3d4c316f17 Added new decorator syntax to property.__doc__
Guido prefers _x over __x.
2007-11-12 01:15:40 +00:00
Guido van Rossum d1ef78942a Issue 1416. Add getter, setter, deleter methods to properties that can be
used as decorators to create fully-populated properties.
2007-11-10 22:12:24 +00:00
Martin v. Löwis 6819210b9e PEP 3123: Provide forward compatibility with Python 3.0, while keeping
backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and
PyVarObject_HEAD_INIT.
2007-07-21 06:55:02 +00:00
Georg Brandl e9462c72bd Change fix for segfaulting property(), add a NEWS entry and a test. 2006-08-04 18:03:37 +00:00
Georg Brandl 45381938e9 Fix bug caused by first decrefing, then increfing. 2006-08-04 06:03:53 +00:00
Martin v. Löwis d5cfa5491a Put method-wrappers into trashcan. Fixes #927248. 2006-07-03 13:47:40 +00:00
Armin Rigo fd01d7933b (arre, arigo) SF bug #1350060
Give a consistent behavior for comparison and hashing of method objects
(both user- and built-in methods).  Now compares the 'self' recursively.
The hash was already asking for the hash of 'self'.
2006-06-08 10:56:24 +00:00
Thomas Wouters c6e55068ca Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
using a custom, nearly-identical macro. This probably changes how some of
these functions are compiled, which may result in fractionally slower (or
faster) execution. Considering the nature of traversal, visiting much of the
address space in unpredictable patterns, I'd argue the code readability and
maintainability is well worth it ;P
2006-04-15 21:47:09 +00:00
Georg Brandl 347b30042b Remove unnecessary casts in type object initializers. 2006-03-30 11:57:00 +00:00
Georg Brandl 533ff6fc06 Patch #1434038: property() now uses the getter's docstring if there is
no "doc" argument given. This makes it possible to legitimately use
property() as a decorator to produce a read-only property.
2006-03-08 18:09:27 +00:00
Martin v. Löwis 15e62742fa Revert backwards-incompatible const changes. 2006-02-27 16:46:16 +00:00
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Jeremy Hylton af68c874a6 Add const to several API functions that take char *.
In C++, it's an error to pass a string literal to a char* function
without a const_cast().  Rather than require every C++ extension
module to put a cast around string literals, fix the API to state the
const-ness.

I focused on parts of the API where people usually pass literals:
PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type
slots, etc.  Predictably, there were a large set of functions that
needed to be fixed as a result of these changes.  The most pervasive
change was to make the keyword args list passed to
PyArg_ParseTupleAndKewords() to be a const char *kwlist[].

One cast was required as a result of the changes:  A type object
mallocs the memory for its tp_doc slot and later frees it.
PyTypeObject says that tp_doc is const char *; but if the type was
created by type_new(), we know it is safe to cast to char *.
2005-12-10 18:50:16 +00:00
Armin Rigo c6686b7c7e Added proper reflection on instances of <type 'method-wrapper'>, e.g.
'[].__add__', to match what the other internal descriptor types provide:
'__objclass__' attribute, '__self__' member, and reasonable repr and
comparison.

Added a test.
2005-11-07 08:38:00 +00:00
Barry Warsaw c8d907c60b As per discussion on python-dev, descriptors defined in C with a NULL setter
now raise AttributeError instead of TypeError, for consistency with their
pure-Python equivalent.
2005-04-19 23:43:40 +00:00
Raymond Hettinger d3ae6729e7 Use PyDict_Contains() instead of PySequence_Contains(). 2003-12-13 11:58:56 +00:00
Guido van Rossum 98c65bed91 Return a bool rather than an int from proxy_has_key(). 2003-10-09 03:47:08 +00:00
Raymond Hettinger 574aa32578 SF patch #798467: Update docstring of has_key for bool changes
(Contributed by George Yoshida.)
2003-09-01 22:12:08 +00:00
Guido van Rossum 00bf8280f5 property_traverse() should also traverse into prop_doc -- there's no
typecheck that guarantees it's a string, and BTW string subclasses
could hide references.
2003-04-09 17:05:33 +00:00
Guido van Rossum b6e5a0c658 Put proper tests in classmethod_get(). Remove the type argument to
descr_check(); it wasn't useful.  Change the type argument of the
various _get() methods to PyObject * because the call signature of
tp_descr_get doesn't guarantee its type.
2003-02-11 18:44:42 +00:00
Raymond Hettinger ea3fdf44a2 SF patch #659536: Use PyArg_UnpackTuple where possible.
Obtain cleaner coding and a system wide
performance boost by using the fast, pre-parsed
PyArg_Unpack function instead of PyArg_ParseTuple
function which is driven by a format string.
2002-12-29 16:33:45 +00:00
Tim Peters bca1cbc6f8 SF 548651: Fix the METH_CLASS implementation.
Most of these patches are from Thomas Heller, with long lines folded
by Tim.  The change to test_descr.py is from Guido.  See the bug report.

Not a bugfix candidate -- METH_CLASS is new in 2.3.
2002-12-09 22:56:13 +00:00
Raymond Hettinger 29a6d449ef Added comparison functions to dict proxies.
Now all non-mutating dict methods are in the proxy also.
Inspired by SF bug #602232,
2002-08-31 15:51:04 +00:00
Guido van Rossum 492b46f29e Make PyDescr_IsData() a macro. It's too simple to be a function.
Should save 4% on slot lookups.
2002-08-19 18:45:37 +00:00
Guido van Rossum c588e9041a Simple but important optimization for descr_check(): instead of the
expensive and overly general PyObject_IsInstance(), call
PyObject_TypeCheck() which is a macro that often avoids a call, and if
it does make a call, calls the much more efficient PyType_IsSubtype().
This saved 6% on a benchmark for slot lookups.
2002-08-19 16:02:33 +00:00
Neal Norwitz 5dc2a37f0f Allow more docstrings to be removed during compilation 2002-08-13 22:19:13 +00:00
Guido van Rossum bea18ccde6 SF patch 568629 by Oren Tirosh: types made callable.
These built-in functions are replaced by their (now callable) type:

    slice()
    buffer()

and these types can also be called (but have no built-in named
function named after them)

    classobj (type name used to be "class")
    code
    function
    instance
    instancemethod (type name used to be "instance method")

The module "new" has been replaced with a small backward compatibility
placeholder in Python.

A large portion of the patch simply removes the new module from
various platform-specific build recipes.  The following binary Mac
project files still have references to it:

    Mac/Build/PythonCore.mcp
    Mac/Build/PythonStandSmall.mcp
    Mac/Build/PythonStandalone.mcp

[I've tweaked the code layout and the doc strings here and there, and
added a comment to types.py about StringTypes vs. basestring.  --Guido]
2002-06-14 20:41:17 +00:00
Martin v. Löwis 14f8b4cfcb Patch #568124: Add doc string macros. 2002-06-13 20:33:02 +00:00
Guido van Rossum 5961042061 Fold long lines. (Walter, please take note! :-) 2002-04-13 14:06:36 +00:00
Neil Schemenauer 99b5d28467 PyObject_GC_Del can now be used as a function designator. 2002-04-12 02:44:22 +00:00
Walter Dörwald e990c79fa8 Add missing methods iterkeys, itervalues and iteritems to
dict-proxy objects.

Add real docstrings to all methods.
2002-03-25 17:43:22 +00:00
Guido van Rossum 2b8235e485 SF bug #493561: incorrect format string descrobject.c (Neal Norwitz)
%300s should be %.300s, twice.
2001-12-15 05:00:30 +00:00
Guido van Rossum 7171f1c8d8 Well what do you know. The Python implementation contained the same
bug as the C code. :-(
2001-12-10 18:06:21 +00:00
Guido van Rossum ba2485f947 Fix the Python property class in a comment right. 2001-12-10 18:03:34 +00:00