Tim Peters [Wed, 4 Aug 2004 20:04:32 +0000 (20:04 +0000)]
Example.__init__: this cannot use assert, because that fails to trigger
in a -O run, and so test_doctest was failing under -O. Simple cause,
simple cure.
Tim Peters [Wed, 4 Aug 2004 18:46:34 +0000 (18:46 +0000)]
Edward Loper's cool and massive refactoring of doctest.py, merged from
the tim-doctest-merge-24a2 tag on the the tim-doctest-branch branch.
We did development on the branch in case it wouldn't land in time for
2.4a2, but the branch looked good: Edward's tests passed there, ditto
Python's tests, and ditto the Zope3 tests. Together, those hit doctest
heavily.
Hye-Shik Chang [Wed, 4 Aug 2004 17:36:41 +0000 (17:36 +0000)]
SF #941229: Decode source code with sys.stdin.encoding in interactive
modes like non-interactive modes. This allows for non-latin-1 users
to write unicode strings directly and sets Japanese users free from
weird manual escaping <wink> in shift_jis environments.
(Reviewed by Martin v. Loewis)
To ever run this test "you must import TestSkipped" from the right
place! (can that please be it for silly mistakes in this file? :-) I
know I started it, but...).
Hye-Shik Chang [Wed, 4 Aug 2004 07:38:35 +0000 (07:38 +0000)]
SF #989185: Drop unicode.iswide() and unicode.width() and add
unicodedata.east_asian_width(). You can still implement your own
simple width() function using it like this:
def width(u):
w = 0
for c in unicodedata.normalize('NFC', u):
cwidth = unicodedata.east_asian_width(c)
if cwidth in ('W', 'F'): w += 2
else: w += 1
return w
Hye-Shik Chang [Wed, 4 Aug 2004 06:33:51 +0000 (06:33 +0000)]
Add a workaround for a problem that UTF-8 strings can be corrupted
or broken by basic ctype functions in 4.4BSD descendants. This
will be fixed in their future development branches but they'll keep
the POSIX-incompatibility for their backward-compatiblities in near
future.
Fred Drake [Tue, 3 Aug 2004 16:37:40 +0000 (16:37 +0000)]
This allows additional commands to be provided for existing setup.py
scripts without modifying either the distutils installation or the
setup.py scripts of packages with which the new commands will be used.
Specifically, an option is added to distutils that allows additional
packages to be searched for command implementations in addition to
distutils.command. The additional packages can be specified on the
command line or via the installation or personal configuration files
already loaded by distutils.
Fred Drake [Tue, 3 Aug 2004 14:47:25 +0000 (14:47 +0000)]
Be more careful about maintaining the invariants; it was actually
possible that the callback-less flavors of the ref or proxy could have
been added during GC, so we don't want to replace them.
Anthony Baxter [Tue, 3 Aug 2004 11:05:04 +0000 (11:05 +0000)]
Removed use of 'cgi.initlog()' - the first call to cgi.log is actually
an initlog() (and initlog()'s docstring says "don't use this"!) This
allows test_cgi to be run repeatedly in a single run of the interpreter.
Repair the same thinko in two places about handling of _Py_RefTotal in
the case of __del__ resurrecting an object.
This makes the apparent reference leaks in test_descr go away (which I
expected) and also kills off those in test_gc (which is more surprising
but less so once you actually think about it a bit).
Brett Cannon [Tue, 3 Aug 2004 04:53:29 +0000 (04:53 +0000)]
Tweak previous patch to silence a warning about the unused left value in the
comma expression in listpop() that was being returned. Still essentially
unused (as it is meant to be), but now the compiler thinks it is worth
*something* by having it incremented.
Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
have differing refcount semantics. If anyone sees a prettier way to
acheive the same ends, then please go for it.
I think this is the first time I've ever used Py_XINCREF.
Completed the patch for Bug #215126.
* Fixes an incorrect variable in a PyDict_CheckExact.
* Allow general mapping locals arguments for the execfile() function
and exec statement.
* Add tests.
Tim Peters [Mon, 2 Aug 2004 03:58:27 +0000 (03:58 +0000)]
New tests:
test_failing_import_sticks -- if an import raises an exception,
ensure that trying to import it again continues raising exceptions
test_failing_reload -- if a module loads OK, but a reload raises an
exception, ensure that the module is still in sys.modules, and
that its __dict__ reflects as much of the reload attempt as
succeeded. That doesn't seem like sane semantics, but it is
backward-compatible semantics <wink>.
Tim Peters [Mon, 2 Aug 2004 03:52:12 +0000 (03:52 +0000)]
PyImport_ExecCodeModuleEx(): remove module from sys.modules in error cases.
PyImport_ReloadModule(): restore the module to sys.modules in error cases.
load_package(): semantic-neutral refactoring from an earlier stab at
this patch; giving it a common error exit made the code
easier to follow, so retaining that part.
_RemoveModule(): new little utility to delete a key from sys.modules.
Tim Peters [Mon, 2 Aug 2004 03:46:45 +0000 (03:46 +0000)]
PyImport_ImportModule, PyImport_ImportModuleEx, PyImport_ExecCodeModule:
in failure cases, incompletely initalized module objects are no longer
left behind in sys.modules.
Tim Peters [Sat, 31 Jul 2004 21:53:19 +0000 (21:53 +0000)]
list_ass_slice(): Document the obscure new intent that deleting a slice
of no more than 8 elements cannot fail.
listpop(): Take advantage of that its calls to list_resize() and
list_ass_slice() can't fail. This is assert'ed in a debug build now, but
in an icky way. That is, you can't say:
assert(some_call() >= 0);
because then some_call() won't occur at all in a release build. So it
has to be a big pile of #ifdefs on Py_DEBUG (yuck), or the pleasant:
status = some_call();
assert(status >= 0);
But in that case, compilers may whine in a release build, because status
appears unused then. I'm not certain the ugly trick I used here will
convince all compilers to shut up about status (status is always "used" now,
as the first (ignored) clause in a comma expression).
Tim Peters [Sat, 31 Jul 2004 21:14:28 +0000 (21:14 +0000)]
Be more careful about reverting mutuations to system-wide (sys) variables.
This fixes 15 spurious test failures on Windows (probably all due to
the test leaving a wrong path in sys.argv[0], which then prevented
regrtest.py from finding the expected-output files for tests running
after test_optparse).
Upgrade optparse module and tests to Optik 1.5a1:
* add expansion of default values in help text: the string
"%default" in an option's help string is expanded to str() of
that option's default value, or "none" if no default value.
* bug #955889: option default values that happen to be strings are
now processed in the same way as values from the command line; this
allows generation of nicer help when using custom types. Can
be disabled with parser.set_process_default_values(False).
* bug #960515: don't crash when generating help for callback
options that specify 'type', but not 'dest' or 'metavar'.
* feature #815264: change the default help format for short options
that take an argument from e.g. "-oARG" to "-o ARG"; add
set_short_opt_delimiter() and set_long_opt_delimiter() methods to
HelpFormatter to allow (slight) customization of the formatting.
* patch #736940: internationalize Optik: all built-in user-
targeted literal strings are passed through gettext.gettext(). (If
you want translations (.po files), they're not included with Python
-- you'll find them in the Optik source distribution from
http://optik.sourceforge.net/ .)
* bug #878453: respect $COLUMNS environment variable for
wrapping help output.
* feature #988122: expand "%prog" in the 'description' passed
to OptionParser, just like in the 'usage' and 'version' strings.
(This is *not* done in the 'description' passed to OptionGroup.)
Tim Peters [Sat, 31 Jul 2004 02:54:42 +0000 (02:54 +0000)]
list_ass_slice(): The difference between "recycle" and "recycled" was
impossible to remember, so renamed one to something obvious. Headed
off potential signed-vs-unsigned compiler complaints I introduced by
changing the type of a vrbl to unsigned. Removed the need for the
tedious explanation about "backward pointer loops" by looping on an
int instead.
Tim Peters [Sat, 31 Jul 2004 02:24:20 +0000 (02:24 +0000)]
Armin asked for a list_ass_slice review in his checkin, so here's the
result.
list_resize(): Document the intent. Code is increasingly relying on
subtle aspects of its behavior, and they deserve to be spelled out.
list_ass_slice(): A bit more simplification, by giving it a common
error exit and initializing more values.
Be clearer in comments about what "size" means (# of elements? # of
bytes?).
While the number of elements in a list slice must fit in an int, there's
no guarantee that the number of bytes occupied by the slice will. That
malloc() and memmove() take size_t arguments is a hint about that <wink>.
So changed to use size_t where appropriate.
ihigh - ilow should always be >= 0, but we never asserted that. We do
now.
The loop decref'ing the recycled slice had a subtle insecurity: C doesn't
guarantee that a pointer one slot *before* an array will compare "less
than" to a pointer within the array (it does guarantee that a pointer
one beyond the end of the array compares as expected). This was actually
an issue in KSR's C implementation, so isn't purely theoretical. Python
probably has other "go backwards" loops with a similar glitch.
list_clear() is OK (it marches an integer backwards, not a pointer).