summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_generators.py
Commit message (Collapse)AuthorAgeFilesLines
* SF bug #488514: -Qnew needs workTim Peters2001-12-061-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>.
* Teach regrtest how to pass on doctest failure msgs. This is done via aTim Peters2001-09-091-5/+5
| | | | | | | | | | | horridly inefficient hack in regrtest's Compare class, but it's about as clean as can be: regrtest has to set up the Compare instance before importing a test module, and by the time the module *is* imported it's too late to change that decision. The good news is that the more tests we convert to unittest and doctest, the less the inefficiency here matters. Even now there are few tests with large expected-output files (the new cost here is a Python-level call per .write() when there's an expected- output file).
* Make dir() wordier (see the new docstring). The new behavior is a mixedTim Peters2001-09-031-7/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | bag. It's clearly wrong for classic classes, at heart because a classic class doesn't have a __class__ attribute, and I'm unclear on whether that's feature or bug. I'll repair this once I find out (in the meantime, dir() applied to classic classes won't find the base classes, while dir() applied to a classic-class instance *will* find the base classes but not *their* base classes). Please give the new dir() a try and see whether you love it or hate it. The new dir([]) behavior is something I could come to love. Here's something to hate: >>> class C: ... pass ... >>> c = C() >>> dir(c) ['__doc__', '__module__'] >>> The idea that an instance has a __doc__ attribute is jarring (of course it's really c.__class__.__doc__ == C.__doc__; likewise for __module__). OTOH, the code already has too many special cases, and dir(x) doesn't have a compelling or clear purpose when x isn't a module.
* The change of type(None).__name__ from 'None' to 'NoneType' broke thisGuido van Rossum2001-08-161-2/+2
| | | | test in a trivial way. Fixed.
* Move one of the tests into the "PEP 255" section, to reflect a change inTim Peters2001-08-151-12/+15
| | | | the PEP.
* The message accompanying the TypeError exception on a readonlyGuido van Rossum2001-08-101-1/+1
| | | | attribute changed again.
* Merge of descr-branch back into trunk.Tim Peters2001-08-021-2/+8
|
* Part way to allowing "from __future__ import generators" to communicateTim Peters2001-07-161-0/+2
| | | | | | | | | | that info to code dynamically compiled *by* code compiled with generators enabled. Doesn't yet work because there's still no way to tell the parser that "yield" is OK (unlike nested_scopes, the parser has its fingers in this too). Replaced PyEval_GetNestedScopes by a more-general PyEval_MergeCompilerFlags. Perhaps I should not have? I doubted it was *intended* to be part of the public API, so just did.
* Having fun on my own time: quicker flat_conjoin; Knights Tour solverTim Peters2001-07-131-113/+123
| | | | simplified and generalized to rectangular boards.
* Remove the last remnants of the hacks to worm around leaks.Tim Peters2001-07-121-12/+3
|
* Repair flawed example.Tim Peters2001-07-121-1/+1
|
* Remove now-unnecessary "from __future__ import nested_scopes" stmts.Tim Peters2001-07-121-2/+0
|
* Remove reference cycle breaking code. The GC now takes care of it.Neil Schemenauer2001-07-121-7/+1
|
* Added a non-recursive implementation of conjoin(), and a Knight's Tourunknown2001-07-041-2/+291
| | | | | | | | | | | | solver. In conjunction, they easily found a tour of a 200x200 board: that's 200**2 == 40,000 levels of backtracking. Explicitly resumable generators allow that to be coded as easily as a recursive solver (easier, actually, because different levels can use level-customized algorithms without pain), but without blowing the stack. Indeed, I've never written an exhaustive Tour solver in any language before that can handle boards so large ("exhaustive" == guaranteed to find a solution if one exists, as opposed to probabilistic heuristic approaches; of course, the age of the universe may be a blip in the time needed!).
* A clever union-find implementation from c.l.py, due to David Eppstein.Tim Peters2001-07-021-0/+77
| | | | | This is another one that leaks memory without an explict clear! Time to bite this bullet.
* Derive an industrial-strength conjoin() via cross-recursion loop unrolling,Tim Peters2001-06-301-9/+83
| | | | and fiddle the conjoin tests to exercise all the new possible paths.
* Added a simple but general backtracking generator (conjoin), and a coupleTim Peters2001-06-291-1/+162
| | | | | | | | | examples of use. These poke stuff not specifically targeted before, incl. recursive local generators relying on nested scopes, ditto but also inside class methods and rebinding instance vars, and anonymous partially-evaluated generators (the N-Queens solver creates a different column-generator for each row -- AFAIK this is my invention, and it's really pretty <wink>). No problems, not even a new leak.
* Another "if 0:" hack, this time to complain about otherwise invisibleTim Peters2001-06-281-0/+33
| | | | | | "return expr" instances in generators (which latter may be generators due to otherwise invisible "yield" stmts hiding in "if 0" blocks). This was fun the first time, but this has gotten truly ugly now.
* This no longer leaks memory when run in an infinite loop. However,Tim Peters2001-06-271-81/+58
| | | | | | | | | | | | | | | | | | | | | that required explicitly calling LazyList.clear() in the two tests that use LazyList (I added a LazyList Fibonacci generator too). A real bitch: the extremely inefficient first version of the 2-3-5 test *looked* like a slow leak on Win98SE, but it wasn't "really": it generated so many results that the heap grew over 4Mb (tons of frames! the number of frames grows exponentially in that test). Then Win98SE malloc() starts fragmenting address space allocating more and more heaps, and the visible memory use grew very slowly while the disk was thrashing like mad. Printing fewer results (i.e., keeping the heap burden under 4Mb) made that illusion vanish. Looks like there's no hope for plugging the LazyList leaks automatically short of adding frameobjects and genobjects to gc. OTOH, they're very easy to break by hand, and they're the only *kind* of plausibly realistic leaks I've been able to provoke. Dilemma.
* gen_getattr: make the gi_running and gi_frame members discoverable (butTim Peters2001-06-261-2/+22
| | | | not writable -- too dangerous!) from Python code.
* SF bug #436207: "if 0: yield x" is ignored.Tim Peters2001-06-261-7/+128
| | | | Not anymore <wink>. Pure hack. Doesn't fix any other "if 0:" glitches.
* Teach the types module about generators. Thanks to James Althoff on theTim Peters2001-06-251-0/+20
| | | | Iterators list for bringing it up!
* Repair indentation in comment.Tim Peters2001-06-251-2/+9
| | | | Add a temporary driver to help track down remaining leak(s).
* Added a "generate k-combinations of a list" example posted to c.l.py.Tim Peters2001-06-241-1/+49
|
* New tests to provoke SyntaxErrors unique to generators. Minor fiddlingTim Peters2001-06-241-6/+85
| | | | of other tests.
* Another variant of the 2-3-5 test, mixing generators with a LazyList class.Tim Peters2001-06-241-0/+37
| | | | | | | Good news: Some of this stuff is pretty sophisticated (read nuts), and I haven't bumped into a bug yet. Bad news: If I run the doctest in an infinite loop, memory is clearly leaking.
* More tests.Tim Peters2001-06-241-1/+68
|
* Add a recursive Sieve of Eratosthenes prime generator. Not practical,Tim Peters2001-06-231-1/+39
| | | | but it's a heck of a good generator exerciser (think about it <wink>).
* Add all the examples from PEP 255, and a few email examples.Tim Peters2001-06-231-2/+183
|
* New std test for generators, initially populated with doctests NeilS putTim Peters2001-06-231-0/+139
together.