diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst index 2ef431268bb..83559862512 100644 --- a/Doc/c-api/typeobj.rst +++ b/Doc/c-api/typeobj.rst @@ -652,7 +652,6 @@ type objects) *must* have the :attr:`ob_size` field. :attr:`__weakref__`, the type inherits its :attr:`tp_weaklistoffset` from its base type. - .. cmember:: getiterfunc PyTypeObject.tp_iter An optional pointer to a function that returns an iterator for the object. Its diff --git a/Doc/library/2to3.rst b/Doc/library/2to3.rst index 40234ef6362..375bd10e965 100644 --- a/Doc/library/2to3.rst +++ b/Doc/library/2to3.rst @@ -3,7 +3,7 @@ 2to3 - Automated Python 2 to 3 code translation =============================================== -.. sectionauthor:: Benjamin Peterson +.. sectionauthor:: Benjamin Peterson 2to3 is a Python program that reads Python 2.x source code and applies a series of *fixers* to transform it into valid Python 3.x code. The standard library diff --git a/Doc/library/binascii.rst b/Doc/library/binascii.rst index 2ea0e50d53d..39130a85a6e 100644 --- a/Doc/library/binascii.rst +++ b/Doc/library/binascii.rst @@ -113,8 +113,19 @@ The :mod:`binascii` module defines the following functions: print(binascii.crc32("hello world")) # Or, in two pieces: crc = binascii.crc32("hello") - crc = binascii.crc32(" world", crc) - print(crc) + crc = binascii.crc32(" world", crc) & 0xffffffff + print('crc32 = 0x%08x' % crc) + +.. note:: + To generate the same numeric value across all Python versions and + platforms use crc32(data) & 0xffffffff. If you are only using + the checksum in packed binary format this is not necessary as the + return value will have the correct 32bit binary representation + regardless of sign. + +.. versionchanged:: 3.0 + The return value will always be unsigned and in the range [0, 2**32-1] + regardless of platform. .. function:: b2a_hex(data) diff --git a/Doc/library/hashlib.rst b/Doc/library/hashlib.rst index 7a65d7d846d..955afb8fae8 100644 --- a/Doc/library/hashlib.rst +++ b/Doc/library/hashlib.rst @@ -4,8 +4,8 @@ .. module:: hashlib :synopsis: Secure hash and message digest algorithms. -.. moduleauthor:: Gregory P. Smith -.. sectionauthor:: Gregory P. Smith +.. moduleauthor:: Gregory P. Smith +.. sectionauthor:: Gregory P. Smith .. index:: diff --git a/Doc/library/io.rst b/Doc/library/io.rst index 3b699ccd532..45c99b5a50d 100644 --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -6,7 +6,7 @@ .. moduleauthor:: Guido van Rossum .. moduleauthor:: Mike Verdone .. moduleauthor:: Mark Russell -.. sectionauthor:: Benjamin Peterson +.. sectionauthor:: Benjamin Peterson The :mod:`io` module provides the Python interfaces to stream handling. The builtin :func:`open` function is defined in this module. diff --git a/Doc/library/logging.rst b/Doc/library/logging.rst index 84500c4590d..6e88b709939 100644 --- a/Doc/library/logging.rst +++ b/Doc/library/logging.rst @@ -522,6 +522,9 @@ decides to actually dispatch an event, the :meth:`emit` method is used to send the message to its destination. Most user-defined subclasses of :class:`Handler` will need to override this :meth:`emit`. +Useful Handlers +--------------- + In addition to the base :class:`Handler` class, many useful subclasses are provided: @@ -530,41 +533,44 @@ provided: #. :class:`FileHandler` instances send error messages to disk files. -.. currentmodule:: logging.handlers +.. module:: logging.handlers -#. :class:`BaseRotatingHandler` is the base class for handlers that rotate log - files at a certain point. It is not meant to be instantiated directly. Instead, - use :class:`RotatingFileHandler` or :class:`TimedRotatingFileHandler`. +#. :class:`BaseRotatingHandler` is the base class for handlers that + rotate log files at a certain point. It is not meant to be instantiated + directly. Instead, use :class:`RotatingFileHandler` or + :class:`TimedRotatingFileHandler`. -#. :class:`RotatingFileHandler` instances send error messages to disk files, - with support for maximum log file sizes and log file rotation. +#. :class:`RotatingFileHandler` instances send error messages to disk + files, with support for maximum log file sizes and log file rotation. -#. :class:`TimedRotatingFileHandler` instances send error messages to disk files - rotating the log file at certain timed intervals. +#. :class:`TimedRotatingFileHandler` instances send error messages to + disk files, rotating the log file at certain timed intervals. -#. :class:`SocketHandler` instances send error messages to TCP/IP sockets. +#. :class:`SocketHandler` instances send error messages to TCP/IP + sockets. -#. :class:`DatagramHandler` instances send error messages to UDP sockets. +#. :class:`DatagramHandler` instances send error messages to UDP + sockets. -#. :class:`SMTPHandler` instances send error messages to a designated email - address. +#. :class:`SMTPHandler` instances send error messages to a designated + email address. -#. :class:`SysLogHandler` instances send error messages to a Unix syslog daemon, - possibly on a remote machine. +#. :class:`SysLogHandler` instances send error messages to a Unix + syslog daemon, possibly on a remote machine. -#. :class:`NTEventLogHandler` instances send error messages to a Windows - NT/2000/XP event log. +#. :class:`NTEventLogHandler` instances send error messages to a + Windows NT/2000/XP event log. -#. :class:`MemoryHandler` instances send error messages to a buffer in memory, - which is flushed whenever specific criteria are met. +#. :class:`MemoryHandler` instances send error messages to a buffer + in memory, which is flushed whenever specific criteria are met. -#. :class:`HTTPHandler` instances send error messages to an HTTP server using - either ``GET`` or ``POST`` semantics. +#. :class:`HTTPHandler` instances send error messages to an HTTP + server using either ``GET`` or ``POST`` semantics. -#. :class:`WatchedFileHandler` instances watch the file they are logging to. If -the file changes, it is closed and reopened using the file name. This handler -is only useful on Unix-like systems; Windows does not support the underlying -mechanism used. +#. :class:`WatchedFileHandler` instances watch the file they are + logging to. If the file changes, it is closed and reopened using the file + name. This handler is only useful on Unix-like systems; Windows does not + support the underlying mechanism used. .. currentmodule:: logging @@ -603,6 +609,9 @@ The basic :class:`Filter` functionality allows filtering by specific logger name. If this feature is used, messages sent to the named logger and its children are allowed through the filter, and all others dropped. +Module-Level Functions +---------------------- + In addition to the classes described above, there are a number of module- level functions. @@ -1626,7 +1635,7 @@ See :ref:`library-config` for more information on how to use WatchedFileHandler ^^^^^^^^^^^^^^^^^^ -.. module:: logging.handlers +.. currentmodule:: logging.handlers The :class:`WatchedFileHandler` class, located in the :mod:`logging.handlers` module, is a :class:`FileHandler` which watches the file it is logging to. If diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 254e0694b12..aecef74a669 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -484,6 +484,11 @@ always available. A program is free to modify this list for its own purposes. + .. seealso:: + Module :mod:`site` This describes how to use .pth files to extend + :data:`sys.path`. + + .. data:: platform This string contains a platform identifier that can be used to append @@ -500,7 +505,6 @@ always available. Windows ``'win32'`` Windows/Cygwin ``'cygwin'`` Mac OS X ``'darwin'`` - Mac OS 9 ``'mac'`` OS/2 ``'os2'`` OS/2 EMX ``'os2emx'`` AtheOS ``'atheos'`` @@ -782,11 +786,3 @@ always available. first three characters of :const:`version`. It is provided in the :mod:`sys` module for informational purposes; modifying this value has no effect on the registry keys used by Python. Availability: Windows. - - -.. seealso:: - - Module :mod:`site` - This describes how to use .pth files to extend ``sys.path``. - - diff --git a/Doc/library/turtle.rst b/Doc/library/turtle.rst index 0a7aceae648..da3e475ba91 100644 --- a/Doc/library/turtle.rst +++ b/Doc/library/turtle.rst @@ -322,8 +322,7 @@ Turtle motion :param y: a number (integer or float) - Set the turtle's first coordinate to *y*, leave second coordinate - unchanged. + Set the turtle's second coordinate to *y*, leave first coordinate unchanged. >>> turtle.position() (0.00, 40.00) diff --git a/Doc/library/zlib.rst b/Doc/library/zlib.rst index e55e52a1ca8..b5875ee037c 100644 --- a/Doc/library/zlib.rst +++ b/Doc/library/zlib.rst @@ -31,19 +31,30 @@ The available exception and functions in this module are: Exception raised on compression and decompression errors. -.. function:: adler32(string[, value]) +.. function:: adler32(data[, value]) - Computes a Adler-32 checksum of *string*. (An Adler-32 checksum is almost as + Computes a Adler-32 checksum of *data*. (An Adler-32 checksum is almost as reliable as a CRC32 but can be computed much more quickly.) If *value* is present, it is used as the starting value of the checksum; otherwise, a fixed default value is used. This allows computing a running checksum over the - concatenation of several input strings. The algorithm is not cryptographically + concatenation of several inputs. The algorithm is not cryptographically strong, and should not be used for authentication or digital signatures. Since the algorithm is designed for use as a checksum algorithm, it is not suitable for use as a general hash algorithm. Always returns an unsigned 32-bit integer. +.. note:: + To generate the same numeric value across all Python versions and + platforms use adler32(data) & 0xffffffff. If you are only using + the checksum in packed binary format this is not necessary as the + return value will have the correct 32bit binary representation + regardless of sign. + +.. versionchanged:: 3.0 + The return value will always be unsigned and in the range [0, 2**32-1] + regardless of platform. + .. function:: compress(string[, level]) @@ -62,22 +73,33 @@ The available exception and functions in this module are: ``9`` is slowest and produces the most. The default value is ``6``. -.. function:: crc32(string[, value]) +.. function:: crc32(data[, value]) .. index:: single: Cyclic Redundancy Check single: checksum; Cyclic Redundancy Check - Computes a CRC (Cyclic Redundancy Check) checksum of *string*. If *value* is + Computes a CRC (Cyclic Redundancy Check) checksum of *data*. If *value* is present, it is used as the starting value of the checksum; otherwise, a fixed default value is used. This allows computing a running checksum over the - concatenation of several input strings. The algorithm is not cryptographically + concatenation of several inputs. The algorithm is not cryptographically strong, and should not be used for authentication or digital signatures. Since the algorithm is designed for use as a checksum algorithm, it is not suitable for use as a general hash algorithm. Always returns an unsigned 32-bit integer. +.. note:: + To generate the same numeric value across all Python versions and + platforms use crc32(data) & 0xffffffff. If you are only using + the checksum in packed binary format this is not necessary as the + return value will have the correct 32bit binary representation + regardless of sign. + +.. versionchanged:: 3.0 + The return value will always be unsigned and in the range [0, 2**32-1] + regardless of platform. + .. function:: decompress(string[, wbits[, bufsize]]) diff --git a/Include/pyport.h b/Include/pyport.h index 3991bc5506b..97cc68db982 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -616,6 +616,15 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *); #define Py_FORMAT_PARSETUPLE(func,p1,p2) #endif +/* + * Specify alignment on compilers that support it. + */ +#if defined(__GNUC__) && __GNUC__ >= 3 +#define Py_ALIGNED(x) __attribute__((aligned(x))) +#else +#define Py_ALIGNED(x) +#endif + /* Eliminate end-of-loop code not reached warnings from SunPro C * when using do{...}while(0) macros */ diff --git a/Lib/_abcoll.py b/Lib/_abcoll.py index 72f139748ae..ca82c4113c2 100644 --- a/Lib/_abcoll.py +++ b/Lib/_abcoll.py @@ -283,12 +283,12 @@ class MutableSet(Set): @abstractmethod def add(self, value): - """Return True if it was added, False if already there.""" + """Add an element.""" raise NotImplementedError @abstractmethod def discard(self, value): - """Return True if it was deleted, False if not there.""" + """Remove an element. Do not raise an exception if absent.""" raise NotImplementedError def remove(self, value): diff --git a/Lib/ast.py b/Lib/ast.py index 53130cf3c5f..0b8baf752e0 100644 --- a/Lib/ast.py +++ b/Lib/ast.py @@ -64,6 +64,18 @@ def literal_eval(node_or_string): elif isinstance(node, Name): if node.id in _safe_names: return _safe_names[node.id] + elif isinstance(node, BinOp) and \ + isinstance(node.op, (Add, Sub)) and \ + isinstance(node.right, Num) and \ + isinstance(node.right.n, complex) and \ + isinstance(node.left, Num) and \ + isinstance(node.left.n, (int, float)): + left = node.left.n + right = node.right.n + if isinstance(node.op, Add): + return left + right + else: + return left - right raise ValueError('malformed string') return _convert(node_or_string) diff --git a/Lib/ctypes/test/__init__.py b/Lib/ctypes/test/__init__.py index bdcf62bc538..1e0460a891b 100644 --- a/Lib/ctypes/test/__init__.py +++ b/Lib/ctypes/test/__init__.py @@ -67,9 +67,6 @@ def get_tests(package, mask, verbosity, exclude=()): if verbosity > 1: print("Skipped %s: %s" % (modname, detail), file=sys.stderr) continue - except Exception as detail: - print("Warning: could not import %s: %s" % (modname, detail), file=sys.stderr) - continue for name in dir(mod): if name.startswith("_"): continue diff --git a/Lib/inspect.py b/Lib/inspect.py index da55ac6baeb..b84aec0f6aa 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -249,7 +249,10 @@ def getmembers(object, predicate=None): Optionally, only return members that satisfy a given predicate.""" results = [] for key in dir(object): - value = getattr(object, key) + try: + value = getattr(object, key) + except AttributeError: + continue if not predicate or predicate(value): results.append((key, value)) results.sort() diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 2aa3b8fb009..54a3b35b7a2 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -265,6 +265,12 @@ class ASTHelpers_Test(unittest.TestCase): self.assertEqual(ast.literal_eval('(True, False, None)'), (True, False, None)) self.assertRaises(ValueError, ast.literal_eval, 'foo()') + def test_literal_eval_issue4907(self): + self.assertEqual(ast.literal_eval('2j'), 2j) + self.assertEqual(ast.literal_eval('10 + 2j'), 10 + 2j) + self.assertEqual(ast.literal_eval('1.5 - 2j'), 1.5 - 2j) + self.assertRaises(ValueError, ast.literal_eval, '2 + (3 + 4j)') + def test_main(): support.run_unittest(AST_Tests, ASTHelpers_Test) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index bde6d6c83c7..ac9fcd7999c 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -99,6 +99,17 @@ class TestPredicates(IsTestBase): self.assert_(inspect.isroutine(mod.spam)) self.assert_(inspect.isroutine([].count)) + def test_get_slot_members(self): + class C(object): + __slots__ = ("a", "b") + + x = C() + x.a = 42 + members = dict(inspect.getmembers(x)) + self.assert_('a' in members) + self.assert_('b' not in members) + + class TestInterpreterStack(IsTestBase): def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index b6f41fe00a1..ecb86beb9bb 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -1472,11 +1472,14 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size) size += 1; /* terminating NUL */ size *= sizeof(wchar_t); buffer = (wchar_t *)PyMem_Malloc(size); - if (!buffer) + if (!buffer) { + Py_DECREF(value); return PyErr_NoMemory(); + } memset(buffer, 0, size); keep = PyCObject_FromVoidPtr(buffer, PyMem_Free); if (!keep) { + Py_DECREF(value); PyMem_Free(buffer); return NULL; } diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 7d91af22da0..b7b9a649af0 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -3159,7 +3159,11 @@ socket_gethostbyaddr(PyObject *self, PyObject *args) #ifdef HAVE_GETHOSTBYNAME_R_3_ARG struct hostent_data data; #else - char buf[16384]; + /* glibcs up to 2.10 assume that the buf argument to + gethostbyaddr_r is 8-byte aligned, which at least llvm-gcc + does not ensure. The attribute below instructs the compiler + to maintain this alignment. */ + char buf[16384] Py_ALIGNED(8); int buf_len = (sizeof buf) - 1; int errnop; #endif diff --git a/Tools/scripts/patchcheck.py b/Tools/scripts/patchcheck.py index 73b190a25c8..544b00eae76 100644 --- a/Tools/scripts/patchcheck.py +++ b/Tools/scripts/patchcheck.py @@ -62,12 +62,12 @@ def docs_modified(file_paths): @status("Misc/ACKS updated", modal=True) def credit_given(file_paths): """Check if Misc/ACKS has been changed.""" - return True if 'Misc/ACKS' in file_paths else False + return 'Misc/ACKS' in file_paths @status("Misc/NEWS updated", modal=True) def reported_news(file_paths): """Check if Misc/NEWS has been changed.""" - return True if 'Misc/NEWS' in file_paths else False + return 'Misc/NEWS' in file_paths def main():