summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* Two improvements suggested by Greg Stein:Barry Warsaw2001-08-271-2/+5
| | | | | | | | | PyString_FromFormatV(): In the final resize at the end, we can use PyString_AS_STRING() since we know the object is a string and can avoid the typechecking. PyString_FromFormat(): GS sez: "For safety/propriety, you should call va_end() on the vargs variable."
* PyString_FromFormatV: Massage platform %p output to match what gcc does,Tim Peters2001-08-251-0/+8
| | | | | | | at least in the first two characters. %p is ill-defined, and people will forever commit bad tests otherwise ("bad" in the sense that they fall over (at least on Windows) for lack of a leading '0x'; 5 of the 7 tests in test_repr.py failed on Windows for that reason this time around).
* getset_init(): the function name in the PyArg_ParseTuple() formatGuido van Rossum2001-08-241-1/+1
| | | | should just be "getset", not "getset.__init__".
* Improve the error message issued when an unbound method is called withGuido van Rossum2001-08-241-3/+49
| | | | | | an inappropriate first argument. Now that there are more ways for this to fail, make sure to report the name of the class of the expected instance and of the actual instance.
* repr's converted to using PyString_FromFormat() instead of sprintf'ingBarry Warsaw2001-08-2411-136/+95
| | | | | | into a hardcoded char* buffer. Closes patch #454743.
* PyString_FromFormat() and PyString_FromFormatV(): Largely ripped fromBarry Warsaw2001-08-241-0/+155
| | | | | | | | | | | | | | | | | | | PyErr_Format() these new C API methods can be used instead of sprintf()'s into hardcoded char* buffers. This allows us to fix many situation where long package, module, or class names get truncated in reprs. PyString_FromFormat() is the varargs variety. PyString_FromFormatV() is the va_list variety Original PyErr_Format() code was modified to allow %p and %ld expansions. Many reprs were converted to this, checkins coming soo. Not changed: complex_repr(), float_repr(), float_print(), float_str(), int_repr(). There may be other candidates not yet converted. Closes patch #454743.
* Add 'super', another new object type with magical properties.Guido van Rossum2001-08-241-0/+155
| | | | | | | | | | | super(type) -> unbound super object super(type, obj) -> bound super object; requires isinstance(obj, type) Typical use to call a cooperative superclass method: class C(B): def meth(self, arg): super(C, self).meth(arg);
* Change the getset type to take an optional third function argument:Guido van Rossum2001-08-241-9/+21
| | | | | | the delete function. (Question: should the attribute name also be recorded in the getset object? That makes the protocol more work, but may give us better error messages.)
* getset_descr_set(): guard against deletion (indicated by a set callGuido van Rossum2001-08-241-1/+4
| | | | | with a NULL value), in a somewhat lame way: call the set() function with one argument. Should I add a 3rd function, 'del', instead?
* slot_tp_descr_get(): guard against NULL obj or type (bug reported byGuido van Rossum2001-08-241-2/+11
| | | | | | | Thomas Hellor on python-dev). slot_tp_descr_set(): if value is NULL, call __del__ instead of __set__.
* getset_init(): make the arguments optional.Guido van Rossum2001-08-241-3/+11
| | | | getset_doc: add docstring.
* float_pow: Put *all* of the burden on the libm pow in normalTim Peters2001-08-231-45/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | cases. powu: Deleted. This started with a nonsensical error msg: >>> x = -1. >>> import sys >>> x**(-sys.maxint-1L) Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: negative number cannot be raised to a fractional power >>> The special-casing in float_pow was simply wrong in this case (there's not even anything peculiar about these inputs), and I don't see any point to it in *any* case: a decent libm pow should have worst-case error under 1 ULP, so in particular should deliver the exact result whenever the exact result is representable (else its error is at least 1 ULP). Thus our special fiddling for integral values "shouldn't" buy anything in accuracy, and, to the contrary, repeated multiplication is less accurate than a decent pow when the true result isn't exactly representable. So just letting pow() do its job here (we may not be able to trust libm x-platform in exceptional cases, but these are normal cases).
* Add new built-in type 'getset' (PyGetSet_Type).Guido van Rossum2001-08-231-0/+135
| | | | This implements the 'getset' class from test_binop.py.
* err_ovf(): only raise OverflowError when OverflowWarning was raised.Guido van Rossum2001-08-231-1/+2
|
* int_pow(): Repair typo when passing on to float pow (the 2nd argument wasTim Peters2001-08-231-1/+1
| | | | being passed as both the 2nd and 3rd args). Regression test will follow.
* Change all case where we used to raise OverflowError to issue aGuido van Rossum2001-08-231-56/+88
| | | | warning and then redo the operation using long ints.
* Merge changes from r22a2-branch back into trunk. Also, change patchBarry Warsaw2001-08-221-7/+30
| | | | level to 2.2a2+
* Address SF bug #442813. The sequence getitem wrappers should doGuido van Rossum2001-08-171-8/+50
| | | | | | interpretation of negative indices, since neither the sq_*item slots nor the slot_ wrappers do this. (Slices are a different story, there the size wrapping is done too early.)
* Weak reference support, closing SF bug #451773.Guido van Rossum2001-08-171-21/+51
| | | | | | | | | | | Classes that don't use __slots__ have a __weakref__ member added in the same way as __dict__ is added (i.e. only if the base didn't already have one). Classes using __slots__ can enable weak referenceability by adding '__weakref__' to the __slots__ list. Renamed the __weaklistoffset__ class member to __weakrefoffset__ -- it's not always a list, it seems. (Is tp_weaklistoffset a historical misnomer, or do I misunderstand this?)
* Patch #445762: Support --disable-unicodeMartin v. Löwis2001-08-177-6/+94
| | | | | | | | - Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled - check for Py_USING_UNICODE in all places that use Unicode functions - disables unicode literals, and the builtin functions - add the types.StringTypes list - remove Unicode literals from most tests.
* type_new(): look for __dynamic__ at the module level (after looking inGuido van Rossum2001-08-171-14/+54
| | | | | | | | | | | | | the class dict). Anything but a nonnegative int in either place is *ignored* (before, a non-Boolean was an error). The default is still static -- in a comparative test, Jeremy's Tools/compiler package ran twice as slow (compiling itself) using dynamic as the default. (The static version, which requires a few tweaks to avoid modifying class variables, runs at about the same speed as the classic version.) slot_tp_descr_get(): this also needed fallback behavior. slot_tp_getattro(): remove a debug fprintf() call.
* Fix core dump in repr() of instancemethod whose class==NULL.Guido van Rossum2001-08-171-7/+11
|
* instance_getattr2(): rewritten to remove unnecessary stuff andGuido van Rossum2001-08-171-24/+13
| | | | | | | streamlined a bit. instancemethod_descr_get(): don't bind an unbound method of a class that's not a base class of the argument class.
* Instance methods: allow a NULL value for im_class.Guido van Rossum2001-08-171-2/+2
|
* type_new(): only defer to the winning metatype if it's different fromGuido van Rossum2001-08-171-8/+12
| | | | | | | | the metatype passed in as an argument. This prevents infinite recursion when a metatype written in Python calls type.__new__() as a "super" call. Also tweaked some comments.
* classobject.c:instancemethod_descr_get(): when a bound method isGuido van Rossum2001-08-161-0/+5
| | | | | | | assigned to a class variable and then accessed via an instance, it should not be rebound. test_descr.py:methods(): test for the condition above.
* module_repr(): Instead of fixing the maximum buf size to 400,Barry Warsaw2001-08-161-6/+18
| | | | | | | | calculate it on the fly. This way even modules with long package names get an accurate repr instead of a truncated one. The extra malloc/free cost shouldn't be a problem in a repr function. Closes SF bug #437984
* Fix object_repr() to include the module (using the same rules asGuido van Rossum2001-08-161-2/+23
| | | | type_repr() for when to show or not to show it).
* Patch #427190: Implement and use METH_NOARGS and METH_O.Martin v. Löwis2001-08-1611-383/+223
|
* Fix SF bug #442501: calculate __module__ properly.Guido van Rossum2001-08-161-5/+71
| | | | | | | | | | | | | | | | - type_module(), type_name(): if tp_name contains one or more period, the part before the last period is __module__, the part after that is __name__. Otherwise, for non-heap types, __module__ is "__builtin__". For heap types, __module__ is looked up in tp_defined. - type_new(): heap types have their __module__ set from globals().__name__; a pre-existing __module__ in their dict is not overridden. This is not inherited. - type_repr(): if __module__ exists and is not "__builtin__", it is included in the string representation (just as it already is for classes). For example <type '__main__.C'>.
* Subtle change to make None.__class__ work:Guido van Rossum2001-08-162-4/+2
| | | | | | | | | - descrobject.c:descr_check(): only believe None means the same as NULL if the type given is None's type. - typeobject.c:wrap_descr_get(): don't "conventiently" default an absent type to the type of the object argument. Let the called function figure it out.
* Add a function _Py_ReadyTypes() which initializes various and sundryGuido van Rossum2001-08-161-4/+21
| | | | | | | | | types -- currently Type, List, None and NotImplemented. To be called from Py_Initialize() instead of accumulating calls there. Also rename type(None) to NoneType and type(NotImplemented) to NotImplementedType -- naming the type identical to the object was confusing.
* Update to MvL's patch #424475 to avoid returning 2 when tp_compareGuido van Rossum2001-08-161-2/+5
| | | | | | returns that. (This fix is also by MvL; checkin it in because I want to make more changes here. I'm still not 100% satisfied -- see comments attached to the patch.)
* - Another big step in the right direction. All the overridableGuido van Rossum2001-08-151-47/+226
| | | | | | | | | | | | | | | | | | | | operators for which a default implementation exist now work, both in dynamic classes and in static classes, overridden or not. This affects __repr__, __str__, __hash__, __contains__, __nonzero__, __cmp__, and the rich comparisons (__lt__ etc.). For dynamic classes, this meant copying a lot of code from classobject! (XXX There are still some holes, because the comparison code in object.c uses PyInstance_Check(), meaning new-style classes don't get the same dispensation. This needs more thinking.) - Add object.__hash__, object.__repr__, object.__str__. The __str__ dispatcher now calls the __repr__ dispatcher, as it should. - For static classes, the tp_compare, tp_richcompare and tp_hash slots are now inherited together, or not at all. (XXX I fear there are still some situations where you can inherit __hash__ when you shouldn't, but mostly it's OK now, and I think there's no way we can get that 100% right.)
* PyMethod_Type: add a tp_descr_get slot function to ensure properGuido van Rossum2001-08-151-1/+19
| | | | binding of unbound methods.
* Non-function fields, like tp_dictoffset and tp_weaklistoffset, shouldGuido van Rossum2001-08-141-5/+22
| | | | | | | be inherited in inherit_special(), otherwise dynamic types don't inherit these. Also added some XXX comments about open ends.
* func_getattro(), func_setattro(): Implement the new semantics forBarry Warsaw2001-08-141-8/+22
| | | | | | | | | | setting and deleting a function's __dict__ attribute. Deleting it, or setting it to a non-dictionary result in a TypeError. Note that getting it the first time magically initializes it to an empty dict so that func.__dict__ will always appear to be a dictionary (never None). Closes SF bug #446645.
* Remove much dead code from ceval.cJeremy Hylton2001-08-121-35/+35
| | | | | | | | | | | | | | The descr changes moved the dispatch for calling objects from call_object() in ceval.c to PyObject_Call() in abstract.c. call_object() and the many functions it used in ceval.c were no longer used, but were not removed. Rename meth_call() as PyCFunction_Call() so that it can be called by the CALL_FUNCTION opcode in ceval.c. Also, fix error message that referred to PyEval_EvalCodeEx() by its old name eval_code2(). (I'll probably refer to it by its old name, too.)
* Make dynamic types work as intended. Or at least more so.Guido van Rossum2001-08-121-22/+35
| | | | | | | XXX There are still some loose ends: repr(), str(), hash() and comparisons don't inherit a default implementation from object. This must be resolved similarly to the way it's resolved for classic instances.
* Temporary stop-gap fix for dynamic classes, so they pass the test.Guido van Rossum2001-08-121-1/+6
| | | | | | | | | | XXX This is not sufficient: if a dynamic class has no __repr__ method (for instance), but later one is added, that doesn't add a tp_repr slot, so repr() doesn't call the __repr__ method. To make this work, I'll have to add default implementations of several slots to 'object'. XXX Also, dynamic types currently only inherit slots from their dominant base.
* - Big changes to fix SF bug #442833 (a nasty multiple inheritanceGuido van Rossum2001-08-101-91/+122
| | | | | | | | | | | | | | | | problem). inherit_slots() is split in two parts: inherit_special() which inherits the flags and a few very special members from the dominant base; inherit_slots() which inherits only regular slots, and is now called for each base in the MRO in turn. These are now both void functions since they don't have error returns. - Added object.__setitem__() back -- for the same reason as object.__new__(): a subclass of object should be able to call object.__new__(). - add_wrappers() was moved around to be closer to where it is used (it was defined together with add_methods() etc., but has nothing to do with these).
* Add PyDict_Merge(a, b, override):Guido van Rossum2001-08-101-2/+18
| | | | | | PyDict_Merge(a, b, 1) is the same as PyDict_Update(a, b). PyDict_Merge(a, b, 0) does something similar but leaves existing items unchanged.
* Change PyType_Ready() to use the READY and READYING flags. This makesGuido van Rossum2001-08-101-13/+26
| | | | | it possible to detect recursive calls early (as opposed to when the stack overflows :-).
* SF patch #438013 Remove 2-byte Py_UCS2 assumptionsTim Peters2001-08-091-76/+90
| | | | | | | | Removed all instances of Py_UCS2 from the codebase, and so also (I hope) the last remaining reliance on the platform having an integral type with exactly 16 bits. PyUnicode_DecodeUTF16() and PyUnicode_EncodeUTF16() now read and write one byte at a time.
* Sigh. Strengthen the resriction of the previous checkin: tp_new isGuido van Rossum2001-08-091-1/+2
| | | | | inherited unless *both*: (a) the base type is 'object', and (b) the subtype is not a "heap" type.
* Thinking back to the 2.22 revision, I didn't like what I did there oneGuido van Rossum2001-08-091-13/+4
| | | | | | | | | | | | | | | | | bit. For one, this class: class C(object): def __new__(myclass, ...): ... would have no way to call the __new__ method of its base class, and the workaround (to create an intermediate base class whose __new__ you can call) is ugly. So, I've come up with a better solution that restores object.__new__, but still solves the original problem, which is that built-in and extension types shouldn't inherit object.__new__. The solution is simple: only "heap types" inherit tp_new. Simpler, less code, perfect!
* Apply anonymous SF patch #441229.Guido van Rossum2001-08-091-0/+6
| | | | | | | | | | | | Previously, f.read() and f.readlines() checked for errors on their file object and possibly raised an IOError, but f.readline() didn't. This patch makes f.readline() behave like the others. Note that I've added a call to clearerr() since the other calls to ferror() include that too. I have no way to test this code. :-)
* Proper support for binary operators, including true division and floorGuido van Rossum2001-08-081-136/+199
| | | | | | | | | | | | | | | division. The basic binary operators now all correctly call the __rxxx__ variant when they should. In type_new(), I now make the new type a new-style number unless it inherits from an old-style number that has numeric methods. By way of cosmetics, I've changed the signatures of the SLOT<i> macros to take actual function names and operator names as strings, rather than rely on C preprocessor symbol manipulations. This makes the calls slightly more verbose, but greatly helps simple searches through the file: you can now find out where "__radd__" is used or where the function slot_nb_power() is defined and where it is used.
* Removed extraneous semicolons that caused a gazzilion "empty declaration" ↵Jack Jansen2001-08-081-49/+49
| | | | warnings in the MetroWerks compiler.
* Implement PEP 238 in its (almost) full glory.Guido van Rossum2001-08-086-24/+131
| | | | | | | | | | | | | | | | | | | | | | | | | | This introduces: - A new operator // that means floor division (the kind of division where 1/2 is 0). - The "future division" statement ("from __future__ import division) which changes the meaning of the / operator to implement "true division" (where 1/2 is 0.5). - New overloadable operators __truediv__ and __floordiv__. - New slots in the PyNumberMethods struct for true and floor division, new abstract APIs for them, new opcodes, and so on. I emphasize that without the future division statement, the semantics of / will remain unchanged until Python 3.0. Not yet implemented are warnings (default off) when / is used with int or long arguments. This has been on display since 7/31 as SF patch #443474. Flames to /dev/null.