summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_descr.py
Commit message (Collapse)AuthorAgeFilesLines
* SF bug #541883 (Vincent Fiack).Guido van Rossum2002-04-151-0/+6
| | | | | | | A stupid bug in object_set_class(): didn't check for value==NULL before checking its type. Bugfix candidate.
* - Changed new-style class instantiation so that when C's __new__Guido van Rossum2002-04-061-0/+22
| | | | | method returns something that's not a C instance, its __init__ is not called. [SF bug #537450]
* Add the 'bool' type and its values 'False' and 'True', as described inGuido van Rossum2002-04-031-1/+1
| | | | | | | | | | | | | PEP 285. Everything described in the PEP is here, and there is even some documentation. I had to fix 12 unit tests; all but one of these were printing Boolean outcomes that changed from 0/1 to False/True. (The exception is test_unicode.py, which did a type(x) == type(y) style comparison. I could've fixed that with a single line using issubtype(x, type(y)), but instead chose to be explicit about those places where a bool is expected. Still to do: perhaps more documentation; change standard library modules to return False/True from predicates.
* SF patch 537536 by Phillip J. Eby, fix for SF bug 535444, super()Guido van Rossum2002-04-021-0/+8
| | | | | | broken w/ classmethods. Bugfix candidate.
* There is no TestError, use TestFailed appropriatelyNeal Norwitz2002-04-011-1/+1
|
* Add a simple test of the METH_CLASS and METH_STATIC flags for type methods.Fred Drake2002-03-281-0/+30
|
* Add tests for the iterkeys, itervalues and iteritemsWalter Dörwald2002-03-251-0/+29
| | | | methods in dict-proxy objects.
* Fix for SF bug 528132 (Armin Rigo): classmethod().__get__() segfaultGuido van Rossum2002-03-181-0/+5
| | | | | | | | | | | The proper fix is not quite what was submitted; it's really better to take the class of the object passed rather than calling PyMethod_New with NULL pointer args, because that can then cause other core dumps later. I also added a testcase for the fix to classmethods() in test_descr.py. I've already applied this to the 2.2 branch.
* "Fix" for SF bug #520644: __slots__ are not pickled.Guido van Rossum2002-03-141-0/+89
| | | | | | | | | | | As promised in my response to the bug report, I'm not really fixing it; in fact, one could argule over what the proper fix should do. Instead, I'm adding a little magic that raises TypeError if you try to pickle an instance of a class that has __slots__ but doesn't define or override __getstate__. This is done by adding a bozo __getstate__ that always raises TypeError. Bugfix candidate (also the checkin to typeobject.c, of course).
* Test for the fix I just checked in to moduleobject.c.Guido van Rossum2002-03-121-0/+12
| | | | Bugfix candidate.
* Fix typoNeal Norwitz2002-03-111-1/+1
|
* Add a check that SF bug 516727 is really fixed.Guido van Rossum2002-03-111-0/+10
|
* Bugfix candidate.Guido van Rossum2002-03-111-0/+3
| | | | | | | Adapter from SF patch 528038; fixes SF bug 527816. The wrapper for __nonzero__ should be wrap_inquiry rather than wrap_unaryfunc, since the slot returns an int, not a PyObject *.
* _PyLong_Copy(): was creating a copy of the absolute value, but shouldTim Peters2002-03-021-0/+1
| | | | | | copy the sign too. Added a test to test_descr to ensure that it does. Bugfix candidate.
* SF patch 514641 (Naofumi Honda) - Negative ob_size of LongObjectsGuido van Rossum2002-03-011-0/+4
| | | | | | | | | | Due to the bizarre definition of _PyLong_Copy(), creating an instance of a subclass of long with a negative value could cause core dumps later on. Unfortunately it looks like the behavior of _PyLong_Copy() is quite intentional, so the fix is more work than feels comfortable. This fix is almost, but not quite, the code that Naofumi Honda added; in addition, I added a test case.
* Fix for SF bug ##497426: can't deepcopy recursive new objectsGuido van Rossum2001-12-281-1/+10
| | | | | | | | deepcopy(), _reconstruct(): pass the memo to the other function, so that recursive data structures built out of new-style objects may be deeply copied correctly. 2.2.1 bugfix!
* (Merge into trunk.)Guido van Rossum2001-12-141-0/+10
| | | | | | | | | | | | | | | | | Fix for SF bug #492345. (I could've sworn I checked this in, but apparently I didn't!) This code: class Classic: pass class New(Classic): __metaclass__ = type attempts to create a new-style class with only classic bases -- but it doesn't work right. Attempts to fix it so it works caused problems elsewhere, so I'm now raising a TypeError in this case.
* Additional coverage tests by Neil Norwitz.Guido van Rossum2001-12-111-0/+66
| | | | (SF patch #491418, #491420, #491421.)
* SF bug #488514: -Qnew needs workTim Peters2001-12-061-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Big Hammer to implement -Qnew as PEP 238 says it should work (a global option affecting all instances of "/"). pydebug.h, main.c, pythonrun.c: define a private _Py_QnewFlag flag, true iff -Qnew is passed on the command line. This should go away (as the comments say) when true division becomes The Rule. This is deliberately not exposed to runtime inspection or modification: it's a one-way one-shot switch to pretend you're using Python 3. ceval.c: when _Py_QnewFlag is set, treat BINARY_DIVIDE as BINARY_TRUE_DIVIDE. test_{descr, generators, zipfile}.py: fiddle so these pass under -Qnew too. This was just a matter of s!/!//! in test_generators and test_zipfile. test_descr was trickier, as testbinop() is passed assumptions that "/" is the same as calling a "__div__" method; put a temporary hack there to call "__truediv__" instead when the method name is "__div__" and 1/2 evaluates to 0.5. Three standard tests still fail under -Qnew (on Windows; somebody please try the Linux tests with -Qnew too! Linux runs a whole bunch of tests Windows doesn't): test_augassign test_class test_coercion I can't stay awake longer to stare at this (be my guest). Offhand cures weren't obvious, nor was it even obvious that cures are possible without major hackery. Question: when -Qnew is in effect, should calls to __div__ magically change into calls to __truediv__? See "major hackery" at tail end of last paragraph <wink>.
* Fix SF bug #489581: __slots__ leak.Guido van Rossum2001-12-051-0/+34
| | | | | | It was easier than I thought, assuming that no other things contribute to the instance size besides slots -- a pretty good bet. With a test suite, no less!
* At the PythonLabs meeting someone mentioned it would make Jim reallyGuido van Rossum2001-12-051-6/+1
| | | | | | | | | happy if one could delete the __dict__ attribute of an instance. I love to make Jim happy, so here goes... - New-style objects now support deleting their __dict__. This is for all intents and purposes equivalent to assigning a brand new empty dictionary, but saves space if the object is not used further.
* Fix SF bug #486144: Uninitialized __slot__ vrbl is None.Guido van Rossum2001-12-041-5/+7
| | | | | | | There's now a new structmember code, T_OBJECT_EX, which is used for all __slot__ variables (except __weakref__, which has special behavior anyway). This new code raises AttributeError when the variable is NULL rather than converting NULL to None.
* Fix of SF bug #475877 (Mutable subtype instances are hashable).Guido van Rossum2001-12-031-0/+24
| | | | | | | | | | | | | | | | | Rather than tweaking the inheritance of type object slots (which turns out to be too messy to try), this fix adds a __hash__ to the list and dict types (the only mutable types I'm aware of) that explicitly raises an error. This has the advantage that list.__hash__([]) also raises an error (previously, this would invoke object.__hash__([]), returning the argument's address); ditto for dict.__hash__. The disadvantage for this fix is that 3rd party mutable types aren't automatically fixed. This should be added to the rules for creating subclassable extension types: if you don't want your object to be hashable, add a tp_hash function that raises an exception. Also, it's possible that I've forgotten about other mutable types for which this should be done.
* Address SF patch #480716 as well as related issues.Guido van Rossum2001-12-031-1/+51
| | | | | | | | | | | | | | | | | | | SF patch #480716 by Greg Chapman fixes the problem that super's __get__ method always returns an instance of super, even when the instance whose __get__ method is called is an instance of a subclass of super. Other issues fixed: - super(C, C()).__class__ would return the __class__ attribute of C() rather than the __class__ attribute of the super object. This is confusing. To fix this, I decided to change the semantics of super so that it only applies to code attributes, not to data attributes. After all, overriding data attributes is not supported anyway. - While super(C, x) carefully checked that x is an instance of C, super(C).__get__(x) made no such check, allowing for a loophole. This is now fixed.
* - Change all remaining assertions into verify() and vereq() calls.Guido van Rossum2001-11-241-14/+42
| | | | | | - Add tests for the recent fixes to copy_reg.py: __getstate__/__setstate__ and mixed inheritance from new+classic classes.
* More simple test cases for mixed classic+new multiple inheritance.Tim Peters2001-11-141-0/+35
|
* Changing diapers reminded Guido that he wanted to allow for some measureTim Peters2001-11-141-8/+47
| | | | | | of multiple inheritance from a mix of new- and classic-style classes. This is his patch, plus a start at some test cases from me. Will check in more, plus a NEWS blurb, later tonight.
* Fix bad bug in structseq slicing (NULL pointers in result). Reported byTim Peters2001-10-301-5/+1
| | | | | | Jack Jansen on python-dev. Add simple test case. Move vereq() from test_descr to test_support (it's handy!).
* To cover a recent checkin, added a test to ensure dir(None) == dir(Ellipsis).Tim Peters2001-10-301-0/+4
|
* Just changed some continued-line indentation to read better, due toTim Peters2001-10-301-3/+3
| | | | the earlier s/dictionary/dict/ change.
* Minimal test for __del__ hook.Guido van Rossum2001-10-301-0/+12
|
* Rename "dictionary" (type and constructor) to "dict".Tim Peters2001-10-291-36/+36
|
* dictionary() constructor:Tim Peters2001-10-271-4/+4
| | | | | | + Change keyword arg name from "x" to "items". People passing a mapping object can stretch their imaginations <wink>. + Simplify the docstring text.
* dict_constructor(): The last test was passing for the wrong reason (itTim Peters2001-10-261-1/+1
| | | | | was intended to verify that sub-sequences of lengths 1 and 3 raise ValueError, but was actually testing string lengths).
* Generalize dictionary() to accept a sequence of 2-sequences. At theTim Peters2001-10-261-8/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | outer level, the iterator protocol is used for memory-efficiency (the outer sequence may be very large if fully materialized); at the inner level, PySequence_Fast() is used for time-efficiency (these should always be sequences of length 2). dictobject.c, new functions PyDict_{Merge,Update}FromSeq2. These are wholly analogous to PyDict_{Merge,Update}, but process a sequence-of-2- sequences argument instead of a mapping object. For now, I left these functions file static, so no corresponding doc changes. It's tempting to change dict.update() to allow a sequence-of-2-seqs argument too. Also changed the name of dictionary's keyword argument from "mapping" to "x". Got a better name? "mapping_or_sequence_of_pairs" isn't attractive, although more so than "mosop" <wink>. abstract.h, abstract.tex: Added new PySequence_Fast_GET_SIZE function, much faster than going thru the all-purpose PySequence_Size. libfuncs.tex: - Document dictionary(). - Fiddle tuple() and list() to admit that their argument is optional. - The long-winded repetitions of "a sequence, a container that supports iteration, or an iterator object" is getting to be a PITA. Many months ago I suggested factoring this out into "iterable object", where the definition of that could include being explicit about generators too (as is, I'm not sure a reader outside of PythonLabs could guess that "an iterator object" includes a generator call). - Please check my curly braces -- I'm going blind <0.9 wink>. abstract.c, PySequence_Tuple(): When PyObject_GetIter() fails, leave its error msg alone now (the msg it produces has improved since PySequence_Tuple was generalized to accept iterable objects, and PySequence_Tuple was also stomping on the msg in cases it shouldn't have even before PyObject_GetIter grew a better msg).
* Allow assignment to newinstance.__dict__.Guido van Rossum2001-10-261-0/+26
|
* Fixed denial-of-weak-ref-support test; Jeremy changed the error messageFred Drake2001-10-221-1/+1
| | | | | | used by the weakref code since he didn't like the word "referencable". Is it really necessary to be more specific than to test for TypeError here, though?
* Methods of built-in types now properly check for keyword argumentsGuido van Rossum2001-10-221-0/+9
| | | | | (formerly these were silently ignored). The only built-in methods that take keyword arguments are __call__, __init__ and __new__.
* Fix SF bug #472234: type(obj) calls type->tp_init (Roeland Rengelink)Guido van Rossum2001-10-181-0/+12
| | | | | The fix is a band-aid: type_call() now makes the same exception for a single-argument call to type() as type_new() was already making.
* SF bug [#468061] __str__ ignored in str subclass.Tim Peters2001-10-161-0/+31
| | | | | | | | | | | | | | | | | object.c, PyObject_Str: Don't try to optimize anything except exact string objects here; in particular, let str subclasses go thru tp_str, same as non-str objects. This allows overrides of tp_str to take effect. stringobject.c: + string_print (str's tp_print): If the argument isn't an exact string object, get one from PyObject_Str. + string_str (str's tp_str): Make a genuine-string copy of the object if it's of a proper str subclass type. str() applied to a str subclass that doesn't override __str__ ends up here. test_descr.py: New str_of_str_subclass() test.
* Completely get rid of __dynamic__ and the correspondingGuido van Rossum2001-10-151-53/+21
| | | | | Py_TPFLAGS_DYNAMICTYPE bit. There is no longer a performance benefit, and I don't really see the use case any more.
* SF bug [#470040] ParseTuple t# vs subclasses.Tim Peters2001-10-121-1/+32
| | | | | | | inherit_slots(): tp_as_buffer was getting inherited as if it were a method pointer, rather than a pointer to a vector of method pointers. As a result, inheriting from a type that implemented buffer methods was ineffective, leaving all the tp_as_buffer slots NULL in the subclass.
* Another step in the right direction: when a new class's attributeGuido van Rossum2001-10-111-16/+79
| | | | | | | | | corresponding to a dispatch slot (e.g. __getitem__ or __add__) is set, calculate the proper dispatch slot and propagate the change to all subclasses. Because of multiple inheritance, there's no easy way to avoid always recursing down the tree of subclasses. Who cares? (There's more to do, but this works. There's also a test for this now.)
* Add a bunch of tests for a list subclass that would have caught theGuido van Rossum2001-10-091-0/+22
| | | | previous embarrassment (typeobject.c checking crashing minidom).
* It turned out not so difficult to support old-style numbers (thoseGuido van Rossum2001-10-091-5/+6
| | | | | | | without the Py_TPFLAGS_CHECKTYPES flag) in the wrappers. This required a few changes in test_descr.py to cope with the fact that the complex type has __int__, __long__ and __float__ methods that always raise an exception.
* Change all occurrences of verify(x == y) into vereq(x, y), since whenGuido van Rossum2001-10-081-374/+376
| | | | | | | | this type of test fails, vereq() does a better job of reporting than verify(). Change vereq(x, y) to use "not x == y" rather than "x != y" -- it makes a difference is some overloading tests.
* class_docstrings(): The new-style class tests should use new-styleTim Peters2001-10-041-4/+4
| | | | classes (sheesh!).
* SF bug [#467331] ClassType.__doc__ always None.Tim Peters2001-10-041-1/+34
| | | | | | | | | For a dynamically constructed type object, fill in the tp_doc slot with a copy of the argument dict's "__doc__" value, provided the latter exists and is a string. NOTE: I don't know what to do if it's a Unicode string, so in that case tp_doc is left NULL (which shows up as Py_None if you do Class.__doc__). Note that tp_doc holds a char*, not a general PyObject*.
* dynamics(): add a dummy __getattr__ method to the C class so that theGuido van Rossum2001-10-031-0/+5
| | | | | | test for modifying __getattr__ works, now that slot_tp_getattr_hook zaps the slot if there's no hook. Added an XXX comment with a ref back to slot_tp_getattr_hook.
* pickles():Guido van Rossum2001-10-021-18/+22
| | | | | | | | - The test for deepcopy() in pickles() was indented wrongly, so it got run twice (one for binary pickle mode, one for text pickle mode; but the test doesn't depend on the pickle mode). - In verbose mode, show which subtest (pickle/cPickle/deepcopy, text/bin).