Commit Graph

343 Commits

Author SHA1 Message Date
Neal Norwitz 92e212f7d9 Accept keyword arguments for __import__ and doc the addition of the level param from PEP 328. 2006-04-03 04:48:37 +00:00
Georg Brandl ccadf84a1b Patch #1460496: round() now accepts keyword arguments. 2006-03-31 18:54:53 +00:00
Martin v. Löwis 725507b52e Change int to Py_ssize_t in several places.
Add (int) casts to silence compiler warnings.
Raise Python exceptions for overflows.
2006-03-07 12:08:51 +00:00
Thomas Wouters f7f438ba3b SF patch #1438387, PEP 328: relative and absolute imports.
- IMPORT_NAME takes an extra argument from the stack: the relativeness of
   the import. Only passed to __import__ when it's not -1.

 - __import__() takes an optional 5th argument for the same thing; it
   __defaults to -1 (old semantics: try relative, then absolute)

 - 'from . import name' imports name (be it module or regular attribute)
   from the current module's *package*. Likewise, 'from .module import name'
   will import name from a sibling to the current module.

 - Importing from outside a package is not allowed; 'from . import sys' in a
   toplevel module will not work, nor will 'from .. import sys' in a
   (single-level) package.

 - 'from __future__ import absolute_import' will turn on the new semantics
   for import and from-import: imports will be absolute, except for
   from-import with dots.

Includes tests for regular imports and importhooks, parser changes and a
NEWS item, but no compiler-package changes or documentation changes.
2006-02-28 16:09:29 +00:00
Martin v. Löwis 15e62742fa Revert backwards-incompatible const changes. 2006-02-27 16:46:16 +00:00
Martin v. Löwis bd260da900 Generate code to recursively copy an AST into
a tree of Python objects. Expose this through compile().
2006-02-26 19:42:26 +00:00
Neal Norwitz a361bd8dce Fix compiler warning (int vs Py_ssize_t mismatch 2006-02-19 19:31:50 +00:00
Martin v. Löwis d96ee90993 Use Py_ssize_t to count the 2006-02-16 14:37:16 +00:00
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Armin Rigo f5b3e36493 Renamed _length_cue() to __length_hint__(). See:
http://mail.python.org/pipermail/python-dev/2006-February/060524.html
2006-02-11 21:32:43 +00:00
Neal Norwitz 6f0d479c78 Fix an int/long mismatch identified here:
http://www.tortall.net/mu/blog/2005/12/01

Pointed out from SF #1365916.

Backport candidate.
2005-12-15 06:40:36 +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
Neal Norwitz 3a9a3e7864 Fix memory leaks 2005-11-27 20:38:31 +00:00
Jeremy Hylton ec97a28b60 Fix a bunch of imports to use code.h instead of compile.h.
Remove duplicate declarations from compile.h
2005-10-21 14:58:06 +00:00
Jeremy Hylton 3e0055f8c6 Merge ast-branch to head
This change implements a new bytecode compiler, based on a
transformation of the parse tree to an abstract syntax defined in
Parser/Python.asdl.

The compiler implementation is not complete, but it is in stable
enough shape to run the entire test suite excepting two disabled
tests.
2005-10-20 19:59:25 +00:00
Raymond Hettinger 6b27cda643 Convert iterator __len__() methods to a private API. 2005-09-24 21:23:05 +00:00
Armin Rigo 71d7e704b8 Removed a check "if (args != NULL)" which is always True and makes no sense. 2005-09-20 18:13:03 +00:00
Georg Brandl 77c85e63b4 bug [ 868706 ] Calling builtin function 'eval' from C causes seg fault. 2005-09-15 10:46:13 +00:00
Georg Brandl 99d7e4e8eb Whitespace normalization. 2005-08-31 22:21:15 +00:00
Raymond Hettinger a710b331da SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Fix over-aggressive PyErr_Clear().  The same code fragment appears in
various guises in list.extend(), map(), filter(), zip(), and internally
in PySequence_Tuple().
2005-08-21 11:03:59 +00:00
Georg Brandl e35b657efd Fix cleanup DECREF logic in builtin_filter function. 2005-07-19 22:20:20 +00:00
Raymond Hettinger 96229b1918 Add two new functions, any() and all(). 2005-03-11 06:49:40 +00:00
Brett Cannon 9e635cf3ae Put parentheses around the assignment in the 'while' loop conditional
expression in min_max() to shut gcc up.
2004-12-07 00:25:35 +00:00
Raymond Hettinger 3b0c7c20a1 SF patch #1077353: add key= argument to min and max
(First draft of patch contributed by Steven Bethard.)
2004-12-03 08:30:39 +00:00
Martin v. Löwis 8d494f3241 Patch #1015021: Stop claiming that coerce can return None.
Will backport to 2.3.
2004-08-25 10:42:41 +00:00
Martin v. Löwis fd39ad4937 Patch #1005468: Disambiguate "min() or max()" exception string. 2004-08-12 14:42:37 +00:00
Jeremy Hylton 4c989ddc9c Subclasses of string can no longer be interned. The semantics of
interning were not clear here -- a subclass could be mutable, for
example -- and had bugs.  Explicitly interning a subclass of string
via intern() will raise a TypeError.  Internal operations that attempt
to intern a string subclass will have no effect.

Added a few tests to test_builtin that includes the old buggy code and
verifies that calls like PyObject_SetAttr() don't fail.  Perhaps these
tests should have gone in test_string.
2004-08-07 19:20:05 +00:00
Michael W. Hudson 52db519faa for some reason, the lack of adherence to Python's C whitespace rules
must have annoyed me at some point.
2004-08-02 13:21:09 +00:00
Raymond Hettinger 66bd233225 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.
2004-08-02 08:30:07 +00:00
Neil Schemenauer 3a313e3655 Check the type of values returned by __int__, __float__, __long__,
__oct__, and __hex__.  Raise TypeError if an invalid type is
returned.  Note that PyNumber_Int and PyNumber_Long can still
return ints or longs.  Fixes SF bug #966618.
2004-07-19 16:29:17 +00:00
Michael W. Hudson 30ea2f223f This closes patch:
[ 960406 ] unblock signals in threads

although the changes do not correspond exactly to any patch attached to
that report.

Non-main threads no longer have all signals masked.

A different interface to readline is used.

The handling of signals inside calls to PyOS_Readline is now rather
different.

These changes are all a bit scary!  Review and cross-platform testing
much appreciated.
2004-07-07 17:44:12 +00:00
Raymond Hettinger 513ffe8112 * Fix missing return after error message is set.
* Add a test case that would have caught it.
2004-07-06 13:44:41 +00:00
Raymond Hettinger 214b1c3aae SF Bug #215126: Over restricted type checking on eval() function
The builtin eval() function now accepts any mapping for the locals argument.
Time sensitive steps guarded by PyDict_CheckExact() to keep from slowing
down the normal case.  My timings so no measurable impact.
2004-07-02 06:41:07 +00:00
Andrew MacIntyre da4d6cb573 OS/2 VACPP build updates/fixes 2004-03-29 11:53:38 +00:00
Hye-Shik Chang ff83c2bacc Fix input() builtin function to respect compiler flags.
(SF patch 876178, patch by mwh, unittest by perky)
2004-02-02 13:39:01 +00:00
Raymond Hettinger b86269db45 Apply pre-sizing optimization to a broader class of objects.
Formerly, the length was only fetched from sequence objects.
Now, any object that reports its length can benefit from pre-sizing.
2004-01-04 11:00:08 +00:00
Raymond Hettinger 77f3c87113 Apply map/zip pre-sizing optimization to a broader class of objects.
Formerly, the length was only fetched from sequence objects.
Now, any object that reports its length can benefit from pre-sizing.
2004-01-04 08:54:44 +00:00
Raymond Hettinger 64958a15d7 Guido grants a Christmas wish:
sorted() becomes a regular function instead of a classmethod.
2003-12-17 20:43:33 +00:00
Fred Drake d75ede3238 Remove the PendingDeprecationWarning from apply(). apply() will
remain deprecated in the documentation.
2003-12-05 17:34:27 +00:00
Raymond Hettinger a690a9967e * Migrate set() and frozenset() from the sandbox.
* Install the unittests, docs, newsitem, include file, and makefile update.
* Exercise the new functions whereever sets.py was being used.

Includes the docs for libfuncs.tex.  Separate docs for the types are
forthcoming.
2003-11-16 16:17:49 +00:00
Raymond Hettinger 85c20a41df Implement and apply PEP 322, reverse iteration 2003-11-06 14:06:48 +00:00
Alex Martelli a253e183b8 regressing the performance bugfix -- Guido wants the performance bug left
alone, because there can be no guarantee re the semantics of += vs + .
2003-10-25 23:24:14 +00:00
Alex Martelli a2777d3a55 Changed builtin_sum to use PyNumber_InPlaceAdd (same semantics, but fixes
a performance bug in sum(manylists)), same as in 2.3 maintenance branch.
2003-10-25 12:49:56 +00:00
Raymond Hettinger 5cf6394b12 Use PyArg_UnpackTuple() where possible. 2003-10-25 06:41:37 +00:00
Raymond Hettinger 8ae4689657 Simplify and speedup uses of Py_BuildValue():
* Py_BuildValue("(OOO)",a,b,c)  -->  PyTuple_Pack(3,a,b,c)
* Py_BuildValue("()",a)         -->  PyTuple_New(0)
* Py_BuildValue("O", a)         -->  Py_INCREF(a)
2003-10-12 19:09:37 +00:00
Jeremy Hylton 364f6becad Correct check of PyUnicode_Resize() return value. 2003-09-16 03:17:16 +00:00
Jeremy Hylton 1aad9c7dad Reflow long lines and reformat. 2003-09-16 03:10:59 +00:00
Walter Dörwald c58a3a10a9 Fix a crash: when sq_item failed the code continued blindly and used the
NULL pointer. (Detected by Michael Hudson, patch provided by Neal Norwitz).

Fix refcounting leak in filtertuple().
2003-08-18 18:28:45 +00:00
Neil Schemenauer 689735562d Make filter(bool, ...) as fast as filter(None, ...). 2003-08-14 20:37:34 +00:00
Raymond Hettinger eaef615116 As discussed on python-dev, changed builtin.zip() to handle zero arguments
by returning an empty list instead of raising a TypeError.
2003-08-02 07:42:57 +00:00