Commit Graph

252 Commits

Author SHA1 Message Date
Jack Jansen 7b8c7546eb Mass checkin of universal newline support.
Highlights: import and friends will understand any of \r, \n and \r\n
as end of line. Python file input will do the same if you use mode 'U'.
Everything can be disabled by configuring with --without-universal-newlines.

See PEP278 for details.
2002-04-14 20:12:41 +00:00
Guido van Rossum 77f6a65eb0 Add the 'bool' type and its values 'False' and 'True', as described in
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.
2002-04-03 22:41:51 +00:00
Martin v. Löwis 3484a18af1 Patch #494045: patches errno and stat to cope on plan9. 2002-03-09 12:07:51 +00:00
Tim Peters d50e544b9f Docstring for filter(): Someone on the Tutor list reasonably complained
that it didn't tell enough of the truth.
Bugfix candidate (I guess -- it helps and it's harmless).
2002-03-09 00:06:26 +00:00
Martin v. Löwis cdc4451222 Include <unistd.h> in Python.h. Fixes #500924. 2002-01-12 11:05:12 +00:00
Jeremy Hylton 733c8935f9 Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Based on the patch from Danny Yoo.  The fix is in exec_statement() in
ceval.c.

There are also changes to introduce use of PyCode_GetNumFree() in
several places.
2001-12-13 19:51:56 +00:00
Jeremy Hylton 518ab1c02a Use PyOS_snprintf instead of sprintf. 2001-11-28 20:42:20 +00:00
Tim Peters 603c6831d0 SF patch 473749 compile under OS/2 VA C++, from Michael Muller.
Changes enabling Python to compile under OS/2 Visual Age C++.
2001-11-05 02:45:59 +00:00
Tim Peters a427a2b8d0 Rename "dictionary" (type and constructor) to "dict". 2001-10-29 22:25:45 +00:00
Guido van Rossum e2ae77b8b8 SF patch #474590 -- RISC OS support 2001-10-24 20:42:55 +00:00
Guido van Rossum d892357bf7 SF patch #471852 (anonymous) notes that getattr(obj, name, default)
masks any exception, not just AttributeError.  Fix this.
2001-10-16 21:31:32 +00:00
Guido van Rossum 03290ecbf1 Implement isinstance(x, (A, B, ...)). Note that we only allow tuples,
not other sequences (then we'd have to except strings, and we'd still
be susceptible to recursive attacks).
2001-10-07 20:54:12 +00:00
Tim Peters 742dfd6f17 Get rid of builtin_open() entirely (the C code and docstring, not the
builtin function); Guido pointed out that it could be just another
name in the __builtin__ dict for the file constructor now.
2001-09-13 21:49:44 +00:00
Tim Peters 4b7625ee83 _PyBuiltin_Init(): For clarity, macroize this purely repetitive code. 2001-09-13 21:37:17 +00:00
Tim Peters 59c9a645e2 SF bug [#460467] file objects should be subclassable.
Preliminary support.  What's here works, but needs fine-tuning.
2001-09-13 05:38:56 +00:00
Guido van Rossum 8bce4acb17 Rename 'getset' to 'property'. 2001-09-06 21:56:42 +00:00
Guido van Rossum b3a639ed7d builtin_execfile(): initialize another local that the GCC on leroy
found it necessary to warn about.
2001-09-05 13:37:47 +00:00
Tim Peters 7eea37e831 At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
__builtin__.dir().  Moved the guts from bltinmodule.c to object.c.
2001-09-04 22:08:56 +00:00
Tim Peters 37a309db70 builtin_dir(): Treat classic classes like types. Use PyDict_Keys instead
of PyMapping_Keys because we know we have a real dict.  Tolerate that
objects may have an attr named "__dict__" that's not a dict (Py_None
popped up during testing).

test_descr.py, test_dir():  Test the new classic-class behavior; beef up
the new-style class test similarly.

test_pyclbr.py, checkModule():  dir(C) is no longer a synonym for
C.__dict__.keys() when C is a classic class (looks like the same thing
that burned distutils! -- should it be *made* a synoym again?  Then it
would be inconsistent with new-style class behavior.).
2001-09-04 01:20:04 +00:00
Tim Peters 5d2b77cf31 Make dir() wordier (see the new docstring). The new behavior is a mixed
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.
2001-09-03 05:47:38 +00:00
Guido van Rossum f5cb357468 Add 'super' builtin type. 2001-08-24 16:52:18 +00:00
Guido van Rossum 29a62dd6eb Add new built-in type 'getset' (PyGetSet_Type).
This implements the 'getset' class from test_binop.py.
2001-08-23 21:40:38 +00:00
Tim Peters 9fa96bed6f Fix for bug [#452230] future division isn't propagated.
builtin_eval wasn't merging in the compiler flags from the current frame;
I suppose we never noticed this before because future division is the
first future-feature that can affect expressions (nested_scopes and
generators had only statement-level effects).
2001-08-17 23:04:59 +00:00
Tim Peters 6cd6a82db9 A fiddled version of the rest of Michael Hudson's SF patch
#449043 supporting __future__ in simulated shells
which implements PEP 264.
2001-08-17 22:11:27 +00:00
Martin v. Löwis 339d0f720e Patch #445762: Support --disable-unicode
- 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.
2001-08-17 18:39:25 +00:00
Martin v. Löwis e3eb1f2b23 Patch #427190: Implement and use METH_NOARGS and METH_O. 2001-08-16 13:15:00 +00:00
Martin v. Löwis f9836ba4fe Put conditional S_ISDIR definition(s) into pyport.h. 2001-08-08 10:28:06 +00:00
Tim Peters 257b3bfa76 Repair the Windows build (S_ISDIR() macro doesn't exist).
Somebody else should feel free to repair this a different way; see Python-
Dev for discussion.
2001-08-08 06:24:48 +00:00
Martin v. Löwis 6b3a2c4a48 Patch #448227: Raise an exception when a directory is passed to execfile. 2001-08-08 05:30:36 +00:00
Tim Peters 6d6c1a35e0 Merge of descr-branch back into trunk. 2001-08-02 04:15:00 +00:00
Jeremy Hylton 302b54acd9 Do for hasattr() what was done for getattr()
Namely, an exception is raised if the second arg to hasattr() is not a
string or Unicode.
2001-07-30 22:45:19 +00:00
Jeremy Hylton 0eb1115f44 Fix for SF byg [ #420304 ] getattr function w/ default
Fix suggested by Michael Hudson: Raise TypeError if attribute name
passed to getattr() is not a string or Unicode.  There is some
unfortunate duplication of code between builtin_getattr() and
PyObject_GetAttr(), but it appears to be unavoidable.
2001-07-30 22:39:31 +00:00
Jeremy Hylton 15c1c4f6d2 Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
If the code object has free variables, raise TypeError.
2001-07-30 21:50:55 +00:00
Marc-André Lemburg ae21df59c3 Undoing the UCS-4 patch addition which caused unichr() to return
surrogates for Unicode code points outside range(0x10000) on narrow
Python builds.
2001-07-26 16:29:25 +00:00
Tim Peters 5ba5866281 Part way to allowing "from __future__ import generators" to communicate
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.
2001-07-16 02:29:45 +00:00
Thomas Wouters efafcea280 Re-add 'advanced' xrange features, adding DeprecationWarnings as discussed
on python-dev. The features will still vanish, however, just one release
later.
2001-07-09 12:30:54 +00:00
Guido van Rossum cfd829eefc Complete the xrange-simplification checkins: call PyRange_New() with
fewer arguments.
2001-07-05 14:44:41 +00:00
Fredrik Lundh 8f4558583f use Py_UNICODE_WIDE instead of USE_UCS4_STORAGE and Py_UNICODE_SIZE
tests.
2001-06-27 18:59:43 +00:00
Guido van Rossum 236d8b7974 Cosmetic changes to MvL's change to unichr():
- the correct range for the error message is range(0x110000);

- put the 4-byte Unicode-size code inside the same else branch as the
  2-byte code, rather generating unreachable code in the 2-byte case.

- Don't hide the 'else' behine the '}'.

(I would prefer that in 4-byte mode, any value should be accepted, but
reasonable people can argue about that, so I'll put that off.)
2001-06-26 23:12:25 +00:00
Martin v. Löwis 0ba70cc3c8 Support using UCS-4 as the Py_UNICODE type:
Add configure option --enable-unicode.
Add config.h macros Py_USING_UNICODE, PY_UNICODE_TYPE, Py_UNICODE_SIZE,
                    SIZEOF_WCHAR_T.
Define Py_UCS2.
Encode and decode large UTF-8 characters into single Py_UNICODE values
for wide Unicode types; likewise for UTF-16.
Remove test whether sizeof Py_UNICODE is two.
2001-06-26 22:22:37 +00:00
Fredrik Lundh 0dcf67e56d more unicode tweaks: make unichr(0xdddddddd) behave like u"\Udddddddd"
wrt surrogates.  (this extends the valid range from 65535 to 1114111)
2001-06-26 20:01:56 +00:00
Fredrik Lundh 5b97935604 experimental UCS-4 support: don't assume that MS_WIN32 implies
HAVE_USABLE_WCHAR_T
2001-06-26 17:46:10 +00:00
Tim Peters 4324aa3572 Cruft cleanup: Removed the unused last_is_sticky argument from the internal
_PyTuple_Resize().
2001-05-28 22:30:08 +00:00
Tim Peters 3c6b148a67 SF bug #425836: Reference leak in filter().
Mark Hammond claimed that the iterized filter() forgot to decref the
iterator upon return.  He was right!
2001-05-21 08:07:05 +00:00
Mark Hammond 26cffde4c2 Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule. 2001-05-14 12:17:34 +00:00
Mark Hammond ef8b654bbe Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465. 2001-05-13 08:04:26 +00:00
Tim Peters 8572b4fedf Generalize zip() to work with iterators.
NEEDS DOC CHANGES.
More AttributeErrors transmuted into TypeErrors, in test_b2.py, and,
again, this strikes me as a good thing.
This checkin completes the iterator generalization work that obviously
needed to be done.  Can anyone think of others that should be changed?
2001-05-06 01:05:02 +00:00
Tim Peters f4848dac41 Make PyIter_Next() a little smarter (wrt its knowledge of iterator
internals) so clients can be a lot dumber (wrt their knowledge).
2001-05-05 00:14:56 +00:00
Tim Peters 15d81efb8a Generalize reduce() to work with iterators.
NEEDS DOC CHANGES.
2001-05-04 04:39:21 +00:00
Tim Peters 4e9afdca39 Generalize map() to work with iterators.
NEEDS DOC CHANGES.
Possibly contentious:  The first time s.next() yields StopIteration (for
a given map argument s) is the last time map() *tries* s.next().  That
is, if other sequence args are longer, s will never again contribute
anything but None values to the result, even if trying s.next() again
could yield another result.  This is the same behavior map() used to have
wrt IndexError, so it's the only way to be wholly backward-compatible.
I'm not a fan of letting StopIteration mean "try again later" anyway.
2001-05-03 23:54:49 +00:00