summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* Marc-Andre Lemburg: added new builtin functions unicode() andGuido van Rossum2000-03-101-5/+78
| | | | | unichr(); changed ord() to support Unicode strings; added new exception UnicodeError; fixed a typo in doc string for buffer().
* Massive patch by Skip Montanaro to add ":name" to as manyGuido van Rossum2000-02-291-5/+5
| | | | PyArg_ParseTuple() format string arguments as possible.
* Changes by Mark Hammond related to the new WindowsError exception.Guido van Rossum2000-02-171-0/+6
|
* Adjusted apply() docstring based on comments from Gerrit HollFred Drake1999-12-231-3/+4
| | | | <gerrit.holl@pobox.com>.
* Mainlining the string_methods branch. See branch revision logBarry Warsaw1999-10-121-42/+67
| | | | messages for specific changes.
* Fixed order of parameters in slice() docstring. The Library ReferenceFred Drake1999-07-191-1/+1
| | | | had it right! Reported by Tim Hochberg <tim.hochberg@ieee.org>.
* Patch by Tim Peters:Guido van Rossum1999-06-221-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce a new builtin exception, UnboundLocalError, raised when ceval.c tries to retrieve or delete a local name that isn't bound to a value. Currently raises NameError, which makes this behavior a FAQ since the same error is raised for "missing" global names too: when the user has a global of the same name as the unbound local, NameError makes no sense to them. Even in the absence of shadowing, knowing whether a bogus name is local or global is a real aid to quick understanding. Example: D:\src\PCbuild>type local.py x = 42 def f(): print x x = 13 return x f() D:\src\PCbuild>python local.py Traceback (innermost last): File "local.py", line 8, in ? f() File "local.py", line 4, in f print x UnboundLocalError: x D:\src\PCbuild> Note that UnboundLocalError is a subclass of NameError, for compatibility with existing class-exception code that may be trying to catch this as a NameError. Unfortunately, I see no way to make this wholly compatible with -X (see comments in bltinmodule.c): under -X, [UnboundLocalError is an alias for NameError --GvR]. [The ceval.c patch differs slightly from the second version that Tim submitted; I decided not to raise UnboundLocalError for DELETE_NAME, only for DELETE_LOCAL. DELETE_NAME is only generated at the module level, and since at that level a NameError is raised for referencing an undefined name, it should also be raised for deleting one.]
* # Darn! Local variable l declared but not used in abstract_issubclass().Guido van Rossum1999-06-171-1/+1
|
* Patch by Jim Fulton (code style tweaked a bit) to supportGuido van Rossum1999-06-161-17/+94
| | | | | | | | | | | | | | | | ExtensionClasses in isinstance() and issubclass(). - abstract instance and class protocols are used *only* in those cases that would generate errors before the patch. That is, there's no penalty for the normal case. - instance protocol: an object smells like an instance if it has a __class__ attribute that smells like a class. - class protocol: an object smells like a class if it has a __bases__ attribute that is a tuple with elements that smell like classes (although not all elements may actually get sniffed ;).
* Remove unused variable from complex_from_string() code.Guido van Rossum1999-04-071-1/+1
|
* Patch by Nick and Stephanie Lockwood to implement complex() with a stringGuido van Rossum1999-03-251-4/+133
| | | | argument. This closes TODO item 2.19.
* New builtin buffer() creates a derived read-only buffer from anyGuido van Rossum1999-03-191-0/+24
| | | | object that supports the buffer interface (e.g. strings, arrays).
* (initerrors): Make sure that the exception tuples ("base-classes" whenBarry Warsaw1999-02-241-8/+18
| | | | | string-based exceptions are used) reflect the real class hierarchy, i.e. that SystemExit derives from Exception not StandardError.
* Patch by Tim Peters to improve the range checks for range() andGuido van Rossum1999-02-231-30/+48
| | | | | | | xrange(), especially for platforms where int and long are different sizes (so sys.maxint isn't actually the theoretical limit for the length of a list, but the largest C int is -- sys.maxint is the largest Python int, which is actually a C long).
* bltin_exc[]: EnvironmentError is not a "leaf exception", so set it'sBarry Warsaw1999-01-291-1/+1
| | | | leaf_exc flag to zero otherwise the name leaks memory.
* builtin_map(): A better fix for the previous leak plug (rememberBarry Warsaw1999-01-281-3/+6
| | | | | | PyList_Append steals a reference even if it fails). builtin_filter(): Had the same leak problem as builtin_map().
* builtin_map(): Nailed memory leak. PyList_Append() borrows aBarry Warsaw1999-01-281-0/+1
| | | | | reference, so you have to DECREF the appended value. This was a fun one!
* builtin_complex(): Nailed memory leak. This one's in the instanceBarry Warsaw1999-01-271-0/+1
| | | | | | test for classes with a __complex__() method. The attribute is pulled out of the instance with PyObject_GetAttr() but this transfers ownership and the function object was never DECREF'd.
* Avoid overflow if possible in calculations for range(); reportGuido van Rossum1999-01-121-7/+28
| | | | unavoidable overflow as OverflowError.
* Added new builtin standard exception: NotImplementedError (its CBarry Warsaw1998-12-011-0/+2
| | | | counterpart is PyExc_NotImplementedError).
* Fix cosmetic bug in delattr docstring discovered by JvR.Guido van Rossum1998-11-231-1/+1
|
* builtin_apply(): Second argument type check is relaxed to allow any sequence.Barry Warsaw1998-10-011-6/+18
|
* Several changes that Python carry on in the face of errors in theBarry Warsaw1998-09-141-26/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | initialization of class exceptions. Specifically: init_class_exc(): This function now returns an integer status of the class exception initialization. No fatal errors in this method now. Also, use PySys_WriteStderr() when writing error messages. When an error occurs in this function, 0 is returned, but the partial creation of the exception classes is not undone (this happens elsewhere). Things that could trigger the fallback: - exceptions.py fails to be imported (due to syntax error, etc.) - one of the exception classes is missing (e.g. due to library version mismatch) - exception class can't be inserted into __builtin__'s dictionary - MemoryError instance can't be pre-allocated - some other PyErr_Occurred newstdexception(): Changed the error message. This is still a fatal error because if the string based exceptions can't be created, we really can't continue. initerrors(): Be sure to xdecref the .exc field, which might be non-NULL if class exceptions init was aborted. _PyBuiltin_Init_2(): If class exception init fails, print a warning message and reinstate the string based exceptions.
* Should no longer surround PyOS_Readline() call withGuido van Rossum1998-09-031-4/+0
| | | | | Py_{BEGIN,END}_ALLOW_THREADS macros. Also get rid of the declaration for it (it's now in pythonrun.h).
* Added support for two new standard errors: EnvironmentError andBarry Warsaw1998-07-231-5/+16
| | | | | | | | | OSError. The EnvironmentError serves primarily as the (common implementation) base class for IOError and OSError. OSError is used by posixmodule.c Also added tuple definition of EnvironmentError when using string based exceptions.
* Small changes to map() and filter():Guido van Rossum1998-07-101-5/+8
| | | | | | | (1) If a sequence S is shorter than len(S) indicated, don't fail -- just use the shorter size. (I.e, len(S) is just a hint.) (2) Implement the special case map(None, S) as list(S) -- it's faster.
* Fix a stupid little bug: len() of an unsized returns -1 and leaves anGuido van Rossum1998-06-291-1/+5
| | | | exception waiting to happen next...
* Experimental feature: add default argument to getattr().Guido van Rossum1998-06-291-5/+13
|
* Added doc strings.Guido van Rossum1998-06-261-52/+432
|
* In raw_input(prompt), make sure that str(prompt) really a stringGuido van Rossum1998-06-261-0/+2
| | | | object before using it.
* Remove a few unused locals (I love VC++ for this!).Guido van Rossum1998-05-291-2/+0
|
* A bunch of functions are now properly implemented in abstract.c, andGuido van Rossum1998-05-221-356/+40
| | | | | | | | | | | the code here becomes much simpler. In particular: abs(), divmod(), pow(), int(), long(), float(), len(), tuple(), list(). Also make sure that no use of a function pointer gotten from a tp_as_sequence or tp_as_mapping structure is made without checking it for NULL first. A few other cosmetic things, such as properly reindenting slice().
* Implement round() slightly different, so that for negative ndigits noGuido van Rossum1998-05-091-5/+13
| | | | | additional errors happen in the last step. The trick is to avoid division by 0.1**n -- multiply by 10.0**n instead.
* Fred's right -- we need PyList_SET_ITEM().Guido van Rossum1998-04-241-1/+1
|
* In-line the code in range() to set the list items; there's really noGuido van Rossum1998-04-231-1/+1
| | | | | need to call PyList_SetItem(v,i,w) when PyList_GET_ITEM(v,i)=w {sic} will do.
* Make new gcc -Wall happyGuido van Rossum1998-04-101-2/+4
|
* Use a faster way to check for null bytes in the string argument forGuido van Rossum1998-03-131-7/+18
| | | | int(), long(), float().
* Need a cast when comparing type object in isinstance()Guido van Rossum1997-12-101-1/+1
|
* Support type objects in isinstance().Guido van Rossum1997-12-021-10/+15
| | | | | E.g. isinstance('',types.StringType) will return true now instead of raising a TypeError exception. This is for JPython compatibility.
* Release interpreter lock around readline call in [raw_]input().Guido van Rossum1997-09-261-0/+2
|
* initerrors(): Eliminate circular reference which was causing a smallBarry Warsaw1997-09-181-3/+3
| | | | | | | | | | | | but annoying memory leak. This was introduced when PyExc_Exception was added; the loop above populating the PyExc_StandardError exception tuple started at index 1 in bltin_exc, but PyExc_Exception was added at index 0, so PyExc_StandardError was getting inserted in itself! How else can a tuple include itself?! Change the loop to start at index 2. This was a *fun* one! :-)
* [Py_Exc]NumberError => [Py_Exc]ArithmeticErrorBarry Warsaw1997-09-161-7/+7
|
* Introduce PyExc_Exception as the conceptual root class for all exceptions.Guido van Rossum1997-09-161-0/+7
|
* First part of package support.Guido van Rossum1997-09-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This doesn't yet support "import a.b.c" or "from a.b.c import x", but it does recognize directories. When importing a directory, it initializes __path__ to a list containing the directory name, and loads the __init__ module if found. The (internal) find_module() and load_module() functions are restructured so that they both also handle built-in and frozen modules and Mac resources (and directories of course). The imp module's find_module() and (new) load_module() also have this functionality. Moreover, imp unconditionally defines constants for all module types, and has two more new functions: find_module_in_package() and find_module_in_directory(). There's also a new API function, PyImport_ImportModuleEx(), which takes all four __import__ arguments (name, globals, locals, fromlist). The last three may be NULL. This is currently the same as PyImport_ImportModule() but in the future it will be able to do relative dotted-path imports. Other changes: - bltinmodule.c: in __import__, call PyImport_ImportModuleEx(). - ceval.c: always pass the fromlist to __import__, even if it is a C function, so PyImport_ImportModuleEx() is useful. - getmtime.c: the function has a second argument, the FILE*, on which it applies fstat(). According to Sjoerd this is much faster. The first (pathname) argument is ignored, but remains for backward compatibility (so the Mac version still works without changes). By cleverly combining the new imp functionality, the full support for dotted names in Python (mini.py, not checked in) is now about 7K, lavishly commented (vs. 14K for ni plus 11K for ihooks, also lavishly commented). Good night!
* Removed obsolete exception PyExc_AccessError.Barry Warsaw1997-08-291-43/+171
| | | | | | | | | | | | | | | | | | | | | Added PyErr_MemoryErrorInst to hold the pre-instantiated instance when using class based exceptions. Simplified the creation of all built-in exceptions, both class based and string based. Actually, for class based exceptions, the string ones are still created just in case there's a problem creating the class based ones (so you still get *some* exception handling!). Now the init and fini functions run through a list of structure elements, creating the strings (and optionally classes) for every entry. initerrors(): the new base class exceptions StandardError, LookupError, and NumberError are initialized when using string exceptions, to tuples containing the list of derived string exceptions. This GvR trick enables forward compatibility! One bit of nastiness is that the C code has to know the inheritance tree embodied in exceptions.py. Added the two phase init and fini functions.
* Two new built-in functions: issubclass() and isinstance(). Both takeBarry Warsaw1997-08-221-5/+59
| | | | | | | | | | | | classes as their second arguments. The former takes a class as the first argument and returns true iff first is second, or is a subclass of second. The latter takes any object as the first argument and returns true iff first is an instance of the second, or any subclass of second. Also, change all occurances of pointer compares against PyExc_IndexError with PyErr_ExceptionMatches() calls.
* The last of the mass checkins for separate (sub)interpreters.Guido van Rossum1997-08-021-50/+71
| | | | | | | Everything should now work again. See the comments for the .h files mass checkin (e.g. pystate.h) for more detail.
* PyObject_Compare can raise an exception now.Guido van Rossum1997-05-231-4/+14
|
* Oops -- missed FloatingPointError in renaming.Guido van Rossum1997-05-091-2/+2
|
* Instead of importing graminit.h whenever one of the three grammar 'root'Guido van Rossum1997-05-071-7/+6
| | | | symbols is needed, define these in Python.h with a Py_ prefix.