From python-checkins at python.org Fri Apr 1 03:26:23 2016 From: python-checkins at python.org (martin.panter) Date: Fri, 01 Apr 2016 07:26:23 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326676=3A_Add_miss?= =?utf-8?q?ing_XMLPullParser_to_ElementTree=2E=5F=5Fall=5F=5F?= Message-ID: <20160401072620.35142.14148.0F6F3C62@psf.io> https://hg.python.org/cpython/rev/3d6b67361749 changeset: 100820:3d6b67361749 user: Martin Panter date: Fri Apr 01 06:55:55 2016 +0000 summary: Issue #26676: Add missing XMLPullParser to ElementTree.__all__ files: Doc/whatsnew/3.6.rst | 3 ++- Lib/test/test_xml_etree.py | 6 ++++-- Lib/xml/etree/ElementTree.py | 2 +- Misc/NEWS | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -460,7 +460,8 @@ * The following modules have had missing APIs added to their :attr:`__all__` attributes to match the documented APIs: :mod:`calendar`, :mod:`csv`, - :mod:`enum`, :mod:`fileinput`, :mod:`ftplib`, :mod:`logging`, + :mod:`~xml.etree.ElementTree`, :mod:`enum`, + :mod:`fileinput`, :mod:`ftplib`, :mod:`logging`, :mod:`optparse`, :mod:`tarfile`, :mod:`threading` and :mod:`wave`. This means they will export new symbols when ``import *`` is used. See :issue:`23883`. diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -91,8 +91,6 @@ class ModuleTest(unittest.TestCase): - # TODO: this should be removed once we get rid of the global module vars - def test_sanity(self): # Import sanity. @@ -100,6 +98,10 @@ from xml.etree import ElementInclude from xml.etree import ElementPath + def test_all(self): + names = ("xml.etree.ElementTree", "_elementtree") + support.check__all__(self, ET, names, blacklist=("HTML_EMPTY",)) + def serialize(elem, to_string=True, encoding='unicode', **options): if encoding != 'unicode': diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -85,7 +85,7 @@ "TreeBuilder", "VERSION", "XML", "XMLID", - "XMLParser", + "XMLParser", "XMLPullParser", "register_namespace", ] diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -237,6 +237,8 @@ Library ------- +- Issue #26676: Added missing XMLPullParser to ElementTree.__all__. + - Issue #22854: Change BufferedReader.writable() and BufferedWriter.readable() to always return False. -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Fri Apr 1 06:00:22 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 01 Apr 2016 10:00:22 +0000 Subject: [Python-checkins] Daily reference leaks (307da5f21fd4): sum=-2 Message-ID: <20160401100018.53128.78089.2B6F2A46@psf.io> results for 307da5f21fd4 on branch "default" -------------------------------------------- test_collections leaked [-4, 0, 0] references, sum=-4 test_collections leaked [-2, 0, 0] memory blocks, sum=-2 test_functools leaked [0, 2, 2] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogbwJlnG', '--timeout', '7200'] From lp_benchmark_robot at intel.com Fri Apr 1 07:16:38 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Fri, 1 Apr 2016 12:16:38 +0100 Subject: [Python-checkins] NEUTRAL Benchmark Results for Python Default 2016-04-01 Message-ID: Results for project Python default, build date 2016-04-01 02:09:01 +0000 commit: 307da5f21fd4 previous commit: b6eebe7cf5ae revision date: 2016-03-31 23:20:03 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.38% 0.58% 9.78% 13.25% :-| pybench 0.32% -0.10% 0.51% 5.97% :-( regex_v8 2.70% -0.12% -4.57% 5.47% :-) nbody 0.09% -0.19% 2.59% 3.66% :-( json_dump_v2 0.29% -0.17% -2.25% 10.94% :-| normal_startup 0.92% -0.12% 0.10% 5.44% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/neutral-benchmark-results-for-python-default-2016-04-01/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Fri Apr 1 07:18:37 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Fri, 1 Apr 2016 12:18:37 +0100 Subject: [Python-checkins] BAD Benchmark Results for Python 2.7 2016-04-01 Message-ID: <5ec88fc7-263b-4bde-a863-9063c7f12a88@irsmsx105.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-01 03:00:45 +0000 commit: 1d79e70e67b5 previous commit: 249ef9d02aa6 revision date: 2016-03-31 12:31:04 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-( django_v2 0.29% -3.15% 2.61% 9.16% :-) pybench 0.08% -0.07% 5.95% 4.10% :-( regex_v8 0.79% -0.38% -3.02% 11.18% :-) nbody 0.08% -0.36% 7.12% 3.77% :-) json_dump_v2 0.25% -0.31% 3.40% 12.04% :-( normal_startup 2.05% 0.46% -5.24% 2.21% :-) ssbench 0.18% 0.06% 2.53% 0.97% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/bad-benchmark-results-for-python-2-7-2016-04-01/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Fri Apr 1 13:52:39 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 01 Apr 2016 17:52:39 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Update_PEP_512_to_denote_that?= =?utf-8?q?_the_initial_GH_work_is_done?= Message-ID: <20160401175238.18444.59416.4E958B75@psf.io> https://hg.python.org/peps/rev/d3f3fae42274 changeset: 6274:d3f3fae42274 user: Brett Cannon date: Fri Apr 01 10:52:34 2016 -0700 summary: Update PEP 512 to denote that the initial GH work is done files: pep-0512.txt | 48 ++++++++++++++++++++++++--------------- 1 files changed, 29 insertions(+), 19 deletions(-) diff --git a/pep-0512.txt b/pep-0512.txt --- a/pep-0512.txt +++ b/pep-0512.txt @@ -172,12 +172,19 @@ fact as part of someone's bugs.python.org user profile. What this means is that an association will be needed between a person's bugs.python.org [#b.p.o]_ account and their GitHub account, which -will be done through a new field in a user's profile. - -This does implicitly require that contributors will need both a +will be done through a new field in a user's profile. This does +implicitly require that contributors will need both a GitHub [#github]_ and bugs.python.org account in order to sign the CLA and contribute through GitHub. +An API is provided to query bugs.python.org to see if a GitHub +username corresponds to someone who has signed the CLA. Making a GET +request to e.g. +http://bugs.python.org/user?@template=clacheck&github_names=brettcannon,notanuser +returns a JSON dictionary with the keys of the usernames requested +and a ``true`` value if they have sigend the CLA, ``false`` if they +have not, and ``null`` if no corresponding GitHub username was found. + A bot to enforce CLA signing ++++++++++++++++++++++++++++ With an association between someone's GitHub account and their @@ -187,20 +194,22 @@ If the user has signed the CLA, the bot will add a positive label to the issue to denote the pull request has no CLA issues (e.g., a green -label stating, "CLA: ?"). If the contributor has not signed a CLA, +label stating, "CLA signed"). If the contributor has not signed a CLA, a negative label will be added to the pull request will be blocked -using GitHub's status API (e.g., a red label stating, "CLA: ?"). If a -contributor lacks a bugs.python.org account, that will lead to -another label (e.g., "CLA: ? (no account)"). Using a label for both +using GitHub's status API (e.g., a red label stating, "CLA not signed"). +If a contributor lacks a bugs.python.org account, that will lead to +the negative label being used as well. Using a label for both positive and negative cases provides a fallback notification if the bot happens to fail, preventing potential false-positives or false-negatives. It also allows for an easy way to trigger the bot -again by simply removing a CLA-related label. +again by simply removing a CLA-related label (this is in contrast to +using a GitHub status check [#gh-status-check]_ which is only +triggered on code changes). -If no pre-existing, maintained bot exists that fits our needs, one -will be written from scratch. It will be hosted on Heroku [#heroku]_ -and written to target Python 3.5 to act as a showcase for -asynchronous programming. +As no pre-existing bot exists to meet our needs, it will be hosted on +Heroku [#heroku]_ and written to target Python 3.5 to act as a +showcase for asynchronous programming. The code for the bot is hosted +in the Knights Who Say Ni project [#ni]_. Requirements for Web-Related Repositories ----------------------------------------- @@ -526,22 +535,17 @@ - `Create a 'python-dev' team`_ - * In progress - `A bot to enforce CLA signing`_: https://github.com/python/the-knights-who-say-ni (Brett Cannon) - `Define commands to move a Mercurial repository to Git`_: https://github.com/orsenthil/cpython-hg-to-git (Senthil Kumaran) - - `Adding GitHub username support to bugs.python.org`_ (HTTP API): - http://psf.upfronthosting.co.za/roundup/meta/issue581 - (Maciej Szulik and Ezio Melotti) * Completed - - `Adding GitHub username support to bugs.python.org`_: - GitHub usernames on bugs.python.org - (Maciej Szulik and Ezio Melotti) + - `Adding GitHub username support to bugs.python.org`_ + (Maciej Szulik and Ezio Melotti) Repositories whose build steps need updating: @@ -882,6 +886,12 @@ .. [#heroku] Heroku (https://www.heroku.com/) +.. [#gh-status-check] GitHub status checks + (https://developer.github.com/v3/repos/statuses/) + +.. [#ni] The Knights Who Say Ni project + (https://github.com/python/the-knights-who-say-ni) + Copyright ========= -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Fri Apr 1 15:41:03 2016 From: python-checkins at python.org (victor.stinner) Date: Fri, 01 Apr 2016 19:41:03 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogYXN5bmNpbzogc3lu?= =?utf-8?q?c_overlapped=2Ec_with_GitHub?= Message-ID: <20160401194103.9964.68702.E5992B69@psf.io> https://hg.python.org/cpython/rev/466d2e21acf8 changeset: 100821:466d2e21acf8 branch: 3.5 parent: 100816:b3c79e0ba477 user: Victor Stinner date: Fri Apr 01 21:37:41 2016 +0200 summary: asyncio: sync overlapped.c with GitHub On Python 3.3, use aliases: * PyMem_RawMalloc = PyMem_Malloc * PyMem_RawFree = PyMem_Free These aliases are not need in Python 3.5, but this change makes synchronization of code base simpler. files: Modules/overlapped.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/Modules/overlapped.c b/Modules/overlapped.c --- a/Modules/overlapped.c +++ b/Modules/overlapped.c @@ -23,6 +23,12 @@ # define T_POINTER T_ULONGLONG #endif +/* Compatibility with Python 3.3 */ +#if PY_VERSION_HEX < 0x03040000 +# define PyMem_RawMalloc PyMem_Malloc +# define PyMem_RawFree PyMem_Free +#endif + #define F_HANDLE F_POINTER #define F_ULONG_PTR F_POINTER #define F_DWORD "k" -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 15:41:03 2016 From: python-checkins at python.org (victor.stinner) Date: Fri, 01 Apr 2016 19:41:03 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogYXN5bmNpbzogYWxs?= =?utf-8?q?ow_None_as_wait_timeout?= Message-ID: <20160401194103.7797.27315.77D12F8A@psf.io> https://hg.python.org/cpython/rev/6dc33c07e517 changeset: 100822:6dc33c07e517 branch: 3.5 user: Victor Stinner date: Fri Apr 01 21:39:09 2016 +0200 summary: asyncio: allow None as wait timeout Fix GH#325: Allow to pass None as a timeout value to disable timeout logic. Change written by Andrew Svetlov and merged by Guido van Rossum. files: Lib/asyncio/tasks.py | 14 ++++++++------ Lib/test/test_asyncio/test_tasks.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -401,7 +401,7 @@ @coroutine def _wait(fs, timeout, return_when, loop): - """Internal helper for wait() and _wait_for(). + """Internal helper for wait() and wait_for(). The fs argument must be a collection of Futures. """ @@ -747,7 +747,7 @@ ... yield from coro() - timeout: timeout value in seconds + timeout: timeout value in seconds or None to disable timeout logic loop: asyncio compatible event loop """ if loop is None: @@ -768,8 +768,9 @@ if self._task is None: raise RuntimeError('Timeout context manager should be used ' 'inside a task') - self._cancel_handler = self._loop.call_later( - self._timeout, self._cancel_task) + if self._timeout is not None: + self._cancel_handler = self._loop.call_later( + self._timeout, self._cancel_task) return self def __exit__(self, exc_type, exc_val, exc_tb): @@ -777,8 +778,9 @@ self._cancel_handler = None self._task = None raise futures.TimeoutError - self._cancel_handler.cancel() - self._cancel_handler = None + if self._timeout is not None: + self._cancel_handler.cancel() + self._cancel_handler = None self._task = None def _cancel_task(self): diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2382,6 +2382,22 @@ self.loop.run_until_complete(go()) + def test_timeout_disable(self): + @asyncio.coroutine + def long_running_task(): + yield from asyncio.sleep(0.1, loop=self.loop) + return 'done' + + @asyncio.coroutine + def go(): + t0 = self.loop.time() + with asyncio.timeout(None, loop=self.loop): + resp = yield from long_running_task() + self.assertEqual(resp, 'done') + dt = self.loop.time() - t0 + self.assertTrue(0.09 < dt < 0.11, dt) + self.loop.run_until_complete(go()) + def test_raise_runtimeerror_if_no_task(self): with self.assertRaises(RuntimeError): with asyncio.timeout(0.1, loop=self.loop): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 15:41:05 2016 From: python-checkins at python.org (victor.stinner) Date: Fri, 01 Apr 2016 19:41:05 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_3=2E5_=28asyncio=29?= Message-ID: <20160401194103.97847.32455.1E691AE0@psf.io> https://hg.python.org/cpython/rev/e3ecbac90eaf changeset: 100823:e3ecbac90eaf parent: 100820:3d6b67361749 parent: 100822:6dc33c07e517 user: Victor Stinner date: Fri Apr 01 21:40:14 2016 +0200 summary: Merge 3.5 (asyncio) files: Lib/asyncio/tasks.py | 14 ++++++++------ Lib/test/test_asyncio/test_tasks.py | 16 ++++++++++++++++ Modules/overlapped.c | 6 ++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -401,7 +401,7 @@ @coroutine def _wait(fs, timeout, return_when, loop): - """Internal helper for wait() and _wait_for(). + """Internal helper for wait() and wait_for(). The fs argument must be a collection of Futures. """ @@ -747,7 +747,7 @@ ... yield from coro() - timeout: timeout value in seconds + timeout: timeout value in seconds or None to disable timeout logic loop: asyncio compatible event loop """ if loop is None: @@ -768,8 +768,9 @@ if self._task is None: raise RuntimeError('Timeout context manager should be used ' 'inside a task') - self._cancel_handler = self._loop.call_later( - self._timeout, self._cancel_task) + if self._timeout is not None: + self._cancel_handler = self._loop.call_later( + self._timeout, self._cancel_task) return self def __exit__(self, exc_type, exc_val, exc_tb): @@ -777,8 +778,9 @@ self._cancel_handler = None self._task = None raise futures.TimeoutError - self._cancel_handler.cancel() - self._cancel_handler = None + if self._timeout is not None: + self._cancel_handler.cancel() + self._cancel_handler = None self._task = None def _cancel_task(self): diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2382,6 +2382,22 @@ self.loop.run_until_complete(go()) + def test_timeout_disable(self): + @asyncio.coroutine + def long_running_task(): + yield from asyncio.sleep(0.1, loop=self.loop) + return 'done' + + @asyncio.coroutine + def go(): + t0 = self.loop.time() + with asyncio.timeout(None, loop=self.loop): + resp = yield from long_running_task() + self.assertEqual(resp, 'done') + dt = self.loop.time() - t0 + self.assertTrue(0.09 < dt < 0.11, dt) + self.loop.run_until_complete(go()) + def test_raise_runtimeerror_if_no_task(self): with self.assertRaises(RuntimeError): with asyncio.timeout(0.1, loop=self.loop): diff --git a/Modules/overlapped.c b/Modules/overlapped.c --- a/Modules/overlapped.c +++ b/Modules/overlapped.c @@ -23,6 +23,12 @@ # define T_POINTER T_ULONGLONG #endif +/* Compatibility with Python 3.3 */ +#if PY_VERSION_HEX < 0x03040000 +# define PyMem_RawMalloc PyMem_Malloc +# define PyMem_RawFree PyMem_Free +#endif + #define F_HANDLE F_POINTER #define F_ULONG_PTR F_POINTER #define F_DWORD "k" -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 15:45:08 2016 From: python-checkins at python.org (victor.stinner) Date: Fri, 01 Apr 2016 19:45:08 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_3=2E5_=28asyncio=29?= Message-ID: <20160401194505.97845.76844.1C96B139@psf.io> https://hg.python.org/cpython/rev/a442bf076a32 changeset: 100825:a442bf076a32 parent: 100823:e3ecbac90eaf parent: 100824:68e694475483 user: Victor Stinner date: Fri Apr 01 21:43:54 2016 +0200 summary: Merge 3.5 (asyncio) files: Lib/asyncio/base_events.py | 6 ++++++ Lib/asyncio/proactor_events.py | 2 +- Lib/asyncio/selector_events.py | 3 +-- Lib/asyncio/sslproto.py | 2 +- Lib/asyncio/unix_events.py | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -54,6 +54,12 @@ # before cleanup of cancelled handles is performed. _MIN_CANCELLED_TIMER_HANDLES_FRACTION = 0.5 +# Exceptions which must not call the exception handler in fatal error +# methods (_fatal_error()) +_FATAL_ERROR_IGNORE = (BrokenPipeError, + ConnectionResetError, ConnectionAbortedError) + + def _format_handle(handle): cb = handle._callback if inspect.ismethod(cb) and isinstance(cb.__self__, tasks.Task): diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -91,7 +91,7 @@ self.close() def _fatal_error(self, exc, message='Fatal error on pipe transport'): - if isinstance(exc, (BrokenPipeError, ConnectionResetError)): + if isinstance(exc, base_events._FATAL_ERROR_IGNORE): if self._loop.get_debug(): logger.debug("%r: %s", self, message, exc_info=True) else: diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -579,8 +579,7 @@ def _fatal_error(self, exc, message='Fatal error on transport'): # Should be called from exception handler only. - if isinstance(exc, (BrokenPipeError, - ConnectionResetError, ConnectionAbortedError)): + if isinstance(exc, base_events._FATAL_ERROR_IGNORE): if self._loop.get_debug(): logger.debug("%r: %s", self, message, exc_info=True) else: diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py --- a/Lib/asyncio/sslproto.py +++ b/Lib/asyncio/sslproto.py @@ -656,7 +656,7 @@ def _fatal_error(self, exc, message='Fatal error on transport'): # Should be called from exception handler only. - if isinstance(exc, (BrokenPipeError, ConnectionResetError)): + if isinstance(exc, base_events._FATAL_ERROR_IGNORE): if self._loop.get_debug(): logger.debug("%r: %s", self, message, exc_info=True) else: diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -577,7 +577,7 @@ def _fatal_error(self, exc, message='Fatal error on pipe transport'): # should be called by exception handler only - if isinstance(exc, (BrokenPipeError, ConnectionResetError)): + if isinstance(exc, base_events._FATAL_ERROR_IGNORE): if self._loop.get_debug(): logger.debug("%r: %s", self, message, exc_info=True) else: -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 15:45:08 2016 From: python-checkins at python.org (victor.stinner) Date: Fri, 01 Apr 2016 19:45:08 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogYXN5bmNpbzogRG9u?= =?utf-8?q?=27t_log_ConnectionAbortedError?= Message-ID: <20160401194505.94566.70603.14361043@psf.io> https://hg.python.org/cpython/rev/68e694475483 changeset: 100824:68e694475483 branch: 3.5 parent: 100822:6dc33c07e517 user: Victor Stinner date: Fri Apr 01 21:43:39 2016 +0200 summary: asyncio: Don't log ConnectionAbortedError Issue #26509: In fatal error handlers, don't log ConnectionAbortedError which occur on Windows. files: Lib/asyncio/base_events.py | 6 ++++++ Lib/asyncio/proactor_events.py | 2 +- Lib/asyncio/selector_events.py | 3 +-- Lib/asyncio/sslproto.py | 2 +- Lib/asyncio/unix_events.py | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -54,6 +54,12 @@ # before cleanup of cancelled handles is performed. _MIN_CANCELLED_TIMER_HANDLES_FRACTION = 0.5 +# Exceptions which must not call the exception handler in fatal error +# methods (_fatal_error()) +_FATAL_ERROR_IGNORE = (BrokenPipeError, + ConnectionResetError, ConnectionAbortedError) + + def _format_handle(handle): cb = handle._callback if inspect.ismethod(cb) and isinstance(cb.__self__, tasks.Task): diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -90,7 +90,7 @@ self.close() def _fatal_error(self, exc, message='Fatal error on pipe transport'): - if isinstance(exc, (BrokenPipeError, ConnectionResetError)): + if isinstance(exc, base_events._FATAL_ERROR_IGNORE): if self._loop.get_debug(): logger.debug("%r: %s", self, message, exc_info=True) else: diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -578,8 +578,7 @@ def _fatal_error(self, exc, message='Fatal error on transport'): # Should be called from exception handler only. - if isinstance(exc, (BrokenPipeError, - ConnectionResetError, ConnectionAbortedError)): + if isinstance(exc, base_events._FATAL_ERROR_IGNORE): if self._loop.get_debug(): logger.debug("%r: %s", self, message, exc_info=True) else: diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py --- a/Lib/asyncio/sslproto.py +++ b/Lib/asyncio/sslproto.py @@ -655,7 +655,7 @@ def _fatal_error(self, exc, message='Fatal error on transport'): # Should be called from exception handler only. - if isinstance(exc, (BrokenPipeError, ConnectionResetError)): + if isinstance(exc, base_events._FATAL_ERROR_IGNORE): if self._loop.get_debug(): logger.debug("%r: %s", self, message, exc_info=True) else: diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -575,7 +575,7 @@ def _fatal_error(self, exc, message='Fatal error on pipe transport'): # should be called by exception handler only - if isinstance(exc, (BrokenPipeError, ConnectionResetError)): + if isinstance(exc, base_events._FATAL_ERROR_IGNORE): if self._loop.get_debug(): logger.debug("%r: %s", self, message, exc_info=True) else: -- Repository URL: https://hg.python.org/cpython From nad at python.org Fri Apr 1 16:16:28 2016 From: nad at python.org (Ned Deily) Date: Fri, 1 Apr 2016 16:16:28 -0400 Subject: [Python-checkins] [Python-Dev] cpython: Python 8: no pep8, no chocolate! In-Reply-To: References: <20160331214027.11092.50943.0083A2D0@psf.io> Message-ID: <7B294850-BFD9-48D3-8E12-0FA3312136BB@python.org> On Apr 1, 2016, at 14:07, Brett Cannon wrote: > Are you planning on removing this after today? My worry about leaving it in is if it's a modified copy that follows your Python 8 April Fools joke then it will quite possibly trip people up who try and run pep8 but don't have it installed, leading them to wonder why the heck their imports are now all flagged as broken. > > On Thu, 31 Mar 2016 at 14:40 victor.stinner wrote: > https://hg.python.org/cpython/rev/9aedec2dbc01 > changeset: 100818:9aedec2dbc01 > user: Victor Stinner > date: Thu Mar 31 23:30:53 2016 +0200 > summary: > Python 8: no pep8, no chocolate! > > files: > Include/patchlevel.h | 6 +- > Lib/pep8.py | 2151 ++++++++++++++++++++++++++++++ > Lib/site.py | 56 + > 3 files changed, 2210 insertions(+), 3 deletions(-) [...] It has already been removed, a few hours after it was pushed, since it broke all of the 3x buidbots, and would have confused and/or added extra work to anyone trying to build or push changes. On behalf of my fellow release managers, may I suggest that, in the future, if anyone feels the urge to check something like this in to the live cpython repository, please resist that urge? :) A patch would be just as amusing without the need to use the soft cushion or the comfy chair. Inquisitorly yours, --Ned -- Ned Deily nad at python.org -- [] From python-checkins at python.org Fri Apr 1 18:14:23 2016 From: python-checkins at python.org (vinay.sajip) Date: Fri, 01 Apr 2016 22:14:23 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merged_documentation_update_from_3=2E5=2E?= Message-ID: <20160401221423.9982.19665.BE41402B@psf.io> https://hg.python.org/cpython/rev/09cd137a2e8b changeset: 100828:09cd137a2e8b parent: 100825:a442bf076a32 parent: 100827:98d6a20a6c71 user: Vinay Sajip date: Fri Apr 01 23:13:48 2016 +0100 summary: Merged documentation update from 3.5. files: Doc/howto/logging-cookbook.rst | 102 +++++++++++++++++++++ 1 files changed, 102 insertions(+), 0 deletions(-) diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -2409,3 +2409,105 @@ showing how the time is formatted both as local time and UTC, one for each handler. + + +.. _context-manager: + +Using a context manager for selective logging +--------------------------------------------- + +There are times when it would be useful to temporarily change the logging +configuration and revert it back after doing something. For this, a context +manager is the most obvious way of saving and restoring the logging context. +Here is a simple example of such a context manager, which allows you to +optionally change the logging level and add a logging handler purely in the +scope of the context manager:: + + import logging + import sys + + class LoggingContext(object): + def __init__(self, logger, level=None, handler=None, close=True): + self.logger = logger + self.level = level + self.handler = handler + self.close = close + + def __enter__(self): + if self.level is not None: + self.old_level = self.logger.level + self.logger.setLevel(self.level) + if self.handler: + self.logger.addHandler(self.handler) + + def __exit__(self, et, ev, tb): + if self.level is not None: + self.logger.setLevel(self.old_level) + if self.handler: + self.logger.removeHandler(self.handler) + if self.handler and self.close: + self.handler.close() + # implicit return of None => don't swallow exceptions + +If you specify a level value, the logger's level is set to that value in the +scope of the with block covered by the context manager. If you specify a +handler, it is added to the logger on entry to the block and removed on exit +from the block. You can also ask the manager to close the handler for you on +block exit - you could do this if you don't need the handler any more. + +To illustrate how it works, we can add the following block of code to the +above:: + + if __name__ == '__main__': + logger = logging.getLogger('foo') + logger.addHandler(logging.StreamHandler()) + logger.setLevel(logging.INFO) + logger.info('1. This should appear just once on stderr.') + logger.debug('2. This should not appear.') + with LoggingContext(logger, level=logging.DEBUG): + logger.debug('3. This should appear once on stderr.') + logger.debug('4. This should not appear.') + h = logging.StreamHandler(sys.stdout) + with LoggingContext(logger, level=logging.DEBUG, handler=h, close=True): + logger.debug('5. This should appear twice - once on stderr and once on stdout.') + logger.info('6. This should appear just once on stderr.') + logger.debug('7. This should not appear.') + +We initially set the logger's level to ``INFO``, so message #1 appears and +message #2 doesn't. We then change the level to ``DEBUG`` temporarily in the +following ``with`` block, and so message #3 appears. After the block exits, the +logger's level is restored to ``INFO`` and so message #4 doesn't appear. In the +next ``with`` block, we set the level to ``DEBUG`` again but also add a handler +writing to ``sys.stdout``. Thus, message #5 appears twice on the console (once +via ``stderr`` and once via ``stdout``). After the ``with`` statement's +completion, the status is as it was before so message #6 appears (like message +#1) whereas message #7 doesn't (just like message #2). + +If we run the resulting script, the result is as follows:: + + $ python logctx.py + 1. This should appear just once on stderr. + 3. This should appear once on stderr. + 5. This should appear twice - once on stderr and once on stdout. + 5. This should appear twice - once on stderr and once on stdout. + 6. This should appear just once on stderr. + +If we run it again, but pipe ``stderr`` to ``/dev/null``, we see the following, +which is the only message written to ``stdout``:: + + $ python logctx.py 2>/dev/null + 5. This should appear twice - once on stderr and once on stdout. + +Once again, but piping ``stdout`` to ``/dev/null``, we get:: + + $ python logctx.py >/dev/null + 1. This should appear just once on stderr. + 3. This should appear once on stderr. + 5. This should appear twice - once on stderr and once on stdout. + 6. This should appear just once on stderr. + +In this case, the message #5 printed to ``stdout`` doesn't appear, as expected. + +Of course, the approach described here can be generalised, for example to attach +logging filters temporarily. Note that the above code works in Python 2 as well +as Python 3. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 18:14:24 2016 From: python-checkins at python.org (vinay.sajip) Date: Fri, 01 Apr 2016 22:14:24 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Added_a_cookbo?= =?utf-8?q?ok_recipe_for_a_logging_context_manager=2E?= Message-ID: <20160401221423.97869.92553.22840845@psf.io> https://hg.python.org/cpython/rev/98d6a20a6c71 changeset: 100827:98d6a20a6c71 branch: 3.5 parent: 100824:68e694475483 user: Vinay Sajip date: Fri Apr 01 23:13:01 2016 +0100 summary: Added a cookbook recipe for a logging context manager. files: Doc/howto/logging-cookbook.rst | 102 +++++++++++++++++++++ 1 files changed, 102 insertions(+), 0 deletions(-) diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -2409,3 +2409,105 @@ showing how the time is formatted both as local time and UTC, one for each handler. + + +.. _context-manager: + +Using a context manager for selective logging +--------------------------------------------- + +There are times when it would be useful to temporarily change the logging +configuration and revert it back after doing something. For this, a context +manager is the most obvious way of saving and restoring the logging context. +Here is a simple example of such a context manager, which allows you to +optionally change the logging level and add a logging handler purely in the +scope of the context manager:: + + import logging + import sys + + class LoggingContext(object): + def __init__(self, logger, level=None, handler=None, close=True): + self.logger = logger + self.level = level + self.handler = handler + self.close = close + + def __enter__(self): + if self.level is not None: + self.old_level = self.logger.level + self.logger.setLevel(self.level) + if self.handler: + self.logger.addHandler(self.handler) + + def __exit__(self, et, ev, tb): + if self.level is not None: + self.logger.setLevel(self.old_level) + if self.handler: + self.logger.removeHandler(self.handler) + if self.handler and self.close: + self.handler.close() + # implicit return of None => don't swallow exceptions + +If you specify a level value, the logger's level is set to that value in the +scope of the with block covered by the context manager. If you specify a +handler, it is added to the logger on entry to the block and removed on exit +from the block. You can also ask the manager to close the handler for you on +block exit - you could do this if you don't need the handler any more. + +To illustrate how it works, we can add the following block of code to the +above:: + + if __name__ == '__main__': + logger = logging.getLogger('foo') + logger.addHandler(logging.StreamHandler()) + logger.setLevel(logging.INFO) + logger.info('1. This should appear just once on stderr.') + logger.debug('2. This should not appear.') + with LoggingContext(logger, level=logging.DEBUG): + logger.debug('3. This should appear once on stderr.') + logger.debug('4. This should not appear.') + h = logging.StreamHandler(sys.stdout) + with LoggingContext(logger, level=logging.DEBUG, handler=h, close=True): + logger.debug('5. This should appear twice - once on stderr and once on stdout.') + logger.info('6. This should appear just once on stderr.') + logger.debug('7. This should not appear.') + +We initially set the logger's level to ``INFO``, so message #1 appears and +message #2 doesn't. We then change the level to ``DEBUG`` temporarily in the +following ``with`` block, and so message #3 appears. After the block exits, the +logger's level is restored to ``INFO`` and so message #4 doesn't appear. In the +next ``with`` block, we set the level to ``DEBUG`` again but also add a handler +writing to ``sys.stdout``. Thus, message #5 appears twice on the console (once +via ``stderr`` and once via ``stdout``). After the ``with`` statement's +completion, the status is as it was before so message #6 appears (like message +#1) whereas message #7 doesn't (just like message #2). + +If we run the resulting script, the result is as follows:: + + $ python logctx.py + 1. This should appear just once on stderr. + 3. This should appear once on stderr. + 5. This should appear twice - once on stderr and once on stdout. + 5. This should appear twice - once on stderr and once on stdout. + 6. This should appear just once on stderr. + +If we run it again, but pipe ``stderr`` to ``/dev/null``, we see the following, +which is the only message written to ``stdout``:: + + $ python logctx.py 2>/dev/null + 5. This should appear twice - once on stderr and once on stdout. + +Once again, but piping ``stdout`` to ``/dev/null``, we get:: + + $ python logctx.py >/dev/null + 1. This should appear just once on stderr. + 3. This should appear once on stderr. + 5. This should appear twice - once on stderr and once on stdout. + 6. This should appear just once on stderr. + +In this case, the message #5 printed to ``stdout`` doesn't appear, as expected. + +Of course, the approach described here can be generalised, for example to attach +logging filters temporarily. Note that the above code works in Python 2 as well +as Python 3. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 18:14:24 2016 From: python-checkins at python.org (vinay.sajip) Date: Fri, 01 Apr 2016 22:14:24 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Added_a_cookbo?= =?utf-8?q?ok_recipe_for_a_logging_context_manager=2E?= Message-ID: <20160401221422.97853.23713.26F4A8CE@psf.io> https://hg.python.org/cpython/rev/a3a4155dfc1a changeset: 100826:a3a4155dfc1a branch: 2.7 parent: 100814:1d79e70e67b5 user: Vinay Sajip date: Fri Apr 01 23:06:57 2016 +0100 summary: Added a cookbook recipe for a logging context manager. files: Doc/howto/logging-cookbook.rst | 102 +++++++++++++++++++++ 1 files changed, 102 insertions(+), 0 deletions(-) diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -1425,3 +1425,105 @@ showing how the time is formatted both as local time and UTC, one for each handler. + + +.. _context-manager: + +Using a context manager for selective logging +--------------------------------------------- + +There are times when it would be useful to temporarily change the logging +configuration and revert it back after doing something. For this, a context +manager is the most obvious way of saving and restoring the logging context. +Here is a simple example of such a context manager, which allows you to +optionally change the logging level and add a logging handler purely in the +scope of the context manager:: + + import logging + import sys + + class LoggingContext(object): + def __init__(self, logger, level=None, handler=None, close=True): + self.logger = logger + self.level = level + self.handler = handler + self.close = close + + def __enter__(self): + if self.level is not None: + self.old_level = self.logger.level + self.logger.setLevel(self.level) + if self.handler: + self.logger.addHandler(self.handler) + + def __exit__(self, et, ev, tb): + if self.level is not None: + self.logger.setLevel(self.old_level) + if self.handler: + self.logger.removeHandler(self.handler) + if self.handler and self.close: + self.handler.close() + # implicit return of None => don't swallow exceptions + +If you specify a level value, the logger's level is set to that value in the +scope of the with block covered by the context manager. If you specify a +handler, it is added to the logger on entry to the block and removed on exit +from the block. You can also ask the manager to close the handler for you on +block exit - you could do this if you don't need the handler any more. + +To illustrate how it works, we can add the following block of code to the +above:: + + if __name__ == '__main__': + logger = logging.getLogger('foo') + logger.addHandler(logging.StreamHandler()) + logger.setLevel(logging.INFO) + logger.info('1. This should appear just once on stderr.') + logger.debug('2. This should not appear.') + with LoggingContext(logger, level=logging.DEBUG): + logger.debug('3. This should appear once on stderr.') + logger.debug('4. This should not appear.') + h = logging.StreamHandler(sys.stdout) + with LoggingContext(logger, level=logging.DEBUG, handler=h, close=True): + logger.debug('5. This should appear twice - once on stderr and once on stdout.') + logger.info('6. This should appear just once on stderr.') + logger.debug('7. This should not appear.') + +We initially set the logger's level to ``INFO``, so message #1 appears and +message #2 doesn't. We then change the level to ``DEBUG`` temporarily in the +following ``with`` block, and so message #3 appears. After the block exits, the +logger's level is restored to ``INFO`` and so message #4 doesn't appear. In the +next ``with`` block, we set the level to ``DEBUG`` again but also add a handler +writing to ``sys.stdout``. Thus, message #5 appears twice on the console (once +via ``stderr`` and once via ``stdout``). After the ``with`` statement's +completion, the status is as it was before so message #6 appears (like message +#1) whereas message #7 doesn't (just like message #2). + +If we run the resulting script, the result is as follows:: + + $ python logctx.py + 1. This should appear just once on stderr. + 3. This should appear once on stderr. + 5. This should appear twice - once on stderr and once on stdout. + 5. This should appear twice - once on stderr and once on stdout. + 6. This should appear just once on stderr. + +If we run it again, but pipe ``stderr`` to ``/dev/null``, we see the following, +which is the only message written to ``stdout``:: + + $ python logctx.py 2>/dev/null + 5. This should appear twice - once on stderr and once on stdout. + +Once again, but piping ``stdout`` to ``/dev/null``, we get:: + + $ python logctx.py >/dev/null + 1. This should appear just once on stderr. + 3. This should appear once on stderr. + 5. This should appear twice - once on stderr and once on stdout. + 6. This should appear just once on stderr. + +In this case, the message #5 printed to ``stdout`` doesn't appear, as expected. + +Of course, the approach described here can be generalised, for example to attach +logging filters temporarily. Note that the above code works in Python 2 as well +as Python 3. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 20:03:30 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 02 Apr 2016 00:03:30 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2Njc4?= =?utf-8?q?=3A_Fix_datetime=2Etzinfo_indexing_and_=E2=80=9Ctzinfo=E2=80=9D?= =?utf-8?q?_attribute_links?= Message-ID: <20160402000328.70495.70219.51356D79@psf.io> https://hg.python.org/cpython/rev/4cad272cec82 changeset: 100831:4cad272cec82 branch: 2.7 parent: 100826:a3a4155dfc1a user: Martin Panter date: Fri Apr 01 21:48:24 2016 +0000 summary: Issue #26678: Fix datetime.tzinfo indexing and ?tzinfo? attribute links files: Doc/library/datetime.rst | 103 +++++++++++++------------- 1 files changed, 53 insertions(+), 50 deletions(-) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -33,7 +33,7 @@ and to work with, at the cost of ignoring some aspects of reality. For applications requiring aware objects, :class:`.datetime` and :class:`.time` -objects have an optional time zone information attribute, :attr:`tzinfo`, that +objects have an optional time zone information attribute, :attr:`!tzinfo`, that can be set to an instance of a subclass of the abstract :class:`tzinfo` class. These :class:`tzinfo` objects capture information about the offset from UTC time, the time zone name, and whether Daylight Saving Time is in effect. Note @@ -83,7 +83,7 @@ An idealized time, independent of any particular day, assuming that every day has exactly 24\*60\*60 seconds (there is no notion of "leap seconds" here). Attributes: :attr:`hour`, :attr:`minute`, :attr:`second`, :attr:`microsecond`, - and :attr:`tzinfo`. + and :attr:`.tzinfo`. .. class:: datetime @@ -91,7 +91,7 @@ A combination of a date and a time. Attributes: :attr:`year`, :attr:`month`, :attr:`day`, :attr:`hour`, :attr:`minute`, :attr:`second`, :attr:`microsecond`, - and :attr:`tzinfo`. + and :attr:`.tzinfo`. .. class:: timedelta @@ -102,6 +102,7 @@ .. class:: tzinfo + :noindex: An abstract base class for time zone information objects. These are used by the :class:`.datetime` and :class:`.time` classes to provide a customizable notion of @@ -650,7 +651,7 @@ .. classmethod:: datetime.today() - Return the current local datetime, with :attr:`tzinfo` ``None``. This is + Return the current local datetime, with :attr:`.tzinfo` ``None``. This is equivalent to ``datetime.fromtimestamp(time.time())``. See also :meth:`now`, :meth:`fromtimestamp`. @@ -663,15 +664,15 @@ (for example, this may be possible on platforms supplying the C :c:func:`gettimeofday` function). - Else *tz* must be an instance of a class :class:`tzinfo` subclass, and the - current date and time are converted to *tz*'s time zone. In this case the + If *tz* is not ``None``, it must be an instance of a :class:`tzinfo` subclass, and the + current date and time are converted to *tz*?s time zone. In this case the result is equivalent to ``tz.fromutc(datetime.utcnow().replace(tzinfo=tz))``. See also :meth:`today`, :meth:`utcnow`. .. classmethod:: datetime.utcnow() - Return the current UTC date and time, with :attr:`tzinfo` ``None``. This is like + Return the current UTC date and time, with :attr:`.tzinfo` ``None``. This is like :meth:`now`, but returns the current UTC date and time, as a naive :class:`.datetime` object. See also :meth:`now`. @@ -683,8 +684,8 @@ specified, the timestamp is converted to the platform's local date and time, and the returned :class:`.datetime` object is naive. - Else *tz* must be an instance of a class :class:`tzinfo` subclass, and the - timestamp is converted to *tz*'s time zone. In this case the result is + If *tz* is not ``None``, it must be an instance of a :class:`tzinfo` subclass, and the + timestamp is converted to *tz*?s time zone. In this case the result is equivalent to ``tz.fromutc(datetime.utcfromtimestamp(timestamp).replace(tzinfo=tz))``. @@ -700,7 +701,7 @@ .. classmethod:: datetime.utcfromtimestamp(timestamp) Return the UTC :class:`.datetime` corresponding to the POSIX timestamp, with - :attr:`tzinfo` ``None``. This may raise :exc:`ValueError`, if the timestamp is + :attr:`.tzinfo` ``None``. This may raise :exc:`ValueError`, if the timestamp is out of the range of values supported by the platform C :c:func:`gmtime` function. It's common for this to be restricted to years in 1970 through 2038. See also :meth:`fromtimestamp`. @@ -711,17 +712,17 @@ Return the :class:`.datetime` corresponding to the proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1. :exc:`ValueError` is raised unless ``1 <= ordinal <= datetime.max.toordinal()``. The hour, minute, second and - microsecond of the result are all 0, and :attr:`tzinfo` is ``None``. + microsecond of the result are all 0, and :attr:`.tzinfo` is ``None``. .. classmethod:: datetime.combine(date, time) Return a new :class:`.datetime` object whose date components are equal to the - given :class:`date` object's, and whose time components and :attr:`tzinfo` + given :class:`date` object's, and whose time components and :attr:`.tzinfo` attributes are equal to the given :class:`.time` object's. For any :class:`.datetime` object *d*, ``d == datetime.combine(d.date(), d.timetz())``. If date is a - :class:`.datetime` object, its time components and :attr:`tzinfo` attributes + :class:`.datetime` object, its time components and :attr:`.tzinfo` attributes are ignored. @@ -818,7 +819,7 @@ (1) datetime2 is a duration of timedelta removed from datetime1, moving forward in time if ``timedelta.days`` > 0, or backward if ``timedelta.days`` < 0. The - result has the same :attr:`tzinfo` attribute as the input datetime, and + result has the same :attr:`~.datetime.tzinfo` attribute as the input datetime, and datetime2 - datetime1 == timedelta after. :exc:`OverflowError` is raised if datetime2.year would be smaller than :const:`MINYEAR` or larger than :const:`MAXYEAR`. Note that no time zone adjustments are done even if the @@ -826,7 +827,7 @@ (2) Computes the datetime2 such that datetime2 + timedelta == datetime1. As for - addition, the result has the same :attr:`tzinfo` attribute as the input + addition, the result has the same :attr:`~.datetime.tzinfo` attribute as the input datetime, and no time zone adjustments are done even if the input is aware. This isn't quite equivalent to datetime1 + (-timedelta), because -timedelta in isolation can overflow in cases where datetime1 - timedelta does not. @@ -836,12 +837,12 @@ both operands are naive, or if both are aware. If one is aware and the other is naive, :exc:`TypeError` is raised. - If both are naive, or both are aware and have the same :attr:`tzinfo` attribute, - the :attr:`tzinfo` attributes are ignored, and the result is a :class:`timedelta` + If both are naive, or both are aware and have the same :attr:`~.datetime.tzinfo` attribute, + the :attr:`~.datetime.tzinfo` attributes are ignored, and the result is a :class:`timedelta` object *t* such that ``datetime2 + t == datetime1``. No time zone adjustments are done in this case. - If both are aware and have different :attr:`tzinfo` attributes, ``a-b`` acts + If both are aware and have different :attr:`~.datetime.tzinfo` attributes, ``a-b`` acts as if *a* and *b* were first converted to naive UTC datetimes first. The result is ``(a.replace(tzinfo=None) - a.utcoffset()) - (b.replace(tzinfo=None) - b.utcoffset())`` except that the implementation never overflows. @@ -851,9 +852,9 @@ *datetime2* in time. If one comparand is naive and the other is aware, :exc:`TypeError` is raised. - If both comparands are aware, and have the same :attr:`tzinfo` attribute, the - common :attr:`tzinfo` attribute is ignored and the base datetimes are - compared. If both comparands are aware and have different :attr:`tzinfo` + If both comparands are aware, and have the same :attr:`~.datetime.tzinfo` attribute, the + common :attr:`~.datetime.tzinfo` attribute is ignored and the base datetimes are + compared. If both comparands are aware and have different :attr:`~.datetime.tzinfo` attributes, the comparands are first adjusted by subtracting their UTC offsets (obtained from ``self.utcoffset()``). @@ -882,7 +883,7 @@ .. method:: datetime.time() Return :class:`.time` object with same hour, minute, second and microsecond. - :attr:`tzinfo` is ``None``. See also method :meth:`timetz`. + :attr:`.tzinfo` is ``None``. See also method :meth:`timetz`. .. method:: datetime.timetz() @@ -901,7 +902,7 @@ .. method:: datetime.astimezone(tz) - Return a :class:`.datetime` object with new :attr:`tzinfo` attribute *tz*, + Return a :class:`.datetime` object with new :attr:`.tzinfo` attribute *tz*, adjusting the date and time data so the result is the same UTC time as *self*, but in *tz*'s local time. @@ -939,7 +940,7 @@ .. method:: datetime.utcoffset() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.utcoffset(self)``, and raises an exception if the latter doesn't return ``None``, or a :class:`timedelta` object representing a whole number of minutes with magnitude less than one day. @@ -947,7 +948,7 @@ .. method:: datetime.dst() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.dst(self)``, and raises an exception if the latter doesn't return ``None``, or a :class:`timedelta` object representing a whole number of minutes with magnitude less than one day. @@ -955,7 +956,7 @@ .. method:: datetime.tzname() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.tzname(self)``, raises an exception if the latter doesn't return ``None`` or a string object, @@ -967,7 +968,7 @@ d.hour, d.minute, d.second, d.weekday(), yday, dst))``, where ``yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1`` is the day number within the current year starting with ``1`` for January 1st. The :attr:`tm_isdst` flag - of the result is set according to the :meth:`dst` method: :attr:`tzinfo` is + of the result is set according to the :meth:`dst` method: :attr:`.tzinfo` is ``None`` or :meth:`dst` returns ``None``, :attr:`tm_isdst` is set to ``-1``; else if :meth:`dst` returns a non-zero value, :attr:`tm_isdst` is set to ``1``; else :attr:`tm_isdst` is set to ``0``. @@ -1242,9 +1243,9 @@ * comparison of :class:`.time` to :class:`.time`, where *a* is considered less than *b* when *a* precedes *b* in time. If one comparand is naive and the other is aware, :exc:`TypeError` is raised. If both comparands are aware, and have - the same :attr:`tzinfo` attribute, the common :attr:`tzinfo` attribute is + the same :attr:`~time.tzinfo` attribute, the common :attr:`~time.tzinfo` attribute is ignored and the base times are compared. If both comparands are aware and - have different :attr:`tzinfo` attributes, the comparands are first adjusted by + have different :attr:`~time.tzinfo` attributes, the comparands are first adjusted by subtracting their UTC offsets (obtained from ``self.utcoffset()``). In order to stop mixed-type comparisons from falling back to the default comparison by object address, when a :class:`.time` object is compared to an object of a @@ -1299,7 +1300,7 @@ .. method:: time.utcoffset() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.utcoffset(None)``, and raises an exception if the latter doesn't return ``None`` or a :class:`timedelta` object representing a whole number of minutes with magnitude less than one day. @@ -1307,7 +1308,7 @@ .. method:: time.dst() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.dst(None)``, and raises an exception if the latter doesn't return ``None``, or a :class:`timedelta` object representing a whole number of minutes with magnitude less than one day. @@ -1315,7 +1316,7 @@ .. method:: time.tzname() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.tzname(None)``, or raises an exception if the latter doesn't return ``None`` or a string object. @@ -1352,26 +1353,28 @@ :class:`tzinfo` Objects ----------------------- -:class:`tzinfo` is an abstract base class, meaning that this class should not be -instantiated directly. You need to derive a concrete subclass, and (at least) -supply implementations of the standard :class:`tzinfo` methods needed by the -:class:`.datetime` methods you use. The :mod:`datetime` module does not supply -any concrete subclasses of :class:`tzinfo`. +.. class:: tzinfo() -An instance of (a concrete subclass of) :class:`tzinfo` can be passed to the -constructors for :class:`.datetime` and :class:`.time` objects. The latter objects -view their attributes as being in local time, and the :class:`tzinfo` object -supports methods revealing offset of local time from UTC, the name of the time -zone, and DST offset, all relative to a date or time object passed to them. + This is an abstract base class, meaning that this class should not be + instantiated directly. You need to derive a concrete subclass, and (at least) + supply implementations of the standard :class:`tzinfo` methods needed by the + :class:`.datetime` methods you use. The :mod:`datetime` module does not supply + any concrete subclasses of :class:`tzinfo`. -Special requirement for pickling: A :class:`tzinfo` subclass must have an -:meth:`__init__` method that can be called with no arguments, else it can be -pickled but possibly not unpickled again. This is a technical requirement that -may be relaxed in the future. + An instance of (a concrete subclass of) :class:`tzinfo` can be passed to the + constructors for :class:`.datetime` and :class:`.time` objects. The latter objects + view their attributes as being in local time, and the :class:`tzinfo` object + supports methods revealing offset of local time from UTC, the name of the time + zone, and DST offset, all relative to a date or time object passed to them. -A concrete subclass of :class:`tzinfo` may need to implement the following -methods. Exactly which methods are needed depends on the uses made of aware -:mod:`datetime` objects. If in doubt, simply implement all of them. + Special requirement for pickling: A :class:`tzinfo` subclass must have an + :meth:`__init__` method that can be called with no arguments, else it can be + pickled but possibly not unpickled again. This is a technical requirement that + may be relaxed in the future. + + A concrete subclass of :class:`tzinfo` may need to implement the following + methods. Exactly which methods are needed depends on the uses made of aware + :mod:`datetime` objects. If in doubt, simply implement all of them. .. method:: tzinfo.utcoffset(self, dt) @@ -1404,7 +1407,7 @@ (see :meth:`utcoffset` for details). Note that DST offset, if applicable, has already been added to the UTC offset returned by :meth:`utcoffset`, so there's no need to consult :meth:`dst` unless you're interested in obtaining DST info - separately. For example, :meth:`datetime.timetuple` calls its :attr:`tzinfo` + separately. For example, :meth:`datetime.timetuple` calls its :attr:`~.datetime.tzinfo` attribute's :meth:`dst` method to determine how the :attr:`tm_isdst` flag should be set, and :meth:`tzinfo.fromutc` calls :meth:`dst` to account for DST changes when crossing time zones. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 20:03:30 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 02 Apr 2016 00:03:30 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2Njc4?= =?utf-8?q?=3A_Fix_indexing_of_datetime=2Etzinfo_and_timezone_classes?= Message-ID: <20160402000327.70511.69605.65C57416@psf.io> https://hg.python.org/cpython/rev/30e077f886cc changeset: 100829:30e077f886cc branch: 3.5 parent: 100827:98d6a20a6c71 user: Martin Panter date: Fri Apr 01 21:48:24 2016 +0000 summary: Issue #26678: Fix indexing of datetime.tzinfo and timezone classes Also fix links to the ?tzinfo? class and attributes. files: Doc/library/datetime.rst | 128 +++++++++++++------------- 1 files changed, 66 insertions(+), 62 deletions(-) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -33,7 +33,7 @@ understand and to work with, at the cost of ignoring some aspects of reality. For applications requiring aware objects, :class:`.datetime` and :class:`.time` -objects have an optional time zone information attribute, :attr:`tzinfo`, that +objects have an optional time zone information attribute, :attr:`!tzinfo`, that can be set to an instance of a subclass of the abstract :class:`tzinfo` class. These :class:`tzinfo` objects capture information about the offset from UTC time, the time zone name, and whether Daylight Saving Time is in effect. Note @@ -85,7 +85,7 @@ An idealized time, independent of any particular day, assuming that every day has exactly 24\*60\*60 seconds (there is no notion of "leap seconds" here). Attributes: :attr:`hour`, :attr:`minute`, :attr:`second`, :attr:`microsecond`, - and :attr:`tzinfo`. + and :attr:`.tzinfo`. .. class:: datetime @@ -93,7 +93,7 @@ A combination of a date and a time. Attributes: :attr:`year`, :attr:`month`, :attr:`day`, :attr:`hour`, :attr:`minute`, :attr:`second`, :attr:`microsecond`, - and :attr:`tzinfo`. + and :attr:`.tzinfo`. .. class:: timedelta @@ -104,6 +104,7 @@ .. class:: tzinfo + :noindex: An abstract base class for time zone information objects. These are used by the :class:`.datetime` and :class:`.time` classes to provide a customizable notion of @@ -111,6 +112,7 @@ time). .. class:: timezone + :noindex: A class that implements the :class:`tzinfo` abstract base class as a fixed offset from the UTC. @@ -697,7 +699,7 @@ .. classmethod:: datetime.today() - Return the current local datetime, with :attr:`tzinfo` ``None``. This is + Return the current local datetime, with :attr:`.tzinfo` ``None``. This is equivalent to ``datetime.fromtimestamp(time.time())``. See also :meth:`now`, :meth:`fromtimestamp`. @@ -710,15 +712,15 @@ (for example, this may be possible on platforms supplying the C :c:func:`gettimeofday` function). - Else *tz* must be an instance of a class :class:`tzinfo` subclass, and the - current date and time are converted to *tz*'s time zone. In this case the + If *tz* is not ``None``, it must be an instance of a :class:`tzinfo` subclass, and the + current date and time are converted to *tz*?s time zone. In this case the result is equivalent to ``tz.fromutc(datetime.utcnow().replace(tzinfo=tz))``. See also :meth:`today`, :meth:`utcnow`. .. classmethod:: datetime.utcnow() - Return the current UTC date and time, with :attr:`tzinfo` ``None``. This is like + Return the current UTC date and time, with :attr:`.tzinfo` ``None``. This is like :meth:`now`, but returns the current UTC date and time, as a naive :class:`.datetime` object. An aware current UTC datetime can be obtained by calling ``datetime.now(timezone.utc)``. See also :meth:`now`. @@ -730,8 +732,8 @@ specified, the timestamp is converted to the platform's local date and time, and the returned :class:`.datetime` object is naive. - Else *tz* must be an instance of a class :class:`tzinfo` subclass, and the - timestamp is converted to *tz*'s time zone. In this case the result is + If *tz* is not ``None``, it must be an instance of a :class:`tzinfo` subclass, and the + timestamp is converted to *tz*?s time zone. In this case the result is equivalent to ``tz.fromutc(datetime.utcfromtimestamp(timestamp).replace(tzinfo=tz))``. @@ -756,7 +758,7 @@ .. classmethod:: datetime.utcfromtimestamp(timestamp) Return the UTC :class:`.datetime` corresponding to the POSIX timestamp, with - :attr:`tzinfo` ``None``. This may raise :exc:`OverflowError`, if the timestamp is + :attr:`.tzinfo` ``None``. This may raise :exc:`OverflowError`, if the timestamp is out of the range of values supported by the platform C :c:func:`gmtime` function, and :exc:`OSError` on :c:func:`gmtime` failure. It's common for this to be restricted to years in 1970 through 2038. @@ -785,17 +787,17 @@ Return the :class:`.datetime` corresponding to the proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1. :exc:`ValueError` is raised unless ``1 <= ordinal <= datetime.max.toordinal()``. The hour, minute, second and - microsecond of the result are all 0, and :attr:`tzinfo` is ``None``. + microsecond of the result are all 0, and :attr:`.tzinfo` is ``None``. .. classmethod:: datetime.combine(date, time) Return a new :class:`.datetime` object whose date components are equal to the - given :class:`date` object's, and whose time components and :attr:`tzinfo` + given :class:`date` object's, and whose time components and :attr:`.tzinfo` attributes are equal to the given :class:`.time` object's. For any :class:`.datetime` object *d*, ``d == datetime.combine(d.date(), d.timetz())``. If date is a - :class:`.datetime` object, its time components and :attr:`tzinfo` attributes + :class:`.datetime` object, its time components and :attr:`.tzinfo` attributes are ignored. @@ -891,7 +893,7 @@ (1) datetime2 is a duration of timedelta removed from datetime1, moving forward in time if ``timedelta.days`` > 0, or backward if ``timedelta.days`` < 0. The - result has the same :attr:`tzinfo` attribute as the input datetime, and + result has the same :attr:`~.datetime.tzinfo` attribute as the input datetime, and datetime2 - datetime1 == timedelta after. :exc:`OverflowError` is raised if datetime2.year would be smaller than :const:`MINYEAR` or larger than :const:`MAXYEAR`. Note that no time zone adjustments are done even if the @@ -899,7 +901,7 @@ (2) Computes the datetime2 such that datetime2 + timedelta == datetime1. As for - addition, the result has the same :attr:`tzinfo` attribute as the input + addition, the result has the same :attr:`~.datetime.tzinfo` attribute as the input datetime, and no time zone adjustments are done even if the input is aware. This isn't quite equivalent to datetime1 + (-timedelta), because -timedelta in isolation can overflow in cases where datetime1 - timedelta does not. @@ -909,12 +911,12 @@ both operands are naive, or if both are aware. If one is aware and the other is naive, :exc:`TypeError` is raised. - If both are naive, or both are aware and have the same :attr:`tzinfo` attribute, - the :attr:`tzinfo` attributes are ignored, and the result is a :class:`timedelta` + If both are naive, or both are aware and have the same :attr:`~.datetime.tzinfo` attribute, + the :attr:`~.datetime.tzinfo` attributes are ignored, and the result is a :class:`timedelta` object *t* such that ``datetime2 + t == datetime1``. No time zone adjustments are done in this case. - If both are aware and have different :attr:`tzinfo` attributes, ``a-b`` acts + If both are aware and have different :attr:`~.datetime.tzinfo` attributes, ``a-b`` acts as if *a* and *b* were first converted to naive UTC datetimes first. The result is ``(a.replace(tzinfo=None) - a.utcoffset()) - (b.replace(tzinfo=None) - b.utcoffset())`` except that the implementation never overflows. @@ -927,14 +929,14 @@ is raised if an order comparison is attempted. For equality comparisons, naive instances are never equal to aware instances. - If both comparands are aware, and have the same :attr:`tzinfo` attribute, the - common :attr:`tzinfo` attribute is ignored and the base datetimes are - compared. If both comparands are aware and have different :attr:`tzinfo` + If both comparands are aware, and have the same :attr:`~.datetime.tzinfo` attribute, the + common :attr:`~.datetime.tzinfo` attribute is ignored and the base datetimes are + compared. If both comparands are aware and have different :attr:`~.datetime.tzinfo` attributes, the comparands are first adjusted by subtracting their UTC offsets (obtained from ``self.utcoffset()``). .. versionchanged:: 3.3 - Equality comparisons between naive and aware :class:`datetime` + Equality comparisons between naive and aware :class:`.datetime` instances don't raise :exc:`TypeError`. .. note:: @@ -962,7 +964,7 @@ .. method:: datetime.time() Return :class:`.time` object with same hour, minute, second and microsecond. - :attr:`tzinfo` is ``None``. See also method :meth:`timetz`. + :attr:`.tzinfo` is ``None``. See also method :meth:`timetz`. .. method:: datetime.timetz() @@ -981,7 +983,7 @@ .. method:: datetime.astimezone(tz=None) - Return a :class:`datetime` object with new :attr:`tzinfo` attribute *tz*, + Return a :class:`.datetime` object with new :attr:`.tzinfo` attribute *tz*, adjusting the date and time data so the result is the same UTC time as *self*, but in *tz*'s local time. @@ -991,7 +993,7 @@ not return ``None``). If called without arguments (or with ``tz=None``) the system local - timezone is assumed. The ``tzinfo`` attribute of the converted + timezone is assumed. The ``.tzinfo`` attribute of the converted datetime instance will be set to an instance of :class:`timezone` with the zone name and offset obtained from the OS. @@ -1027,7 +1029,7 @@ .. method:: datetime.utcoffset() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.utcoffset(self)``, and raises an exception if the latter doesn't return ``None``, or a :class:`timedelta` object representing a whole number of minutes with magnitude less than one day. @@ -1035,7 +1037,7 @@ .. method:: datetime.dst() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.dst(self)``, and raises an exception if the latter doesn't return ``None``, or a :class:`timedelta` object representing a whole number of minutes with magnitude less than one day. @@ -1043,7 +1045,7 @@ .. method:: datetime.tzname() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.tzname(self)``, raises an exception if the latter doesn't return ``None`` or a string object, @@ -1055,7 +1057,7 @@ d.hour, d.minute, d.second, d.weekday(), yday, dst))``, where ``yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1`` is the day number within the current year starting with ``1`` for January 1st. The :attr:`tm_isdst` flag - of the result is set according to the :meth:`dst` method: :attr:`tzinfo` is + of the result is set according to the :meth:`dst` method: :attr:`.tzinfo` is ``None`` or :meth:`dst` returns ``None``, :attr:`tm_isdst` is set to ``-1``; else if :meth:`dst` returns a non-zero value, :attr:`tm_isdst` is set to ``1``; else :attr:`tm_isdst` is set to ``0``. @@ -1082,18 +1084,18 @@ .. method:: datetime.timestamp() - Return POSIX timestamp corresponding to the :class:`datetime` + Return POSIX timestamp corresponding to the :class:`.datetime` instance. The return value is a :class:`float` similar to that returned by :func:`time.time`. - Naive :class:`datetime` instances are assumed to represent local + Naive :class:`.datetime` instances are assumed to represent local time and this method relies on the platform C :c:func:`mktime` - function to perform the conversion. Since :class:`datetime` + function to perform the conversion. Since :class:`.datetime` supports wider range of values than :c:func:`mktime` on many platforms, this method may raise :exc:`OverflowError` for times far in the past or far in the future. - For aware :class:`datetime` instances, the return value is computed + For aware :class:`.datetime` instances, the return value is computed as:: (dt - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds() @@ -1103,7 +1105,7 @@ .. note:: There is no method to obtain the POSIX timestamp directly from a - naive :class:`datetime` instance representing UTC time. If your + naive :class:`.datetime` instance representing UTC time. If your application uses this convention and your system timezone is not set to UTC, you can obtain the POSIX timestamp by supplying ``tzinfo=timezone.utc``:: @@ -1367,9 +1369,9 @@ comparisons, naive instances are never equal to aware instances. If both comparands are aware, and have - the same :attr:`tzinfo` attribute, the common :attr:`tzinfo` attribute is + the same :attr:`~time.tzinfo` attribute, the common :attr:`~time.tzinfo` attribute is ignored and the base times are compared. If both comparands are aware and - have different :attr:`tzinfo` attributes, the comparands are first adjusted by + have different :attr:`~time.tzinfo` attributes, the comparands are first adjusted by subtracting their UTC offsets (obtained from ``self.utcoffset()``). In order to stop mixed-type comparisons from falling back to the default comparison by object address, when a :class:`.time` object is compared to an object of a @@ -1432,7 +1434,7 @@ .. method:: time.utcoffset() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.utcoffset(None)``, and raises an exception if the latter doesn't return ``None`` or a :class:`timedelta` object representing a whole number of minutes with magnitude less than one day. @@ -1440,7 +1442,7 @@ .. method:: time.dst() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.dst(None)``, and raises an exception if the latter doesn't return ``None``, or a :class:`timedelta` object representing a whole number of minutes with magnitude less than one day. @@ -1448,7 +1450,7 @@ .. method:: time.tzname() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.tzname(None)``, or raises an exception if the latter doesn't return ``None`` or a string object. @@ -1485,28 +1487,30 @@ :class:`tzinfo` Objects ----------------------- -:class:`tzinfo` is an abstract base class, meaning that this class should not be -instantiated directly. You need to derive a concrete subclass, and (at least) -supply implementations of the standard :class:`tzinfo` methods needed by the -:class:`.datetime` methods you use. The :mod:`datetime` module supplies -a simple concrete subclass of :class:`tzinfo` :class:`timezone` which can represent -timezones with fixed offset from UTC such as UTC itself or North American EST and -EDT. - -An instance of (a concrete subclass of) :class:`tzinfo` can be passed to the -constructors for :class:`.datetime` and :class:`.time` objects. The latter objects -view their attributes as being in local time, and the :class:`tzinfo` object -supports methods revealing offset of local time from UTC, the name of the time -zone, and DST offset, all relative to a date or time object passed to them. - -Special requirement for pickling: A :class:`tzinfo` subclass must have an -:meth:`__init__` method that can be called with no arguments, else it can be -pickled but possibly not unpickled again. This is a technical requirement that -may be relaxed in the future. - -A concrete subclass of :class:`tzinfo` may need to implement the following -methods. Exactly which methods are needed depends on the uses made of aware -:mod:`datetime` objects. If in doubt, simply implement all of them. +.. class:: tzinfo() + + This is an abstract base class, meaning that this class should not be + instantiated directly. You need to derive a concrete subclass, and (at least) + supply implementations of the standard :class:`tzinfo` methods needed by the + :class:`.datetime` methods you use. The :mod:`datetime` module supplies + a simple concrete subclass of :class:`tzinfo`, :class:`timezone`, which can represent + timezones with fixed offset from UTC such as UTC itself or North American EST and + EDT. + + An instance of (a concrete subclass of) :class:`tzinfo` can be passed to the + constructors for :class:`.datetime` and :class:`.time` objects. The latter objects + view their attributes as being in local time, and the :class:`tzinfo` object + supports methods revealing offset of local time from UTC, the name of the time + zone, and DST offset, all relative to a date or time object passed to them. + + Special requirement for pickling: A :class:`tzinfo` subclass must have an + :meth:`__init__` method that can be called with no arguments, else it can be + pickled but possibly not unpickled again. This is a technical requirement that + may be relaxed in the future. + + A concrete subclass of :class:`tzinfo` may need to implement the following + methods. Exactly which methods are needed depends on the uses made of aware + :mod:`datetime` objects. If in doubt, simply implement all of them. .. method:: tzinfo.utcoffset(dt) @@ -1539,7 +1543,7 @@ (see :meth:`utcoffset` for details). Note that DST offset, if applicable, has already been added to the UTC offset returned by :meth:`utcoffset`, so there's no need to consult :meth:`dst` unless you're interested in obtaining DST info - separately. For example, :meth:`datetime.timetuple` calls its :attr:`tzinfo` + separately. For example, :meth:`datetime.timetuple` calls its :attr:`~.datetime.tzinfo` attribute's :meth:`dst` method to determine how the :attr:`tm_isdst` flag should be set, and :meth:`tzinfo.fromutc` calls :meth:`dst` to account for DST changes when crossing time zones. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 20:03:30 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 02 Apr 2016 00:03:30 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326678=3A_Merge_datetime_doc_fixes_from_3=2E5?= Message-ID: <20160402000327.49914.29798.C791B0CF@psf.io> https://hg.python.org/cpython/rev/854db1a2cd98 changeset: 100830:854db1a2cd98 parent: 100828:09cd137a2e8b parent: 100829:30e077f886cc user: Martin Panter date: Fri Apr 01 23:20:52 2016 +0000 summary: Issue #26678: Merge datetime doc fixes from 3.5 files: Doc/library/datetime.rst | 128 +++++++++++++------------- 1 files changed, 66 insertions(+), 62 deletions(-) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -33,7 +33,7 @@ understand and to work with, at the cost of ignoring some aspects of reality. For applications requiring aware objects, :class:`.datetime` and :class:`.time` -objects have an optional time zone information attribute, :attr:`tzinfo`, that +objects have an optional time zone information attribute, :attr:`!tzinfo`, that can be set to an instance of a subclass of the abstract :class:`tzinfo` class. These :class:`tzinfo` objects capture information about the offset from UTC time, the time zone name, and whether Daylight Saving Time is in effect. Note @@ -85,7 +85,7 @@ An idealized time, independent of any particular day, assuming that every day has exactly 24\*60\*60 seconds (there is no notion of "leap seconds" here). Attributes: :attr:`hour`, :attr:`minute`, :attr:`second`, :attr:`microsecond`, - and :attr:`tzinfo`. + and :attr:`.tzinfo`. .. class:: datetime @@ -93,7 +93,7 @@ A combination of a date and a time. Attributes: :attr:`year`, :attr:`month`, :attr:`day`, :attr:`hour`, :attr:`minute`, :attr:`second`, :attr:`microsecond`, - and :attr:`tzinfo`. + and :attr:`.tzinfo`. .. class:: timedelta @@ -104,6 +104,7 @@ .. class:: tzinfo + :noindex: An abstract base class for time zone information objects. These are used by the :class:`.datetime` and :class:`.time` classes to provide a customizable notion of @@ -111,6 +112,7 @@ time). .. class:: timezone + :noindex: A class that implements the :class:`tzinfo` abstract base class as a fixed offset from the UTC. @@ -698,7 +700,7 @@ .. classmethod:: datetime.today() - Return the current local datetime, with :attr:`tzinfo` ``None``. This is + Return the current local datetime, with :attr:`.tzinfo` ``None``. This is equivalent to ``datetime.fromtimestamp(time.time())``. See also :meth:`now`, :meth:`fromtimestamp`. @@ -711,15 +713,15 @@ (for example, this may be possible on platforms supplying the C :c:func:`gettimeofday` function). - Else *tz* must be an instance of a class :class:`tzinfo` subclass, and the - current date and time are converted to *tz*'s time zone. In this case the + If *tz* is not ``None``, it must be an instance of a :class:`tzinfo` subclass, and the + current date and time are converted to *tz*?s time zone. In this case the result is equivalent to ``tz.fromutc(datetime.utcnow().replace(tzinfo=tz))``. See also :meth:`today`, :meth:`utcnow`. .. classmethod:: datetime.utcnow() - Return the current UTC date and time, with :attr:`tzinfo` ``None``. This is like + Return the current UTC date and time, with :attr:`.tzinfo` ``None``. This is like :meth:`now`, but returns the current UTC date and time, as a naive :class:`.datetime` object. An aware current UTC datetime can be obtained by calling ``datetime.now(timezone.utc)``. See also :meth:`now`. @@ -731,8 +733,8 @@ specified, the timestamp is converted to the platform's local date and time, and the returned :class:`.datetime` object is naive. - Else *tz* must be an instance of a class :class:`tzinfo` subclass, and the - timestamp is converted to *tz*'s time zone. In this case the result is + If *tz* is not ``None``, it must be an instance of a :class:`tzinfo` subclass, and the + timestamp is converted to *tz*?s time zone. In this case the result is equivalent to ``tz.fromutc(datetime.utcfromtimestamp(timestamp).replace(tzinfo=tz))``. @@ -757,7 +759,7 @@ .. classmethod:: datetime.utcfromtimestamp(timestamp) Return the UTC :class:`.datetime` corresponding to the POSIX timestamp, with - :attr:`tzinfo` ``None``. This may raise :exc:`OverflowError`, if the timestamp is + :attr:`.tzinfo` ``None``. This may raise :exc:`OverflowError`, if the timestamp is out of the range of values supported by the platform C :c:func:`gmtime` function, and :exc:`OSError` on :c:func:`gmtime` failure. It's common for this to be restricted to years in 1970 through 2038. @@ -786,17 +788,17 @@ Return the :class:`.datetime` corresponding to the proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1. :exc:`ValueError` is raised unless ``1 <= ordinal <= datetime.max.toordinal()``. The hour, minute, second and - microsecond of the result are all 0, and :attr:`tzinfo` is ``None``. + microsecond of the result are all 0, and :attr:`.tzinfo` is ``None``. .. classmethod:: datetime.combine(date, time) Return a new :class:`.datetime` object whose date components are equal to the - given :class:`date` object's, and whose time components and :attr:`tzinfo` + given :class:`date` object's, and whose time components and :attr:`.tzinfo` attributes are equal to the given :class:`.time` object's. For any :class:`.datetime` object *d*, ``d == datetime.combine(d.date(), d.timetz())``. If date is a - :class:`.datetime` object, its time components and :attr:`tzinfo` attributes + :class:`.datetime` object, its time components and :attr:`.tzinfo` attributes are ignored. @@ -892,7 +894,7 @@ (1) datetime2 is a duration of timedelta removed from datetime1, moving forward in time if ``timedelta.days`` > 0, or backward if ``timedelta.days`` < 0. The - result has the same :attr:`tzinfo` attribute as the input datetime, and + result has the same :attr:`~.datetime.tzinfo` attribute as the input datetime, and datetime2 - datetime1 == timedelta after. :exc:`OverflowError` is raised if datetime2.year would be smaller than :const:`MINYEAR` or larger than :const:`MAXYEAR`. Note that no time zone adjustments are done even if the @@ -900,7 +902,7 @@ (2) Computes the datetime2 such that datetime2 + timedelta == datetime1. As for - addition, the result has the same :attr:`tzinfo` attribute as the input + addition, the result has the same :attr:`~.datetime.tzinfo` attribute as the input datetime, and no time zone adjustments are done even if the input is aware. This isn't quite equivalent to datetime1 + (-timedelta), because -timedelta in isolation can overflow in cases where datetime1 - timedelta does not. @@ -910,12 +912,12 @@ both operands are naive, or if both are aware. If one is aware and the other is naive, :exc:`TypeError` is raised. - If both are naive, or both are aware and have the same :attr:`tzinfo` attribute, - the :attr:`tzinfo` attributes are ignored, and the result is a :class:`timedelta` + If both are naive, or both are aware and have the same :attr:`~.datetime.tzinfo` attribute, + the :attr:`~.datetime.tzinfo` attributes are ignored, and the result is a :class:`timedelta` object *t* such that ``datetime2 + t == datetime1``. No time zone adjustments are done in this case. - If both are aware and have different :attr:`tzinfo` attributes, ``a-b`` acts + If both are aware and have different :attr:`~.datetime.tzinfo` attributes, ``a-b`` acts as if *a* and *b* were first converted to naive UTC datetimes first. The result is ``(a.replace(tzinfo=None) - a.utcoffset()) - (b.replace(tzinfo=None) - b.utcoffset())`` except that the implementation never overflows. @@ -928,14 +930,14 @@ is raised if an order comparison is attempted. For equality comparisons, naive instances are never equal to aware instances. - If both comparands are aware, and have the same :attr:`tzinfo` attribute, the - common :attr:`tzinfo` attribute is ignored and the base datetimes are - compared. If both comparands are aware and have different :attr:`tzinfo` + If both comparands are aware, and have the same :attr:`~.datetime.tzinfo` attribute, the + common :attr:`~.datetime.tzinfo` attribute is ignored and the base datetimes are + compared. If both comparands are aware and have different :attr:`~.datetime.tzinfo` attributes, the comparands are first adjusted by subtracting their UTC offsets (obtained from ``self.utcoffset()``). .. versionchanged:: 3.3 - Equality comparisons between naive and aware :class:`datetime` + Equality comparisons between naive and aware :class:`.datetime` instances don't raise :exc:`TypeError`. .. note:: @@ -963,7 +965,7 @@ .. method:: datetime.time() Return :class:`.time` object with same hour, minute, second and microsecond. - :attr:`tzinfo` is ``None``. See also method :meth:`timetz`. + :attr:`.tzinfo` is ``None``. See also method :meth:`timetz`. .. method:: datetime.timetz() @@ -982,7 +984,7 @@ .. method:: datetime.astimezone(tz=None) - Return a :class:`datetime` object with new :attr:`tzinfo` attribute *tz*, + Return a :class:`.datetime` object with new :attr:`.tzinfo` attribute *tz*, adjusting the date and time data so the result is the same UTC time as *self*, but in *tz*'s local time. @@ -992,7 +994,7 @@ not return ``None``). If called without arguments (or with ``tz=None``) the system local - timezone is assumed. The ``tzinfo`` attribute of the converted + timezone is assumed. The ``.tzinfo`` attribute of the converted datetime instance will be set to an instance of :class:`timezone` with the zone name and offset obtained from the OS. @@ -1028,7 +1030,7 @@ .. method:: datetime.utcoffset() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.utcoffset(self)``, and raises an exception if the latter doesn't return ``None``, or a :class:`timedelta` object representing a whole number of minutes with magnitude less than one day. @@ -1036,7 +1038,7 @@ .. method:: datetime.dst() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.dst(self)``, and raises an exception if the latter doesn't return ``None``, or a :class:`timedelta` object representing a whole number of minutes with magnitude less than one day. @@ -1044,7 +1046,7 @@ .. method:: datetime.tzname() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.tzname(self)``, raises an exception if the latter doesn't return ``None`` or a string object, @@ -1056,7 +1058,7 @@ d.hour, d.minute, d.second, d.weekday(), yday, dst))``, where ``yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1`` is the day number within the current year starting with ``1`` for January 1st. The :attr:`tm_isdst` flag - of the result is set according to the :meth:`dst` method: :attr:`tzinfo` is + of the result is set according to the :meth:`dst` method: :attr:`.tzinfo` is ``None`` or :meth:`dst` returns ``None``, :attr:`tm_isdst` is set to ``-1``; else if :meth:`dst` returns a non-zero value, :attr:`tm_isdst` is set to ``1``; else :attr:`tm_isdst` is set to ``0``. @@ -1083,18 +1085,18 @@ .. method:: datetime.timestamp() - Return POSIX timestamp corresponding to the :class:`datetime` + Return POSIX timestamp corresponding to the :class:`.datetime` instance. The return value is a :class:`float` similar to that returned by :func:`time.time`. - Naive :class:`datetime` instances are assumed to represent local + Naive :class:`.datetime` instances are assumed to represent local time and this method relies on the platform C :c:func:`mktime` - function to perform the conversion. Since :class:`datetime` + function to perform the conversion. Since :class:`.datetime` supports wider range of values than :c:func:`mktime` on many platforms, this method may raise :exc:`OverflowError` for times far in the past or far in the future. - For aware :class:`datetime` instances, the return value is computed + For aware :class:`.datetime` instances, the return value is computed as:: (dt - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds() @@ -1104,7 +1106,7 @@ .. note:: There is no method to obtain the POSIX timestamp directly from a - naive :class:`datetime` instance representing UTC time. If your + naive :class:`.datetime` instance representing UTC time. If your application uses this convention and your system timezone is not set to UTC, you can obtain the POSIX timestamp by supplying ``tzinfo=timezone.utc``:: @@ -1400,9 +1402,9 @@ comparisons, naive instances are never equal to aware instances. If both comparands are aware, and have - the same :attr:`tzinfo` attribute, the common :attr:`tzinfo` attribute is + the same :attr:`~time.tzinfo` attribute, the common :attr:`~time.tzinfo` attribute is ignored and the base times are compared. If both comparands are aware and - have different :attr:`tzinfo` attributes, the comparands are first adjusted by + have different :attr:`~time.tzinfo` attributes, the comparands are first adjusted by subtracting their UTC offsets (obtained from ``self.utcoffset()``). In order to stop mixed-type comparisons from falling back to the default comparison by object address, when a :class:`.time` object is compared to an object of a @@ -1499,7 +1501,7 @@ .. method:: time.utcoffset() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.utcoffset(None)``, and raises an exception if the latter doesn't return ``None`` or a :class:`timedelta` object representing a whole number of minutes with magnitude less than one day. @@ -1507,7 +1509,7 @@ .. method:: time.dst() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.dst(None)``, and raises an exception if the latter doesn't return ``None``, or a :class:`timedelta` object representing a whole number of minutes with magnitude less than one day. @@ -1515,7 +1517,7 @@ .. method:: time.tzname() - If :attr:`tzinfo` is ``None``, returns ``None``, else returns + If :attr:`.tzinfo` is ``None``, returns ``None``, else returns ``self.tzinfo.tzname(None)``, or raises an exception if the latter doesn't return ``None`` or a string object. @@ -1552,28 +1554,30 @@ :class:`tzinfo` Objects ----------------------- -:class:`tzinfo` is an abstract base class, meaning that this class should not be -instantiated directly. You need to derive a concrete subclass, and (at least) -supply implementations of the standard :class:`tzinfo` methods needed by the -:class:`.datetime` methods you use. The :mod:`datetime` module supplies -a simple concrete subclass of :class:`tzinfo` :class:`timezone` which can represent -timezones with fixed offset from UTC such as UTC itself or North American EST and -EDT. - -An instance of (a concrete subclass of) :class:`tzinfo` can be passed to the -constructors for :class:`.datetime` and :class:`.time` objects. The latter objects -view their attributes as being in local time, and the :class:`tzinfo` object -supports methods revealing offset of local time from UTC, the name of the time -zone, and DST offset, all relative to a date or time object passed to them. - -Special requirement for pickling: A :class:`tzinfo` subclass must have an -:meth:`__init__` method that can be called with no arguments, else it can be -pickled but possibly not unpickled again. This is a technical requirement that -may be relaxed in the future. - -A concrete subclass of :class:`tzinfo` may need to implement the following -methods. Exactly which methods are needed depends on the uses made of aware -:mod:`datetime` objects. If in doubt, simply implement all of them. +.. class:: tzinfo() + + This is an abstract base class, meaning that this class should not be + instantiated directly. You need to derive a concrete subclass, and (at least) + supply implementations of the standard :class:`tzinfo` methods needed by the + :class:`.datetime` methods you use. The :mod:`datetime` module supplies + a simple concrete subclass of :class:`tzinfo`, :class:`timezone`, which can represent + timezones with fixed offset from UTC such as UTC itself or North American EST and + EDT. + + An instance of (a concrete subclass of) :class:`tzinfo` can be passed to the + constructors for :class:`.datetime` and :class:`.time` objects. The latter objects + view their attributes as being in local time, and the :class:`tzinfo` object + supports methods revealing offset of local time from UTC, the name of the time + zone, and DST offset, all relative to a date or time object passed to them. + + Special requirement for pickling: A :class:`tzinfo` subclass must have an + :meth:`__init__` method that can be called with no arguments, else it can be + pickled but possibly not unpickled again. This is a technical requirement that + may be relaxed in the future. + + A concrete subclass of :class:`tzinfo` may need to implement the following + methods. Exactly which methods are needed depends on the uses made of aware + :mod:`datetime` objects. If in doubt, simply implement all of them. .. method:: tzinfo.utcoffset(dt) @@ -1606,7 +1610,7 @@ (see :meth:`utcoffset` for details). Note that DST offset, if applicable, has already been added to the UTC offset returned by :meth:`utcoffset`, so there's no need to consult :meth:`dst` unless you're interested in obtaining DST info - separately. For example, :meth:`datetime.timetuple` calls its :attr:`tzinfo` + separately. For example, :meth:`datetime.timetuple` calls its :attr:`~.datetime.tzinfo` attribute's :meth:`dst` method to determine how the :attr:`tm_isdst` flag should be set, and :meth:`tzinfo.fromutc` calls :meth:`dst` to account for DST changes when crossing time zones. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 21:32:24 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 02 Apr 2016 01:32:24 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2Njg4?= =?utf-8?q?=3A_Fix_module_name_in_mock_docs?= Message-ID: <20160402013223.28257.72232.6FFD0AF4@psf.io> https://hg.python.org/cpython/rev/73279e4a1107 changeset: 100832:73279e4a1107 branch: 3.5 parent: 100829:30e077f886cc user: Berker Peksag date: Sat Apr 02 04:32:06 2016 +0300 summary: Issue #26688: Fix module name in mock docs Patch by Ashley Anderson. files: Doc/library/unittest.mock-examples.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/unittest.mock-examples.rst b/Doc/library/unittest.mock-examples.rst --- a/Doc/library/unittest.mock-examples.rst +++ b/Doc/library/unittest.mock-examples.rst @@ -359,7 +359,7 @@ A nice pattern is to actually decorate test methods themselves: - >>> class MyTest(unittest2.TestCase): + >>> class MyTest(unittest.TestCase): ... @patch.object(SomeClass, 'attribute', sentinel.attribute) ... def test_something(self): ... self.assertEqual(SomeClass.attribute, sentinel.attribute) @@ -372,7 +372,7 @@ (or :func:`patch.object` with two arguments). The mock will be created for you and passed into the test function / method: - >>> class MyTest(unittest2.TestCase): + >>> class MyTest(unittest.TestCase): ... @patch.object(SomeClass, 'static_method') ... def test_something(self, mock_method): ... SomeClass.static_method() @@ -382,7 +382,7 @@ You can stack up multiple patch decorators using this pattern: - >>> class MyTest(unittest2.TestCase): + >>> class MyTest(unittest.TestCase): ... @patch('package.module.ClassName1') ... @patch('package.module.ClassName2') ... def test_something(self, MockClass2, MockClass1): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 21:32:25 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 02 Apr 2016 01:32:25 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326688=3A_Fix_module_name_in_mock_docs?= Message-ID: <20160402013224.70497.45088.6FF24840@psf.io> https://hg.python.org/cpython/rev/24efe844e598 changeset: 100833:24efe844e598 parent: 100830:854db1a2cd98 parent: 100832:73279e4a1107 user: Berker Peksag date: Sat Apr 02 04:32:26 2016 +0300 summary: Issue #26688: Fix module name in mock docs Patch by Ashley Anderson. files: Doc/library/unittest.mock-examples.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/unittest.mock-examples.rst b/Doc/library/unittest.mock-examples.rst --- a/Doc/library/unittest.mock-examples.rst +++ b/Doc/library/unittest.mock-examples.rst @@ -359,7 +359,7 @@ A nice pattern is to actually decorate test methods themselves: - >>> class MyTest(unittest2.TestCase): + >>> class MyTest(unittest.TestCase): ... @patch.object(SomeClass, 'attribute', sentinel.attribute) ... def test_something(self): ... self.assertEqual(SomeClass.attribute, sentinel.attribute) @@ -372,7 +372,7 @@ (or :func:`patch.object` with two arguments). The mock will be created for you and passed into the test function / method: - >>> class MyTest(unittest2.TestCase): + >>> class MyTest(unittest.TestCase): ... @patch.object(SomeClass, 'static_method') ... def test_something(self, mock_method): ... SomeClass.static_method() @@ -382,7 +382,7 @@ You can stack up multiple patch decorators using this pattern: - >>> class MyTest(unittest2.TestCase): + >>> class MyTest(unittest.TestCase): ... @patch('package.module.ClassName1') ... @patch('package.module.ClassName2') ... def test_something(self, MockClass2, MockClass1): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 21:48:45 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 02 Apr 2016 01:48:45 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326679=3A_Fix_description_of_KEY=5FPPAGE_and_KEY?= =?utf-8?q?=5FNPAGE_constants?= Message-ID: <20160402014845.7809.58114.B23887CE@psf.io> https://hg.python.org/cpython/rev/23d986228c6b changeset: 100835:23d986228c6b parent: 100833:24efe844e598 parent: 100834:f41d3321007f user: Berker Peksag date: Sat Apr 02 04:48:46 2016 +0300 summary: Issue #26679: Fix description of KEY_PPAGE and KEY_NPAGE constants Patch by Robert Bachmann and SilentGhost. files: Doc/library/curses.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/curses.rst b/Doc/library/curses.rst --- a/Doc/library/curses.rst +++ b/Doc/library/curses.rst @@ -1508,9 +1508,9 @@ +------------------+-----------+ | :kbd:`End` | KEY_END | +------------------+-----------+ -| :kbd:`Page Up` | KEY_NPAGE | +| :kbd:`Page Up` | KEY_PPAGE | +------------------+-----------+ -| :kbd:`Page Down` | KEY_PPAGE | +| :kbd:`Page Down` | KEY_NPAGE | +------------------+-----------+ The following table lists characters from the alternate character set. These are -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 1 21:48:45 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 02 Apr 2016 01:48:45 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2Njc5?= =?utf-8?q?=3A_Fix_description_of_KEY=5FPPAGE_and_KEY=5FNPAGE_constants?= Message-ID: <20160402014844.7803.84532.CD841491@psf.io> https://hg.python.org/cpython/rev/f41d3321007f changeset: 100834:f41d3321007f branch: 3.5 parent: 100832:73279e4a1107 user: Berker Peksag date: Sat Apr 02 04:48:27 2016 +0300 summary: Issue #26679: Fix description of KEY_PPAGE and KEY_NPAGE constants Patch by Robert Bachmann and SilentGhost. files: Doc/library/curses.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/curses.rst b/Doc/library/curses.rst --- a/Doc/library/curses.rst +++ b/Doc/library/curses.rst @@ -1508,9 +1508,9 @@ +------------------+-----------+ | :kbd:`End` | KEY_END | +------------------+-----------+ -| :kbd:`Page Up` | KEY_NPAGE | +| :kbd:`Page Up` | KEY_PPAGE | +------------------+-----------+ -| :kbd:`Page Down` | KEY_PPAGE | +| :kbd:`Page Down` | KEY_NPAGE | +------------------+-----------+ The following table lists characters from the alternate character set. These are -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Sat Apr 2 05:52:23 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 02 Apr 2016 09:52:23 +0000 Subject: [Python-checkins] Daily reference leaks (23d986228c6b): sum=4 Message-ID: <20160402095219.70517.86698.B473D1B2@psf.io> results for 23d986228c6b on branch "default" -------------------------------------------- test_functools leaked [0, 2, 2] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogHewu8f', '--timeout', '7200'] From brett at snarky.ca Fri Apr 1 14:07:18 2016 From: brett at snarky.ca (Brett Cannon) Date: Fri, 01 Apr 2016 18:07:18 +0000 Subject: [Python-checkins] cpython: Python 8: no pep8, no chocolate! In-Reply-To: <20160331214027.11092.50943.0083A2D0@psf.io> References: <20160331214027.11092.50943.0083A2D0@psf.io> Message-ID: Are you planning on removing this after today? My worry about leaving it in is if it's a modified copy that follows your Python 8 April Fools joke then it will quite possibly trip people up who try and run pep8 but don't have it installed, leading them to wonder why the heck their imports are now all flagged as broken. On Thu, 31 Mar 2016 at 14:40 victor.stinner wrote: > https://hg.python.org/cpython/rev/9aedec2dbc01 > changeset: 100818:9aedec2dbc01 > user: Victor Stinner > date: Thu Mar 31 23:30:53 2016 +0200 > summary: > Python 8: no pep8, no chocolate! > > files: > Include/patchlevel.h | 6 +- > Lib/pep8.py | 2151 ++++++++++++++++++++++++++++++ > Lib/site.py | 56 + > 3 files changed, 2210 insertions(+), 3 deletions(-) > > > diff --git a/Include/patchlevel.h b/Include/patchlevel.h > --- a/Include/patchlevel.h > +++ b/Include/patchlevel.h > @@ -16,14 +16,14 @@ > > /* Version parsed out into numeric values */ > /*--start constants--*/ > -#define PY_MAJOR_VERSION 3 > -#define PY_MINOR_VERSION 6 > +#define PY_MAJOR_VERSION 8 > +#define PY_MINOR_VERSION 0 > #define PY_MICRO_VERSION 0 > #define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_ALPHA > #define PY_RELEASE_SERIAL 0 > > /* Version as a string */ > -#define PY_VERSION "3.6.0a0" > +#define PY_VERSION "8.0.0a0" > /*--end constants--*/ > > /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. > diff --git a/Lib/pep8.py b/Lib/pep8.py > new file mode 100644 > --- /dev/null > +++ b/Lib/pep8.py > @@ -0,0 +1,2151 @@ > +#!/usr/bin/env python > +# pep8.py - Check Python source code formatting, according to PEP 8 > +# Copyright (C) 2006-2009 Johann C. Rocholl > +# Copyright (C) 2009-2014 Florent Xicluna > +# Copyright (C) 2014-2016 Ian Lee > +# > +# Permission is hereby granted, free of charge, to any person > +# obtaining a copy of this software and associated documentation files > +# (the "Software"), to deal in the Software without restriction, > +# including without limitation the rights to use, copy, modify, merge, > +# publish, distribute, sublicense, and/or sell copies of the Software, > +# and to permit persons to whom the Software is furnished to do so, > +# subject to the following conditions: > +# > +# The above copyright notice and this permission notice shall be > +# included in all copies or substantial portions of the Software. > +# > +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, > +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF > +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND > +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS > +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN > +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN > +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE > +# SOFTWARE. > + > +r""" > +Check Python source code formatting, according to PEP 8. > + > +For usage and a list of options, try this: > +$ python pep8.py -h > + > +This program and its regression test suite live here: > +https://github.com/pycqa/pep8 > + > +Groups of errors and warnings: > +E errors > +W warnings > +100 indentation > +200 whitespace > +300 blank lines > +400 imports > +500 line length > +600 deprecation > +700 statements > +900 syntax error > +""" > +from __future__ import with_statement > + > +import os > +import sys > +import re > +import time > +import inspect > +import keyword > +import tokenize > +from optparse import OptionParser > +from fnmatch import fnmatch > +try: > + from configparser import RawConfigParser > + from io import TextIOWrapper > +except ImportError: > + from ConfigParser import RawConfigParser > + > +__version__ = '1.7.0' > + > +DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox' > +DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704' > +try: > + if sys.platform == 'win32': > + USER_CONFIG = os.path.expanduser(r'~\.pep8') > + else: > + USER_CONFIG = os.path.join( > + os.getenv('XDG_CONFIG_HOME') or > os.path.expanduser('~/.config'), > + 'pep8' > + ) > +except ImportError: > + USER_CONFIG = None > + > +PROJECT_CONFIG = ('setup.cfg', 'tox.ini', '.pep8') > +TESTSUITE_PATH = os.path.join(os.path.dirname(__file__), 'testsuite') > +MAX_LINE_LENGTH = 79 > +REPORT_FORMAT = { > + 'default': '%(path)s:%(row)d:%(col)d: %(code)s %(text)s', > + 'pylint': '%(path)s:%(row)d: [%(code)s] %(text)s', > +} > + > +PyCF_ONLY_AST = 1024 > +SINGLETONS = frozenset(['False', 'None', 'True']) > +KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS > +UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-']) > +ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-']) > +WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', > '%']) > +WS_NEEDED_OPERATORS = frozenset([ > + '**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>', > + '%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '=']) > +WHITESPACE = frozenset(' \t') > +NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE]) > +SKIP_TOKENS = NEWLINE.union([tokenize.INDENT, tokenize.DEDENT]) > +# ERRORTOKEN is triggered by backticks in Python 3 > +SKIP_COMMENTS = SKIP_TOKENS.union([tokenize.COMMENT, tokenize.ERRORTOKEN]) > +BENCHMARK_KEYS = ['directories', 'files', 'logical lines', 'physical > lines'] > + > +INDENT_REGEX = re.compile(r'([ \t]*)') > +RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,') > +RERAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,.*,\s*\w+\s*$') > +ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b') > +DOCSTRING_REGEX = re.compile(r'u?r?["\']') > +EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]') > +WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)') > +COMPARE_SINGLETON_REGEX = re.compile(r'(\bNone|\bFalse|\bTrue)?\s*([=!]=)' > + r'\s*(?(1)|(None|False|True))\b') > +COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+[^][)(}{ ]+\s+(in|is)\s') > +COMPARE_TYPE_REGEX = > re.compile(r'(?:[=!]=|is(?:\s+not)?)\s*type(?:s.\w+Type' > + r'|\s*\(\s*([^)]*[^ )])\s*\))') > +KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS)) > +OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)') > +LAMBDA_REGEX = re.compile(r'\blambda\b') > +HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$') > + > +# Work around Python < 2.6 behaviour, which does not generate NL after > +# a comment which is on a line by itself. > +COMMENT_WITH_NL = tokenize.generate_tokens(['#\n'].pop).send(None)[1] == > '#\n' > + > + > > +############################################################################## > +# Plugins (check functions) for physical lines > > +############################################################################## > + > + > +def tabs_or_spaces(physical_line, indent_char): > + r"""Never mix tabs and spaces. > + > + The most popular way of indenting Python is with spaces only. The > + second-most popular way is with tabs only. Code indented with a > mixture > + of tabs and spaces should be converted to using spaces exclusively. > When > + invoking the Python command line interpreter with the -t option, it > issues > + warnings about code that illegally mixes tabs and spaces. When using > -tt > + these warnings become errors. These options are highly recommended! > + > + Okay: if a == 0:\n a = 1\n b = 1 > + E101: if a == 0:\n a = 1\n\tb = 1 > + """ > + indent = INDENT_REGEX.match(physical_line).group(1) > + for offset, char in enumerate(indent): > + if char != indent_char: > + return offset, "E101 indentation contains mixed spaces and > tabs" > + > + > +def tabs_obsolete(physical_line): > + r"""For new projects, spaces-only are strongly recommended over tabs. > + > + Okay: if True:\n return > + W191: if True:\n\treturn > + """ > + indent = INDENT_REGEX.match(physical_line).group(1) > + if '\t' in indent: > + return indent.index('\t'), "W191 indentation contains tabs" > + > + > +def trailing_whitespace(physical_line): > + r"""Trailing whitespace is superfluous. > + > + The warning returned varies on whether the line itself is blank, for > easier > + filtering for those who want to indent their blank lines. > + > + Okay: spam(1)\n# > + W291: spam(1) \n# > + W293: class Foo(object):\n \n bang = 12 > + """ > + physical_line = physical_line.rstrip('\n') # chr(10), newline > + physical_line = physical_line.rstrip('\r') # chr(13), carriage > return > + physical_line = physical_line.rstrip('\x0c') # chr(12), form feed, ^L > + stripped = physical_line.rstrip(' \t\v') > + if physical_line != stripped: > + if stripped: > + return len(stripped), "W291 trailing whitespace" > + else: > + return 0, "W293 blank line contains whitespace" > + > + > +def trailing_blank_lines(physical_line, lines, line_number, total_lines): > + r"""Trailing blank lines are superfluous. > + > + Okay: spam(1) > + W391: spam(1)\n > + > + However the last line should end with a new line (warning W292). > + """ > + if line_number == total_lines: > + stripped_last_line = physical_line.rstrip() > + if not stripped_last_line: > + return 0, "W391 blank line at end of file" > + if stripped_last_line == physical_line: > + return len(physical_line), "W292 no newline at end of file" > + > + > +def maximum_line_length(physical_line, max_line_length, multiline): > + r"""Limit all lines to a maximum of 79 characters. > + > + There are still many devices around that are limited to 80 character > + lines; plus, limiting windows to 80 characters makes it possible to > have > + several windows side-by-side. The default wrapping on such devices > looks > + ugly. Therefore, please limit all lines to a maximum of 79 > characters. > + For flowing long blocks of text (docstrings or comments), limiting the > + length to 72 characters is recommended. > + > + Reports error E501. > + """ > + line = physical_line.rstrip() > + length = len(line) > + if length > max_line_length and not noqa(line): > + # Special case for long URLs in multi-line docstrings or comments, > + # but still report the error when the 72 first chars are > whitespaces. > + chunks = line.split() > + if ((len(chunks) == 1 and multiline) or > + (len(chunks) == 2 and chunks[0] == '#')) and \ > + len(line) - len(chunks[-1]) < max_line_length - 7: > + return > + if hasattr(line, 'decode'): # Python 2 > + # The line could contain multi-byte characters > + try: > + length = len(line.decode('utf-8')) > + except UnicodeError: > + pass > + if length > max_line_length: > + return (max_line_length, "E501 line too long " > + "(%d > %d characters)" % (length, max_line_length)) > + > + > > +############################################################################## > +# Plugins (check functions) for logical lines > > +############################################################################## > + > + > +def blank_lines(logical_line, blank_lines, indent_level, line_number, > + blank_before, previous_logical, previous_indent_level): > + r"""Separate top-level function and class definitions with two blank > lines. > + > + Method definitions inside a class are separated by a single blank > line. > + > + Extra blank lines may be used (sparingly) to separate groups of > related > + functions. Blank lines may be omitted between a bunch of related > + one-liners (e.g. a set of dummy implementations). > + > + Use blank lines in functions, sparingly, to indicate logical sections. > + > + Okay: def a():\n pass\n\n\ndef b():\n pass > + Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass > + > + E301: class Foo:\n b = 0\n def bar():\n pass > + E302: def a():\n pass\n\ndef b(n):\n pass > + E303: def a():\n pass\n\n\n\ndef b(n):\n pass > + E303: def a():\n\n\n\n pass > + E304: @decorator\n\ndef a():\n pass > + """ > + if line_number < 3 and not previous_logical: > + return # Don't expect blank lines before the first line > + if previous_logical.startswith('@'): > + if blank_lines: > + yield 0, "E304 blank lines found after function decorator" > + elif blank_lines > 2 or (indent_level and blank_lines == 2): > + yield 0, "E303 too many blank lines (%d)" % blank_lines > + elif logical_line.startswith(('def ', 'class ', '@')): > + if indent_level: > + if not (blank_before or previous_indent_level < indent_level > or > + DOCSTRING_REGEX.match(previous_logical)): > + yield 0, "E301 expected 1 blank line, found 0" > + elif blank_before != 2: > + yield 0, "E302 expected 2 blank lines, found %d" % > blank_before > + > + > +def extraneous_whitespace(logical_line): > + r"""Avoid extraneous whitespace. > + > + Avoid extraneous whitespace in these situations: > + - Immediately inside parentheses, brackets or braces. > + - Immediately before a comma, semicolon, or colon. > + > + Okay: spam(ham[1], {eggs: 2}) > + E201: spam( ham[1], {eggs: 2}) > + E201: spam(ham[ 1], {eggs: 2}) > + E201: spam(ham[1], { eggs: 2}) > + E202: spam(ham[1], {eggs: 2} ) > + E202: spam(ham[1 ], {eggs: 2}) > + E202: spam(ham[1], {eggs: 2 }) > + > + E203: if x == 4: print x, y; x, y = y , x > + E203: if x == 4: print x, y ; x, y = y, x > + E203: if x == 4 : print x, y; x, y = y, x > + """ > + line = logical_line > + for match in EXTRANEOUS_WHITESPACE_REGEX.finditer(line): > + text = match.group() > + char = text.strip() > + found = match.start() > + if text == char + ' ': > + # assert char in '([{' > + yield found + 1, "E201 whitespace after '%s'" % char > + elif line[found - 1] != ',': > + code = ('E202' if char in '}])' else 'E203') # if char in > ',;:' > + yield found, "%s whitespace before '%s'" % (code, char) > + > + > +def whitespace_around_keywords(logical_line): > + r"""Avoid extraneous whitespace around keywords. > + > + Okay: True and False > + E271: True and False > + E272: True and False > + E273: True and\tFalse > + E274: True\tand False > + """ > + for match in KEYWORD_REGEX.finditer(logical_line): > + before, after = match.groups() > + > + if '\t' in before: > + yield match.start(1), "E274 tab before keyword" > + elif len(before) > 1: > + yield match.start(1), "E272 multiple spaces before keyword" > + > + if '\t' in after: > + yield match.start(2), "E273 tab after keyword" > + elif len(after) > 1: > + yield match.start(2), "E271 multiple spaces after keyword" > + > + > +def missing_whitespace(logical_line): > + r"""Each comma, semicolon or colon should be followed by whitespace. > + > + Okay: [a, b] > + Okay: (3,) > + Okay: a[1:4] > + Okay: a[:4] > + Okay: a[1:] > + Okay: a[1:4:2] > + E231: ['a','b'] > + E231: foo(bar,baz) > + E231: [{'a':'b'}] > + """ > + line = logical_line > + for index in range(len(line) - 1): > + char = line[index] > + if char in ',;:' and line[index + 1] not in WHITESPACE: > + before = line[:index] > + if char == ':' and before.count('[') > before.count(']') and \ > + before.rfind('{') < before.rfind('['): > + continue # Slice syntax, no space required > + if char == ',' and line[index + 1] == ')': > + continue # Allow tuple with only one element: (3,) > + yield index, "E231 missing whitespace after '%s'" % char > + > + > +def indentation(logical_line, previous_logical, indent_char, > + indent_level, previous_indent_level): > + r"""Use 4 spaces per indentation level. > + > + For really old code that you don't want to mess up, you can continue > to > + use 8-space tabs. > + > + Okay: a = 1 > + Okay: if a == 0:\n a = 1 > + E111: a = 1 > + E114: # a = 1 > + > + Okay: for item in items:\n pass > + E112: for item in items:\npass > + E115: for item in items:\n# Hi\n pass > + > + Okay: a = 1\nb = 2 > + E113: a = 1\n b = 2 > + E116: a = 1\n # b = 2 > + """ > + c = 0 if logical_line else 3 > + tmpl = "E11%d %s" if logical_line else "E11%d %s (comment)" > + if indent_level % 4: > + yield 0, tmpl % (1 + c, "indentation is not a multiple of four") > + indent_expect = previous_logical.endswith(':') > + if indent_expect and indent_level <= previous_indent_level: > + yield 0, tmpl % (2 + c, "expected an indented block") > + elif not indent_expect and indent_level > previous_indent_level: > + yield 0, tmpl % (3 + c, "unexpected indentation") > + > + > +def continued_indentation(logical_line, tokens, indent_level, > hang_closing, > + indent_char, noqa, verbose): > + r"""Continuation lines indentation. > + > + Continuation lines should align wrapped elements either vertically > + using Python's implicit line joining inside parentheses, brackets > + and braces, or using a hanging indent. > + > + When using a hanging indent these considerations should be applied: > + - there should be no arguments on the first line, and > + - further indentation should be used to clearly distinguish itself as > a > + continuation line. > + > + Okay: a = (\n) > + E123: a = (\n ) > + > + Okay: a = (\n 42) > + E121: a = (\n 42) > + E122: a = (\n42) > + E123: a = (\n 42\n ) > + E124: a = (24,\n 42\n) > + E125: if (\n b):\n pass > + E126: a = (\n 42) > + E127: a = (24,\n 42) > + E128: a = (24,\n 42) > + E129: if (a or\n b):\n pass > + E131: a = (\n 42\n 24) > + """ > + first_row = tokens[0][2][0] > + nrows = 1 + tokens[-1][2][0] - first_row > + if noqa or nrows == 1: > + return > + > + # indent_next tells us whether the next block is indented; assuming > + # that it is indented by 4 spaces, then we should not allow 4-space > + # indents on the final continuation line; in turn, some other > + # indents are allowed to have an extra 4 spaces. > + indent_next = logical_line.endswith(':') > + > + row = depth = 0 > + valid_hangs = (4,) if indent_char != '\t' else (4, 8) > + # remember how many brackets were opened on each line > + parens = [0] * nrows > + # relative indents of physical lines > + rel_indent = [0] * nrows > + # for each depth, collect a list of opening rows > + open_rows = [[0]] > + # for each depth, memorize the hanging indentation > + hangs = [None] > + # visual indents > + indent_chances = {} > + last_indent = tokens[0][2] > + visual_indent = None > + last_token_multiline = False > + # for each depth, memorize the visual indent column > + indent = [last_indent[1]] > + if verbose >= 3: > + print(">>> " + tokens[0][4].rstrip()) > + > + for token_type, text, start, end, line in tokens: > + > + newline = row < start[0] - first_row > + if newline: > + row = start[0] - first_row > + newline = not last_token_multiline and token_type not in > NEWLINE > + > + if newline: > + # this is the beginning of a continuation line. > + last_indent = start > + if verbose >= 3: > + print("... " + line.rstrip()) > + > + # record the initial indent. > + rel_indent[row] = expand_indent(line) - indent_level > + > + # identify closing bracket > + close_bracket = (token_type == tokenize.OP and text in ']})') > + > + # is the indent relative to an opening bracket line? > + for open_row in reversed(open_rows[depth]): > + hang = rel_indent[row] - rel_indent[open_row] > + hanging_indent = hang in valid_hangs > + if hanging_indent: > + break > + if hangs[depth]: > + hanging_indent = (hang == hangs[depth]) > + # is there any chance of visual indent? > + visual_indent = (not close_bracket and hang > 0 and > + indent_chances.get(start[1])) > + > + if close_bracket and indent[depth]: > + # closing bracket for visual indent > + if start[1] != indent[depth]: > + yield (start, "E124 closing bracket does not match " > + "visual indentation") > + elif close_bracket and not hang: > + # closing bracket matches indentation of opening > bracket's line > + if hang_closing: > + yield start, "E133 closing bracket is missing > indentation" > + elif indent[depth] and start[1] < indent[depth]: > + if visual_indent is not True: > + # visual indent is broken > + yield (start, "E128 continuation line " > + "under-indented for visual indent") > + elif hanging_indent or (indent_next and rel_indent[row] == 8): > + # hanging indent is verified > + if close_bracket and not hang_closing: > + yield (start, "E123 closing bracket does not match " > + "indentation of opening bracket's line") > + hangs[depth] = hang > + elif visual_indent is True: > + # visual indent is verified > + indent[depth] = start[1] > + elif visual_indent in (text, str): > + # ignore token lined up with matching one from a previous > line > + pass > + else: > + # indent is broken > + if hang <= 0: > + error = "E122", "missing indentation or outdented" > + elif indent[depth]: > + error = "E127", "over-indented for visual indent" > + elif not close_bracket and hangs[depth]: > + error = "E131", "unaligned for hanging indent" > + else: > + hangs[depth] = hang > + if hang > 4: > + error = "E126", "over-indented for hanging indent" > + else: > + error = "E121", "under-indented for hanging > indent" > + yield start, "%s continuation line %s" % error > + > + # look for visual indenting > + if (parens[row] and > + token_type not in (tokenize.NL, tokenize.COMMENT) and > + not indent[depth]): > + indent[depth] = start[1] > + indent_chances[start[1]] = True > + if verbose >= 4: > + print("bracket depth %s indent to %s" % (depth, start[1])) > + # deal with implicit string concatenation > + elif (token_type in (tokenize.STRING, tokenize.COMMENT) or > + text in ('u', 'ur', 'b', 'br')): > + indent_chances[start[1]] = str > + # special case for the "if" statement because len("if (") == 4 > + elif not indent_chances and not row and not depth and text == > 'if': > + indent_chances[end[1] + 1] = True > + elif text == ':' and line[end[1]:].isspace(): > + open_rows[depth].append(row) > + > + # keep track of bracket depth > + if token_type == tokenize.OP: > + if text in '([{': > + depth += 1 > + indent.append(0) > + hangs.append(None) > + if len(open_rows) == depth: > + open_rows.append([]) > + open_rows[depth].append(row) > + parens[row] += 1 > + if verbose >= 4: > + print("bracket depth %s seen, col %s, visual min = > %s" % > + (depth, start[1], indent[depth])) > + elif text in ')]}' and depth > 0: > + # parent indents should not be more than this one > + prev_indent = indent.pop() or last_indent[1] > + hangs.pop() > + for d in range(depth): > + if indent[d] > prev_indent: > + indent[d] = 0 > + for ind in list(indent_chances): > + if ind >= prev_indent: > + del indent_chances[ind] > + del open_rows[depth + 1:] > + depth -= 1 > + if depth: > + indent_chances[indent[depth]] = True > + for idx in range(row, -1, -1): > + if parens[idx]: > + parens[idx] -= 1 > + break > + assert len(indent) == depth + 1 > + if start[1] not in indent_chances: > + # allow to line up tokens > + indent_chances[start[1]] = text > + > + last_token_multiline = (start[0] != end[0]) > + if last_token_multiline: > + rel_indent[end[0] - first_row] = rel_indent[row] > + > + if indent_next and expand_indent(line) == indent_level + 4: > + pos = (start[0], indent[0] + 4) > + if visual_indent: > + code = "E129 visually indented line" > + else: > + code = "E125 continuation line" > + yield pos, "%s with same indent as next logical line" % code > + > + > +def whitespace_before_parameters(logical_line, tokens): > + r"""Avoid extraneous whitespace. > + > + Avoid extraneous whitespace in the following situations: > + - before the open parenthesis that starts the argument list of a > + function call. > + - before the open parenthesis that starts an indexing or slicing. > + > + Okay: spam(1) > + E211: spam (1) > + > + Okay: dict['key'] = list[index] > + E211: dict ['key'] = list[index] > + E211: dict['key'] = list [index] > + """ > + prev_type, prev_text, __, prev_end, __ = tokens[0] > + for index in range(1, len(tokens)): > + token_type, text, start, end, __ = tokens[index] > + if (token_type == tokenize.OP and > + text in '([' and > + start != prev_end and > + (prev_type == tokenize.NAME or prev_text in '}])') and > + # Syntax "class A (B):" is allowed, but avoid it > + (index < 2 or tokens[index - 2][1] != 'class') and > + # Allow "return (a.foo for a in range(5))" > + not keyword.iskeyword(prev_text)): > + yield prev_end, "E211 whitespace before '%s'" % text > + prev_type = token_type > + prev_text = text > + prev_end = end > + > + > +def whitespace_around_operator(logical_line): > + r"""Avoid extraneous whitespace around an operator. > + > + Okay: a = 12 + 3 > + E221: a = 4 + 5 > + E222: a = 4 + 5 > + E223: a = 4\t+ 5 > + E224: a = 4 +\t5 > + """ > + for match in OPERATOR_REGEX.finditer(logical_line): > + before, after = match.groups() > + > + if '\t' in before: > + yield match.start(1), "E223 tab before operator" > + elif len(before) > 1: > + yield match.start(1), "E221 multiple spaces before operator" > + > + if '\t' in after: > + yield match.start(2), "E224 tab after operator" > + elif len(after) > 1: > + yield match.start(2), "E222 multiple spaces after operator" > + > + > +def missing_whitespace_around_operator(logical_line, tokens): > + r"""Surround operators with a single space on either side. > + > + - Always surround these binary operators with a single space on > + either side: assignment (=), augmented assignment (+=, -= etc.), > + comparisons (==, <, >, !=, <=, >=, in, not in, is, is not), > + Booleans (and, or, not). > + > + - If operators with different priorities are used, consider adding > + whitespace around the operators with the lowest priorities. > + > + Okay: i = i + 1 > + Okay: submitted += 1 > + Okay: x = x * 2 - 1 > + Okay: hypot2 = x * x + y * y > + Okay: c = (a + b) * (a - b) > + Okay: foo(bar, key='word', *args, **kwargs) > + Okay: alpha[:-i] > + > + E225: i=i+1 > + E225: submitted +=1 > + E225: x = x /2 - 1 > + E225: z = x **y > + E226: c = (a+b) * (a-b) > + E226: hypot2 = x*x + y*y > + E227: c = a|b > + E228: msg = fmt%(errno, errmsg) > + """ > + parens = 0 > + need_space = False > + prev_type = tokenize.OP > + prev_text = prev_end = None > + for token_type, text, start, end, line in tokens: > + if token_type in SKIP_COMMENTS: > + continue > + if text in ('(', 'lambda'): > + parens += 1 > + elif text == ')': > + parens -= 1 > + if need_space: > + if start != prev_end: > + # Found a (probably) needed space > + if need_space is not True and not need_space[1]: > + yield (need_space[0], > + "E225 missing whitespace around operator") > + need_space = False > + elif text == '>' and prev_text in ('<', '-'): > + # Tolerate the "<>" operator, even if running Python 3 > + # Deal with Python 3's annotated return value "->" > + pass > + else: > + if need_space is True or need_space[1]: > + # A needed trailing space was not found > + yield prev_end, "E225 missing whitespace around > operator" > + elif prev_text != '**': > + code, optype = 'E226', 'arithmetic' > + if prev_text == '%': > + code, optype = 'E228', 'modulo' > + elif prev_text not in ARITHMETIC_OP: > + code, optype = 'E227', 'bitwise or shift' > + yield (need_space[0], "%s missing whitespace " > + "around %s operator" % (code, optype)) > + need_space = False > + elif token_type == tokenize.OP and prev_end is not None: > + if text == '=' and parens: > + # Allow keyword args or defaults: foo(bar=None). > + pass > + elif text in WS_NEEDED_OPERATORS: > + need_space = True > + elif text in UNARY_OPERATORS: > + # Check if the operator is being used as a binary operator > + # Allow unary operators: -123, -x, +1. > + # Allow argument unpacking: foo(*args, **kwargs). > + if (prev_text in '}])' if prev_type == tokenize.OP > + else prev_text not in KEYWORDS): > + need_space = None > + elif text in WS_OPTIONAL_OPERATORS: > + need_space = None > + > + if need_space is None: > + # Surrounding space is optional, but ensure that > + # trailing space matches opening space > + need_space = (prev_end, start != prev_end) > + elif need_space and start == prev_end: > + # A needed opening space was not found > + yield prev_end, "E225 missing whitespace around operator" > + need_space = False > + prev_type = token_type > + prev_text = text > + prev_end = end > + > + > +def whitespace_around_comma(logical_line): > + r"""Avoid extraneous whitespace after a comma or a colon. > + > + Note: these checks are disabled by default > + > + Okay: a = (1, 2) > + E241: a = (1, 2) > + E242: a = (1,\t2) > + """ > + line = logical_line > + for m in WHITESPACE_AFTER_COMMA_REGEX.finditer(line): > + found = m.start() + 1 > + if '\t' in m.group(): > + yield found, "E242 tab after '%s'" % m.group()[0] > + else: > + yield found, "E241 multiple spaces after '%s'" % m.group()[0] > + > + > +def whitespace_around_named_parameter_equals(logical_line, tokens): > + r"""Don't use spaces around the '=' sign in function arguments. > + > + Don't use spaces around the '=' sign when used to indicate a > + keyword argument or a default parameter value. > + > + Okay: def complex(real, imag=0.0): > + Okay: return magic(r=real, i=imag) > + Okay: boolean(a == b) > + Okay: boolean(a != b) > + Okay: boolean(a <= b) > + Okay: boolean(a >= b) > + Okay: def foo(arg: int = 42): > + > + E251: def complex(real, imag = 0.0): > + E251: return magic(r = real, i = imag) > + """ > + parens = 0 > + no_space = False > + prev_end = None > + annotated_func_arg = False > + in_def = logical_line.startswith('def') > + message = "E251 unexpected spaces around keyword / parameter equals" > + for token_type, text, start, end, line in tokens: > + if token_type == tokenize.NL: > + continue > + if no_space: > + no_space = False > + if start != prev_end: > + yield (prev_end, message) > + if token_type == tokenize.OP: > + if text == '(': > + parens += 1 > + elif text == ')': > + parens -= 1 > + elif in_def and text == ':' and parens == 1: > + annotated_func_arg = True > + elif parens and text == ',' and parens == 1: > + annotated_func_arg = False > + elif parens and text == '=' and not annotated_func_arg: > + no_space = True > + if start != prev_end: > + yield (prev_end, message) > + if not parens: > + annotated_func_arg = False > + > + prev_end = end > + > + > +def whitespace_before_comment(logical_line, tokens): > + r"""Separate inline comments by at least two spaces. > + > + An inline comment is a comment on the same line as a statement. > Inline > + comments should be separated by at least two spaces from the > statement. > + They should start with a # and a single space. > + > + Each line of a block comment starts with a # and a single space > + (unless it is indented text inside the comment). > + > + Okay: x = x + 1 # Increment x > + Okay: x = x + 1 # Increment x > + Okay: # Block comment > + E261: x = x + 1 # Increment x > + E262: x = x + 1 #Increment x > + E262: x = x + 1 # Increment x > + E265: #Block comment > + E266: ### Block comment > + """ > + prev_end = (0, 0) > + for token_type, text, start, end, line in tokens: > + if token_type == tokenize.COMMENT: > + inline_comment = line[:start[1]].strip() > + if inline_comment: > + if prev_end[0] == start[0] and start[1] < prev_end[1] + 2: > + yield (prev_end, > + "E261 at least two spaces before inline > comment") > + symbol, sp, comment = text.partition(' ') > + bad_prefix = symbol not in '#:' and (symbol.lstrip('#')[:1] > or '#') > + if inline_comment: > + if bad_prefix or comment[:1] in WHITESPACE: > + yield start, "E262 inline comment should start with > '# '" > + elif bad_prefix and (bad_prefix != '!' or start[0] > 1): > + if bad_prefix != '#': > + yield start, "E265 block comment should start with '# > '" > + elif comment: > + yield start, "E266 too many leading '#' for block > comment" > + elif token_type != tokenize.NL: > + prev_end = end > + > + > +def imports_on_separate_lines(logical_line): > + r"""Imports should usually be on separate lines. > + > + Okay: import os\nimport sys > + E401: import sys, os > + > + Okay: from subprocess import Popen, PIPE > + Okay: from myclas import MyClass > + Okay: from foo.bar.yourclass import YourClass > + Okay: import myclass > + Okay: import foo.bar.yourclass > + """ > + line = logical_line > + if line.startswith('import '): > + found = line.find(',') > + if -1 < found and ';' not in line[:found]: > + yield found, "E401 multiple imports on one line" > + > + > +def module_imports_on_top_of_file( > + logical_line, indent_level, checker_state, noqa): > + r"""Imports are always put at the top of the file, just after any > module > + comments and docstrings, and before module globals and constants. > + > + Okay: import os > + Okay: # this is a comment\nimport os > + Okay: '''this is a module docstring'''\nimport os > + Okay: r'''this is a module docstring'''\nimport os > + Okay: try:\n import x\nexcept:\n pass\nelse:\n pass\nimport y > + Okay: try:\n import x\nexcept:\n pass\nfinally:\n > pass\nimport y > + E402: a=1\nimport os > + E402: 'One string'\n"Two string"\nimport os > + E402: a=1\nfrom sys import x > + > + Okay: if x:\n import os > + """ > + def is_string_literal(line): > + if line[0] in 'uUbB': > + line = line[1:] > + if line and line[0] in 'rR': > + line = line[1:] > + return line and (line[0] == '"' or line[0] == "'") > + > + allowed_try_keywords = ('try', 'except', 'else', 'finally') > + > + if indent_level: # Allow imports in conditional statements or > functions > + return > + if not logical_line: # Allow empty lines or comments > + return > + if noqa: > + return > + line = logical_line > + if line.startswith('import ') or line.startswith('from '): > + if checker_state.get('seen_non_imports', False): > + yield 0, "E402 module level import not at top of file" > + elif any(line.startswith(kw) for kw in allowed_try_keywords): > + # Allow try, except, else, finally keywords intermixed with > imports in > + # order to support conditional importing > + return > + elif is_string_literal(line): > + # The first literal is a docstring, allow it. Otherwise, report > error. > + if checker_state.get('seen_docstring', False): > + checker_state['seen_non_imports'] = True > + else: > + checker_state['seen_docstring'] = True > + else: > + checker_state['seen_non_imports'] = True > + > + > +def compound_statements(logical_line): > + r"""Compound statements (on the same line) are generally discouraged. > + > + While sometimes it's okay to put an if/for/while with a small body > + on the same line, never do this for multi-clause statements. > + Also avoid folding such long lines! > + > + Always use a def statement instead of an assignment statement that > + binds a lambda expression directly to a name. > + > + Okay: if foo == 'blah':\n do_blah_thing() > + Okay: do_one() > + Okay: do_two() > + Okay: do_three() > + > + E701: if foo == 'blah': do_blah_thing() > + E701: for x in lst: total += x > + E701: while t < 10: t = delay() > + E701: if foo == 'blah': do_blah_thing() > + E701: else: do_non_blah_thing() > + E701: try: something() > + E701: finally: cleanup() > + E701: if foo == 'blah': one(); two(); three() > + E702: do_one(); do_two(); do_three() > + E703: do_four(); # useless semicolon > + E704: def f(x): return 2*x > + E731: f = lambda x: 2*x > + """ > + line = logical_line > + last_char = len(line) - 1 > + found = line.find(':') > + while -1 < found < last_char: > + before = line[:found] > + if ((before.count('{') <= before.count('}') and # {'a': 1} > (dict) > + before.count('[') <= before.count(']') and # [1:2] (slice) > + before.count('(') <= before.count(')'))): # (annotation) > + lambda_kw = LAMBDA_REGEX.search(before) > + if lambda_kw: > + before = line[:lambda_kw.start()].rstrip() > + if before[-1:] == '=' and > isidentifier(before[:-1].strip()): > + yield 0, ("E731 do not assign a lambda expression, > use a " > + "def") > + break > + if before.startswith('def '): > + yield 0, "E704 multiple statements on one line (def)" > + else: > + yield found, "E701 multiple statements on one line > (colon)" > + found = line.find(':', found + 1) > + found = line.find(';') > + while -1 < found: > + if found < last_char: > + yield found, "E702 multiple statements on one line > (semicolon)" > + else: > + yield found, "E703 statement ends with a semicolon" > + found = line.find(';', found + 1) > + > + > +def explicit_line_join(logical_line, tokens): > + r"""Avoid explicit line join between brackets. > + > + The preferred way of wrapping long lines is by using Python's implied > line > + continuation inside parentheses, brackets and braces. Long lines can > be > + broken over multiple lines by wrapping expressions in parentheses. > These > + should be used in preference to using a backslash for line > continuation. > + > + E502: aaa = [123, \\n 123] > + E502: aaa = ("bbb " \\n "ccc") > + > + Okay: aaa = [123,\n 123] > + Okay: aaa = ("bbb "\n "ccc") > + Okay: aaa = "bbb " \\n "ccc" > + Okay: aaa = 123 # \\ > + """ > + prev_start = prev_end = parens = 0 > + comment = False > + backslash = None > + for token_type, text, start, end, line in tokens: > + if token_type == tokenize.COMMENT: > + comment = True > + if start[0] != prev_start and parens and backslash and not > comment: > + yield backslash, "E502 the backslash is redundant between > brackets" > + if end[0] != prev_end: > + if line.rstrip('\r\n').endswith('\\'): > + backslash = (end[0], len(line.splitlines()[-1]) - 1) > + else: > + backslash = None > + prev_start = prev_end = end[0] > + else: > + prev_start = start[0] > + if token_type == tokenize.OP: > + if text in '([{': > + parens += 1 > + elif text in ')]}': > + parens -= 1 > + > + > +def break_around_binary_operator(logical_line, tokens): > + r""" > + Avoid breaks before binary operators. > + > + The preferred place to break around a binary operator is after the > + operator, not before it. > + > + W503: (width == 0\n + height == 0) > + W503: (width == 0\n and height == 0) > + > + Okay: (width == 0 +\n height == 0) > + Okay: foo(\n -x) > + Okay: foo(x\n []) > + Okay: x = '''\n''' + '' > + Okay: foo(x,\n -y) > + Okay: foo(x, # comment\n -y) > + """ > + def is_binary_operator(token_type, text): > + # The % character is strictly speaking a binary operator, but the > + # common usage seems to be to put it next to the format > parameters, > + # after a line break. > + return ((token_type == tokenize.OP or text in ['and', 'or']) and > + text not in "()[]{},:.;@=%") > + > + line_break = False > + unary_context = True > + for token_type, text, start, end, line in tokens: > + if token_type == tokenize.COMMENT: > + continue > + if ('\n' in text or '\r' in text) and token_type != > tokenize.STRING: > + line_break = True > + else: > + if (is_binary_operator(token_type, text) and line_break and > + not unary_context): > + yield start, "W503 line break before binary operator" > + unary_context = text in '([{,;' > + line_break = False > + > + > +def comparison_to_singleton(logical_line, noqa): > + r"""Comparison to singletons should use "is" or "is not". > + > + Comparisons to singletons like None should always be done > + with "is" or "is not", never the equality operators. > + > + Okay: if arg is not None: > + E711: if arg != None: > + E711: if None == arg: > + E712: if arg == True: > + E712: if False == arg: > + > + Also, beware of writing if x when you really mean if x is not None -- > + e.g. when testing whether a variable or argument that defaults to > None was > + set to some other value. The other value might have a type (such as a > + container) that could be false in a boolean context! > + """ > + match = not noqa and COMPARE_SINGLETON_REGEX.search(logical_line) > + if match: > + singleton = match.group(1) or match.group(3) > + same = (match.group(2) == '==') > + > + msg = "'if cond is %s:'" % (('' if same else 'not ') + singleton) > + if singleton in ('None',): > + code = 'E711' > + else: > + code = 'E712' > + nonzero = ((singleton == 'True' and same) or > + (singleton == 'False' and not same)) > + msg += " or 'if %scond:'" % ('' if nonzero else 'not ') > + yield match.start(2), ("%s comparison to %s should be %s" % > + (code, singleton, msg)) > + > + > +def comparison_negative(logical_line): > + r"""Negative comparison should be done using "not in" and "is not". > + > + Okay: if x not in y:\n pass > + Okay: assert (X in Y or X is Z) > + Okay: if not (X in Y):\n pass > + Okay: zz = x is not y > + E713: Z = not X in Y > + E713: if not X.B in Y:\n pass > + E714: if not X is Y:\n pass > + E714: Z = not X.B is Y > + """ > + match = COMPARE_NEGATIVE_REGEX.search(logical_line) > + if match: > + pos = match.start(1) > + if match.group(2) == 'in': > + yield pos, "E713 test for membership should be 'not in'" > + else: > + yield pos, "E714 test for object identity should be 'is not'" > + > + > +def comparison_type(logical_line, noqa): > + r"""Object type comparisons should always use isinstance(). > + > + Do not compare types directly. > + > + Okay: if isinstance(obj, int): > + E721: if type(obj) is type(1): > + > + When checking if an object is a string, keep in mind that it might be > a > + unicode string too! In Python 2.3, str and unicode have a common base > + class, basestring, so you can do: > + > + Okay: if isinstance(obj, basestring): > + Okay: if type(a1) is type(b1): > + """ > + match = COMPARE_TYPE_REGEX.search(logical_line) > + if match and not noqa: > + inst = match.group(1) > + if inst and isidentifier(inst) and inst not in SINGLETONS: > + return # Allow comparison for types which are not obvious > + yield match.start(), "E721 do not compare types, use > 'isinstance()'" > + > + > +def python_3000_has_key(logical_line, noqa): > + r"""The {}.has_key() method is removed in Python 3: use the 'in' > operator. > + > + Okay: if "alph" in d:\n print d["alph"] > + W601: assert d.has_key('alph') > + """ > + pos = logical_line.find('.has_key(') > + if pos > -1 and not noqa: > + yield pos, "W601 .has_key() is deprecated, use 'in'" > + > + > +def python_3000_raise_comma(logical_line): > + r"""When raising an exception, use "raise ValueError('message')". > + > + The older form is removed in Python 3. > + > + Okay: raise DummyError("Message") > + W602: raise DummyError, "Message" > + """ > + match = RAISE_COMMA_REGEX.match(logical_line) > + if match and not RERAISE_COMMA_REGEX.match(logical_line): > + yield match.end() - 1, "W602 deprecated form of raising exception" > + > + > +def python_3000_not_equal(logical_line): > + r"""New code should always use != instead of <>. > + > + The older syntax is removed in Python 3. > + > + Okay: if a != 'no': > + W603: if a <> 'no': > + """ > + pos = logical_line.find('<>') > + if pos > -1: > + yield pos, "W603 '<>' is deprecated, use '!='" > + > + > +def python_3000_backticks(logical_line): > + r"""Backticks are removed in Python 3: use repr() instead. > + > + Okay: val = repr(1 + 2) > + W604: val = `1 + 2` > + """ > + pos = logical_line.find('`') > + if pos > -1: > + yield pos, "W604 backticks are deprecated, use 'repr()'" > + > + > > +############################################################################## > +# Helper functions > > +############################################################################## > + > + > +if sys.version_info < (3,): > + # Python 2: implicit encoding. > + def readlines(filename): > + """Read the source code.""" > + with open(filename, 'rU') as f: > + return f.readlines() > + isidentifier = re.compile(r'[a-zA-Z_]\w*$').match > + stdin_get_value = sys.stdin.read > +else: > + # Python 3 > + def readlines(filename): > + """Read the source code.""" > + try: > + with open(filename, 'rb') as f: > + (coding, lines) = tokenize.detect_encoding(f.readline) > + f = TextIOWrapper(f, coding, line_buffering=True) > + return [l.decode(coding) for l in lines] + f.readlines() > + except (LookupError, SyntaxError, UnicodeError): > + # Fall back if file encoding is improperly declared > + with open(filename, encoding='latin-1') as f: > + return f.readlines() > + isidentifier = str.isidentifier > + > + def stdin_get_value(): > + return TextIOWrapper(sys.stdin.buffer, errors='ignore').read() > +noqa = re.compile(r'# no(?:qa|pep8)\b', re.I).search > + > + > +def expand_indent(line): > + r"""Return the amount of indentation. > + > + Tabs are expanded to the next multiple of 8. > + > + >>> expand_indent(' ') > + 4 > + >>> expand_indent('\t') > + 8 > + >>> expand_indent(' \t') > + 8 > + >>> expand_indent(' \t') > + 16 > + """ > + if '\t' not in line: > + return len(line) - len(line.lstrip()) > + result = 0 > + for char in line: > + if char == '\t': > + result = result // 8 * 8 + 8 > + elif char == ' ': > + result += 1 > + else: > + break > + return result > + > + > +def mute_string(text): > + """Replace contents with 'xxx' to prevent syntax matching. > + > + >>> mute_string('"abc"') > + '"xxx"' > + >>> mute_string("'''abc'''") > + "'''xxx'''" > + >>> mute_string("r'abc'") > + "r'xxx'" > + """ > + # String modifiers (e.g. u or r) > + start = text.index(text[-1]) + 1 > + end = len(text) - 1 > + # Triple quotes > + if text[-3:] in ('"""', "'''"): > + start += 2 > + end -= 2 > + return text[:start] + 'x' * (end - start) + text[end:] > + > + > +def parse_udiff(diff, patterns=None, parent='.'): > + """Return a dictionary of matching lines.""" > + # For each file of the diff, the entry key is the filename, > + # and the value is a set of row numbers to consider. > + rv = {} > + path = nrows = None > + for line in diff.splitlines(): > + if nrows: > + if line[:1] != '-': > + nrows -= 1 > + continue > + if line[:3] == '@@ ': > + hunk_match = HUNK_REGEX.match(line) > + (row, nrows) = [int(g or '1') for g in hunk_match.groups()] > + rv[path].update(range(row, row + nrows)) > + elif line[:3] == '+++': > + path = line[4:].split('\t', 1)[0] > + if path[:2] == 'b/': > + path = path[2:] > + rv[path] = set() > + return dict([(os.path.join(parent, path), rows) > + for (path, rows) in rv.items() > + if rows and filename_match(path, patterns)]) > + > + > +def normalize_paths(value, parent=os.curdir): > + """Parse a comma-separated list of paths. > + > + Return a list of absolute paths. > + """ > + if not value: > + return [] > + if isinstance(value, list): > + return value > + paths = [] > + for path in value.split(','): > + path = path.strip() > + if '/' in path: > + path = os.path.abspath(os.path.join(parent, path)) > + paths.append(path.rstrip('/')) > + return paths > + > + > +def filename_match(filename, patterns, default=True): > + """Check if patterns contains a pattern that matches filename. > + > + If patterns is unspecified, this always returns True. > + """ > + if not patterns: > + return default > + return any(fnmatch(filename, pattern) for pattern in patterns) > + > + > +def _is_eol_token(token): > + return token[0] in NEWLINE or token[4][token[3][1]:].lstrip() == > '\\\n' > +if COMMENT_WITH_NL: > + def _is_eol_token(token, _eol_token=_is_eol_token): > + return _eol_token(token) or (token[0] == tokenize.COMMENT and > + token[1] == token[4]) > + > > +############################################################################## > +# Framework to run all checks > > +############################################################################## > + > + > +_checks = {'physical_line': {}, 'logical_line': {}, 'tree': {}} > + > + > +def _get_parameters(function): > + if sys.version_info >= (3, 3): > + return [parameter.name > + for parameter > + in inspect.signature(function).parameters.values() > + if parameter.kind == parameter.POSITIONAL_OR_KEYWORD] > + else: > + return inspect.getargspec(function)[0] > + > + > +def register_check(check, codes=None): > + """Register a new check object.""" > + def _add_check(check, kind, codes, args): > + if check in _checks[kind]: > + _checks[kind][check][0].extend(codes or []) > + else: > + _checks[kind][check] = (codes or [''], args) > + if inspect.isfunction(check): > + args = _get_parameters(check) > + if args and args[0] in ('physical_line', 'logical_line'): > + if codes is None: > + codes = ERRORCODE_REGEX.findall(check.__doc__ or '') > + _add_check(check, args[0], codes, args) > + elif inspect.isclass(check): > + if _get_parameters(check.__init__)[:2] == ['self', 'tree']: > + _add_check(check, 'tree', codes, None) > + > + > +def init_checks_registry(): > + """Register all globally visible functions. > + > + The first argument name is either 'physical_line' or 'logical_line'. > + """ > + mod = inspect.getmodule(register_check) > + for (name, function) in inspect.getmembers(mod, inspect.isfunction): > + register_check(function) > +init_checks_registry() > + > + > +class Checker(object): > + """Load a Python source file, tokenize it, check coding style.""" > + > + def __init__(self, filename=None, lines=None, > + options=None, report=None, **kwargs): > + if options is None: > + options = StyleGuide(kwargs).options > + else: > + assert not kwargs > + self._io_error = None > + self._physical_checks = options.physical_checks > + self._logical_checks = options.logical_checks > + self._ast_checks = options.ast_checks > + self.max_line_length = options.max_line_length > + self.multiline = False # in a multiline string? > + self.hang_closing = options.hang_closing > + self.verbose = options.verbose > + self.filename = filename > + # Dictionary where a checker can store its custom state. > + self._checker_states = {} > + if filename is None: > + self.filename = 'stdin' > + self.lines = lines or [] > + elif filename == '-': > + self.filename = 'stdin' > + self.lines = stdin_get_value().splitlines(True) > + elif lines is None: > + try: > + self.lines = readlines(filename) > + except IOError: > + (exc_type, exc) = sys.exc_info()[:2] > + self._io_error = '%s: %s' % (exc_type.__name__, exc) > + self.lines = [] > + else: > + self.lines = lines > + if self.lines: > + ord0 = ord(self.lines[0][0]) > + if ord0 in (0xef, 0xfeff): # Strip the UTF-8 BOM > + if ord0 == 0xfeff: > + self.lines[0] = self.lines[0][1:] > + elif self.lines[0][:3] == '\xef\xbb\xbf': > + self.lines[0] = self.lines[0][3:] > + self.report = report or options.report > + self.report_error = self.report.error > + > + def report_invalid_syntax(self): > + """Check if the syntax is valid.""" > + (exc_type, exc) = sys.exc_info()[:2] > + if len(exc.args) > 1: > + offset = exc.args[1] > + if len(offset) > 2: > + offset = offset[1:3] > + else: > + offset = (1, 0) > + self.report_error(offset[0], offset[1] or 0, > + 'E901 %s: %s' % (exc_type.__name__, > exc.args[0]), > + self.report_invalid_syntax) > + > + def readline(self): > + """Get the next line from the input buffer.""" > + if self.line_number >= self.total_lines: > + return '' > + line = self.lines[self.line_number] > + self.line_number += 1 > + if self.indent_char is None and line[:1] in WHITESPACE: > + self.indent_char = line[0] > + return line > + > + def run_check(self, check, argument_names): > + """Run a check plugin.""" > + arguments = [] > + for name in argument_names: > + arguments.append(getattr(self, name)) > + return check(*arguments) > + > + def init_checker_state(self, name, argument_names): > + """ Prepares a custom state for the specific checker plugin.""" > + if 'checker_state' in argument_names: > + self.checker_state = self._checker_states.setdefault(name, {}) > + > + def check_physical(self, line): > + """Run all physical checks on a raw input line.""" > + self.physical_line = line > + for name, check, argument_names in self._physical_checks: > + self.init_checker_state(name, argument_names) > + result = self.run_check(check, argument_names) > + if result is not None: > + (offset, text) = result > + self.report_error(self.line_number, offset, text, check) > + if text[:4] == 'E101': > + self.indent_char = line[0] > + > + def build_tokens_line(self): > + """Build a logical line from tokens.""" > + logical = [] > + comments = [] > + length = 0 > + prev_row = prev_col = mapping = None > + for token_type, text, start, end, line in self.tokens: > + if token_type in SKIP_TOKENS: > + continue > + if not mapping: > + mapping = [(0, start)] > + if token_type == tokenize.COMMENT: > + comments.append(text) > + continue > + if token_type == tokenize.STRING: > + text = mute_string(text) > + if prev_row: > + (start_row, start_col) = start > + if prev_row != start_row: # different row > + prev_text = self.lines[prev_row - 1][prev_col - 1] > + if prev_text == ',' or (prev_text not in '{[(' and > + text not in '}])'): > + text = ' ' + text > + elif prev_col != start_col: # different column > + text = line[prev_col:start_col] + text > + logical.append(text) > + length += len(text) > + mapping.append((length, end)) > + (prev_row, prev_col) = end > + self.logical_line = ''.join(logical) > + self.noqa = comments and noqa(''.join(comments)) > + return mapping > + > + def check_logical(self): > + """Build a line from tokens and run all logical checks on it.""" > + self.report.increment_logical_line() > + mapping = self.build_tokens_line() > + > + if not mapping: > + return > + > + (start_row, start_col) = mapping[0][1] > + start_line = self.lines[start_row - 1] > + self.indent_level = expand_indent(start_line[:start_col]) > + if self.blank_before < self.blank_lines: > + self.blank_before = self.blank_lines > + if self.verbose >= 2: > + print(self.logical_line[:80].rstrip()) > + for name, check, argument_names in self._logical_checks: > + if self.verbose >= 4: > + print(' ' + name) > + self.init_checker_state(name, argument_names) > + for offset, text in self.run_check(check, argument_names) or > (): > + if not isinstance(offset, tuple): > + for token_offset, pos in mapping: > + if offset <= token_offset: > + break > + offset = (pos[0], pos[1] + offset - token_offset) > + self.report_error(offset[0], offset[1], text, check) > + if self.logical_line: > + self.previous_indent_level = self.indent_level > + self.previous_logical = self.logical_line > + self.blank_lines = 0 > + self.tokens = [] > + > + def check_ast(self): > + """Build the file's AST and run all AST checks.""" > + try: > + tree = compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST) > + except (ValueError, SyntaxError, TypeError): > + return self.report_invalid_syntax() > + for name, cls, __ in self._a -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-checkins at python.org Sat Apr 2 22:02:19 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 03 Apr 2016 02:02:19 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NTg2?= =?utf-8?q?=3A_Handle_excessive_header_fields_in_http=2Eserver=2C_by_Xiang?= =?utf-8?q?_Zhang?= Message-ID: <20160403020219.7815.93997.1B55F0E7@psf.io> https://hg.python.org/cpython/rev/f5247195238f changeset: 100836:f5247195238f branch: 3.5 parent: 100834:f41d3321007f user: Martin Panter date: Sun Apr 03 00:45:46 2016 +0000 summary: Issue #26586: Handle excessive header fields in http.server, by Xiang Zhang files: Lib/http/server.py | 7 +++++++ Lib/test/test_httpservers.py | 7 +++++++ Misc/NEWS | 4 ++++ 3 files changed, 18 insertions(+), 0 deletions(-) diff --git a/Lib/http/server.py b/Lib/http/server.py --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -337,6 +337,13 @@ HTTPStatus.BAD_REQUEST, "Line too long") return False + except http.client.HTTPException as err: + self.send_error( + HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE, + "Too many headers", + str(err) + ) + return False conntype = self.headers.get('Connection', "") if conntype.lower() == 'close': diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -858,6 +858,13 @@ self.assertFalse(self.handler.get_called) self.assertEqual(self.handler.requestline, 'GET / HTTP/1.1') + def test_too_many_headers(self): + result = self.send_typical_request( + b'GET / HTTP/1.1\r\n' + b'X-Foo: bar\r\n' * 101 + b'\r\n') + self.assertEqual(result[0], b'HTTP/1.1 431 Too many headers\r\n') + self.assertFalse(self.handler.get_called) + self.assertEqual(self.handler.requestline, 'GET / HTTP/1.1') + def test_close_connection(self): # handle_one_request() should be repeatedly called until # it sets close_connection diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -99,6 +99,10 @@ Library ------- +- Issue #26586: In http.server, respond with "413 Request header fields too + large" if there are too many header fields to parse, rather than killing + the connection and raising an unhandled exception. Patch by Xiang Zhang. + - Issue #22854: Change BufferedReader.writable() and BufferedWriter.readable() to always return False. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 2 22:02:20 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 03 Apr 2016 02:02:20 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326586=3A_Merge_excessive_HTTP_header_handling_f?= =?utf-8?q?rom_3=2E5?= Message-ID: <20160403020219.94576.85467.409DCC12@psf.io> https://hg.python.org/cpython/rev/e8edddb4f74b changeset: 100837:e8edddb4f74b parent: 100835:23d986228c6b parent: 100836:f5247195238f user: Martin Panter date: Sun Apr 03 01:28:49 2016 +0000 summary: Issue #26586: Merge excessive HTTP header handling from 3.5 files: Lib/http/server.py | 7 +++++++ Lib/test/test_httpservers.py | 7 +++++++ Misc/NEWS | 4 ++++ 3 files changed, 18 insertions(+), 0 deletions(-) diff --git a/Lib/http/server.py b/Lib/http/server.py --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -338,6 +338,13 @@ HTTPStatus.BAD_REQUEST, "Line too long") return False + except http.client.HTTPException as err: + self.send_error( + HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE, + "Too many headers", + str(err) + ) + return False conntype = self.headers.get('Connection', "") if conntype.lower() == 'close': diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -859,6 +859,13 @@ self.assertFalse(self.handler.get_called) self.assertEqual(self.handler.requestline, 'GET / HTTP/1.1') + def test_too_many_headers(self): + result = self.send_typical_request( + b'GET / HTTP/1.1\r\n' + b'X-Foo: bar\r\n' * 101 + b'\r\n') + self.assertEqual(result[0], b'HTTP/1.1 431 Too many headers\r\n') + self.assertFalse(self.handler.get_called) + self.assertEqual(self.handler.requestline, 'GET / HTTP/1.1') + def test_close_connection(self): # handle_one_request() should be repeatedly called until # it sets close_connection diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -237,6 +237,10 @@ Library ------- +- Issue #26586: In http.server, respond with "413 Request header fields too + large" if there are too many header fields to parse, rather than killing + the connection and raising an unhandled exception. Patch by Xiang Zhang. + - Issue #26676: Added missing XMLPullParser to ElementTree.__all__. - Issue #22854: Change BufferedReader.writable() and -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 2 22:02:20 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 03 Apr 2016 02:02:20 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326586=3A_Simple_e?= =?utf-8?q?nhancements_to_BaseHTTPRequestHandler_by_Xiang_Zhang?= Message-ID: <20160403020220.32749.2595.C7DEFBC8@psf.io> https://hg.python.org/cpython/rev/1b696c744559 changeset: 100838:1b696c744559 user: Martin Panter date: Sun Apr 03 01:28:53 2016 +0000 summary: Issue #26586: Simple enhancements to BaseHTTPRequestHandler by Xiang Zhang files: Lib/http/server.py | 28 +++++++++++------------ Lib/test/test_httpservers.py | 2 +- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Lib/http/server.py b/Lib/http/server.py --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -137,7 +137,7 @@ def server_bind(self): """Override server_bind to store the server name.""" socketserver.TCPServer.server_bind(self) - host, port = self.socket.getsockname()[:2] + host, port = self.server_address[:2] self.server_name = socket.getfqdn(host) self.server_port = port @@ -283,12 +283,9 @@ words = requestline.split() if len(words) == 3: command, path, version = words - if version[:5] != 'HTTP/': - self.send_error( - HTTPStatus.BAD_REQUEST, - "Bad request version (%r)" % version) - return False try: + if version[:5] != 'HTTP/': + raise ValueError base_version_number = version.split('/', 1)[1] version_number = base_version_number.split(".") # RFC 2145 section 3.1 says there can be only one "." and @@ -310,7 +307,7 @@ if version_number >= (2, 0): self.send_error( HTTPStatus.HTTP_VERSION_NOT_SUPPORTED, - "Invalid HTTP Version (%s)" % base_version_number) + "Invalid HTTP version (%s)" % base_version_number) return False elif len(words) == 2: command, path = words @@ -333,10 +330,11 @@ try: self.headers = http.client.parse_headers(self.rfile, _class=self.MessageClass) - except http.client.LineTooLong: + except http.client.LineTooLong as err: self.send_error( - HTTPStatus.BAD_REQUEST, - "Line too long") + HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE, + "Line too long", + str(err)) return False except http.client.HTTPException as err: self.send_error( @@ -482,12 +480,12 @@ def send_response_only(self, code, message=None): """Send the response header only.""" - if message is None: - if code in self.responses: - message = self.responses[code][0] - else: - message = '' if self.request_version != 'HTTP/0.9': + if message is None: + if code in self.responses: + message = self.responses[code][0] + else: + message = '' if not hasattr(self, '_headers_buffer'): self._headers_buffer = [] self._headers_buffer.append(("%s %d %s\r\n" % diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -855,7 +855,7 @@ # Issue #6791: same for headers result = self.send_typical_request( b'GET / HTTP/1.1\r\nX-Foo: bar' + b'r' * 65537 + b'\r\n\r\n') - self.assertEqual(result[0], b'HTTP/1.1 400 Line too long\r\n') + self.assertEqual(result[0], b'HTTP/1.1 431 Line too long\r\n') self.assertFalse(self.handler.get_called) self.assertEqual(self.handler.requestline, 'GET / HTTP/1.1') -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 2 22:38:06 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 03 Apr 2016 02:38:06 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2325951=3A_Fix_SSLS?= =?utf-8?q?ocket=2Esendall=28=29_to_return_None=2C_by_Aviv_Palivoda?= Message-ID: <20160403023806.28267.15773.A6C1035A@psf.io> https://hg.python.org/cpython/rev/92947704321c changeset: 100839:92947704321c user: Martin Panter date: Sun Apr 03 02:12:54 2016 +0000 summary: Issue #25951: Fix SSLSocket.sendall() to return None, by Aviv Palivoda files: Lib/ssl.py | 1 - Lib/test/test_ssl.py | 18 +++++++++++------- Misc/NEWS | 3 +++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Lib/ssl.py b/Lib/ssl.py --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -886,7 +886,6 @@ while (count < amount): v = self.send(data[count:]) count += v - return amount else: return socket.sendall(self, data, flags) diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -2709,12 +2709,13 @@ count, addr = s.recvfrom_into(b) return b[:count] + # (name, method, expect success?, *args, return value func) + send_methods = [ + ('send', s.send, True, [], len), + ('sendto', s.sendto, False, ["some.address"], len), + ('sendall', s.sendall, True, [], lambda x: None), + ] # (name, method, whether to expect success, *args) - send_methods = [ - ('send', s.send, True, []), - ('sendto', s.sendto, False, ["some.address"]), - ('sendall', s.sendall, True, []), - ] recv_methods = [ ('recv', s.recv, True, []), ('recvfrom', s.recvfrom, False, ["some.address"]), @@ -2723,10 +2724,13 @@ ] data_prefix = "PREFIX_" - for meth_name, send_meth, expect_success, args in send_methods: + for (meth_name, send_meth, expect_success, args, + ret_val_meth) in send_methods: indata = (data_prefix + meth_name).encode('ascii') try: - send_meth(indata, *args) + ret = send_meth(indata, *args) + msg = "sending with {}".format(meth_name) + self.assertEqual(ret, ret_val_meth(indata), msg=msg) outdata = s.read() if outdata != indata.lower(): self.fail( diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -237,6 +237,9 @@ Library ------- +- Issue #25951: Change SSLSocket.sendall() to return None, as explicitly + documented for plain socket objects. Patch by Aviv Palivoda. + - Issue #26586: In http.server, respond with "413 Request header fields too large" if there are too many header fields to parse, rather than killing the connection and raising an unhandled exception. Patch by Xiang Zhang. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 3 00:21:02 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 03 Apr 2016 04:21:02 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2323735=3A_Merge_Readline_resize_handling_from_3?= =?utf-8?q?=2E5?= Message-ID: <20160403042102.28243.82966.118D296F@psf.io> https://hg.python.org/cpython/rev/41c2f8742bfe changeset: 100841:41c2f8742bfe parent: 100839:92947704321c parent: 100840:b29edd0108ee user: Martin Panter date: Sun Apr 03 03:19:27 2016 +0000 summary: Issue #23735: Merge Readline resize handling from 3.5 files: Misc/ACKS | 1 + Misc/NEWS | 3 ++ Modules/readline.c | 31 +++++++++++++++++++++++ configure | 44 ++++++++++++++++++++++++++++++++++ configure.ac | 5 +++ pyconfig.h.in | 3 ++ 6 files changed, 87 insertions(+), 0 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1160,6 +1160,7 @@ Amrit Prem Paul Prescod Donovan Preston +Eric Price Paul Price Iuliia Proskurnia Dorian Pula diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -237,6 +237,9 @@ Library ------- +- Issue #23735: Handle terminal resizing with Readline 6.3+ by installing our + own SIGWINCH handler. Patch by Eric Price. + - Issue #25951: Change SSLSocket.sendall() to return None, as explicitly documented for plain socket objects. Patch by Aviv Palivoda. diff --git a/Modules/readline.c b/Modules/readline.c --- a/Modules/readline.c +++ b/Modules/readline.c @@ -926,6 +926,26 @@ #endif +#ifdef HAVE_RL_RESIZE_TERMINAL +static volatile sig_atomic_t sigwinch_received; +static sighandler_t sigwinch_ohandler; + +static void +readline_sigwinch_handler(int signum) +{ + sigwinch_received = 1; + if (sigwinch_ohandler && + sigwinch_ohandler != SIG_IGN && sigwinch_ohandler != SIG_DFL) + sigwinch_ohandler(signum); + +#ifndef HAVE_SIGACTION + /* If the handler was installed with signal() rather than sigaction(), + we need to reinstall it. */ + PyOS_setsig(SIGWINCH, readline_sigwinch_handler); +#endif +} +#endif + /* C function to call the Python completer. */ static char * @@ -1031,6 +1051,10 @@ /* Bind both ESC-TAB and ESC-ESC to the completion function */ rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap); rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap); +#ifdef HAVE_RL_RESIZE_TERMINAL + /* Set up signal handler for window resize */ + sigwinch_ohandler = PyOS_setsig(SIGWINCH, readline_sigwinch_handler); +#endif /* Set our hook functions */ rl_startup_hook = on_startup_hook; #ifdef HAVE_RL_PRE_INPUT_HOOK @@ -1116,6 +1140,13 @@ struct timeval *timeoutp = NULL; if (PyOS_InputHook) timeoutp = &timeout; +#ifdef HAVE_RL_RESIZE_TERMINAL + /* Update readline's view of the window size after SIGWINCH */ + if (sigwinch_received) { + sigwinch_received = 0; + rl_resize_terminal(); + } +#endif FD_SET(fileno(rl_instream), &selectset); /* select resets selectset if no input was available */ has_input = select(fileno(rl_instream) + 1, &selectset, diff --git a/configure b/configure --- a/configure +++ b/configure @@ -14929,6 +14929,50 @@ fi +# also in 4.0, but not in editline +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_resize_terminal in -lreadline" >&5 +$as_echo_n "checking for rl_resize_terminal in -lreadline... " >&6; } +if ${ac_cv_lib_readline_rl_resize_terminal+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lreadline $READLINE_LIBS $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char rl_resize_terminal (); +int +main () +{ +return rl_resize_terminal (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_readline_rl_resize_terminal=yes +else + ac_cv_lib_readline_rl_resize_terminal=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_readline_rl_resize_terminal" >&5 +$as_echo "$ac_cv_lib_readline_rl_resize_terminal" >&6; } +if test "x$ac_cv_lib_readline_rl_resize_terminal" = xyes; then : + +$as_echo "#define HAVE_RL_RESIZE_TERMINAL 1" >>confdefs.h + +fi + + # check for readline 4.2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_completion_matches in -lreadline" >&5 $as_echo_n "checking for rl_completion_matches in -lreadline... " >&6; } diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -4527,6 +4527,11 @@ AC_DEFINE(HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK, 1, [Define if you have readline 4.0]), ,$READLINE_LIBS) +# also in 4.0, but not in editline +AC_CHECK_LIB(readline, rl_resize_terminal, + AC_DEFINE(HAVE_RL_RESIZE_TERMINAL, 1, + [Define if you have readline 4.0]), ,$READLINE_LIBS) + # check for readline 4.2 AC_CHECK_LIB(readline, rl_completion_matches, AC_DEFINE(HAVE_RL_COMPLETION_MATCHES, 1, diff --git a/pyconfig.h.in b/pyconfig.h.in --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -735,6 +735,9 @@ /* Define if you have readline 4.0 */ #undef HAVE_RL_PRE_INPUT_HOOK +/* Define if you have readline 4.0 */ +#undef HAVE_RL_RESIZE_TERMINAL + /* Define to 1 if you have the `round' function. */ #undef HAVE_ROUND -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 3 00:21:02 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 03 Apr 2016 04:21:02 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzIzNzM1?= =?utf-8?q?=3A_Add_SIGWINCH_handler_for_Readline_6=2E3+_support=2C_by_Eric?= =?utf-8?q?_Price?= Message-ID: <20160403042102.97855.41210.7B0736CC@psf.io> https://hg.python.org/cpython/rev/9f237e81cd15 changeset: 100842:9f237e81cd15 branch: 2.7 parent: 100831:4cad272cec82 user: Martin Panter date: Sun Apr 03 02:54:58 2016 +0000 summary: Issue #23735: Add SIGWINCH handler for Readline 6.3+ support, by Eric Price files: Misc/ACKS | 1 + Misc/NEWS | 3 ++ Modules/readline.c | 31 +++++++++++++++++++++++ configure | 44 ++++++++++++++++++++++++++++++++++ configure.ac | 5 +++ pyconfig.h.in | 3 ++ 6 files changed, 87 insertions(+), 0 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1099,6 +1099,7 @@ Amrit Prem Paul Prescod Donovan Preston +Eric Price Paul Price Iuliia Proskurnia Dorian Pula diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -65,6 +65,9 @@ Library ------- +- Issue #23735: Handle terminal resizing with Readline 6.3+ by installing our + own SIGWINCH handler. Patch by Eric Price. + - Issue #26644: Raise ValueError rather than SystemError when a negative length is passed to SSLSocket.recv() or read(). diff --git a/Modules/readline.c b/Modules/readline.c --- a/Modules/readline.c +++ b/Modules/readline.c @@ -817,6 +817,26 @@ } +#ifdef HAVE_RL_RESIZE_TERMINAL +static volatile sig_atomic_t sigwinch_received; +static sighandler_t sigwinch_ohandler; + +static void +readline_sigwinch_handler(int signum) +{ + sigwinch_received = 1; + if (sigwinch_ohandler && + sigwinch_ohandler != SIG_IGN && sigwinch_ohandler != SIG_DFL) + sigwinch_ohandler(signum); + +#ifndef HAVE_SIGACTION + /* If the handler was installed with signal() rather than sigaction(), + we need to reinstall it. */ + PyOS_setsig(SIGWINCH, readline_sigwinch_handler); +#endif +} +#endif + /* C function to call the Python completer. */ static char * @@ -918,6 +938,10 @@ /* Bind both ESC-TAB and ESC-ESC to the completion function */ rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap); rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap); +#ifdef HAVE_RL_RESIZE_TERMINAL + /* Set up signal handler for window resize */ + sigwinch_ohandler = PyOS_setsig(SIGWINCH, readline_sigwinch_handler); +#endif /* Set our hook functions */ rl_startup_hook = on_startup_hook; #ifdef HAVE_RL_PRE_INPUT_HOOK @@ -1003,6 +1027,13 @@ struct timeval *timeoutp = NULL; if (PyOS_InputHook) timeoutp = &timeout; +#ifdef HAVE_RL_RESIZE_TERMINAL + /* Update readline's view of the window size after SIGWINCH */ + if (sigwinch_received) { + sigwinch_received = 0; + rl_resize_terminal(); + } +#endif FD_SET(fileno(rl_instream), &selectset); /* select resets selectset if no input was available */ has_input = select(fileno(rl_instream) + 1, &selectset, diff --git a/configure b/configure --- a/configure +++ b/configure @@ -13925,6 +13925,50 @@ fi +# also in 4.0, but not in editline +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_resize_terminal in -lreadline" >&5 +$as_echo_n "checking for rl_resize_terminal in -lreadline... " >&6; } +if ${ac_cv_lib_readline_rl_resize_terminal+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lreadline $READLINE_LIBS $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char rl_resize_terminal (); +int +main () +{ +return rl_resize_terminal (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_readline_rl_resize_terminal=yes +else + ac_cv_lib_readline_rl_resize_terminal=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_readline_rl_resize_terminal" >&5 +$as_echo "$ac_cv_lib_readline_rl_resize_terminal" >&6; } +if test "x$ac_cv_lib_readline_rl_resize_terminal" = xyes; then : + +$as_echo "#define HAVE_RL_RESIZE_TERMINAL 1" >>confdefs.h + +fi + + # check for readline 4.2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_completion_matches in -lreadline" >&5 $as_echo_n "checking for rl_completion_matches in -lreadline... " >&6; } diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -4199,6 +4199,11 @@ AC_DEFINE(HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK, 1, [Define if you have readline 4.0]), ,$READLINE_LIBS) +# also in 4.0, but not in editline +AC_CHECK_LIB(readline, rl_resize_terminal, + AC_DEFINE(HAVE_RL_RESIZE_TERMINAL, 1, + [Define if you have readline 4.0]), ,$READLINE_LIBS) + # check for readline 4.2 AC_CHECK_LIB(readline, rl_completion_matches, AC_DEFINE(HAVE_RL_COMPLETION_MATCHES, 1, diff --git a/pyconfig.h.in b/pyconfig.h.in --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -580,6 +580,9 @@ /* Define if you have readline 4.0 */ #undef HAVE_RL_PRE_INPUT_HOOK +/* Define if you have readline 4.0 */ +#undef HAVE_RL_RESIZE_TERMINAL + /* Define to 1 if you have the `round' function. */ #undef HAVE_ROUND -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 3 00:21:02 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 03 Apr 2016 04:21:02 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzIzNzM1?= =?utf-8?q?=3A_Add_SIGWINCH_handler_for_Readline_6=2E3+_support=2C_by_Eric?= =?utf-8?q?_Price?= Message-ID: <20160403042101.70489.25967.C985DF7F@psf.io> https://hg.python.org/cpython/rev/b29edd0108ee changeset: 100840:b29edd0108ee branch: 3.5 parent: 100836:f5247195238f user: Martin Panter date: Sun Apr 03 02:54:58 2016 +0000 summary: Issue #23735: Add SIGWINCH handler for Readline 6.3+ support, by Eric Price files: Misc/ACKS | 1 + Misc/NEWS | 3 ++ Modules/readline.c | 31 +++++++++++++++++++++++ configure | 44 ++++++++++++++++++++++++++++++++++ configure.ac | 5 +++ pyconfig.h.in | 3 ++ 6 files changed, 87 insertions(+), 0 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1155,6 +1155,7 @@ Amrit Prem Paul Prescod Donovan Preston +Eric Price Paul Price Iuliia Proskurnia Dorian Pula diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -99,6 +99,9 @@ Library ------- +- Issue #23735: Handle terminal resizing with Readline 6.3+ by installing our + own SIGWINCH handler. Patch by Eric Price. + - Issue #26586: In http.server, respond with "413 Request header fields too large" if there are too many header fields to parse, rather than killing the connection and raising an unhandled exception. Patch by Xiang Zhang. diff --git a/Modules/readline.c b/Modules/readline.c --- a/Modules/readline.c +++ b/Modules/readline.c @@ -928,6 +928,26 @@ #endif +#ifdef HAVE_RL_RESIZE_TERMINAL +static volatile sig_atomic_t sigwinch_received; +static sighandler_t sigwinch_ohandler; + +static void +readline_sigwinch_handler(int signum) +{ + sigwinch_received = 1; + if (sigwinch_ohandler && + sigwinch_ohandler != SIG_IGN && sigwinch_ohandler != SIG_DFL) + sigwinch_ohandler(signum); + +#ifndef HAVE_SIGACTION + /* If the handler was installed with signal() rather than sigaction(), + we need to reinstall it. */ + PyOS_setsig(SIGWINCH, readline_sigwinch_handler); +#endif +} +#endif + /* C function to call the Python completer. */ static char * @@ -1033,6 +1053,10 @@ /* Bind both ESC-TAB and ESC-ESC to the completion function */ rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap); rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap); +#ifdef HAVE_RL_RESIZE_TERMINAL + /* Set up signal handler for window resize */ + sigwinch_ohandler = PyOS_setsig(SIGWINCH, readline_sigwinch_handler); +#endif /* Set our hook functions */ rl_startup_hook = on_startup_hook; #ifdef HAVE_RL_PRE_INPUT_HOOK @@ -1118,6 +1142,13 @@ struct timeval *timeoutp = NULL; if (PyOS_InputHook) timeoutp = &timeout; +#ifdef HAVE_RL_RESIZE_TERMINAL + /* Update readline's view of the window size after SIGWINCH */ + if (sigwinch_received) { + sigwinch_received = 0; + rl_resize_terminal(); + } +#endif FD_SET(fileno(rl_instream), &selectset); /* select resets selectset if no input was available */ has_input = select(fileno(rl_instream) + 1, &selectset, diff --git a/configure b/configure --- a/configure +++ b/configure @@ -14929,6 +14929,50 @@ fi +# also in 4.0, but not in editline +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_resize_terminal in -lreadline" >&5 +$as_echo_n "checking for rl_resize_terminal in -lreadline... " >&6; } +if ${ac_cv_lib_readline_rl_resize_terminal+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lreadline $READLINE_LIBS $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char rl_resize_terminal (); +int +main () +{ +return rl_resize_terminal (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_readline_rl_resize_terminal=yes +else + ac_cv_lib_readline_rl_resize_terminal=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_readline_rl_resize_terminal" >&5 +$as_echo "$ac_cv_lib_readline_rl_resize_terminal" >&6; } +if test "x$ac_cv_lib_readline_rl_resize_terminal" = xyes; then : + +$as_echo "#define HAVE_RL_RESIZE_TERMINAL 1" >>confdefs.h + +fi + + # check for readline 4.2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_completion_matches in -lreadline" >&5 $as_echo_n "checking for rl_completion_matches in -lreadline... " >&6; } diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -4527,6 +4527,11 @@ AC_DEFINE(HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK, 1, [Define if you have readline 4.0]), ,$READLINE_LIBS) +# also in 4.0, but not in editline +AC_CHECK_LIB(readline, rl_resize_terminal, + AC_DEFINE(HAVE_RL_RESIZE_TERMINAL, 1, + [Define if you have readline 4.0]), ,$READLINE_LIBS) + # check for readline 4.2 AC_CHECK_LIB(readline, rl_completion_matches, AC_DEFINE(HAVE_RL_COMPLETION_MATCHES, 1, diff --git a/pyconfig.h.in b/pyconfig.h.in --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -735,6 +735,9 @@ /* Define if you have readline 4.0 */ #undef HAVE_RL_PRE_INPUT_HOOK +/* Define if you have readline 4.0 */ +#undef HAVE_RL_RESIZE_TERMINAL + /* Define to 1 if you have the `round' function. */ #undef HAVE_ROUND -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 3 04:28:19 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 03 Apr 2016 08:28:19 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2323735=3A_Merge_sighandler=5Ft_fix_from_3=2E5?= Message-ID: <20160403082819.32757.50756.7A0367B1@psf.io> https://hg.python.org/cpython/rev/0e576d094dc4 changeset: 100844:0e576d094dc4 parent: 100841:41c2f8742bfe parent: 100843:e3f375047edf user: Martin Panter date: Sun Apr 03 08:04:35 2016 +0000 summary: Issue #23735: Merge sighandler_t fix from 3.5 files: Modules/readline.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/readline.c b/Modules/readline.c --- a/Modules/readline.c +++ b/Modules/readline.c @@ -928,7 +928,7 @@ #ifdef HAVE_RL_RESIZE_TERMINAL static volatile sig_atomic_t sigwinch_received; -static sighandler_t sigwinch_ohandler; +static PyOS_sighandler_t sigwinch_ohandler; static void readline_sigwinch_handler(int signum) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 3 04:28:19 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 03 Apr 2016 08:28:19 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzIzNzM1?= =?utf-8?q?=3A_Avoid_sighandler=5Ft_Gnu-ism?= Message-ID: <20160403082819.32751.23640.0A72C436@psf.io> https://hg.python.org/cpython/rev/596946c06a31 changeset: 100845:596946c06a31 branch: 2.7 parent: 100842:9f237e81cd15 user: Martin Panter date: Sun Apr 03 08:00:49 2016 +0000 summary: Issue #23735: Avoid sighandler_t Gnu-ism files: Modules/readline.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/readline.c b/Modules/readline.c --- a/Modules/readline.c +++ b/Modules/readline.c @@ -819,7 +819,7 @@ #ifdef HAVE_RL_RESIZE_TERMINAL static volatile sig_atomic_t sigwinch_received; -static sighandler_t sigwinch_ohandler; +static PyOS_sighandler_t sigwinch_ohandler; static void readline_sigwinch_handler(int signum) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 3 04:28:19 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 03 Apr 2016 08:28:19 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzIzNzM1?= =?utf-8?q?=3A_Avoid_sighandler=5Ft_Gnu-ism?= Message-ID: <20160403082819.94582.27552.E95713B5@psf.io> https://hg.python.org/cpython/rev/e3f375047edf changeset: 100843:e3f375047edf branch: 3.5 parent: 100840:b29edd0108ee user: Martin Panter date: Sun Apr 03 08:00:49 2016 +0000 summary: Issue #23735: Avoid sighandler_t Gnu-ism files: Modules/readline.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/readline.c b/Modules/readline.c --- a/Modules/readline.c +++ b/Modules/readline.c @@ -930,7 +930,7 @@ #ifdef HAVE_RL_RESIZE_TERMINAL static volatile sig_atomic_t sigwinch_received; -static sighandler_t sigwinch_ohandler; +static PyOS_sighandler_t sigwinch_ohandler; static void readline_sigwinch_handler(int signum) -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Sun Apr 3 05:49:36 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sun, 03 Apr 2016 09:49:36 +0000 Subject: [Python-checkins] Daily reference leaks (41c2f8742bfe): sum=4 Message-ID: <20160403094936.94580.36381.B2ABC34C@psf.io> results for 41c2f8742bfe on branch "default" -------------------------------------------- test_functools leaked [0, 2, 2] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflog64wmky', '--timeout', '7200'] From solipsis at pitrou.net Mon Apr 4 05:49:27 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 04 Apr 2016 09:49:27 +0000 Subject: [Python-checkins] Daily reference leaks (0e576d094dc4): sum=4 Message-ID: <20160404094927.9088.88549.8D20F35F@psf.io> results for 0e576d094dc4 on branch "default" -------------------------------------------- test_functools leaked [0, 2, 2] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogc6yDAB', '--timeout', '7200'] From lp_benchmark_robot at intel.com Mon Apr 4 11:10:25 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Mon, 4 Apr 2016 16:10:25 +0100 Subject: [Python-checkins] NEUTRAL Benchmark Results for Python Default 2016-04-04 Message-ID: <9a2bc164-7fe0-4288-93d7-447c530b18ec@irsmsx104.ger.corp.intel.com> Results for project Python default, build date 2016-04-04 08:18:00 +0000 commit: 0e576d094dc4 previous commit: 307da5f21fd4 revision date: 2016-04-03 08:04:35 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.21% -0.53% 9.30% 14.92% :-| pybench 0.16% 0.05% 0.57% 5.36% :-( regex_v8 2.73% -0.09% -4.66% 4.67% :-) nbody 0.08% 0.04% 2.63% 3.39% :-( json_dump_v2 0.19% -0.44% -2.69% 13.20% :-| normal_startup 0.85% 0.05% 0.08% 5.17% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/neutral-benchmark-results-for-python-default-2016-04-04/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Mon Apr 4 11:11:58 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Mon, 4 Apr 2016 16:11:58 +0100 Subject: [Python-checkins] GOOD Benchmark Results for Python 2.7 2016-04-04 Message-ID: <519c202a-dc76-47cb-8a6c-1c0a21f1fa51@irsmsx104.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-04 09:53:51 +0000 commit: 596946c06a31 previous commit: 1d79e70e67b5 revision date: 2016-04-03 08:00:49 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.15% 2.65% 5.20% 6.76% :-) pybench 0.13% 0.02% 5.98% 4.78% :-( regex_v8 0.78% 0.43% -2.58% 11.73% :-) nbody 0.10% -0.16% 6.97% 5.89% :-) json_dump_v2 0.22% 0.54% 3.92% 12.56% :-( normal_startup 2.07% -0.28% -5.53% 2.45% :-) ssbench 0.20% -0.01% 2.53% 1.10% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/good-benchmark-results-for-python-2-7-2016-04-04/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Mon Apr 4 14:04:21 2016 From: python-checkins at python.org (guido.van.rossum) Date: Mon, 04 Apr 2016 18:04:21 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_collections=2EReversib?= =?utf-8?q?le=2E_Patch_by_Ivan_Levkivskyi=2E_Fixes_issue_=2325987=2E?= Message-ID: <20160404175955.49907.94109.85E774BC@psf.io> https://hg.python.org/cpython/rev/07f73360ea8e changeset: 100846:07f73360ea8e parent: 100844:0e576d094dc4 user: Guido van Rossum date: Mon Apr 04 10:59:29 2016 -0700 summary: Add collections.Reversible. Patch by Ivan Levkivskyi. Fixes issue #25987. files: Doc/library/collections.abc.rst | 7 ++++- Doc/library/typing.rst | 11 +++---- Lib/_collections_abc.py | 23 ++++++++++++++- Lib/test/test_collections.py | 31 ++++++++++++++++++-- Lib/test/test_functools.py | 2 +- 5 files changed, 61 insertions(+), 13 deletions(-) diff --git a/Doc/library/collections.abc.rst b/Doc/library/collections.abc.rst --- a/Doc/library/collections.abc.rst +++ b/Doc/library/collections.abc.rst @@ -40,12 +40,13 @@ :class:`Hashable` ``__hash__`` :class:`Iterable` ``__iter__`` :class:`Iterator` :class:`Iterable` ``__next__`` ``__iter__`` +:class:`Reversible` :class:`Iterable` ``__reversed__`` :class:`Generator` :class:`Iterator` ``send``, ``throw`` ``close``, ``__iter__``, ``__next__`` :class:`Sized` ``__len__`` :class:`Callable` ``__call__`` :class:`Sequence` :class:`Sized`, ``__getitem__``, ``__contains__``, ``__iter__``, ``__reversed__``, - :class:`Iterable`, ``__len__`` ``index``, and ``count`` + :class:`Reversible`, ``__len__`` ``index``, and ``count`` :class:`Container` :class:`MutableSequence` :class:`Sequence` ``__getitem__``, Inherited :class:`Sequence` methods and @@ -107,6 +108,10 @@ :meth:`~iterator.__next__` methods. See also the definition of :term:`iterator`. +.. class:: Reversible + + ABC for classes that provide the :meth:`__reversed__` method. + .. class:: Generator ABC for generator classes that implement the protocol defined in diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -351,6 +351,10 @@ A generic version of the :class:`collections.abc.Iterator`. +.. class:: Reversible(Iterable[T_co]) + + A generic version of the :class:`collections.abc.Reversible`. + .. class:: SupportsInt An ABC with one abstract method ``__int__``. @@ -369,11 +373,6 @@ An ABC with one abstract method ``__round__`` that is covariant in its return type. -.. class:: Reversible - - An ABC with one abstract method ``__reversed__`` returning - an ``Iterator[T_co]``. - .. class:: Container(Generic[T_co]) A generic version of :class:`collections.abc.Container`. @@ -394,7 +393,7 @@ A generic version of :class:`collections.abc.MutableMapping`. -.. class:: Sequence(Sized, Iterable[T_co], Container[T_co]) +.. class:: Sequence(Sized, Reversible[T_co], Container[T_co]) A generic version of :class:`collections.abc.Sequence`. diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py --- a/Lib/_collections_abc.py +++ b/Lib/_collections_abc.py @@ -10,7 +10,7 @@ import sys __all__ = ["Awaitable", "Coroutine", "AsyncIterable", "AsyncIterator", - "Hashable", "Iterable", "Iterator", "Generator", + "Hashable", "Iterable", "Iterator", "Generator", "Reversible", "Sized", "Container", "Callable", "Set", "MutableSet", "Mapping", "MutableMapping", @@ -240,6 +240,25 @@ Iterator.register(zip_iterator) +class Reversible(Iterable): + + __slots__ = () + + @abstractmethod + def __reversed__(self): + return NotImplemented + + @classmethod + def __subclasshook__(cls, C): + if cls is Reversible: + for B in C.__mro__: + if "__reversed__" in B.__dict__: + if B.__dict__["__reversed__"] is not None: + return True + break + return NotImplemented + + class Generator(Iterator): __slots__ = () @@ -794,7 +813,7 @@ ### SEQUENCES ### -class Sequence(Sized, Iterable, Container): +class Sequence(Sized, Reversible, Container): """All the operations on a read-only sequence. diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -20,7 +20,7 @@ from collections import ChainMap from collections import deque from collections.abc import Awaitable, Coroutine, AsyncIterator, AsyncIterable -from collections.abc import Hashable, Iterable, Iterator, Generator +from collections.abc import Hashable, Iterable, Iterator, Generator, Reversible from collections.abc import Sized, Container, Callable from collections.abc import Set, MutableSet from collections.abc import Mapping, MutableMapping, KeysView, ItemsView @@ -689,6 +689,31 @@ self.validate_abstract_methods(Iterable, '__iter__') self.validate_isinstance(Iterable, '__iter__') + def test_Reversible(self): + # Check some non-reversibles + non_samples = [None, 42, 3.14, 1j, dict(), set(), frozenset()] + for x in non_samples: + self.assertNotIsInstance(x, Reversible) + self.assertFalse(issubclass(type(x), Reversible), repr(type(x))) + # Check some reversibles + samples = [tuple(), list()] + for x in samples: + self.assertIsInstance(x, Reversible) + self.assertTrue(issubclass(type(x), Reversible), repr(type(x))) + # Check also Mapping, MutableMapping, and Sequence + self.assertTrue(issubclass(Sequence, Reversible), repr(Sequence)) + self.assertFalse(issubclass(Mapping, Reversible), repr(Mapping)) + self.assertFalse(issubclass(MutableMapping, Reversible), repr(MutableMapping)) + # Check direct subclassing + class R(Reversible): + def __iter__(self): + return iter(list()) + def __reversed__(self): + return iter(list()) + self.assertEqual(list(reversed(R())), []) + self.assertFalse(issubclass(float, R)) + self.validate_abstract_methods(Reversible, '__reversed__', '__iter__') + def test_Iterator(self): non_samples = [None, 42, 3.14, 1j, b"", "", (), [], {}, set()] for x in non_samples: @@ -842,14 +867,14 @@ self.validate_isinstance(Callable, '__call__') def test_direct_subclassing(self): - for B in Hashable, Iterable, Iterator, Sized, Container, Callable: + for B in Hashable, Iterable, Iterator, Reversible, Sized, Container, Callable: class C(B): pass self.assertTrue(issubclass(C, B)) self.assertFalse(issubclass(int, C)) def test_registration(self): - for B in Hashable, Iterable, Iterator, Sized, Container, Callable: + for B in Hashable, Iterable, Iterator, Reversible, Sized, Container, Callable: class C: __hash__ = None # Make sure it isn't hashable by default self.assertFalse(issubclass(C, B), B.__name__) diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -1516,7 +1516,7 @@ m = mro(D, bases) self.assertEqual(m, [D, c.MutableSequence, c.Sequence, c.defaultdict, dict, c.MutableMapping, - c.Mapping, c.Sized, c.Iterable, c.Container, + c.Mapping, c.Sized, c.Reversible, c.Iterable, c.Container, object]) # Container and Callable are registered on different base classes and -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 4 20:40:51 2016 From: python-checkins at python.org (guido.van.rossum) Date: Tue, 05 Apr 2016 00:40:51 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Update_the_section_on_type_er?= =?utf-8?q?asure_to_disallow_Node=5Bint=5D=28=29_--_you_must_use_a?= Message-ID: <20160405004049.70507.93157.FA538F77@psf.io> https://hg.python.org/peps/rev/1ad9e828ca36 changeset: 6275:1ad9e828ca36 user: Guido van Rossum date: Mon Apr 04 17:39:26 2016 -0700 summary: Update the section on type erasure to disallow Node[int]() -- you must use a type alias. files: pep-0484.txt | 65 +++++++++++++++++++++++++-------------- 1 files changed, 41 insertions(+), 24 deletions(-) diff --git a/pep-0484.txt b/pep-0484.txt --- a/pep-0484.txt +++ b/pep-0484.txt @@ -462,41 +462,58 @@ class Node(Generic[T]): ... -Now there are two ways we can instantiate this class; the type -inferred by a type checker may be different depending on the form we -use. The first way is to give the value of the type parameter -explicitly -- this overrides whatever type inference the type -checker would otherwise perform:: +To create ``Node`` instances you call ``Node()`` just as for a regular +class. At runtime the type (class) of the instance will be ``Node``. +But what type does it have to the type checker? The answer depends on +how much information is available in the call. If the constructor +(``__init__`` or ``__new__``) uses ``T`` in its signature, and a +corresponding argument value is passed, the type of the corresponding +argument(s) is substituted. Otherwise, ``Any`` is assumed. Example:: - x = Node[T]() # The type inferred for x is Node[T]. + from typing import TypeVar, Generic - y = Node[int]() # The type inferred for y is Node[int]. + T = TypeVar('T') -If no explicit types are given, the type checker is given some -freedom. Consider this code:: + class Node(Generic[T]): + def __init__(self, label: T = None) -> None: + ... - x = Node() + x = Node('') # Inferred type is Node[str] + y = Node(0) # Inferred type is Node[int] + z = Node() # Inferred type is Node[Any] -The inferred type could be ``Node[Any]``, as there isn't enough -context to infer a more precise type. Alternatively, a type checker -may reject the line and require an explicit annotation, like this:: +In case the inferred type uses ``[Any]`` but the intended type is more +specific, you can use a type comment (see below) to force the type of +the variable, e.g.:: - x = Node() # type: Node[int] # Inferred type is Node[int]. + # (continued from previous example) + a = Node() # type: Node[int] + b = Node() # type: Node[str] -A type checker with more powerful type inference could look at how -``x`` is used elsewhere in the file and try to infer a more precise -type such as ``Node[int]`` even without an explicit type annotation. -However, it is probably impossible to make such type inference work -well in all cases, since Python programs can be very dynamic. +You can also create a type alias (see above) for a specific concrete +type and instantiate it, e.g.:: -This PEP doesn't specify the details of how type inference should -work. We allow different tools to experiment with various approaches. -We may give more explicit rules in future revisions. + # (continued from previous example) + IntNode = Node[int] + StrNode = Node[str] + p = IntNode() # Inferred type is Node[str] + q = StrNode() # Inferred type is Node[int] + r = IntNode('') # Error + s = StrNode(0) # Error -At runtime the type is not preserved, and the class of ``x`` is just -``Node`` in all cases. This behavior is called "type erasure"; it is +Note that the runtime type (class) of p and q is still just ``Node`` +-- ``IntNode`` and ``StrNode`` are distinguishable class objects, but +the type (class) of the objects created by instantiating them doesn't +record the distinction. This behavior is called "type erasure"; it is common practice in languages with generics (e.g. Java, TypeScript). +You cannot use the subscripted class (e.g. ``Node[int]``) directly in +an expression -- you must define a type alias. (This restriction +exists because creating the subscripted class, e.g. ``Node[int]``, is +an expensive operation -- usually many times as expensive as +constructing an instance of it. Using a type alias is also more +readable.) + Arbitrary generic types as base classes --------------------------------------- -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Tue Apr 5 03:01:09 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 05 Apr 2016 07:01:09 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_typos_in_d?= =?utf-8?q?ocumentation_and_comments?= Message-ID: <20160405070107.62151.75396.EDFA701D@psf.io> https://hg.python.org/cpython/rev/f99543cae6ab changeset: 100849:f99543cae6ab branch: 2.7 parent: 100845:596946c06a31 user: Martin Panter date: Tue Apr 05 06:19:42 2016 +0000 summary: Fix typos in documentation and comments files: Include/unicodeobject.h | 2 +- Lib/test/test_argparse.py | 10 +++++----- Misc/NEWS | 2 +- README | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -1318,7 +1318,7 @@ /* Checks whether element is contained in container and return 1/0 accordingly. - element has to coerce to an one element Unicode string. -1 is + element has to coerce to a one element Unicode string. -1 is returned in case of an error. */ PyAPI_FUNC(int) PyUnicode_Contains( diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -548,7 +548,7 @@ class TestOptionalsNargs1(ParserTestCase): - """Tests specifying the 1 arg for an Optional""" + """Tests specifying 1 arg for an Optional""" argument_signatures = [Sig('-x', nargs=1)] failures = ['a', '-x'] @@ -559,7 +559,7 @@ class TestOptionalsNargs3(ParserTestCase): - """Tests specifying the 3 args for an Optional""" + """Tests specifying 3 args for an Optional""" argument_signatures = [Sig('-x', nargs=3)] failures = ['a', '-x', '-x a', '-x a b', 'a -x', 'a -x b'] @@ -593,7 +593,7 @@ class TestOptionalsNargsZeroOrMore(ParserTestCase): - """Tests specifying an args for an Optional that accepts zero or more""" + """Tests specifying args for an Optional that accepts zero or more""" argument_signatures = [ Sig('-x', nargs='*'), @@ -612,7 +612,7 @@ class TestOptionalsNargsOneOrMore(ParserTestCase): - """Tests specifying an args for an Optional that accepts one or more""" + """Tests specifying args for an Optional that accepts one or more""" argument_signatures = [ Sig('-x', nargs='+'), @@ -1232,7 +1232,7 @@ class TestNargsZeroOrMore(ParserTestCase): - """Tests specifying an args for an Optional that accepts zero or more""" + """Tests specifying args for an Optional that accepts zero or more""" argument_signatures = [Sig('-x', nargs='*'), Sig('y', nargs='*')] failures = [] diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -3025,7 +3025,7 @@ - Issue #16152: fix tokenize to ignore whitespace at the end of the code when no newline is found. Patch by Ned Batchelder. -- Issue #16230: Fix a crash in select.select() when one the lists changes +- Issue #16230: Fix a crash in select.select() when one of the lists changes size while iterated on. Patch by Serhiy Storchaka. - Issue #16228: Fix a crash in the json module where a list changes size diff --git a/README b/README --- a/README +++ b/README @@ -210,7 +210,7 @@ and stderr, that may appear at this step is supressed. Finally, the last step is to rebuild the interpreter, using the information -collected in the previous one. The end result will be a the Python binary +collected in the previous one. The end result will be a Python binary that is optimized and suitable for distribution or production installation. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 5 03:01:09 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 05 Apr 2016 07:01:09 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_typo_fixes_from_3=2E5?= Message-ID: <20160405070107.94572.81074.24DEC33C@psf.io> https://hg.python.org/cpython/rev/ff71c15e48f1 changeset: 100848:ff71c15e48f1 parent: 100846:07f73360ea8e parent: 100847:364105f9a620 user: Martin Panter date: Tue Apr 05 06:20:32 2016 +0000 summary: Merge typo fixes from 3.5 files: Doc/library/dis.rst | 2 +- Include/unicodeobject.h | 2 +- Lib/http/client.py | 2 +- Lib/test/test_argparse.py | 10 +++++----- Lib/warnings.py | 2 +- Misc/NEWS | 6 +++--- README | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -708,7 +708,7 @@ Implements assignment with a starred target: Unpacks an iterable in TOS into individual values, where the total number of values can be smaller than the - number of items in the iterable: one the new values will be a list of all + number of items in the iterable: one of the new values will be a list of all leftover items. The low byte of *counts* is the number of values before the list value, the diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -2069,7 +2069,7 @@ /* Checks whether element is contained in container and return 1/0 accordingly. - element has to coerce to an one element Unicode string. -1 is + element has to coerce to a one element Unicode string. -1 is returned in case of an error. */ PyAPI_FUNC(int) PyUnicode_Contains( diff --git a/Lib/http/client.py b/Lib/http/client.py --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -1204,7 +1204,7 @@ If the HTTPConnection is in the correct state, returns an instance of HTTPResponse or of whatever object is returned by - class the response_class variable. + the response_class variable. If a request has not been sent or if a previous response has not be handled, ResponseNotReady is raised. If the HTTP diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -534,7 +534,7 @@ class TestOptionalsNargs1(ParserTestCase): - """Tests specifying the 1 arg for an Optional""" + """Tests specifying 1 arg for an Optional""" argument_signatures = [Sig('-x', nargs=1)] failures = ['a', '-x'] @@ -545,7 +545,7 @@ class TestOptionalsNargs3(ParserTestCase): - """Tests specifying the 3 args for an Optional""" + """Tests specifying 3 args for an Optional""" argument_signatures = [Sig('-x', nargs=3)] failures = ['a', '-x', '-x a', '-x a b', 'a -x', 'a -x b'] @@ -579,7 +579,7 @@ class TestOptionalsNargsZeroOrMore(ParserTestCase): - """Tests specifying an args for an Optional that accepts zero or more""" + """Tests specifying args for an Optional that accepts zero or more""" argument_signatures = [ Sig('-x', nargs='*'), @@ -598,7 +598,7 @@ class TestOptionalsNargsOneOrMore(ParserTestCase): - """Tests specifying an args for an Optional that accepts one or more""" + """Tests specifying args for an Optional that accepts one or more""" argument_signatures = [ Sig('-x', nargs='+'), @@ -1251,7 +1251,7 @@ class TestNargsZeroOrMore(ParserTestCase): - """Tests specifying an args for an Optional that accepts zero or more""" + """Tests specifying args for an Optional that accepts zero or more""" argument_signatures = [Sig('-x', nargs='*'), Sig('y', nargs='*')] failures = [] diff --git a/Lib/warnings.py b/Lib/warnings.py --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -43,7 +43,7 @@ line = linecache.getline(msg.filename, msg.lineno) except Exception: # When a warning is logged during Python shutdown, linecache - # and the improt machinery don't work anymore + # and the import machinery don't work anymore line = None linecache = None else: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2406,7 +2406,7 @@ Build ----- -- Issue #23817: FreeBSD now uses "1.0" the the SOVERSION as other operating +- Issue #23817: FreeBSD now uses "1.0" in the SOVERSION as other operating systems, instead of just "1". - Issue #23501: Argument Clinic now generates code into separate files by default. @@ -7420,7 +7420,7 @@ Thomas Barlow. - Issue #17358: Modules loaded by imp.load_source() and load_compiled() (and by - extention load_module()) now have a better chance of working when reloaded. + extension load_module()) now have a better chance of working when reloaded. - Issue #17804: New function ``struct.iter_unpack`` allows for streaming struct unpacking. @@ -8103,7 +8103,7 @@ - Issue #16284: Prevent keeping unnecessary references to worker functions in concurrent.futures ThreadPoolExecutor. -- Issue #16230: Fix a crash in select.select() when one the lists changes +- Issue #16230: Fix a crash in select.select() when one of the lists changes size while iterated on. Patch by Serhiy Storchaka. - Issue #16228: Fix a crash in the json module where a list changes size diff --git a/README b/README --- a/README +++ b/README @@ -71,7 +71,7 @@ and stderr, that may appear at this step is supressed. Finally, the last step is to rebuild the interpreter, using the information -collected in the previous one. The end result will be a the Python binary +collected in the previous one. The end result will be a Python binary that is optimized and suitable for distribution or production installation. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 5 03:01:09 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 05 Apr 2016 07:01:09 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Fix_typos_in_d?= =?utf-8?q?ocumentation_and_comments?= Message-ID: <20160405070107.49905.24531.3F374E1A@psf.io> https://hg.python.org/cpython/rev/364105f9a620 changeset: 100847:364105f9a620 branch: 3.5 parent: 100843:e3f375047edf user: Martin Panter date: Tue Apr 05 06:19:42 2016 +0000 summary: Fix typos in documentation and comments files: Doc/library/dis.rst | 2 +- Include/unicodeobject.h | 2 +- Lib/http/client.py | 2 +- Lib/test/test_argparse.py | 10 +++++----- Lib/warnings.py | 2 +- Misc/NEWS | 6 +++--- README | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -708,7 +708,7 @@ Implements assignment with a starred target: Unpacks an iterable in TOS into individual values, where the total number of values can be smaller than the - number of items in the iterable: one the new values will be a list of all + number of items in the iterable: one of the new values will be a list of all leftover items. The low byte of *counts* is the number of values before the list value, the diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -2052,7 +2052,7 @@ /* Checks whether element is contained in container and return 1/0 accordingly. - element has to coerce to an one element Unicode string. -1 is + element has to coerce to a one element Unicode string. -1 is returned in case of an error. */ PyAPI_FUNC(int) PyUnicode_Contains( diff --git a/Lib/http/client.py b/Lib/http/client.py --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -1155,7 +1155,7 @@ If the HTTPConnection is in the correct state, returns an instance of HTTPResponse or of whatever object is returned by - class the response_class variable. + the response_class variable. If a request has not been sent or if a previous response has not be handled, ResponseNotReady is raised. If the HTTP diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -534,7 +534,7 @@ class TestOptionalsNargs1(ParserTestCase): - """Tests specifying the 1 arg for an Optional""" + """Tests specifying 1 arg for an Optional""" argument_signatures = [Sig('-x', nargs=1)] failures = ['a', '-x'] @@ -545,7 +545,7 @@ class TestOptionalsNargs3(ParserTestCase): - """Tests specifying the 3 args for an Optional""" + """Tests specifying 3 args for an Optional""" argument_signatures = [Sig('-x', nargs=3)] failures = ['a', '-x', '-x a', '-x a b', 'a -x', 'a -x b'] @@ -579,7 +579,7 @@ class TestOptionalsNargsZeroOrMore(ParserTestCase): - """Tests specifying an args for an Optional that accepts zero or more""" + """Tests specifying args for an Optional that accepts zero or more""" argument_signatures = [ Sig('-x', nargs='*'), @@ -598,7 +598,7 @@ class TestOptionalsNargsOneOrMore(ParserTestCase): - """Tests specifying an args for an Optional that accepts one or more""" + """Tests specifying args for an Optional that accepts one or more""" argument_signatures = [ Sig('-x', nargs='+'), @@ -1251,7 +1251,7 @@ class TestNargsZeroOrMore(ParserTestCase): - """Tests specifying an args for an Optional that accepts zero or more""" + """Tests specifying args for an Optional that accepts zero or more""" argument_signatures = [Sig('-x', nargs='*'), Sig('y', nargs='*')] failures = [] diff --git a/Lib/warnings.py b/Lib/warnings.py --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -28,7 +28,7 @@ line = linecache.getline(filename, lineno) except Exception: # When a warning is logged during Python shutdown, linecache - # and the improt machinery don't work anymore + # and the import machinery don't work anymore line = None if line: line = line.strip() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -1812,7 +1812,7 @@ Build ----- -- Issue #23817: FreeBSD now uses "1.0" the the SOVERSION as other operating +- Issue #23817: FreeBSD now uses "1.0" in the SOVERSION as other operating systems, instead of just "1". - Issue #23501: Argument Clinic now generates code into separate files by default. @@ -6826,7 +6826,7 @@ Thomas Barlow. - Issue #17358: Modules loaded by imp.load_source() and load_compiled() (and by - extention load_module()) now have a better chance of working when reloaded. + extension load_module()) now have a better chance of working when reloaded. - Issue #17804: New function ``struct.iter_unpack`` allows for streaming struct unpacking. @@ -7509,7 +7509,7 @@ - Issue #16284: Prevent keeping unnecessary references to worker functions in concurrent.futures ThreadPoolExecutor. -- Issue #16230: Fix a crash in select.select() when one the lists changes +- Issue #16230: Fix a crash in select.select() when one of the lists changes size while iterated on. Patch by Serhiy Storchaka. - Issue #16228: Fix a crash in the json module where a list changes size diff --git a/README b/README --- a/README +++ b/README @@ -71,7 +71,7 @@ and stderr, that may appear at this step is supressed. Finally, the last step is to rebuild the interpreter, using the information -collected in the previous one. The end result will be a the Python binary +collected in the previous one. The end result will be a Python binary that is optimized and suitable for distribution or production installation. -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Tue Apr 5 05:42:20 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Tue, 05 Apr 2016 09:42:20 +0000 Subject: [Python-checkins] Daily reference leaks (07f73360ea8e): sum=62 Message-ID: <20160405094218.94586.29413.4C0EB3DE@psf.io> results for 07f73360ea8e on branch "default" -------------------------------------------- test_functools leaked [0, 3, 1] memory blocks, sum=4 test_multiprocessing_spawn leaked [0, 0, 38] references, sum=38 test_multiprocessing_spawn leaked [0, 0, 18] memory blocks, sum=18 test_multiprocessing_spawn leaked [0, 0, 2] file descriptors, sum=2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogcU1HE_', '--timeout', '7200'] From python-checkins at python.org Tue Apr 5 06:31:35 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 05 Apr 2016 10:31:35 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzY5NTM6?= =?utf-8?q?_Rearrange_and_expand_Readline_module_documentation?= Message-ID: <20160405103135.9990.43744.8855C13E@psf.io> https://hg.python.org/cpython/rev/6137c46cb8df changeset: 100850:6137c46cb8df branch: 2.7 user: Martin Panter date: Tue Apr 05 07:37:22 2016 +0000 summary: Issue #6953: Rearrange and expand Readline module documentation * Group functions into six new subsections * Document the underlying Readline function or variable accessed * get_history_length() returns the history file limit * clear_history() is conditionally compiled in * Clarify zero and one bases for history item indexes * parse_and_bind() uses its argument directly as an init line * Change "command line" to "line buffer" for consistency * read_init_file() also executes the file * read_history_file() replaces the previous history * write_history_file() overwrites any existing file * Differentiate history file lines from history list items, which could be multi-line * Add more information about completion, also addressing Issue #10796 * libedit (Editline) may be used on any platform; detection is OS X specific files: Doc/library/readline.rst | 180 +++++++++++++++++--------- Misc/NEWS | 7 + Modules/readline.c | 30 ++-- 3 files changed, 140 insertions(+), 77 deletions(-) diff --git a/Doc/library/readline.rst b/Doc/library/readline.rst --- a/Doc/library/readline.rst +++ b/Doc/library/readline.rst @@ -9,15 +9,18 @@ The :mod:`readline` module defines a number of functions to facilitate completion and reading/writing of history files from the Python interpreter. -This module can be used directly or via the :mod:`rlcompleter` module. Settings +This module can be used directly, or via the :mod:`rlcompleter` module, which +supports completion of Python identifiers at the interactive prompt. Settings made using this module affect the behaviour of both the interpreter's interactive prompt and the prompts offered by the :func:`raw_input` and :func:`input` built-in functions. .. note:: - On MacOS X the :mod:`readline` module can be implemented using + The underlying Readline library API may be implemented by the ``libedit`` library instead of GNU readline. + On MacOS X the :mod:`readline` module detects which library is being used + at run time. The configuration file for ``libedit`` is different from that of GNU readline. If you programmatically load configuration strings @@ -25,64 +28,97 @@ to differentiate between GNU readline and libedit. -The :mod:`readline` module defines the following functions: +Init file +--------- + +The following functions relate to the init file and user configuration: .. function:: parse_and_bind(string) - Parse and execute single line of a readline init file. + Execute the init line provided in the *string* argument. This calls + :c:func:`rl_parse_and_bind` in the underlying library. + + +.. function:: read_init_file([filename]) + + Execute a readline initialization file. The default filename is the last filename + used. This calls :c:func:`rl_read_init_file` in the underlying library. + + +Line buffer +----------- + +The following functions operate on the line buffer: .. function:: get_line_buffer() - Return the current contents of the line buffer. + Return the current contents of the line buffer (:c:data:`rl_line_buffer` + in the underlying library). .. function:: insert_text(string) - Insert text into the command line. + Insert text into the line buffer at the cursor position. This calls + :c:func:`rl_insert_text` in the underlying library, but ignores + the return value. -.. function:: read_init_file([filename]) +.. function:: redisplay() - Parse a readline initialization file. The default filename is the last filename - used. + Change what's displayed on the screen to reflect the current contents of the + line buffer. This calls :c:func:`rl_redisplay` in the underlying library. + + +History file +------------ + +The following functions operate on a history file: .. function:: read_history_file([filename]) - Load a readline history file. The default filename is :file:`~/.history`. + Load a readline history file, and append it to the history list. + The default filename is :file:`~/.history`. This calls + :c:func:`read_history` in the underlying library. .. function:: write_history_file([filename]) - Save a readline history file. The default filename is :file:`~/.history`. + Save the history list to a readline history file, overwriting any + existing file. The default filename is :file:`~/.history`. This calls + :c:func:`write_history` in the underlying library. + + +.. function:: get_history_length() + set_history_length(length) + + Set or return the desired number of lines to save in the history file. + The :func:`write_history_file` function uses this value to truncate + the history file, by calling :c:func:`history_truncate_file` in + the underlying library. Negative values imply + unlimited history file size. + + +History list +------------ + +The following functions operate on a global history list: .. function:: clear_history() - Clear the current history. (Note: this function is not available if the - installed version of GNU readline doesn't support it.) + Clear the current history. This calls :c:func:`clear_history` in the + underlying library. The Python function only exists if Python was + compiled for a version of the library that supports it. .. versionadded:: 2.4 -.. function:: get_history_length() - - Return the desired length of the history file. Negative values imply unlimited - history file size. - - -.. function:: set_history_length(length) - - Set the number of lines to save in the history file. :func:`write_history_file` - uses this value to truncate the history file when saving. Negative values imply - unlimited history file size. - - .. function:: get_current_history_length() - Return the number of lines currently in the history. (This is different from + Return the number of items currently in the history. (This is different from :func:`get_history_length`, which returns the maximum number of lines that will be written to a history file.) @@ -91,7 +127,8 @@ .. function:: get_history_item(index) - Return the current contents of history item at *index*. + Return the current contents of history item at *index*. The item index + is one-based. This calls :c:func:`history_get` in the underlying library. .. versionadded:: 2.3 @@ -99,42 +136,63 @@ .. function:: remove_history_item(pos) Remove history item specified by its position from the history. + The position is zero-based. This calls :c:func:`remove_history` in + the underlying library. .. versionadded:: 2.4 .. function:: replace_history_item(pos, line) - Replace history item specified by its position with the given line. + Replace history item specified by its position with *line*. + The position is zero-based. This calls :c:func:`replace_history_entry` + in the underlying library. .. versionadded:: 2.4 -.. function:: redisplay() +.. function:: add_history(line) - Change what's displayed on the screen to reflect the current contents of the - line buffer. + Append *line* to the history buffer, as if it was the last line typed. + This calls :c:func:`add_history` in the underlying library. + + +Startup hooks +------------- .. versionadded:: 2.3 .. function:: set_startup_hook([function]) - Set or remove the startup_hook function. If *function* is specified, it will be - used as the new startup_hook function; if omitted or ``None``, any hook function - already installed is removed. The startup_hook function is called with no + Set or remove the function invoked by the :c:data:`rl_startup_hook` + callback of the underlying library. If *function* is specified, it will + be used as the new hook function; if omitted or ``None``, any function + already installed is removed. The hook is called with no arguments just before readline prints the first prompt. .. function:: set_pre_input_hook([function]) - Set or remove the pre_input_hook function. If *function* is specified, it will - be used as the new pre_input_hook function; if omitted or ``None``, any hook - function already installed is removed. The pre_input_hook function is called + Set or remove the function invoked by the :c:data:`rl_pre_input_hook` + callback of the underlying library. If *function* is specified, it will + be used as the new hook function; if omitted or ``None``, any + function already installed is removed. The hook is called with no arguments after the first prompt has been printed and just before readline starts reading input characters. +Completion +---------- + +The following functions relate to implementing a custom word completion +function. This is typically operated by the Tab key, and can suggest and +automatically complete a word being typed. By default, Readline is set up +to be used by :mod:`rlcompleter` to complete Python identifiers for +the interactive interpreter. If the :mod:`readline` module is to be used +with a custom completer, a different set of word delimiters should be set. + + .. function:: set_completer([function]) Set or remove the completer function. If *function* is specified, it will be @@ -144,6 +202,12 @@ returns a non-string value. It should return the next possible completion starting with *text*. + The installed completer function is invoked by the *entry_func* callback + passed to :c:func:`rl_completion_matches` in the underlying library. + The *text* string comes from the first parameter to the + :c:data:`rl_attempted_completion_function` callback of the + underlying library. + .. function:: get_completer() @@ -154,50 +218,42 @@ .. function:: get_completion_type() - Get the type of completion being attempted. + Get the type of completion being attempted. This returns the + :c:data:`rl_completion_type` variable in the underlying library as + an integer. .. versionadded:: 2.6 .. function:: get_begidx() + get_endidx() - Get the beginning index of the readline tab-completion scope. - - -.. function:: get_endidx() - - Get the ending index of the readline tab-completion scope. + Get the beginning or ending index of the completion scope. + These indexes are the *start* and *end* arguments passed to the + :c:data:`rl_attempted_completion_function` callback of the + underlying library. .. function:: set_completer_delims(string) + get_completer_delims() - Set the readline word delimiters for tab-completion. - - -.. function:: get_completer_delims() - - Get the readline word delimiters for tab-completion. + Set or get the word delimiters for completion. These determine the + start of the word to be considered for completion (the completion scope). + These functions access the :c:data:`rl_completer_word_break_characters` + variable in the underlying library. .. function:: set_completion_display_matches_hook([function]) Set or remove the completion display function. If *function* is specified, it will be used as the new completion display function; if omitted or ``None``, any completion display function already - installed is removed. The completion display function is called as + installed is removed. This sets or clears the + :c:data:`rl_completion_display_matches_hook` callback in the + underlying library. The completion display function is called as ``function(substitution, [matches], longest_match_length)`` once each time matches need to be displayed. .. versionadded:: 2.6 -.. function:: add_history(line) - - Append a line to the history buffer, as if it was the last line typed. - -.. seealso:: - - Module :mod:`rlcompleter` - Completion of Python identifiers at the interactive prompt. - - .. _readline-example: Example diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -184,6 +184,13 @@ installing IDLE 2.7 on OS X: default configuration settings are no longer installed from OS X specific copies. +Documentation +------------- + +- Issue #6953: Rework the Readline module documentation to group related + functions together, and add more details such as what underlying Readline + functions and variables are accessed. + Tests ----- diff --git a/Modules/readline.c b/Modules/readline.c --- a/Modules/readline.c +++ b/Modules/readline.c @@ -96,7 +96,7 @@ PyDoc_STRVAR(doc_parse_and_bind, "parse_and_bind(string) -> None\n\ -Parse and execute single line of a readline init file."); +Execute the init line provided in the string argument."); /* Exported function to parse a readline init file */ @@ -115,7 +115,7 @@ PyDoc_STRVAR(doc_read_init_file, "read_init_file([filename]) -> None\n\ -Parse a readline initialization file.\n\ +Execute a readline initialization file.\n\ The default filename is the last filename used."); @@ -176,7 +176,7 @@ PyDoc_STRVAR(set_history_length_doc, "set_history_length(length) -> None\n\ -set the maximal number of items which will be written to\n\ +set the maximal number of lines which will be written to\n\ the history file. A negative length is used to inhibit\n\ history truncation."); @@ -191,7 +191,7 @@ PyDoc_STRVAR(get_history_length_doc, "get_history_length() -> int\n\ -return the maximum number of items that will be written to\n\ +return the maximum number of lines that will be written to\n\ the history file."); @@ -269,7 +269,7 @@ PyDoc_STRVAR(doc_set_startup_hook, "set_startup_hook([function]) -> None\n\ -Set or remove the startup_hook function.\n\ +Set or remove the function invoked by the rl_startup_hook callback.\n\ The function is called with no arguments just\n\ before readline prints the first prompt."); @@ -286,7 +286,7 @@ PyDoc_STRVAR(doc_set_pre_input_hook, "set_pre_input_hook([function]) -> None\n\ -Set or remove the pre_input_hook function.\n\ +Set or remove the function invoked by the rl_pre_input_hook callback.\n\ The function is called with no arguments after the first prompt\n\ has been printed and just before readline starts reading input\n\ characters."); @@ -325,7 +325,7 @@ PyDoc_STRVAR(doc_get_begidx, "get_begidx() -> int\n\ -get the beginning index of the readline tab-completion scope"); +get the beginning index of the completion scope"); /* Get the ending index for the scope of the tab-completion */ @@ -339,7 +339,7 @@ PyDoc_STRVAR(doc_get_endidx, "get_endidx() -> int\n\ -get the ending index of the readline tab-completion scope"); +get the ending index of the completion scope"); /* Set the tab-completion word-delimiters that readline uses */ @@ -368,7 +368,7 @@ PyDoc_STRVAR(doc_set_completer_delims, "set_completer_delims(string) -> None\n\ -set the readline word delimiters for tab-completion"); +set the word delimiters for completion"); /* _py_free_history_entry: Utility function to free a history entry. */ @@ -408,7 +408,7 @@ int entry_number; HIST_ENTRY *entry; - if (!PyArg_ParseTuple(args, "i:remove_history", &entry_number)) + if (!PyArg_ParseTuple(args, "i:remove_history_item", &entry_number)) return NULL; if (entry_number < 0) { PyErr_SetString(PyExc_ValueError, @@ -438,7 +438,7 @@ char *line; HIST_ENTRY *old_entry; - if (!PyArg_ParseTuple(args, "is:replace_history", &entry_number, + if (!PyArg_ParseTuple(args, "is:replace_history_item", &entry_number, &line)) { return NULL; } @@ -479,7 +479,7 @@ PyDoc_STRVAR(doc_add_history, "add_history(string) -> None\n\ -add a line to the history buffer"); +add an item to the history buffer"); /* Get the tab-completion word-delimiters that readline uses */ @@ -492,7 +492,7 @@ PyDoc_STRVAR(doc_get_completer_delims, "get_completer_delims() -> string\n\ -get the readline word delimiters for tab-completion"); +get the word delimiters for completion"); /* Set the completer function */ @@ -553,7 +553,7 @@ int idx = 0; HIST_ENTRY *hist_ent; - if (!PyArg_ParseTuple(args, "i:index", &idx)) + if (!PyArg_ParseTuple(args, "i:get_history_item", &idx)) return NULL; #ifdef __APPLE__ if (using_libedit_emulation) { @@ -645,7 +645,7 @@ PyDoc_STRVAR(doc_insert_text, "insert_text(string) -> None\n\ -Insert text into the command line."); +Insert text into the line buffer at the cursor position."); /* Redisplay the line buffer */ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 5 06:32:00 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 05 Apr 2016 10:32:00 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzY5NTM6?= =?utf-8?q?_Rearrange_and_expand_Readline_module_documentation?= Message-ID: <20160405103135.70499.30652.5694CE5D@psf.io> https://hg.python.org/cpython/rev/b1acd6cf15b6 changeset: 100851:b1acd6cf15b6 branch: 3.5 parent: 100847:364105f9a620 user: Martin Panter date: Tue Apr 05 07:37:22 2016 +0000 summary: Issue #6953: Rearrange and expand Readline module documentation * Group functions into six new subsections * Document the underlying Readline function or variable accessed * get_history_length() returns the history file limit * clear_history() is conditionally compiled in * Clarify zero and one bases for history item indexes * parse_and_bind() uses its argument directly as an init line * Change "command line" to "line buffer" for consistency * read_init_file() also executes the file * read_history_file() replaces the previous history * write_history_file() overwrites any existing file * Differentiate history file lines from history list items, which could be multi-line * Add more information about completion, also addressing Issue #10796 * libedit (Editline) may be used on any platform; detection is OS X specific files: Doc/library/readline.rst | 185 +++++++++++++++++--------- Misc/NEWS | 4 + Modules/readline.c | 32 ++-- 3 files changed, 141 insertions(+), 80 deletions(-) diff --git a/Doc/library/readline.rst b/Doc/library/readline.rst --- a/Doc/library/readline.rst +++ b/Doc/library/readline.rst @@ -9,15 +9,18 @@ The :mod:`readline` module defines a number of functions to facilitate completion and reading/writing of history files from the Python interpreter. -This module can be used directly or via the :mod:`rlcompleter` module. Settings +This module can be used directly, or via the :mod:`rlcompleter` module, which +supports completion of Python identifiers at the interactive prompt. Settings made using this module affect the behaviour of both the interpreter's interactive prompt and the prompts offered by the built-in :func:`input` function. .. note:: - On MacOS X the :mod:`readline` module can be implemented using + The underlying Readline library API may be implemented by the ``libedit`` library instead of GNU readline. + On MacOS X the :mod:`readline` module detects which library is being used + at run time. The configuration file for ``libedit`` is different from that of GNU readline. If you programmatically load configuration strings @@ -25,112 +28,168 @@ to differentiate between GNU readline and libedit. -The :mod:`readline` module defines the following functions: +Init file +--------- + +The following functions relate to the init file and user configuration: .. function:: parse_and_bind(string) - Parse and execute single line of a readline init file. + Execute the init line provided in the *string* argument. This calls + :c:func:`rl_parse_and_bind` in the underlying library. + + +.. function:: read_init_file([filename]) + + Execute a readline initialization file. The default filename is the last filename + used. This calls :c:func:`rl_read_init_file` in the underlying library. + + +Line buffer +----------- + +The following functions operate on the line buffer: .. function:: get_line_buffer() - Return the current contents of the line buffer. + Return the current contents of the line buffer (:c:data:`rl_line_buffer` + in the underlying library). .. function:: insert_text(string) - Insert text into the command line. + Insert text into the line buffer at the cursor position. This calls + :c:func:`rl_insert_text` in the underlying library, but ignores + the return value. -.. function:: read_init_file([filename]) +.. function:: redisplay() - Parse a readline initialization file. The default filename is the last filename - used. + Change what's displayed on the screen to reflect the current contents of the + line buffer. This calls :c:func:`rl_redisplay` in the underlying library. + + +History file +------------ + +The following functions operate on a history file: .. function:: read_history_file([filename]) - Load a readline history file. The default filename is :file:`~/.history`. + Load a readline history file, and append it to the history list. + The default filename is :file:`~/.history`. This calls + :c:func:`read_history` in the underlying library. .. function:: write_history_file([filename]) - Save a readline history file. The default filename is :file:`~/.history`. + Save the history list to a readline history file, overwriting any + existing file. The default filename is :file:`~/.history`. This calls + :c:func:`write_history` in the underlying library. .. function:: append_history_file(nelements[, filename]) - Append the last *nelements* of history to a file. The default filename is - :file:`~/.history`. The file must already exist. + Append the last *nelements* items of history to a file. The default filename is + :file:`~/.history`. The file must already exist. This calls + :c:func:`append_history` in the underlying library. .. versionadded:: 3.5 +.. function:: get_history_length() + set_history_length(length) + + Set or return the desired number of lines to save in the history file. + The :func:`write_history_file` function uses this value to truncate + the history file, by calling :c:func:`history_truncate_file` in + the underlying library. Negative values imply + unlimited history file size. + + +History list +------------ + +The following functions operate on a global history list: + + .. function:: clear_history() - Clear the current history. (Note: this function is not available if the - installed version of GNU readline doesn't support it.) - - -.. function:: get_history_length() - - Return the desired length of the history file. Negative values imply unlimited - history file size. - - -.. function:: set_history_length(length) - - Set the number of lines to save in the history file. :func:`write_history_file` - uses this value to truncate the history file when saving. Negative values imply - unlimited history file size. + Clear the current history. This calls :c:func:`clear_history` in the + underlying library. The Python function only exists if Python was + compiled for a version of the library that supports it. .. function:: get_current_history_length() - Return the number of lines currently in the history. (This is different from + Return the number of items currently in the history. (This is different from :func:`get_history_length`, which returns the maximum number of lines that will be written to a history file.) .. function:: get_history_item(index) - Return the current contents of history item at *index*. + Return the current contents of history item at *index*. The item index + is one-based. This calls :c:func:`history_get` in the underlying library. .. function:: remove_history_item(pos) Remove history item specified by its position from the history. + The position is zero-based. This calls :c:func:`remove_history` in + the underlying library. .. function:: replace_history_item(pos, line) - Replace history item specified by its position with the given line. + Replace history item specified by its position with *line*. + The position is zero-based. This calls :c:func:`replace_history_entry` + in the underlying library. -.. function:: redisplay() +.. function:: add_history(line) - Change what's displayed on the screen to reflect the current contents of the - line buffer. + Append *line* to the history buffer, as if it was the last line typed. + This calls :c:func:`add_history` in the underlying library. + + +Startup hooks +------------- .. function:: set_startup_hook([function]) - Set or remove the startup_hook function. If *function* is specified, it will be - used as the new startup_hook function; if omitted or ``None``, any hook function - already installed is removed. The startup_hook function is called with no + Set or remove the function invoked by the :c:data:`rl_startup_hook` + callback of the underlying library. If *function* is specified, it will + be used as the new hook function; if omitted or ``None``, any function + already installed is removed. The hook is called with no arguments just before readline prints the first prompt. .. function:: set_pre_input_hook([function]) - Set or remove the pre_input_hook function. If *function* is specified, it will - be used as the new pre_input_hook function; if omitted or ``None``, any hook - function already installed is removed. The pre_input_hook function is called + Set or remove the function invoked by the :c:data:`rl_pre_input_hook` + callback of the underlying library. If *function* is specified, it will + be used as the new hook function; if omitted or ``None``, any + function already installed is removed. The hook is called with no arguments after the first prompt has been printed and just before readline starts reading input characters. +Completion +---------- + +The following functions relate to implementing a custom word completion +function. This is typically operated by the Tab key, and can suggest and +automatically complete a word being typed. By default, Readline is set up +to be used by :mod:`rlcompleter` to complete Python identifiers for +the interactive interpreter. If the :mod:`readline` module is to be used +with a custom completer, a different set of word delimiters should be set. + + .. function:: set_completer([function]) Set or remove the completer function. If *function* is specified, it will be @@ -140,6 +199,12 @@ returns a non-string value. It should return the next possible completion starting with *text*. + The installed completer function is invoked by the *entry_func* callback + passed to :c:func:`rl_completion_matches` in the underlying library. + The *text* string comes from the first parameter to the + :c:data:`rl_attempted_completion_function` callback of the + underlying library. + .. function:: get_completer() @@ -148,27 +213,27 @@ .. function:: get_completion_type() - Get the type of completion being attempted. + Get the type of completion being attempted. This returns the + :c:data:`rl_completion_type` variable in the underlying library as + an integer. .. function:: get_begidx() + get_endidx() - Get the beginning index of the readline tab-completion scope. - - -.. function:: get_endidx() - - Get the ending index of the readline tab-completion scope. + Get the beginning or ending index of the completion scope. + These indexes are the *start* and *end* arguments passed to the + :c:data:`rl_attempted_completion_function` callback of the + underlying library. .. function:: set_completer_delims(string) + get_completer_delims() - Set the readline word delimiters for tab-completion. - - -.. function:: get_completer_delims() - - Get the readline word delimiters for tab-completion. + Set or get the word delimiters for completion. These determine the + start of the word to be considered for completion (the completion scope). + These functions access the :c:data:`rl_completer_word_break_characters` + variable in the underlying library. .. function:: set_completion_display_matches_hook([function]) @@ -176,21 +241,13 @@ Set or remove the completion display function. If *function* is specified, it will be used as the new completion display function; if omitted or ``None``, any completion display function already - installed is removed. The completion display function is called as + installed is removed. This sets or clears the + :c:data:`rl_completion_display_matches_hook` callback in the + underlying library. The completion display function is called as ``function(substitution, [matches], longest_match_length)`` once each time matches need to be displayed. -.. function:: add_history(line) - - Append a line to the history buffer, as if it was the last line typed. - -.. seealso:: - - Module :mod:`rlcompleter` - Completion of Python identifiers at the interactive prompt. - - .. _readline-example: Example diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -340,6 +340,10 @@ Documentation ------------- +- Issue #6953: Rework the Readline module documentation to group related + functions together, and add more details such as what underlying Readline + functions and variables are accessed. + - Issue #23606: Adds note to ctypes documentation regarding cdll.msvcrt. - Issue #25500: Fix documentation to not claim that __import__ is searched for diff --git a/Modules/readline.c b/Modules/readline.c --- a/Modules/readline.c +++ b/Modules/readline.c @@ -149,7 +149,7 @@ PyDoc_STRVAR(doc_parse_and_bind, "parse_and_bind(string) -> None\n\ -Parse and execute single line of a readline init file."); +Execute the init line provided in the string argument."); /* Exported function to parse a readline init file */ @@ -174,7 +174,7 @@ PyDoc_STRVAR(doc_read_init_file, "read_init_file([filename]) -> None\n\ -Parse a readline initialization file.\n\ +Execute a readline initialization file.\n\ The default filename is the last filename used."); @@ -271,7 +271,7 @@ PyDoc_STRVAR(doc_append_history_file, "append_history_file(nelements[, filename]) -> None\n\ -Append the last nelements of the history list to file.\n\ +Append the last nelements items of the history list to file.\n\ The default filename is ~/.history."); #endif @@ -290,7 +290,7 @@ PyDoc_STRVAR(set_history_length_doc, "set_history_length(length) -> None\n\ -set the maximal number of items which will be written to\n\ +set the maximal number of lines which will be written to\n\ the history file. A negative length is used to inhibit\n\ history truncation."); @@ -305,7 +305,7 @@ PyDoc_STRVAR(get_history_length_doc, "get_history_length() -> int\n\ -return the maximum number of items that will be written to\n\ +return the maximum number of lines that will be written to\n\ the history file."); @@ -373,7 +373,7 @@ PyDoc_STRVAR(doc_set_startup_hook, "set_startup_hook([function]) -> None\n\ -Set or remove the startup_hook function.\n\ +Set or remove the function invoked by the rl_startup_hook callback.\n\ The function is called with no arguments just\n\ before readline prints the first prompt."); @@ -390,7 +390,7 @@ PyDoc_STRVAR(doc_set_pre_input_hook, "set_pre_input_hook([function]) -> None\n\ -Set or remove the pre_input_hook function.\n\ +Set or remove the function invoked by the rl_pre_input_hook callback.\n\ The function is called with no arguments after the first prompt\n\ has been printed and just before readline starts reading input\n\ characters."); @@ -421,7 +421,7 @@ PyDoc_STRVAR(doc_get_begidx, "get_begidx() -> int\n\ -get the beginning index of the readline tab-completion scope"); +get the beginning index of the completion scope"); /* Get the ending index for the scope of the tab-completion */ @@ -435,7 +435,7 @@ PyDoc_STRVAR(doc_get_endidx, "get_endidx() -> int\n\ -get the ending index of the readline tab-completion scope"); +get the ending index of the completion scope"); /* Set the tab-completion word-delimiters that readline uses */ @@ -464,7 +464,7 @@ PyDoc_STRVAR(doc_set_completer_delims, "set_completer_delims(string) -> None\n\ -set the readline word delimiters for tab-completion"); +set the word delimiters for completion"); /* _py_free_history_entry: Utility function to free a history entry. */ @@ -504,7 +504,7 @@ int entry_number; HIST_ENTRY *entry; - if (!PyArg_ParseTuple(args, "i:remove_history", &entry_number)) + if (!PyArg_ParseTuple(args, "i:remove_history_item", &entry_number)) return NULL; if (entry_number < 0) { PyErr_SetString(PyExc_ValueError, @@ -534,7 +534,7 @@ char *line; HIST_ENTRY *old_entry; - if (!PyArg_ParseTuple(args, "is:replace_history", &entry_number, + if (!PyArg_ParseTuple(args, "is:replace_history_item", &entry_number, &line)) { return NULL; } @@ -575,7 +575,7 @@ PyDoc_STRVAR(doc_add_history, "add_history(string) -> None\n\ -add a line to the history buffer"); +add an item to the history buffer"); /* Get the tab-completion word-delimiters that readline uses */ @@ -588,7 +588,7 @@ PyDoc_STRVAR(doc_get_completer_delims, "get_completer_delims() -> string\n\ -get the readline word delimiters for tab-completion"); +get the word delimiters for completion"); /* Set the completer function */ @@ -649,7 +649,7 @@ int idx = 0; HIST_ENTRY *hist_ent; - if (!PyArg_ParseTuple(args, "i:index", &idx)) + if (!PyArg_ParseTuple(args, "i:get_history_item", &idx)) return NULL; #ifdef __APPLE__ if (using_libedit_emulation) { @@ -741,7 +741,7 @@ PyDoc_STRVAR(doc_insert_text, "insert_text(string) -> None\n\ -Insert text into the command line."); +Insert text into the line buffer at the cursor position."); /* Redisplay the line buffer */ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 5 06:32:02 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 05 Apr 2016 10:32:02 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=236953=3A_Merge_readline_doc_from_3=2E5?= Message-ID: <20160405103135.59214.32459.D855A87A@psf.io> https://hg.python.org/cpython/rev/856d50130154 changeset: 100852:856d50130154 parent: 100848:ff71c15e48f1 parent: 100851:b1acd6cf15b6 user: Martin Panter date: Tue Apr 05 10:17:38 2016 +0000 summary: Issue #6953: Merge readline doc from 3.5 files: Doc/library/readline.rst | 185 +++++++++++++++++--------- Misc/NEWS | 4 + Modules/readline.c | 32 ++-- 3 files changed, 141 insertions(+), 80 deletions(-) diff --git a/Doc/library/readline.rst b/Doc/library/readline.rst --- a/Doc/library/readline.rst +++ b/Doc/library/readline.rst @@ -9,15 +9,18 @@ The :mod:`readline` module defines a number of functions to facilitate completion and reading/writing of history files from the Python interpreter. -This module can be used directly or via the :mod:`rlcompleter` module. Settings +This module can be used directly, or via the :mod:`rlcompleter` module, which +supports completion of Python identifiers at the interactive prompt. Settings made using this module affect the behaviour of both the interpreter's interactive prompt and the prompts offered by the built-in :func:`input` function. .. note:: - On MacOS X the :mod:`readline` module can be implemented using + The underlying Readline library API may be implemented by the ``libedit`` library instead of GNU readline. + On MacOS X the :mod:`readline` module detects which library is being used + at run time. The configuration file for ``libedit`` is different from that of GNU readline. If you programmatically load configuration strings @@ -25,112 +28,168 @@ to differentiate between GNU readline and libedit. -The :mod:`readline` module defines the following functions: +Init file +--------- + +The following functions relate to the init file and user configuration: .. function:: parse_and_bind(string) - Parse and execute single line of a readline init file. + Execute the init line provided in the *string* argument. This calls + :c:func:`rl_parse_and_bind` in the underlying library. + + +.. function:: read_init_file([filename]) + + Execute a readline initialization file. The default filename is the last filename + used. This calls :c:func:`rl_read_init_file` in the underlying library. + + +Line buffer +----------- + +The following functions operate on the line buffer: .. function:: get_line_buffer() - Return the current contents of the line buffer. + Return the current contents of the line buffer (:c:data:`rl_line_buffer` + in the underlying library). .. function:: insert_text(string) - Insert text into the command line. + Insert text into the line buffer at the cursor position. This calls + :c:func:`rl_insert_text` in the underlying library, but ignores + the return value. -.. function:: read_init_file([filename]) +.. function:: redisplay() - Parse a readline initialization file. The default filename is the last filename - used. + Change what's displayed on the screen to reflect the current contents of the + line buffer. This calls :c:func:`rl_redisplay` in the underlying library. + + +History file +------------ + +The following functions operate on a history file: .. function:: read_history_file([filename]) - Load a readline history file. The default filename is :file:`~/.history`. + Load a readline history file, and append it to the history list. + The default filename is :file:`~/.history`. This calls + :c:func:`read_history` in the underlying library. .. function:: write_history_file([filename]) - Save a readline history file. The default filename is :file:`~/.history`. + Save the history list to a readline history file, overwriting any + existing file. The default filename is :file:`~/.history`. This calls + :c:func:`write_history` in the underlying library. .. function:: append_history_file(nelements[, filename]) - Append the last *nelements* of history to a file. The default filename is - :file:`~/.history`. The file must already exist. + Append the last *nelements* items of history to a file. The default filename is + :file:`~/.history`. The file must already exist. This calls + :c:func:`append_history` in the underlying library. .. versionadded:: 3.5 +.. function:: get_history_length() + set_history_length(length) + + Set or return the desired number of lines to save in the history file. + The :func:`write_history_file` function uses this value to truncate + the history file, by calling :c:func:`history_truncate_file` in + the underlying library. Negative values imply + unlimited history file size. + + +History list +------------ + +The following functions operate on a global history list: + + .. function:: clear_history() - Clear the current history. (Note: this function is not available if the - installed version of GNU readline doesn't support it.) - - -.. function:: get_history_length() - - Return the desired length of the history file. Negative values imply unlimited - history file size. - - -.. function:: set_history_length(length) - - Set the number of lines to save in the history file. :func:`write_history_file` - uses this value to truncate the history file when saving. Negative values imply - unlimited history file size. + Clear the current history. This calls :c:func:`clear_history` in the + underlying library. The Python function only exists if Python was + compiled for a version of the library that supports it. .. function:: get_current_history_length() - Return the number of lines currently in the history. (This is different from + Return the number of items currently in the history. (This is different from :func:`get_history_length`, which returns the maximum number of lines that will be written to a history file.) .. function:: get_history_item(index) - Return the current contents of history item at *index*. + Return the current contents of history item at *index*. The item index + is one-based. This calls :c:func:`history_get` in the underlying library. .. function:: remove_history_item(pos) Remove history item specified by its position from the history. + The position is zero-based. This calls :c:func:`remove_history` in + the underlying library. .. function:: replace_history_item(pos, line) - Replace history item specified by its position with the given line. + Replace history item specified by its position with *line*. + The position is zero-based. This calls :c:func:`replace_history_entry` + in the underlying library. -.. function:: redisplay() +.. function:: add_history(line) - Change what's displayed on the screen to reflect the current contents of the - line buffer. + Append *line* to the history buffer, as if it was the last line typed. + This calls :c:func:`add_history` in the underlying library. + + +Startup hooks +------------- .. function:: set_startup_hook([function]) - Set or remove the startup_hook function. If *function* is specified, it will be - used as the new startup_hook function; if omitted or ``None``, any hook function - already installed is removed. The startup_hook function is called with no + Set or remove the function invoked by the :c:data:`rl_startup_hook` + callback of the underlying library. If *function* is specified, it will + be used as the new hook function; if omitted or ``None``, any function + already installed is removed. The hook is called with no arguments just before readline prints the first prompt. .. function:: set_pre_input_hook([function]) - Set or remove the pre_input_hook function. If *function* is specified, it will - be used as the new pre_input_hook function; if omitted or ``None``, any hook - function already installed is removed. The pre_input_hook function is called + Set or remove the function invoked by the :c:data:`rl_pre_input_hook` + callback of the underlying library. If *function* is specified, it will + be used as the new hook function; if omitted or ``None``, any + function already installed is removed. The hook is called with no arguments after the first prompt has been printed and just before readline starts reading input characters. +Completion +---------- + +The following functions relate to implementing a custom word completion +function. This is typically operated by the Tab key, and can suggest and +automatically complete a word being typed. By default, Readline is set up +to be used by :mod:`rlcompleter` to complete Python identifiers for +the interactive interpreter. If the :mod:`readline` module is to be used +with a custom completer, a different set of word delimiters should be set. + + .. function:: set_completer([function]) Set or remove the completer function. If *function* is specified, it will be @@ -140,6 +199,12 @@ returns a non-string value. It should return the next possible completion starting with *text*. + The installed completer function is invoked by the *entry_func* callback + passed to :c:func:`rl_completion_matches` in the underlying library. + The *text* string comes from the first parameter to the + :c:data:`rl_attempted_completion_function` callback of the + underlying library. + .. function:: get_completer() @@ -148,27 +213,27 @@ .. function:: get_completion_type() - Get the type of completion being attempted. + Get the type of completion being attempted. This returns the + :c:data:`rl_completion_type` variable in the underlying library as + an integer. .. function:: get_begidx() + get_endidx() - Get the beginning index of the readline tab-completion scope. - - -.. function:: get_endidx() - - Get the ending index of the readline tab-completion scope. + Get the beginning or ending index of the completion scope. + These indexes are the *start* and *end* arguments passed to the + :c:data:`rl_attempted_completion_function` callback of the + underlying library. .. function:: set_completer_delims(string) + get_completer_delims() - Set the readline word delimiters for tab-completion. - - -.. function:: get_completer_delims() - - Get the readline word delimiters for tab-completion. + Set or get the word delimiters for completion. These determine the + start of the word to be considered for completion (the completion scope). + These functions access the :c:data:`rl_completer_word_break_characters` + variable in the underlying library. .. function:: set_completion_display_matches_hook([function]) @@ -176,21 +241,13 @@ Set or remove the completion display function. If *function* is specified, it will be used as the new completion display function; if omitted or ``None``, any completion display function already - installed is removed. The completion display function is called as + installed is removed. This sets or clears the + :c:data:`rl_completion_display_matches_hook` callback in the + underlying library. The completion display function is called as ``function(substitution, [matches], longest_match_length)`` once each time matches need to be displayed. -.. function:: add_history(line) - - Append a line to the history buffer, as if it was the last line typed. - -.. seealso:: - - Module :mod:`rlcompleter` - Completion of Python identifiers at the interactive prompt. - - .. _readline-example: Example diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -895,6 +895,10 @@ Documentation ------------- +- Issue #6953: Rework the Readline module documentation to group related + functions together, and add more details such as what underlying Readline + functions and variables are accessed. + - Issue #23606: Adds note to ctypes documentation regarding cdll.msvcrt. - Issue #24952: Clarify the default size argument of stack_size() in diff --git a/Modules/readline.c b/Modules/readline.c --- a/Modules/readline.c +++ b/Modules/readline.c @@ -149,7 +149,7 @@ PyDoc_STRVAR(doc_parse_and_bind, "parse_and_bind(string) -> None\n\ -Parse and execute single line of a readline init file."); +Execute the init line provided in the string argument."); /* Exported function to parse a readline init file */ @@ -174,7 +174,7 @@ PyDoc_STRVAR(doc_read_init_file, "read_init_file([filename]) -> None\n\ -Parse a readline initialization file.\n\ +Execute a readline initialization file.\n\ The default filename is the last filename used."); @@ -271,7 +271,7 @@ PyDoc_STRVAR(doc_append_history_file, "append_history_file(nelements[, filename]) -> None\n\ -Append the last nelements of the history list to file.\n\ +Append the last nelements items of the history list to file.\n\ The default filename is ~/.history."); #endif @@ -290,7 +290,7 @@ PyDoc_STRVAR(set_history_length_doc, "set_history_length(length) -> None\n\ -set the maximal number of items which will be written to\n\ +set the maximal number of lines which will be written to\n\ the history file. A negative length is used to inhibit\n\ history truncation."); @@ -305,7 +305,7 @@ PyDoc_STRVAR(get_history_length_doc, "get_history_length() -> int\n\ -return the maximum number of items that will be written to\n\ +return the maximum number of lines that will be written to\n\ the history file."); @@ -371,7 +371,7 @@ PyDoc_STRVAR(doc_set_startup_hook, "set_startup_hook([function]) -> None\n\ -Set or remove the startup_hook function.\n\ +Set or remove the function invoked by the rl_startup_hook callback.\n\ The function is called with no arguments just\n\ before readline prints the first prompt."); @@ -388,7 +388,7 @@ PyDoc_STRVAR(doc_set_pre_input_hook, "set_pre_input_hook([function]) -> None\n\ -Set or remove the pre_input_hook function.\n\ +Set or remove the function invoked by the rl_pre_input_hook callback.\n\ The function is called with no arguments after the first prompt\n\ has been printed and just before readline starts reading input\n\ characters."); @@ -419,7 +419,7 @@ PyDoc_STRVAR(doc_get_begidx, "get_begidx() -> int\n\ -get the beginning index of the readline tab-completion scope"); +get the beginning index of the completion scope"); /* Get the ending index for the scope of the tab-completion */ @@ -433,7 +433,7 @@ PyDoc_STRVAR(doc_get_endidx, "get_endidx() -> int\n\ -get the ending index of the readline tab-completion scope"); +get the ending index of the completion scope"); /* Set the tab-completion word-delimiters that readline uses */ @@ -462,7 +462,7 @@ PyDoc_STRVAR(doc_set_completer_delims, "set_completer_delims(string) -> None\n\ -set the readline word delimiters for tab-completion"); +set the word delimiters for completion"); /* _py_free_history_entry: Utility function to free a history entry. */ @@ -502,7 +502,7 @@ int entry_number; HIST_ENTRY *entry; - if (!PyArg_ParseTuple(args, "i:remove_history", &entry_number)) + if (!PyArg_ParseTuple(args, "i:remove_history_item", &entry_number)) return NULL; if (entry_number < 0) { PyErr_SetString(PyExc_ValueError, @@ -532,7 +532,7 @@ char *line; HIST_ENTRY *old_entry; - if (!PyArg_ParseTuple(args, "is:replace_history", &entry_number, + if (!PyArg_ParseTuple(args, "is:replace_history_item", &entry_number, &line)) { return NULL; } @@ -573,7 +573,7 @@ PyDoc_STRVAR(doc_add_history, "add_history(string) -> None\n\ -add a line to the history buffer"); +add an item to the history buffer"); /* Get the tab-completion word-delimiters that readline uses */ @@ -586,7 +586,7 @@ PyDoc_STRVAR(doc_get_completer_delims, "get_completer_delims() -> string\n\ -get the readline word delimiters for tab-completion"); +get the word delimiters for completion"); /* Set the completer function */ @@ -647,7 +647,7 @@ int idx = 0; HIST_ENTRY *hist_ent; - if (!PyArg_ParseTuple(args, "i:index", &idx)) + if (!PyArg_ParseTuple(args, "i:get_history_item", &idx)) return NULL; #ifdef __APPLE__ if (using_libedit_emulation) { @@ -739,7 +739,7 @@ PyDoc_STRVAR(doc_insert_text, "insert_text(string) -> None\n\ -Insert text into the command line."); +Insert text into the line buffer at the cursor position."); /* Redisplay the line buffer */ -- Repository URL: https://hg.python.org/cpython From lp_benchmark_robot at intel.com Tue Apr 5 08:11:30 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Tue, 5 Apr 2016 13:11:30 +0100 Subject: [Python-checkins] UGLY Benchmark Results for Python Default 2016-04-05 Message-ID: <4f9b4daa-5df5-4e8a-8ccc-0a05f5ae5c9b@irsmsx103.ger.corp.intel.com> Results for project Python default, build date 2016-04-05 02:06:58 +0000 commit: 07f73360ea8e previous commit: 0e576d094dc4 revision date: 2016-04-04 17:59:29 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.36% 1.42% 10.59% 14.19% :-| pybench 0.12% -0.06% 0.51% 5.32% :-( regex_v8 2.61% -1.51% -6.25% 7.08% :-| nbody 0.09% -1.03% 1.63% 4.17% :-( json_dump_v2 0.25% 0.57% -2.11% 10.94% :-| normal_startup 0.73% -0.41% -0.28% 5.76% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/ugly-benchmark-results-for-python-default-2016-04-05/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Tue Apr 5 08:28:26 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Tue, 5 Apr 2016 13:28:26 +0100 Subject: [Python-checkins] GOOD Benchmark Results for Python 2.7 2016-04-05 Message-ID: <0e5551e8-ec42-4b97-81f0-a9f0b63fa2d4@irsmsx103.ger.corp.intel.com> No new revisions. Here are the previous results: Results for project Python 2.7, build date 2016-04-05 02:58:32 +0000 commit: 596946c06a31 previous commit: 1d79e70e67b5 revision date: 2016-04-03 08:00:49 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.15% 2.65% 5.20% 6.76% :-) pybench 0.13% 0.02% 5.98% 4.78% :-( regex_v8 0.78% 0.43% -2.58% 11.73% :-) nbody 0.10% -0.16% 6.97% 5.89% :-) json_dump_v2 0.22% 0.54% 3.92% 12.56% :-( normal_startup 2.07% -0.28% -5.53% 2.45% :-) ssbench 0.20% -0.01% 2.53% 1.10% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/good-benchmark-results-for-python-2-7-2016-04-05/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Tue Apr 5 11:36:11 2016 From: python-checkins at python.org (guido.van.rossum) Date: Tue, 05 Apr 2016 15:36:11 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_upstream_typing=2Epy_changes_from_3=2E5_branch=2E?= Message-ID: <20160405153544.49923.49944.44D6E0FC@psf.io> https://hg.python.org/cpython/rev/78b84ae0b745 changeset: 100854:78b84ae0b745 parent: 100852:856d50130154 parent: 100853:be3c4151d9bf user: Guido van Rossum date: Tue Apr 05 08:35:22 2016 -0700 summary: Merge upstream typing.py changes from 3.5 branch. files: Lib/test/test_typing.py | 156 +++++++++- Lib/typing.py | 394 +++++++++++++++++---------- 2 files changed, 371 insertions(+), 179 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1,8 +1,7 @@ -import asyncio import pickle import re import sys -from unittest import TestCase, main +from unittest import TestCase, main, skipUnless from typing import Any from typing import TypeVar, AnyStr @@ -133,6 +132,7 @@ def test_constrained_error(self): with self.assertRaises(TypeError): X = TypeVar('X', int) + X def test_union_unique(self): X = TypeVar('X') @@ -317,6 +317,7 @@ def test_union_str_pattern(self): # Shouldn't crash; see http://bugs.python.org/issue25390 A = Union[str, Pattern] + A class TypeVarUnionTests(TestCase): @@ -487,7 +488,7 @@ ... -class MySimpleMapping(SimpleMapping): +class MySimpleMapping(SimpleMapping[XK, XV]): def __init__(self): self.store = {} @@ -541,6 +542,7 @@ assert not issubclass(str, typing.SupportsAbs) def test_supports_round(self): + issubclass(float, typing.SupportsRound) assert issubclass(float, typing.SupportsRound) assert issubclass(int, typing.SupportsRound) assert not issubclass(str, typing.SupportsRound) @@ -551,20 +553,23 @@ def test_protocol_instance_type_error(self): with self.assertRaises(TypeError): - isinstance([], typing.Reversible) + isinstance(0, typing.SupportsAbs) class GenericTests(TestCase): def test_basics(self): X = SimpleMapping[str, Any] + assert X.__parameters__ == () + with self.assertRaises(TypeError): + X[str] + with self.assertRaises(TypeError): + X[str, str] Y = SimpleMapping[XK, str] - X[str, str] - Y[str, str] + assert Y.__parameters__ == (XK,) + Y[str] with self.assertRaises(TypeError): - X[int, str] - with self.assertRaises(TypeError): - Y[str, bytes] + Y[str, str] def test_init(self): T = TypeVar('T') @@ -576,30 +581,61 @@ def test_repr(self): self.assertEqual(repr(SimpleMapping), - __name__ + '.' + 'SimpleMapping[~XK, ~XV]') + __name__ + '.' + 'SimpleMapping<~XK, ~XV>') self.assertEqual(repr(MySimpleMapping), - __name__ + '.' + 'MySimpleMapping[~XK, ~XV]') + __name__ + '.' + 'MySimpleMapping<~XK, ~XV>') + + def test_chain_repr(self): + T = TypeVar('T') + S = TypeVar('S') + + class C(Generic[T]): + pass + + X = C[Tuple[S, T]] + assert X == C[Tuple[S, T]] + assert X != C[Tuple[T, S]] + + Y = X[T, int] + assert Y == X[T, int] + assert Y != X[S, int] + assert Y != X[T, str] + + Z = Y[str] + assert Z == Y[str] + assert Z != Y[int] + assert Z != Y[T] + + assert str(Z).endswith( + '.C<~T>[typing.Tuple[~S, ~T]]<~S, ~T>[~T, int]<~T>[str]') def test_dict(self): T = TypeVar('T') + class B(Generic[T]): pass + b = B() b.foo = 42 self.assertEqual(b.__dict__, {'foo': 42}) + class C(B[int]): pass + c = C() c.bar = 'abc' self.assertEqual(c.__dict__, {'bar': 'abc'}) def test_pickle(self): + global C # pickle wants to reference the class by name T = TypeVar('T') + class B(Generic[T]): pass - global C # pickle wants to reference the class by name + class C(B[int]): pass + c = C() c.foo = 42 c.bar = 'abc' @@ -626,12 +662,12 @@ assert C.__module__ == __name__ if not PY32: assert C.__qualname__ == 'GenericTests.test_repr_2..C' - assert repr(C).split('.')[-1] == 'C[~T]' + assert repr(C).split('.')[-1] == 'C<~T>' X = C[int] assert X.__module__ == __name__ if not PY32: assert X.__qualname__ == 'C' - assert repr(X).split('.')[-1] == 'C[int]' + assert repr(X).split('.')[-1] == 'C<~T>[int]' class Y(C[int]): pass @@ -639,7 +675,7 @@ assert Y.__module__ == __name__ if not PY32: assert Y.__qualname__ == 'GenericTests.test_repr_2..Y' - assert repr(Y).split('.')[-1] == 'Y[int]' + assert repr(Y).split('.')[-1] == 'Y' def test_eq_1(self): assert Generic == Generic @@ -667,15 +703,14 @@ class B(Generic[KT, T]): pass - class C(A, Generic[KT, VT], B): + class C(A[T, VT], Generic[VT, T, KT], B[KT, T]): pass - assert C.__parameters__ == (T, VT, KT) + assert C.__parameters__ == (VT, T, KT) def test_nested(self): - class G(Generic): - pass + G = Generic class Visitor(G[T]): @@ -721,9 +756,30 @@ assert type(a) is Node assert type(b) is Node assert type(c) is Node + assert a.label == x + assert b.label == x + assert c.label == x foo(42) + def test_implicit_any(self): + T = TypeVar('T') + + class C(Generic[T]): + pass + + class D(C): + pass + + assert D.__parameters__ == () + + with self.assertRaises(Exception): + D[int] + with self.assertRaises(Exception): + D[Any] + with self.assertRaises(Exception): + D[T] + class VarianceTests(TestCase): @@ -956,14 +1012,33 @@ from typing import overload with self.assertRaises(RuntimeError): + @overload def blah(): pass + blah() + + def test_overload_succeeds(self): + from typing import overload + + @overload + def blah(): + pass + + def blah(): + pass + + blah() + + +PY35 = sys.version_info[:2] >= (3, 5) + +PY35_TESTS = """ +import asyncio T_a = TypeVar('T') - class AwaitableWrapper(typing.Awaitable[T_a]): def __init__(self, value): @@ -973,7 +1048,6 @@ yield return self.value - class AsyncIteratorWrapper(typing.AsyncIterator[T_a]): def __init__(self, value: typing.Iterable[T_a]): @@ -989,6 +1063,10 @@ return data else: raise StopAsyncIteration +""" + +if PY35: + exec(PY35_TESTS) class CollectionsAbcTests(TestCase): @@ -1015,9 +1093,14 @@ assert isinstance(it, typing.Iterator[int]) assert not isinstance(42, typing.Iterator) + @skipUnless(PY35, 'Python 3.5 required') def test_awaitable(self): - async def foo() -> typing.Awaitable[int]: - return await AwaitableWrapper(42) + ns = {} + exec( + "async def foo() -> typing.Awaitable[int]:\n" + " return await AwaitableWrapper(42)\n", + globals(), ns) + foo = ns['foo'] g = foo() assert issubclass(type(g), typing.Awaitable[int]) assert isinstance(g, typing.Awaitable) @@ -1028,6 +1111,7 @@ typing.Awaitable[Manager]) g.send(None) # Run foo() till completion, to avoid warning. + @skipUnless(PY35, 'Python 3.5 required') def test_async_iterable(self): base_it = range(10) # type: Iterator[int] it = AsyncIteratorWrapper(base_it) @@ -1037,6 +1121,7 @@ typing.AsyncIterable[Employee]) assert not isinstance(42, typing.AsyncIterable) + @skipUnless(PY35, 'Python 3.5 required') def test_async_iterator(self): base_it = range(10) # type: Iterator[int] it = AsyncIteratorWrapper(base_it) @@ -1127,6 +1212,22 @@ d = MyDict() assert isinstance(d, MyDict) + def test_no_defaultdict_instantiation(self): + with self.assertRaises(TypeError): + typing.DefaultDict() + with self.assertRaises(TypeError): + typing.DefaultDict[KT, VT]() + with self.assertRaises(TypeError): + typing.DefaultDict[str, int]() + + def test_defaultdict_subclass_instantiation(self): + + class MyDefDict(typing.DefaultDict[str, int]): + pass + + dd = MyDefDict() + assert isinstance(dd, MyDefDict) + def test_no_set_instantiation(self): with self.assertRaises(TypeError): typing.Set() @@ -1251,7 +1352,7 @@ return a.readline() a = stuff.__annotations__['a'] - assert a.__parameters__ == (str,) + assert a.__parameters__ == () def test_binaryio(self): @@ -1259,7 +1360,7 @@ return a.readline() a = stuff.__annotations__['a'] - assert a.__parameters__ == (bytes,) + assert a.__parameters__ == () def test_io_submodule(self): from typing.io import IO, TextIO, BinaryIO, __all__, __name__ @@ -1346,8 +1447,9 @@ assert 'ValuesView' in a assert 'cast' in a assert 'overload' in a - assert 'io' in a - assert 're' in a + # Check that io and re are not exported. + assert 'io' not in a + assert 're' not in a # Spot-check that stdlib modules aren't exported. assert 'os' not in a assert 'sys' not in a diff --git a/Lib/typing.py b/Lib/typing.py --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1,7 +1,3 @@ -# TODO nits: -# Get rid of asserts that are the caller's fault. -# Docstrings (e.g. ABCs). - import abc from abc import abstractmethod, abstractproperty import collections @@ -56,6 +52,7 @@ # Concrete collection types. 'Dict', + 'DefaultDict', 'List', 'Set', 'NamedTuple', # Not really a type. @@ -68,11 +65,11 @@ 'no_type_check', 'no_type_check_decorator', 'overload', +] - # Submodules. - 'io', - 're', -] +# The pseudo-submodules 're' and 'io' are part of the public +# namespace, but excluded from __all__ because they might stomp on +# legitimate imports of those modules. def _qualname(x): @@ -117,8 +114,8 @@ """ return self - def _has_type_var(self): - return False + def _get_type_vars(self, tvars): + pass def __repr__(self): return '%s.%s' % (self.__module__, _qualname(self)) @@ -214,8 +211,8 @@ someone tries to subclass a type alias (not a good idea). """ if (len(args) == 3 and - isinstance(args[0], str) and - isinstance(args[1], tuple)): + isinstance(args[0], str) and + isinstance(args[1], tuple)): # Close enough. raise TypeError("A type alias cannot be subclassed") return object.__new__(cls) @@ -271,8 +268,16 @@ return issubclass(cls, self.impl_type) -def _has_type_var(t): - return t is not None and isinstance(t, TypingMeta) and t._has_type_var() +def _get_type_vars(types, tvars): + for t in types: + if isinstance(t, TypingMeta): + t._get_type_vars(tvars) + + +def _type_vars(types): + tvars = [] + _get_type_vars(types, tvars) + return tuple(tvars) def _eval_type(t, globalns, localns): @@ -376,7 +381,7 @@ At runtime, isinstance(x, T) will raise TypeError. However, issubclass(C, T) is true for any class C, and issubclass(str, A) and issubclass(bytes, A) are true, and issubclass(int, A) is - false. + false. (TODO: Why is this needed? This may change. See #136.) Type variables may be marked covariant or contravariant by passing covariant=True or contravariant=True. See PEP 484 for more @@ -410,8 +415,9 @@ self.__bound__ = None return self - def _has_type_var(self): - return True + def _get_type_vars(self, tvars): + if self not in tvars: + tvars.append(self) def __repr__(self): if self.__covariant__: @@ -448,7 +454,6 @@ T_contra = TypeVar('T_contra', contravariant=True) # Ditto contravariant. # A useful type variable with constraints. This represents string types. -# TODO: What about bytearray, memoryview? AnyStr = TypeVar('AnyStr', bytes, str) @@ -514,12 +519,9 @@ return self.__class__(self.__name__, self.__bases__, {}, p, _root=True) - def _has_type_var(self): + def _get_type_vars(self, tvars): if self.__union_params__: - for t in self.__union_params__: - if _has_type_var(t): - return True - return False + _get_type_vars(self.__union_params__, tvars) def __repr__(self): r = super().__repr__() @@ -656,12 +658,9 @@ self.__tuple_use_ellipsis__ = use_ellipsis return self - def _has_type_var(self): + def _get_type_vars(self, tvars): if self.__tuple_params__: - for t in self.__tuple_params__: - if _has_type_var(t): - return True - return False + _get_type_vars(self.__tuple_params__, tvars) def _eval_type(self, globalns, localns): tp = self.__tuple_params__ @@ -769,12 +768,9 @@ self.__result__ = result return self - def _has_type_var(self): + def _get_type_vars(self, tvars): if self.__args__: - for t in self.__args__: - if _has_type_var(t): - return True - return _has_type_var(self.__result__) + _get_type_vars(self.__args__, tvars) def _eval_type(self, globalns, localns): if self.__args__ is None and self.__result__ is None: @@ -878,76 +874,106 @@ return _gorg(a) is _gorg(b) +def _next_in_mro(cls): + """Helper for Generic.__new__. + + Returns the class after the last occurrence of Generic or + Generic[...] in cls.__mro__. + """ + next_in_mro = object + # Look for the last occurrence of Generic or Generic[...]. + for i, c in enumerate(cls.__mro__[:-1]): + if isinstance(c, GenericMeta) and _gorg(c) is Generic: + next_in_mro = cls.__mro__[i+1] + return next_in_mro + + class GenericMeta(TypingMeta, abc.ABCMeta): """Metaclass for generic types.""" - # TODO: Constrain more how Generic is used; only a few - # standard patterns should be allowed. - - # TODO: Use a more precise rule than matching __name__ to decide - # whether two classes are the same. Also, save the formal - # parameters. (These things are related! A solution lies in - # using origin.) - __extra__ = None def __new__(cls, name, bases, namespace, - parameters=None, origin=None, extra=None): - if parameters is None: - # Extract parameters from direct base classes. Only - # direct bases are considered and only those that are - # themselves generic, and parameterized with type - # variables. Don't use bases like Any, Union, Tuple, - # Callable or type variables. - params = None + tvars=None, args=None, origin=None, extra=None): + self = super().__new__(cls, name, bases, namespace, _root=True) + + if tvars is not None: + # Called from __getitem__() below. + assert origin is not None + assert all(isinstance(t, TypeVar) for t in tvars), tvars + else: + # Called from class statement. + assert tvars is None, tvars + assert args is None, args + assert origin is None, origin + + # Get the full set of tvars from the bases. + tvars = _type_vars(bases) + # Look for Generic[T1, ..., Tn]. + # If found, tvars must be a subset of it. + # If not found, tvars is it. + # Also check for and reject plain Generic, + # and reject multiple Generic[...]. + gvars = None for base in bases: - if isinstance(base, TypingMeta): - if not isinstance(base, GenericMeta): + if base is Generic: + raise TypeError("Cannot inherit from plain Generic") + if (isinstance(base, GenericMeta) and + base.__origin__ is Generic): + if gvars is not None: raise TypeError( - "You cannot inherit from magic class %s" % - repr(base)) - if base.__parameters__ is None: - continue # The base is unparameterized. - for bp in base.__parameters__: - if _has_type_var(bp) and not isinstance(bp, TypeVar): - raise TypeError( - "Cannot inherit from a generic class " - "parameterized with " - "non-type-variable %s" % bp) - if params is None: - params = [] - if bp not in params: - params.append(bp) - if params is not None: - parameters = tuple(params) - self = super().__new__(cls, name, bases, namespace, _root=True) - self.__parameters__ = parameters + "Cannot inherit from Generic[...] multiple types.") + gvars = base.__parameters__ + if gvars is None: + gvars = tvars + else: + tvarset = set(tvars) + gvarset = set(gvars) + if not tvarset <= gvarset: + raise TypeError( + "Some type variables (%s) " + "are not listed in Generic[%s]" % + (", ".join(str(t) for t in tvars if t not in gvarset), + ", ".join(str(g) for g in gvars))) + tvars = gvars + + self.__parameters__ = tvars + self.__args__ = args + self.__origin__ = origin if extra is not None: self.__extra__ = extra # Else __extra__ is inherited, eventually from the # (meta-)class default above. - self.__origin__ = origin + # Speed hack (https://github.com/python/typing/issues/196). + self.__next_in_mro__ = _next_in_mro(self) return self - def _has_type_var(self): - if self.__parameters__: - for t in self.__parameters__: - if _has_type_var(t): - return True - return False + def _get_type_vars(self, tvars): + if self.__origin__ and self.__parameters__: + _get_type_vars(self.__parameters__, tvars) def __repr__(self): - r = super().__repr__() - if self.__parameters__ is not None: + if self.__origin__ is not None: + r = repr(self.__origin__) + else: + r = super().__repr__() + if self.__args__: r += '[%s]' % ( + ', '.join(_type_repr(p) for p in self.__args__)) + if self.__parameters__: + r += '<%s>' % ( ', '.join(_type_repr(p) for p in self.__parameters__)) return r def __eq__(self, other): if not isinstance(other, GenericMeta): return NotImplemented - return (_geqv(self, other) and - self.__parameters__ == other.__parameters__) + if self.__origin__ is not None: + return (self.__origin__ is other.__origin__ and + self.__args__ == other.__args__ and + self.__parameters__ == other.__parameters__) + else: + return self is other def __hash__(self): return hash((self.__name__, self.__parameters__)) @@ -956,37 +982,45 @@ if not isinstance(params, tuple): params = (params,) if not params: - raise TypeError("Cannot have empty parameter list") + raise TypeError( + "Parameter list to %s[...] cannot be empty" % _qualname(self)) msg = "Parameters to generic types must be types." params = tuple(_type_check(p, msg) for p in params) - if self.__parameters__ is None: - for p in params: - if not isinstance(p, TypeVar): - raise TypeError("Initial parameters must be " - "type variables; got %s" % p) + if self is Generic: + # Generic can only be subscripted with unique type variables. + if not all(isinstance(p, TypeVar) for p in params): + raise TypeError( + "Parameters to Generic[...] must all be type variables") if len(set(params)) != len(params): raise TypeError( - "All type variables in Generic[...] must be distinct.") + "Parameters to Generic[...] must all be unique") + tvars = params + args = None + elif self is _Protocol: + # _Protocol is internal, don't check anything. + tvars = params + args = None + elif self.__origin__ in (Generic, _Protocol): + # Can't subscript Generic[...] or _Protocol[...]. + raise TypeError("Cannot subscript already-subscripted %s" % + repr(self)) else: - if len(params) != len(self.__parameters__): - raise TypeError("Cannot change parameter count from %d to %d" % - (len(self.__parameters__), len(params))) - for new, old in zip(params, self.__parameters__): - if isinstance(old, TypeVar): - if not old.__constraints__: - # Substituting for an unconstrained TypeVar is OK. - continue - if issubclass(new, Union[old.__constraints__]): - # Specializing a constrained type variable is OK. - continue - if not issubclass(new, old): - raise TypeError( - "Cannot substitute %s for %s in %s" % - (_type_repr(new), _type_repr(old), self)) - - return self.__class__(self.__name__, (self,) + self.__bases__, + # Subscripting a regular Generic subclass. + if not self.__parameters__: + raise TypeError("%s is not a generic class" % repr(self)) + alen = len(params) + elen = len(self.__parameters__) + if alen != elen: + raise TypeError( + "Too %s parameters for %s; actual %s, expected %s" % + ("many" if alen > elen else "few", repr(self), alen, elen)) + tvars = _type_vars(params) + args = params + return self.__class__(self.__name__, + (self,) + self.__bases__, dict(self.__dict__), - parameters=params, + tvars=tvars, + args=args, origin=self, extra=self.__extra__) @@ -1006,10 +1040,10 @@ # C[X] is a subclass of C[Y] iff X is a subclass of Y. origin = self.__origin__ if origin is not None and origin is cls.__origin__: - assert len(self.__parameters__) == len(origin.__parameters__) - assert len(cls.__parameters__) == len(origin.__parameters__) - for p_self, p_cls, p_origin in zip(self.__parameters__, - cls.__parameters__, + assert len(self.__args__) == len(origin.__parameters__) + assert len(cls.__args__) == len(origin.__parameters__) + for p_self, p_cls, p_origin in zip(self.__args__, + cls.__args__, origin.__parameters__): if isinstance(p_origin, TypeVar): if p_origin.__covariant__: @@ -1039,6 +1073,10 @@ return issubclass(cls, self.__extra__) +# Prevent checks for Generic to crash when defining Generic. +Generic = None + + class Generic(metaclass=GenericMeta): """Abstract base class for generic types. @@ -1053,29 +1091,23 @@ This class can then be used as follows:: - def lookup_name(mapping: Mapping, key: KT, default: VT) -> VT: + def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default - - For clarity the type variables may be redefined, e.g.:: - - X = TypeVar('X') - Y = TypeVar('Y') - def lookup_name(mapping: Mapping[X, Y], key: X, default: Y) -> Y: - # Same body as above. """ __slots__ = () def __new__(cls, *args, **kwds): - next_in_mro = object - # Look for the last occurrence of Generic or Generic[...]. - for i, c in enumerate(cls.__mro__[:-1]): - if isinstance(c, GenericMeta) and _gorg(c) is Generic: - next_in_mro = cls.__mro__[i+1] - return next_in_mro.__new__(_gorg(cls)) + if cls.__origin__ is None: + return cls.__next_in_mro__.__new__(cls) + else: + origin = _gorg(cls) + obj = cls.__next_in_mro__.__new__(origin) + obj.__init__(*args, **kwds) + return obj def cast(typ, val): @@ -1093,9 +1125,7 @@ """Internal helper to extract the default arguments, by name.""" code = func.__code__ pos_count = code.co_argcount - kw_count = code.co_kwonlyargcount arg_names = code.co_varnames - kwarg_names = arg_names[pos_count:pos_count + kw_count] arg_names = arg_names[:pos_count] defaults = func.__defaults__ or () kwdefaults = func.__kwdefaults__ @@ -1148,7 +1178,6 @@ return hints -# TODO: Also support this as a class decorator. def no_type_check(arg): """Decorator to indicate that annotations are not type hints. @@ -1183,8 +1212,42 @@ return wrapped_decorator +def _overload_dummy(*args, **kwds): + """Helper for @overload to raise when called.""" + raise NotImplementedError( + "You should not call an overloaded function. " + "A series of @overload-decorated functions " + "outside a stub module should always be followed " + "by an implementation that is not @overload-ed.") + + def overload(func): - raise RuntimeError("Overloading is only supported in library stubs") + """Decorator for overloaded functions/methods. + + In a stub file, place two or more stub definitions for the same + function in a row, each decorated with @overload. For example: + + @overload + def utf8(value: None) -> None: ... + @overload + def utf8(value: bytes) -> bytes: ... + @overload + def utf8(value: str) -> bytes: ... + + In a non-stub file (i.e. a regular .py file), do the same but + follow it with an implementation. The implementation should *not* + be decorated with @overload. For example: + + @overload + def utf8(value: None) -> None: ... + @overload + def utf8(value: bytes) -> bytes: ... + @overload + def utf8(value: str) -> bytes: ... + def utf8(value): + # implementation goes here + """ + return _overload_dummy class _ProtocolMeta(GenericMeta): @@ -1232,14 +1295,16 @@ break else: if (not attr.startswith('_abc_') and - attr != '__abstractmethods__' and - attr != '_is_protocol' and - attr != '__dict__' and - attr != '__slots__' and - attr != '_get_protocol_attrs' and - attr != '__parameters__' and - attr != '__origin__' and - attr != '__module__'): + attr != '__abstractmethods__' and + attr != '_is_protocol' and + attr != '__dict__' and + attr != '__args__' and + attr != '__slots__' and + attr != '_get_protocol_attrs' and + attr != '__next_in_mro__' and + attr != '__parameters__' and + attr != '__origin__' and + attr != '__module__'): attrs.add(attr) return attrs @@ -1264,16 +1329,25 @@ Hashable = collections_abc.Hashable # Not generic. -class Awaitable(Generic[T_co], extra=collections_abc.Awaitable): - __slots__ = () +if hasattr(collections_abc, 'Awaitable'): + class Awaitable(Generic[T_co], extra=collections_abc.Awaitable): + __slots__ = () +else: + Awaitable = None -class AsyncIterable(Generic[T_co], extra=collections_abc.AsyncIterable): - __slots__ = () +if hasattr(collections_abc, 'AsyncIterable'): + class AsyncIterable(Generic[T_co], extra=collections_abc.AsyncIterable): + __slots__ = () -class AsyncIterator(AsyncIterable[T_co], extra=collections_abc.AsyncIterator): - __slots__ = () + class AsyncIterator(AsyncIterable[T_co], + extra=collections_abc.AsyncIterator): + __slots__ = () + +else: + AsyncIterable = None + AsyncIterator = None class Iterable(Generic[T_co], extra=collections_abc.Iterable): @@ -1332,12 +1406,16 @@ pass -class Reversible(_Protocol[T_co]): - __slots__ = () +if hasattr(collections_abc, 'Reversible'): + class Reversible(Iterable[T_co], extra=collections_abc.Reversible): + __slots__ = () +else: + class Reversible(_Protocol[T_co]): + __slots__ = () - @abstractmethod - def __reversed__(self) -> 'Iterator[T_co]': - pass + @abstractmethod + def __reversed__(self) -> 'Iterator[T_co]': + pass Sized = collections_abc.Sized # Not generic. @@ -1360,7 +1438,7 @@ # NOTE: Only the value type is covariant. -class Mapping(Sized, Iterable[KT], Container[KT], Generic[VT_co], +class Mapping(Sized, Iterable[KT], Container[KT], Generic[KT, VT_co], extra=collections_abc.Mapping): pass @@ -1368,10 +1446,14 @@ class MutableMapping(Mapping[KT, VT], extra=collections_abc.MutableMapping): pass - -class Sequence(Sized, Iterable[T_co], Container[T_co], +if hasattr(collections_abc, 'Reversible'): + class Sequence(Sized, Reversible[T_co], Container[T_co], extra=collections_abc.Sequence): - pass + pass +else: + class Sequence(Sized, Iterable[T_co], Container[T_co], + extra=collections_abc.Sequence): + pass class MutableSequence(Sequence[T], extra=collections_abc.MutableSequence): @@ -1436,8 +1518,9 @@ pass -# TODO: Enable Set[Tuple[KT, VT_co]] instead of Generic[KT, VT_co]. -class ItemsView(MappingView, Generic[KT, VT_co], +class ItemsView(MappingView[Tuple[KT, VT_co]], + Set[Tuple[KT, VT_co]], + Generic[KT, VT_co], extra=collections_abc.ItemsView): pass @@ -1454,6 +1537,13 @@ "use dict() instead") return dict.__new__(cls, *args, **kwds) +class DefaultDict(collections.defaultdict, MutableMapping[KT, VT]): + + def __new__(cls, *args, **kwds): + if _geqv(cls, DefaultDict): + raise TypeError("Type DefaultDict cannot be instantiated; " + "use collections.defaultdict() instead") + return collections.defaultdict.__new__(cls, *args, **kwds) # Determine what base class to use for Generator. if hasattr(collections_abc, 'Generator'): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 5 11:36:11 2016 From: python-checkins at python.org (guido.van.rossum) Date: Tue, 05 Apr 2016 15:36:11 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Many_changes_f?= =?utf-8?q?rom_the_upstream_repo_=28https=3A//github=2Ecom/python/typing?= =?utf-8?b?KS4=?= Message-ID: <20160405153544.94586.8024.1EE0D331@psf.io> https://hg.python.org/cpython/rev/be3c4151d9bf changeset: 100853:be3c4151d9bf branch: 3.5 parent: 100851:b1acd6cf15b6 user: Guido van Rossum date: Tue Apr 05 08:28:52 2016 -0700 summary: Many changes from the upstream repo (https://github.com/python/typing). This syncs to rev 7b43ada77821d23e55e3a4b35f6055a59b9e1ad7 there. Summary: - Add typing.DefaultDict (as a generic variant of collections.defaultdict). - Use collections.Reversible if it exists (only relevant for Python 3.6). - Revamped generic class behavior to conform to updated PEP 484. - Improve speed of Generic.__new__. - Make sure __init__ is called for new Generic instances. Fix issue #26391. - Refactor async support to be compatible with 3.2, 3.3, 3.4. - Remove 'io' and 're' from __all__ (they still exist, just not included by "import *"). Fix issue #26234. - Change @overload -- you can now use it outside stubs (you still cannot call the decorated function though). files: Lib/test/test_typing.py | 156 +++++++++- Lib/typing.py | 394 +++++++++++++++++---------- 2 files changed, 371 insertions(+), 179 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1,8 +1,7 @@ -import asyncio import pickle import re import sys -from unittest import TestCase, main +from unittest import TestCase, main, skipUnless from typing import Any from typing import TypeVar, AnyStr @@ -133,6 +132,7 @@ def test_constrained_error(self): with self.assertRaises(TypeError): X = TypeVar('X', int) + X def test_union_unique(self): X = TypeVar('X') @@ -317,6 +317,7 @@ def test_union_str_pattern(self): # Shouldn't crash; see http://bugs.python.org/issue25390 A = Union[str, Pattern] + A class TypeVarUnionTests(TestCase): @@ -487,7 +488,7 @@ ... -class MySimpleMapping(SimpleMapping): +class MySimpleMapping(SimpleMapping[XK, XV]): def __init__(self): self.store = {} @@ -541,6 +542,7 @@ assert not issubclass(str, typing.SupportsAbs) def test_supports_round(self): + issubclass(float, typing.SupportsRound) assert issubclass(float, typing.SupportsRound) assert issubclass(int, typing.SupportsRound) assert not issubclass(str, typing.SupportsRound) @@ -551,20 +553,23 @@ def test_protocol_instance_type_error(self): with self.assertRaises(TypeError): - isinstance([], typing.Reversible) + isinstance(0, typing.SupportsAbs) class GenericTests(TestCase): def test_basics(self): X = SimpleMapping[str, Any] + assert X.__parameters__ == () + with self.assertRaises(TypeError): + X[str] + with self.assertRaises(TypeError): + X[str, str] Y = SimpleMapping[XK, str] - X[str, str] - Y[str, str] + assert Y.__parameters__ == (XK,) + Y[str] with self.assertRaises(TypeError): - X[int, str] - with self.assertRaises(TypeError): - Y[str, bytes] + Y[str, str] def test_init(self): T = TypeVar('T') @@ -576,30 +581,61 @@ def test_repr(self): self.assertEqual(repr(SimpleMapping), - __name__ + '.' + 'SimpleMapping[~XK, ~XV]') + __name__ + '.' + 'SimpleMapping<~XK, ~XV>') self.assertEqual(repr(MySimpleMapping), - __name__ + '.' + 'MySimpleMapping[~XK, ~XV]') + __name__ + '.' + 'MySimpleMapping<~XK, ~XV>') + + def test_chain_repr(self): + T = TypeVar('T') + S = TypeVar('S') + + class C(Generic[T]): + pass + + X = C[Tuple[S, T]] + assert X == C[Tuple[S, T]] + assert X != C[Tuple[T, S]] + + Y = X[T, int] + assert Y == X[T, int] + assert Y != X[S, int] + assert Y != X[T, str] + + Z = Y[str] + assert Z == Y[str] + assert Z != Y[int] + assert Z != Y[T] + + assert str(Z).endswith( + '.C<~T>[typing.Tuple[~S, ~T]]<~S, ~T>[~T, int]<~T>[str]') def test_dict(self): T = TypeVar('T') + class B(Generic[T]): pass + b = B() b.foo = 42 self.assertEqual(b.__dict__, {'foo': 42}) + class C(B[int]): pass + c = C() c.bar = 'abc' self.assertEqual(c.__dict__, {'bar': 'abc'}) def test_pickle(self): + global C # pickle wants to reference the class by name T = TypeVar('T') + class B(Generic[T]): pass - global C # pickle wants to reference the class by name + class C(B[int]): pass + c = C() c.foo = 42 c.bar = 'abc' @@ -626,12 +662,12 @@ assert C.__module__ == __name__ if not PY32: assert C.__qualname__ == 'GenericTests.test_repr_2..C' - assert repr(C).split('.')[-1] == 'C[~T]' + assert repr(C).split('.')[-1] == 'C<~T>' X = C[int] assert X.__module__ == __name__ if not PY32: assert X.__qualname__ == 'C' - assert repr(X).split('.')[-1] == 'C[int]' + assert repr(X).split('.')[-1] == 'C<~T>[int]' class Y(C[int]): pass @@ -639,7 +675,7 @@ assert Y.__module__ == __name__ if not PY32: assert Y.__qualname__ == 'GenericTests.test_repr_2..Y' - assert repr(Y).split('.')[-1] == 'Y[int]' + assert repr(Y).split('.')[-1] == 'Y' def test_eq_1(self): assert Generic == Generic @@ -667,15 +703,14 @@ class B(Generic[KT, T]): pass - class C(A, Generic[KT, VT], B): + class C(A[T, VT], Generic[VT, T, KT], B[KT, T]): pass - assert C.__parameters__ == (T, VT, KT) + assert C.__parameters__ == (VT, T, KT) def test_nested(self): - class G(Generic): - pass + G = Generic class Visitor(G[T]): @@ -721,9 +756,30 @@ assert type(a) is Node assert type(b) is Node assert type(c) is Node + assert a.label == x + assert b.label == x + assert c.label == x foo(42) + def test_implicit_any(self): + T = TypeVar('T') + + class C(Generic[T]): + pass + + class D(C): + pass + + assert D.__parameters__ == () + + with self.assertRaises(Exception): + D[int] + with self.assertRaises(Exception): + D[Any] + with self.assertRaises(Exception): + D[T] + class VarianceTests(TestCase): @@ -956,14 +1012,33 @@ from typing import overload with self.assertRaises(RuntimeError): + @overload def blah(): pass + blah() + + def test_overload_succeeds(self): + from typing import overload + + @overload + def blah(): + pass + + def blah(): + pass + + blah() + + +PY35 = sys.version_info[:2] >= (3, 5) + +PY35_TESTS = """ +import asyncio T_a = TypeVar('T') - class AwaitableWrapper(typing.Awaitable[T_a]): def __init__(self, value): @@ -973,7 +1048,6 @@ yield return self.value - class AsyncIteratorWrapper(typing.AsyncIterator[T_a]): def __init__(self, value: typing.Iterable[T_a]): @@ -989,6 +1063,10 @@ return data else: raise StopAsyncIteration +""" + +if PY35: + exec(PY35_TESTS) class CollectionsAbcTests(TestCase): @@ -1015,9 +1093,14 @@ assert isinstance(it, typing.Iterator[int]) assert not isinstance(42, typing.Iterator) + @skipUnless(PY35, 'Python 3.5 required') def test_awaitable(self): - async def foo() -> typing.Awaitable[int]: - return await AwaitableWrapper(42) + ns = {} + exec( + "async def foo() -> typing.Awaitable[int]:\n" + " return await AwaitableWrapper(42)\n", + globals(), ns) + foo = ns['foo'] g = foo() assert issubclass(type(g), typing.Awaitable[int]) assert isinstance(g, typing.Awaitable) @@ -1028,6 +1111,7 @@ typing.Awaitable[Manager]) g.send(None) # Run foo() till completion, to avoid warning. + @skipUnless(PY35, 'Python 3.5 required') def test_async_iterable(self): base_it = range(10) # type: Iterator[int] it = AsyncIteratorWrapper(base_it) @@ -1037,6 +1121,7 @@ typing.AsyncIterable[Employee]) assert not isinstance(42, typing.AsyncIterable) + @skipUnless(PY35, 'Python 3.5 required') def test_async_iterator(self): base_it = range(10) # type: Iterator[int] it = AsyncIteratorWrapper(base_it) @@ -1127,6 +1212,22 @@ d = MyDict() assert isinstance(d, MyDict) + def test_no_defaultdict_instantiation(self): + with self.assertRaises(TypeError): + typing.DefaultDict() + with self.assertRaises(TypeError): + typing.DefaultDict[KT, VT]() + with self.assertRaises(TypeError): + typing.DefaultDict[str, int]() + + def test_defaultdict_subclass_instantiation(self): + + class MyDefDict(typing.DefaultDict[str, int]): + pass + + dd = MyDefDict() + assert isinstance(dd, MyDefDict) + def test_no_set_instantiation(self): with self.assertRaises(TypeError): typing.Set() @@ -1251,7 +1352,7 @@ return a.readline() a = stuff.__annotations__['a'] - assert a.__parameters__ == (str,) + assert a.__parameters__ == () def test_binaryio(self): @@ -1259,7 +1360,7 @@ return a.readline() a = stuff.__annotations__['a'] - assert a.__parameters__ == (bytes,) + assert a.__parameters__ == () def test_io_submodule(self): from typing.io import IO, TextIO, BinaryIO, __all__, __name__ @@ -1346,8 +1447,9 @@ assert 'ValuesView' in a assert 'cast' in a assert 'overload' in a - assert 'io' in a - assert 're' in a + # Check that io and re are not exported. + assert 'io' not in a + assert 're' not in a # Spot-check that stdlib modules aren't exported. assert 'os' not in a assert 'sys' not in a diff --git a/Lib/typing.py b/Lib/typing.py --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1,7 +1,3 @@ -# TODO nits: -# Get rid of asserts that are the caller's fault. -# Docstrings (e.g. ABCs). - import abc from abc import abstractmethod, abstractproperty import collections @@ -56,6 +52,7 @@ # Concrete collection types. 'Dict', + 'DefaultDict', 'List', 'Set', 'NamedTuple', # Not really a type. @@ -68,11 +65,11 @@ 'no_type_check', 'no_type_check_decorator', 'overload', +] - # Submodules. - 'io', - 're', -] +# The pseudo-submodules 're' and 'io' are part of the public +# namespace, but excluded from __all__ because they might stomp on +# legitimate imports of those modules. def _qualname(x): @@ -117,8 +114,8 @@ """ return self - def _has_type_var(self): - return False + def _get_type_vars(self, tvars): + pass def __repr__(self): return '%s.%s' % (self.__module__, _qualname(self)) @@ -214,8 +211,8 @@ someone tries to subclass a type alias (not a good idea). """ if (len(args) == 3 and - isinstance(args[0], str) and - isinstance(args[1], tuple)): + isinstance(args[0], str) and + isinstance(args[1], tuple)): # Close enough. raise TypeError("A type alias cannot be subclassed") return object.__new__(cls) @@ -271,8 +268,16 @@ return issubclass(cls, self.impl_type) -def _has_type_var(t): - return t is not None and isinstance(t, TypingMeta) and t._has_type_var() +def _get_type_vars(types, tvars): + for t in types: + if isinstance(t, TypingMeta): + t._get_type_vars(tvars) + + +def _type_vars(types): + tvars = [] + _get_type_vars(types, tvars) + return tuple(tvars) def _eval_type(t, globalns, localns): @@ -376,7 +381,7 @@ At runtime, isinstance(x, T) will raise TypeError. However, issubclass(C, T) is true for any class C, and issubclass(str, A) and issubclass(bytes, A) are true, and issubclass(int, A) is - false. + false. (TODO: Why is this needed? This may change. See #136.) Type variables may be marked covariant or contravariant by passing covariant=True or contravariant=True. See PEP 484 for more @@ -410,8 +415,9 @@ self.__bound__ = None return self - def _has_type_var(self): - return True + def _get_type_vars(self, tvars): + if self not in tvars: + tvars.append(self) def __repr__(self): if self.__covariant__: @@ -448,7 +454,6 @@ T_contra = TypeVar('T_contra', contravariant=True) # Ditto contravariant. # A useful type variable with constraints. This represents string types. -# TODO: What about bytearray, memoryview? AnyStr = TypeVar('AnyStr', bytes, str) @@ -514,12 +519,9 @@ return self.__class__(self.__name__, self.__bases__, {}, p, _root=True) - def _has_type_var(self): + def _get_type_vars(self, tvars): if self.__union_params__: - for t in self.__union_params__: - if _has_type_var(t): - return True - return False + _get_type_vars(self.__union_params__, tvars) def __repr__(self): r = super().__repr__() @@ -656,12 +658,9 @@ self.__tuple_use_ellipsis__ = use_ellipsis return self - def _has_type_var(self): + def _get_type_vars(self, tvars): if self.__tuple_params__: - for t in self.__tuple_params__: - if _has_type_var(t): - return True - return False + _get_type_vars(self.__tuple_params__, tvars) def _eval_type(self, globalns, localns): tp = self.__tuple_params__ @@ -769,12 +768,9 @@ self.__result__ = result return self - def _has_type_var(self): + def _get_type_vars(self, tvars): if self.__args__: - for t in self.__args__: - if _has_type_var(t): - return True - return _has_type_var(self.__result__) + _get_type_vars(self.__args__, tvars) def _eval_type(self, globalns, localns): if self.__args__ is None and self.__result__ is None: @@ -878,76 +874,106 @@ return _gorg(a) is _gorg(b) +def _next_in_mro(cls): + """Helper for Generic.__new__. + + Returns the class after the last occurrence of Generic or + Generic[...] in cls.__mro__. + """ + next_in_mro = object + # Look for the last occurrence of Generic or Generic[...]. + for i, c in enumerate(cls.__mro__[:-1]): + if isinstance(c, GenericMeta) and _gorg(c) is Generic: + next_in_mro = cls.__mro__[i+1] + return next_in_mro + + class GenericMeta(TypingMeta, abc.ABCMeta): """Metaclass for generic types.""" - # TODO: Constrain more how Generic is used; only a few - # standard patterns should be allowed. - - # TODO: Use a more precise rule than matching __name__ to decide - # whether two classes are the same. Also, save the formal - # parameters. (These things are related! A solution lies in - # using origin.) - __extra__ = None def __new__(cls, name, bases, namespace, - parameters=None, origin=None, extra=None): - if parameters is None: - # Extract parameters from direct base classes. Only - # direct bases are considered and only those that are - # themselves generic, and parameterized with type - # variables. Don't use bases like Any, Union, Tuple, - # Callable or type variables. - params = None + tvars=None, args=None, origin=None, extra=None): + self = super().__new__(cls, name, bases, namespace, _root=True) + + if tvars is not None: + # Called from __getitem__() below. + assert origin is not None + assert all(isinstance(t, TypeVar) for t in tvars), tvars + else: + # Called from class statement. + assert tvars is None, tvars + assert args is None, args + assert origin is None, origin + + # Get the full set of tvars from the bases. + tvars = _type_vars(bases) + # Look for Generic[T1, ..., Tn]. + # If found, tvars must be a subset of it. + # If not found, tvars is it. + # Also check for and reject plain Generic, + # and reject multiple Generic[...]. + gvars = None for base in bases: - if isinstance(base, TypingMeta): - if not isinstance(base, GenericMeta): + if base is Generic: + raise TypeError("Cannot inherit from plain Generic") + if (isinstance(base, GenericMeta) and + base.__origin__ is Generic): + if gvars is not None: raise TypeError( - "You cannot inherit from magic class %s" % - repr(base)) - if base.__parameters__ is None: - continue # The base is unparameterized. - for bp in base.__parameters__: - if _has_type_var(bp) and not isinstance(bp, TypeVar): - raise TypeError( - "Cannot inherit from a generic class " - "parameterized with " - "non-type-variable %s" % bp) - if params is None: - params = [] - if bp not in params: - params.append(bp) - if params is not None: - parameters = tuple(params) - self = super().__new__(cls, name, bases, namespace, _root=True) - self.__parameters__ = parameters + "Cannot inherit from Generic[...] multiple types.") + gvars = base.__parameters__ + if gvars is None: + gvars = tvars + else: + tvarset = set(tvars) + gvarset = set(gvars) + if not tvarset <= gvarset: + raise TypeError( + "Some type variables (%s) " + "are not listed in Generic[%s]" % + (", ".join(str(t) for t in tvars if t not in gvarset), + ", ".join(str(g) for g in gvars))) + tvars = gvars + + self.__parameters__ = tvars + self.__args__ = args + self.__origin__ = origin if extra is not None: self.__extra__ = extra # Else __extra__ is inherited, eventually from the # (meta-)class default above. - self.__origin__ = origin + # Speed hack (https://github.com/python/typing/issues/196). + self.__next_in_mro__ = _next_in_mro(self) return self - def _has_type_var(self): - if self.__parameters__: - for t in self.__parameters__: - if _has_type_var(t): - return True - return False + def _get_type_vars(self, tvars): + if self.__origin__ and self.__parameters__: + _get_type_vars(self.__parameters__, tvars) def __repr__(self): - r = super().__repr__() - if self.__parameters__ is not None: + if self.__origin__ is not None: + r = repr(self.__origin__) + else: + r = super().__repr__() + if self.__args__: r += '[%s]' % ( + ', '.join(_type_repr(p) for p in self.__args__)) + if self.__parameters__: + r += '<%s>' % ( ', '.join(_type_repr(p) for p in self.__parameters__)) return r def __eq__(self, other): if not isinstance(other, GenericMeta): return NotImplemented - return (_geqv(self, other) and - self.__parameters__ == other.__parameters__) + if self.__origin__ is not None: + return (self.__origin__ is other.__origin__ and + self.__args__ == other.__args__ and + self.__parameters__ == other.__parameters__) + else: + return self is other def __hash__(self): return hash((self.__name__, self.__parameters__)) @@ -956,37 +982,45 @@ if not isinstance(params, tuple): params = (params,) if not params: - raise TypeError("Cannot have empty parameter list") + raise TypeError( + "Parameter list to %s[...] cannot be empty" % _qualname(self)) msg = "Parameters to generic types must be types." params = tuple(_type_check(p, msg) for p in params) - if self.__parameters__ is None: - for p in params: - if not isinstance(p, TypeVar): - raise TypeError("Initial parameters must be " - "type variables; got %s" % p) + if self is Generic: + # Generic can only be subscripted with unique type variables. + if not all(isinstance(p, TypeVar) for p in params): + raise TypeError( + "Parameters to Generic[...] must all be type variables") if len(set(params)) != len(params): raise TypeError( - "All type variables in Generic[...] must be distinct.") + "Parameters to Generic[...] must all be unique") + tvars = params + args = None + elif self is _Protocol: + # _Protocol is internal, don't check anything. + tvars = params + args = None + elif self.__origin__ in (Generic, _Protocol): + # Can't subscript Generic[...] or _Protocol[...]. + raise TypeError("Cannot subscript already-subscripted %s" % + repr(self)) else: - if len(params) != len(self.__parameters__): - raise TypeError("Cannot change parameter count from %d to %d" % - (len(self.__parameters__), len(params))) - for new, old in zip(params, self.__parameters__): - if isinstance(old, TypeVar): - if not old.__constraints__: - # Substituting for an unconstrained TypeVar is OK. - continue - if issubclass(new, Union[old.__constraints__]): - # Specializing a constrained type variable is OK. - continue - if not issubclass(new, old): - raise TypeError( - "Cannot substitute %s for %s in %s" % - (_type_repr(new), _type_repr(old), self)) - - return self.__class__(self.__name__, (self,) + self.__bases__, + # Subscripting a regular Generic subclass. + if not self.__parameters__: + raise TypeError("%s is not a generic class" % repr(self)) + alen = len(params) + elen = len(self.__parameters__) + if alen != elen: + raise TypeError( + "Too %s parameters for %s; actual %s, expected %s" % + ("many" if alen > elen else "few", repr(self), alen, elen)) + tvars = _type_vars(params) + args = params + return self.__class__(self.__name__, + (self,) + self.__bases__, dict(self.__dict__), - parameters=params, + tvars=tvars, + args=args, origin=self, extra=self.__extra__) @@ -1006,10 +1040,10 @@ # C[X] is a subclass of C[Y] iff X is a subclass of Y. origin = self.__origin__ if origin is not None and origin is cls.__origin__: - assert len(self.__parameters__) == len(origin.__parameters__) - assert len(cls.__parameters__) == len(origin.__parameters__) - for p_self, p_cls, p_origin in zip(self.__parameters__, - cls.__parameters__, + assert len(self.__args__) == len(origin.__parameters__) + assert len(cls.__args__) == len(origin.__parameters__) + for p_self, p_cls, p_origin in zip(self.__args__, + cls.__args__, origin.__parameters__): if isinstance(p_origin, TypeVar): if p_origin.__covariant__: @@ -1039,6 +1073,10 @@ return issubclass(cls, self.__extra__) +# Prevent checks for Generic to crash when defining Generic. +Generic = None + + class Generic(metaclass=GenericMeta): """Abstract base class for generic types. @@ -1053,29 +1091,23 @@ This class can then be used as follows:: - def lookup_name(mapping: Mapping, key: KT, default: VT) -> VT: + def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default - - For clarity the type variables may be redefined, e.g.:: - - X = TypeVar('X') - Y = TypeVar('Y') - def lookup_name(mapping: Mapping[X, Y], key: X, default: Y) -> Y: - # Same body as above. """ __slots__ = () def __new__(cls, *args, **kwds): - next_in_mro = object - # Look for the last occurrence of Generic or Generic[...]. - for i, c in enumerate(cls.__mro__[:-1]): - if isinstance(c, GenericMeta) and _gorg(c) is Generic: - next_in_mro = cls.__mro__[i+1] - return next_in_mro.__new__(_gorg(cls)) + if cls.__origin__ is None: + return cls.__next_in_mro__.__new__(cls) + else: + origin = _gorg(cls) + obj = cls.__next_in_mro__.__new__(origin) + obj.__init__(*args, **kwds) + return obj def cast(typ, val): @@ -1093,9 +1125,7 @@ """Internal helper to extract the default arguments, by name.""" code = func.__code__ pos_count = code.co_argcount - kw_count = code.co_kwonlyargcount arg_names = code.co_varnames - kwarg_names = arg_names[pos_count:pos_count + kw_count] arg_names = arg_names[:pos_count] defaults = func.__defaults__ or () kwdefaults = func.__kwdefaults__ @@ -1148,7 +1178,6 @@ return hints -# TODO: Also support this as a class decorator. def no_type_check(arg): """Decorator to indicate that annotations are not type hints. @@ -1183,8 +1212,42 @@ return wrapped_decorator +def _overload_dummy(*args, **kwds): + """Helper for @overload to raise when called.""" + raise NotImplementedError( + "You should not call an overloaded function. " + "A series of @overload-decorated functions " + "outside a stub module should always be followed " + "by an implementation that is not @overload-ed.") + + def overload(func): - raise RuntimeError("Overloading is only supported in library stubs") + """Decorator for overloaded functions/methods. + + In a stub file, place two or more stub definitions for the same + function in a row, each decorated with @overload. For example: + + @overload + def utf8(value: None) -> None: ... + @overload + def utf8(value: bytes) -> bytes: ... + @overload + def utf8(value: str) -> bytes: ... + + In a non-stub file (i.e. a regular .py file), do the same but + follow it with an implementation. The implementation should *not* + be decorated with @overload. For example: + + @overload + def utf8(value: None) -> None: ... + @overload + def utf8(value: bytes) -> bytes: ... + @overload + def utf8(value: str) -> bytes: ... + def utf8(value): + # implementation goes here + """ + return _overload_dummy class _ProtocolMeta(GenericMeta): @@ -1232,14 +1295,16 @@ break else: if (not attr.startswith('_abc_') and - attr != '__abstractmethods__' and - attr != '_is_protocol' and - attr != '__dict__' and - attr != '__slots__' and - attr != '_get_protocol_attrs' and - attr != '__parameters__' and - attr != '__origin__' and - attr != '__module__'): + attr != '__abstractmethods__' and + attr != '_is_protocol' and + attr != '__dict__' and + attr != '__args__' and + attr != '__slots__' and + attr != '_get_protocol_attrs' and + attr != '__next_in_mro__' and + attr != '__parameters__' and + attr != '__origin__' and + attr != '__module__'): attrs.add(attr) return attrs @@ -1264,16 +1329,25 @@ Hashable = collections_abc.Hashable # Not generic. -class Awaitable(Generic[T_co], extra=collections_abc.Awaitable): - __slots__ = () +if hasattr(collections_abc, 'Awaitable'): + class Awaitable(Generic[T_co], extra=collections_abc.Awaitable): + __slots__ = () +else: + Awaitable = None -class AsyncIterable(Generic[T_co], extra=collections_abc.AsyncIterable): - __slots__ = () +if hasattr(collections_abc, 'AsyncIterable'): + class AsyncIterable(Generic[T_co], extra=collections_abc.AsyncIterable): + __slots__ = () -class AsyncIterator(AsyncIterable[T_co], extra=collections_abc.AsyncIterator): - __slots__ = () + class AsyncIterator(AsyncIterable[T_co], + extra=collections_abc.AsyncIterator): + __slots__ = () + +else: + AsyncIterable = None + AsyncIterator = None class Iterable(Generic[T_co], extra=collections_abc.Iterable): @@ -1332,12 +1406,16 @@ pass -class Reversible(_Protocol[T_co]): - __slots__ = () +if hasattr(collections_abc, 'Reversible'): + class Reversible(Iterable[T_co], extra=collections_abc.Reversible): + __slots__ = () +else: + class Reversible(_Protocol[T_co]): + __slots__ = () - @abstractmethod - def __reversed__(self) -> 'Iterator[T_co]': - pass + @abstractmethod + def __reversed__(self) -> 'Iterator[T_co]': + pass Sized = collections_abc.Sized # Not generic. @@ -1360,7 +1438,7 @@ # NOTE: Only the value type is covariant. -class Mapping(Sized, Iterable[KT], Container[KT], Generic[VT_co], +class Mapping(Sized, Iterable[KT], Container[KT], Generic[KT, VT_co], extra=collections_abc.Mapping): pass @@ -1368,10 +1446,14 @@ class MutableMapping(Mapping[KT, VT], extra=collections_abc.MutableMapping): pass - -class Sequence(Sized, Iterable[T_co], Container[T_co], +if hasattr(collections_abc, 'Reversible'): + class Sequence(Sized, Reversible[T_co], Container[T_co], extra=collections_abc.Sequence): - pass + pass +else: + class Sequence(Sized, Iterable[T_co], Container[T_co], + extra=collections_abc.Sequence): + pass class MutableSequence(Sequence[T], extra=collections_abc.MutableSequence): @@ -1436,8 +1518,9 @@ pass -# TODO: Enable Set[Tuple[KT, VT_co]] instead of Generic[KT, VT_co]. -class ItemsView(MappingView, Generic[KT, VT_co], +class ItemsView(MappingView[Tuple[KT, VT_co]], + Set[Tuple[KT, VT_co]], + Generic[KT, VT_co], extra=collections_abc.ItemsView): pass @@ -1454,6 +1537,13 @@ "use dict() instead") return dict.__new__(cls, *args, **kwds) +class DefaultDict(collections.defaultdict, MutableMapping[KT, VT]): + + def __new__(cls, *args, **kwds): + if _geqv(cls, DefaultDict): + raise TypeError("Type DefaultDict cannot be instantiated; " + "use collections.defaultdict() instead") + return collections.defaultdict.__new__(cls, *args, **kwds) # Determine what base class to use for Generator. if hasattr(collections_abc, 'Generator'): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 5 12:16:11 2016 From: python-checkins at python.org (guido.van.rossum) Date: Tue, 05 Apr 2016 16:16:11 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_DefaultDict_to_PEP_484=2E?= Message-ID: <20160405161610.7797.21516.F69F01BD@psf.io> https://hg.python.org/peps/rev/7a4e2b94b631 changeset: 6276:7a4e2b94b631 user: Guido van Rossum date: Tue Apr 05 09:16:06 2016 -0700 summary: Add DefaultDict to PEP 484. files: pep-0484.txt | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pep-0484.txt b/pep-0484.txt --- a/pep-0484.txt +++ b/pep-0484.txt @@ -1337,6 +1337,9 @@ * Dict, used as ``Dict[key_type, value_type]`` +* DefaultDict, used as ``DefaultDict[key_type, value_type]``, + a generic variant of ``collections.defaultdict`` + * List, used as ``List[element_type]`` * Set, used as ``Set[element_type]``. See remark for ``AbstractSet`` @@ -1344,10 +1347,10 @@ * FrozenSet, used as ``FrozenSet[element_type]`` -Note: ``Dict``, ``List``, ``Set`` and ``FrozenSet`` are mainly useful -for annotating return values. For arguments, prefer the abstract -collection types defined below, e.g. ``Mapping``, ``Sequence`` or -``AbstractSet``. +Note: ``Dict``, ``DefaultDict``, ``List``, ``Set`` and ``FrozenSet`` +are mainly useful for annotating return values. +For arguments, prefer the abstract collection types defined below, +e.g. ``Mapping``, ``Sequence`` or ``AbstractSet``. Generic variants of container ABCs (and a few non-containers): -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Tue Apr 5 17:57:14 2016 From: python-checkins at python.org (guido.van.rossum) Date: Tue, 05 Apr 2016 21:57:14 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogQWRkIFRleHQ9c3Ry?= =?utf-8?q?=2E_Make_ItemsView_derive_from_AbstractSet=2C_not_Set_=28which_?= =?utf-8?q?is_the?= Message-ID: <20160405215714.7809.74658.563476F2@psf.io> https://hg.python.org/cpython/rev/2577a3684f90 changeset: 100855:2577a3684f90 branch: 3.5 parent: 100853:be3c4151d9bf user: Guido van Rossum date: Tue Apr 05 14:54:25 2016 -0700 summary: Add Text=str. Make ItemsView derive from AbstractSet, not Set (which is the concrete set). files: Lib/typing.py | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/Lib/typing.py b/Lib/typing.py --- a/Lib/typing.py +++ b/Lib/typing.py @@ -65,6 +65,7 @@ 'no_type_check', 'no_type_check_decorator', 'overload', + 'Text', ] # The pseudo-submodules 're' and 'io' are part of the public @@ -1519,7 +1520,7 @@ class ItemsView(MappingView[Tuple[KT, VT_co]], - Set[Tuple[KT, VT_co]], + AbstractSet[Tuple[KT, VT_co]], Generic[KT, VT_co], extra=collections_abc.ItemsView): pass @@ -1592,6 +1593,10 @@ return cls +# Python-version-specific alias (Python 2: unicode; Python 3: str) +Text = str + + class IO(Generic[AnyStr]): """Generic base class for TextIO and BinaryIO. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 5 17:57:14 2016 From: python-checkins at python.org (guido.van.rossum) Date: Tue, 05 Apr 2016 21:57:14 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgdHlwaW5nLnB5IDMuNS0+My42IChUZXh0LCBJdGVtc1ZpZXcp?= =?utf-8?q?=2E?= Message-ID: <20160405215714.11669.35277.06CE8AEF@psf.io> https://hg.python.org/cpython/rev/a94c2ddfd855 changeset: 100856:a94c2ddfd855 parent: 100854:78b84ae0b745 parent: 100855:2577a3684f90 user: Guido van Rossum date: Tue Apr 05 14:57:03 2016 -0700 summary: Merge typing.py 3.5->3.6 (Text, ItemsView). files: Lib/typing.py | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/Lib/typing.py b/Lib/typing.py --- a/Lib/typing.py +++ b/Lib/typing.py @@ -65,6 +65,7 @@ 'no_type_check', 'no_type_check_decorator', 'overload', + 'Text', ] # The pseudo-submodules 're' and 'io' are part of the public @@ -1519,7 +1520,7 @@ class ItemsView(MappingView[Tuple[KT, VT_co]], - Set[Tuple[KT, VT_co]], + AbstractSet[Tuple[KT, VT_co]], Generic[KT, VT_co], extra=collections_abc.ItemsView): pass @@ -1592,6 +1593,10 @@ return cls +# Python-version-specific alias (Python 2: unicode; Python 3: str) +Text = str + + class IO(Generic[AnyStr]): """Generic base class for TextIO and BinaryIO. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 5 19:35:58 2016 From: python-checkins at python.org (guido.van.rossum) Date: Tue, 05 Apr 2016 23:35:58 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_Text_alias=2E?= Message-ID: <20160405233558.28273.52355.7A11BE4D@psf.io> https://hg.python.org/peps/rev/25dba0ec19b3 changeset: 6277:25dba0ec19b3 user: Guido van Rossum date: Tue Apr 05 16:35:54 2016 -0700 summary: Add Text alias. files: pep-0484.txt | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/pep-0484.txt b/pep-0484.txt --- a/pep-0484.txt +++ b/pep-0484.txt @@ -1428,6 +1428,8 @@ * AnyStr, defined as ``TypeVar('AnyStr', str, bytes)`` +* Text, a simple alias for ``str`` in Python 3, for ``unicode`` in Python 2 + * NamedTuple, used as ``NamedTuple(type_name, [(field_name, field_type), ...])`` and equivalent to -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Wed Apr 6 02:51:59 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 06 Apr 2016 06:51:59 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2322570=3A_Renamed_Py=5FSETREF_to_Py=5FXSETREF=2E?= Message-ID: <20160406065159.129684.81413.2FE7FFA0@psf.io> https://hg.python.org/cpython/rev/719c11b6b6ff changeset: 100858:719c11b6b6ff parent: 100856:a94c2ddfd855 parent: 100857:d0c8b2c1544e user: Serhiy Storchaka date: Wed Apr 06 09:50:03 2016 +0300 summary: Issue #22570: Renamed Py_SETREF to Py_XSETREF. files: Include/object.h | 4 +- Modules/_bz2module.c | 2 +- Modules/_csv.c | 4 +- Modules/_ctypes/_ctypes.c | 28 ++++++------ Modules/_curses_panel.c | 2 +- Modules/_datetimemodule.c | 6 +- Modules/_decimal/_decimal.c | 8 +- Modules/_elementtree.c | 26 ++++++------ Modules/_functoolsmodule.c | 8 +- Modules/_io/bufferedio.c | 8 +- Modules/_io/bytesio.c | 4 +- Modules/_io/textio.c | 8 +- Modules/_lsprof.c | 2 +- Modules/_lzmamodule.c | 2 +- Modules/_pickle.c | 8 +- Modules/_sqlite/connection.c | 8 +- Modules/_sqlite/cursor.c | 10 ++-- Modules/_sre.c | 2 +- Modules/_ssl.c | 4 +- Modules/_struct.c | 2 +- Modules/cjkcodecs/multibytecodec.c | 2 +- Modules/faulthandler.c | 6 +- Modules/itertoolsmodule.c | 36 ++++++++-------- Modules/pyexpat.c | 2 +- Modules/readline.c | 2 +- Modules/signalmodule.c | 2 +- Modules/zipimport.c | 2 +- Modules/zlibmodule.c | 16 +++--- Objects/bytesobject.c | 2 +- Objects/descrobject.c | 2 +- Objects/exceptions.c | 38 +++++++++--------- Objects/floatobject.c | 4 +- Objects/frameobject.c | 4 +- Objects/funcobject.c | 22 +++++----- Objects/genobject.c | 4 +- Objects/listobject.c | 4 +- Objects/moduleobject.c | 2 +- Objects/object.c | 2 +- Objects/rangeobject.c | 6 +- Objects/tupleobject.c | 2 +- Objects/typeobject.c | 10 ++-- Objects/unicodeobject.c | 8 +- Parser/tokenizer.c | 2 +- Python/_warnings.c | 2 +- Python/ceval.c | 6 +- Python/compile.c | 2 +- Python/errors.c | 4 +- Python/import.c | 4 +- Python/peephole.c | 2 +- Python/sysmodule.c | 2 +- 50 files changed, 174 insertions(+), 174 deletions(-) diff --git a/Include/object.h b/Include/object.h --- a/Include/object.h +++ b/Include/object.h @@ -856,14 +856,14 @@ * * The safe way is: * - * Py_SETREF(op, op2); + * Py_XSETREF(op, op2); * * That arranges to set `op` to `op2` _before_ decref'ing, so that any code * triggered as a side-effect of `op` getting torn down no longer believes * `op` points to a valid object. */ -#define Py_SETREF(op, op2) \ +#define Py_XSETREF(op, op2) \ do { \ PyObject *_py_tmp = (PyObject *)(op); \ (op) = (op2); \ diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c --- a/Modules/_bz2module.c +++ b/Modules/_bz2module.c @@ -540,7 +540,7 @@ if (d->eof) { d->needs_input = 0; if (d->bzs_avail_in_real > 0) { - Py_SETREF(d->unused_data, + Py_XSETREF(d->unused_data, PyBytes_FromStringAndSize(bzs->next_in, d->bzs_avail_in_real)); if (d->unused_data == NULL) goto error; diff --git a/Modules/_csv.c b/Modules/_csv.c --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -277,7 +277,7 @@ if (PyUnicode_READY(src) == -1) return -1; Py_INCREF(src); - Py_SETREF(*target, src); + Py_XSETREF(*target, src); } } return 0; @@ -783,7 +783,7 @@ static int parse_reset(ReaderObj *self) { - Py_SETREF(self->fields, PyList_New(0)); + Py_XSETREF(self->fields, PyList_New(0)); if (self->fields == NULL) return -1; self->field_len = 0; diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -391,7 +391,7 @@ Py_DECREF((PyObject *)dict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)dict); + Py_XSETREF(result->tp_dict, (PyObject *)dict); dict->format = _ctypes_alloc_format_string(NULL, "B"); if (dict->format == NULL) { Py_DECREF(result); @@ -870,7 +870,7 @@ return -1; } Py_INCREF(proto); - Py_SETREF(stgdict->proto, proto); + Py_XSETREF(stgdict->proto, proto); return 0; } @@ -960,7 +960,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); return (PyObject *)result; } @@ -1403,7 +1403,7 @@ /* replace the class dict by our updated spam dict */ if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) goto error; - Py_SETREF(result->tp_dict, (PyObject *)stgdict); /* steal the reference */ + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); /* steal the reference */ stgdict = NULL; /* Special case for character arrays. @@ -1816,7 +1816,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); return (PyObject *)result; } @@ -1944,7 +1944,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); /* Install from_param class methods in ctypes base classes. Overrides the PyCSimpleType_from_param generic method. @@ -2307,7 +2307,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); if (-1 == make_funcptrtype_dict(stgdict)) { Py_DECREF(result); @@ -2451,7 +2451,7 @@ return -1; } if (ob->b_objects == NULL || !PyDict_CheckExact(ob->b_objects)) { - Py_SETREF(ob->b_objects, keep); /* refcount consumed */ + Py_XSETREF(ob->b_objects, keep); /* refcount consumed */ return 0; } key = unique_key(target, index); @@ -2955,7 +2955,7 @@ return -1; } Py_XINCREF(ob); - Py_SETREF(self->errcheck, ob); + Py_XSETREF(self->errcheck, ob); return 0; } @@ -2984,8 +2984,8 @@ return -1; } Py_INCREF(ob); - Py_SETREF(self->restype, ob); - Py_SETREF(self->checker, PyObject_GetAttrString(ob, "_check_retval_")); + Py_XSETREF(self->restype, ob); + Py_XSETREF(self->checker, PyObject_GetAttrString(ob, "_check_retval_")); if (self->checker == NULL) PyErr_Clear(); return 0; @@ -3022,9 +3022,9 @@ converters = converters_from_argtypes(ob); if (!converters) return -1; - Py_SETREF(self->converters, converters); + Py_XSETREF(self->converters, converters); Py_INCREF(ob); - Py_SETREF(self->argtypes, ob); + Py_XSETREF(self->argtypes, ob); } return 0; } @@ -5150,7 +5150,7 @@ return -1; Py_INCREF(args); - Py_SETREF(((PyBaseExceptionObject *)self)->args, args); + Py_XSETREF(((PyBaseExceptionObject *)self)->args, args); return 0; } diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -313,7 +313,7 @@ return NULL; } Py_INCREF(temp); - Py_SETREF(po->wo, temp); + Py_XSETREF(po->wo, temp); Py_INCREF(Py_None); return Py_None; } diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -1058,7 +1058,7 @@ /* Offset is normalized, so it is negative if days < 0 */ if (GET_TD_DAYS(offset) < 0) { sign = '-'; - Py_SETREF(offset, delta_negative((PyDateTime_Delta *)offset)); + Py_XSETREF(offset, delta_negative((PyDateTime_Delta *)offset)); if (offset == NULL) return -1; } @@ -3045,7 +3045,7 @@ if (dst == Py_None) goto Inconsistent; if (delta_bool((PyDateTime_Delta *)dst) != 0) { - Py_SETREF(result, add_datetime_timedelta((PyDateTime_DateTime *)result, + Py_XSETREF(result, add_datetime_timedelta((PyDateTime_DateTime *)result, (PyDateTime_Delta *)dst, 1)); if (result == NULL) goto Fail; @@ -4445,7 +4445,7 @@ return NULL; if (offdiff != NULL) { - Py_SETREF(result, delta_subtract(result, offdiff)); + Py_XSETREF(result, delta_subtract(result, offdiff)); Py_DECREF(offdiff); } } diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -3439,14 +3439,14 @@ goto error; } - Py_SETREF(exponent, long_methods->nb_power(tmp, exponent, Py_None)); + Py_XSETREF(exponent, long_methods->nb_power(tmp, exponent, Py_None)); Py_DECREF(tmp); if (exponent == NULL) { goto error; } if (exp >= 0) { - Py_SETREF(numerator, long_methods->nb_multiply(numerator, exponent)); + Py_XSETREF(numerator, long_methods->nb_multiply(numerator, exponent)); if (numerator == NULL) { goto error; } @@ -3462,8 +3462,8 @@ if (tmp == NULL) { goto error; } - Py_SETREF(numerator, long_methods->nb_floor_divide(numerator, tmp)); - Py_SETREF(denominator, long_methods->nb_floor_divide(denominator, tmp)); + Py_XSETREF(numerator, long_methods->nb_floor_divide(numerator, tmp)); + Py_XSETREF(denominator, long_methods->nb_floor_divide(denominator, tmp)); Py_DECREF(tmp); if (numerator == NULL || denominator == NULL) { goto error; diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -397,7 +397,7 @@ /* Replace the objects already pointed to by tag, text and tail. */ Py_INCREF(tag); - Py_SETREF(self_elem->tag, tag); + Py_XSETREF(self_elem->tag, tag); tmp = self_elem->text; Py_INCREF(Py_None); @@ -964,7 +964,7 @@ } Py_INCREF(tag); - Py_SETREF(self->tag, tag); + Py_XSETREF(self->tag, tag); _clear_joined_ptr(&self->text); self->text = text ? JOIN_SET(text, PyList_CheckExact(text)) : Py_None; @@ -1008,7 +1008,7 @@ /* Stash attrib. */ if (attrib) { Py_INCREF(attrib); - Py_SETREF(self->extra->attrib, attrib); + Py_XSETREF(self->extra->attrib, attrib); } Py_RETURN_NONE; @@ -1957,7 +1957,7 @@ { _VALIDATE_ATTR_VALUE(value); Py_INCREF(value); - Py_SETREF(self->tag, value); + Py_XSETREF(self->tag, value); return 0; } @@ -1990,7 +1990,7 @@ return -1; } Py_INCREF(value); - Py_SETREF(self->extra->attrib, value); + Py_XSETREF(self->extra->attrib, value); return 0; } @@ -2338,7 +2338,7 @@ { if (element_factory) { Py_INCREF(element_factory); - Py_SETREF(self->element_factory, element_factory); + Py_XSETREF(self->element_factory, element_factory); } return 0; @@ -2524,9 +2524,9 @@ self->index++; Py_INCREF(node); - Py_SETREF(self->this, node); + Py_XSETREF(self->this, node); Py_INCREF(node); - Py_SETREF(self->last, node); + Py_XSETREF(self->last, node); if (treebuilder_append_event(self, self->start_event_obj, node) < 0) goto error; @@ -3583,7 +3583,7 @@ events_append = PyObject_GetAttrString(events_queue, "append"); if (events_append == NULL) return NULL; - Py_SETREF(target->events_append, events_append); + Py_XSETREF(target->events_append, events_append); /* clear out existing events */ Py_CLEAR(target->start_event_obj); @@ -3618,18 +3618,18 @@ Py_INCREF(event_name_obj); if (strcmp(event_name, "start") == 0) { - Py_SETREF(target->start_event_obj, event_name_obj); + Py_XSETREF(target->start_event_obj, event_name_obj); } else if (strcmp(event_name, "end") == 0) { - Py_SETREF(target->end_event_obj, event_name_obj); + Py_XSETREF(target->end_event_obj, event_name_obj); } else if (strcmp(event_name, "start-ns") == 0) { - Py_SETREF(target->start_ns_event_obj, event_name_obj); + Py_XSETREF(target->start_ns_event_obj, event_name_obj); EXPAT(SetNamespaceDeclHandler)( self->parser, (XML_StartNamespaceDeclHandler) expat_start_ns_handler, (XML_EndNamespaceDeclHandler) expat_end_ns_handler ); } else if (strcmp(event_name, "end-ns") == 0) { - Py_SETREF(target->end_ns_event_obj, event_name_obj); + Py_XSETREF(target->end_ns_event_obj, event_name_obj); EXPAT(SetNamespaceDeclHandler)( self->parser, (XML_StartNamespaceDeclHandler) expat_start_ns_handler, diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -294,10 +294,10 @@ else Py_INCREF(dict); - Py_SETREF(pto->fn, fn); - Py_SETREF(pto->args, fnargs); - Py_SETREF(pto->kw, kw); - Py_SETREF(pto->dict, dict); + Py_XSETREF(pto->fn, fn); + Py_XSETREF(pto->args, fnargs); + Py_XSETREF(pto->kw, kw); + Py_XSETREF(pto->dict, dict); Py_RETURN_NONE; } diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -1196,7 +1196,7 @@ Py_CLEAR(res); goto end; } - Py_SETREF(res, _PyBytes_Join(_PyIO_empty_bytes, chunks)); + Py_XSETREF(res, _PyBytes_Join(_PyIO_empty_bytes, chunks)); end: LEAVE_BUFFERED(self) @@ -1452,7 +1452,7 @@ return -1; Py_INCREF(raw); - Py_SETREF(self->raw, raw); + Py_XSETREF(self->raw, raw); self->buffer_size = buffer_size; self->readable = 1; self->writable = 0; @@ -1804,7 +1804,7 @@ return -1; Py_INCREF(raw); - Py_SETREF(self->raw, raw); + Py_XSETREF(self->raw, raw); self->readable = 0; self->writable = 1; @@ -2307,7 +2307,7 @@ return -1; Py_INCREF(raw); - Py_SETREF(self->raw, raw); + Py_XSETREF(self->raw, raw); self->buffer_size = buffer_size; self->readable = 1; self->writable = 1; diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -96,7 +96,7 @@ return -1; memcpy(PyBytes_AS_STRING(new_buf), PyBytes_AS_STRING(self->buf), self->string_size); - Py_SETREF(self->buf, new_buf); + Py_XSETREF(self->buf, new_buf); return 0; } @@ -967,7 +967,7 @@ if (initvalue && initvalue != Py_None) { if (PyBytes_CheckExact(initvalue)) { Py_INCREF(initvalue); - Py_SETREF(self->buf, initvalue); + Py_XSETREF(self->buf, initvalue); self->string_size = PyBytes_GET_SIZE(initvalue); } else { diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -995,7 +995,7 @@ "Oi", self->decoder, (int)self->readtranslate); if (incrementalDecoder == NULL) goto error; - Py_SETREF(self->decoder, incrementalDecoder); + Py_XSETREF(self->decoder, incrementalDecoder); } } @@ -1373,7 +1373,7 @@ static void textiowrapper_set_decoded_chars(textio *self, PyObject *chars) { - Py_SETREF(self->decoded_chars, chars); + Py_XSETREF(self->decoded_chars, chars); self->decoded_chars_used = 0; } @@ -1521,7 +1521,7 @@ dec_buffer = NULL; /* Reference lost to PyBytes_Concat */ goto fail; } - Py_SETREF(self->snapshot, Py_BuildValue("NN", dec_flags, next_input)); + Py_XSETREF(self->snapshot, Py_BuildValue("NN", dec_flags, next_input)); } Py_DECREF(input_chunk); @@ -1627,7 +1627,7 @@ if (chunks != NULL) { if (result != NULL && PyList_Append(chunks, result) < 0) goto fail; - Py_SETREF(result, PyUnicode_Join(_PyIO_empty_str, chunks)); + Py_XSETREF(result, PyUnicode_Join(_PyIO_empty_str, chunks)); if (result == NULL) goto fail; Py_CLEAR(chunks); diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -778,7 +778,7 @@ return -1; pObj->externalTimerUnit = timeunit; Py_XINCREF(timer); - Py_SETREF(pObj->externalTimer, timer); + Py_XSETREF(pObj->externalTimer, timer); return 0; } diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c --- a/Modules/_lzmamodule.c +++ b/Modules/_lzmamodule.c @@ -1011,7 +1011,7 @@ if (d->eof) { d->needs_input = 0; if (lzs->avail_in > 0) { - Py_SETREF(d->unused_data, + Py_XSETREF(d->unused_data, PyBytes_FromStringAndSize((char *)lzs->next_in, lzs->avail_in)); if (d->unused_data == NULL) goto error; diff --git a/Modules/_pickle.c b/Modules/_pickle.c --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -869,7 +869,7 @@ static int _Pickler_ClearBuffer(PicklerObject *self) { - Py_SETREF(self->output_buffer, + Py_XSETREF(self->output_buffer, PyBytes_FromStringAndSize(NULL, self->max_output_len)); if (self->output_buffer == NULL) return -1; @@ -3116,7 +3116,7 @@ return -1; } Py_INCREF(item); - Py_SETREF(*module_name, item); + Py_XSETREF(*module_name, item); } else if (PyErr_Occurred()) { return -1; @@ -4506,7 +4506,7 @@ } Py_INCREF(value); - Py_SETREF(self->pers_func, value); + Py_XSETREF(self->pers_func, value); return 0; } @@ -6955,7 +6955,7 @@ } Py_INCREF(value); - Py_SETREF(self->pers_func, value); + Py_XSETREF(self->pers_func, value); return 0; } diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -204,7 +204,7 @@ node = node->next; } - Py_SETREF(self->statement_cache, + Py_XSETREF(self->statement_cache, (pysqlite_Cache *)PyObject_CallFunction((PyObject *)&pysqlite_CacheType, "O", self)); Py_DECREF(self); self->statement_cache->decref_factory = 0; @@ -319,7 +319,7 @@ if (cursor && self->row_factory != Py_None) { Py_INCREF(self->row_factory); - Py_SETREF(((pysqlite_Cursor *)cursor)->row_factory, self->row_factory); + Py_XSETREF(((pysqlite_Cursor *)cursor)->row_factory, self->row_factory); } return cursor; @@ -794,7 +794,7 @@ } } - Py_SETREF(self->statements, new_list); + Py_XSETREF(self->statements, new_list); } static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) @@ -825,7 +825,7 @@ } } - Py_SETREF(self->cursors, new_list); + Py_XSETREF(self->cursors, new_list); } PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -170,7 +170,7 @@ return 0; } - Py_SETREF(self->row_cast_map, PyList_New(0)); + Py_XSETREF(self->row_cast_map, PyList_New(0)); for (i = 0; i < sqlite3_column_count(self->statement->st); i++) { converter = NULL; @@ -510,7 +510,7 @@ /* reset description and rowcount */ Py_INCREF(Py_None); - Py_SETREF(self->description, Py_None); + Py_XSETREF(self->description, Py_None); self->rowcount = -1L; func_args = PyTuple_New(1); @@ -526,7 +526,7 @@ (void)pysqlite_statement_reset(self->statement); } - Py_SETREF(self->statement, + Py_XSETREF(self->statement, (pysqlite_Statement *)pysqlite_cache_get(self->connection->statement_cache, func_args)); Py_DECREF(func_args); @@ -535,7 +535,7 @@ } if (self->statement->in_use) { - Py_SETREF(self->statement, + Py_XSETREF(self->statement, PyObject_New(pysqlite_Statement, &pysqlite_StatementType)); if (!self->statement) { goto error; @@ -652,7 +652,7 @@ numcols = sqlite3_column_count(self->statement->st); Py_END_ALLOW_THREADS - Py_SETREF(self->description, PyTuple_New(numcols)); + Py_XSETREF(self->description, PyTuple_New(numcols)); if (!self->description) { goto error; } diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -753,7 +753,7 @@ if (!copy) return 0; - Py_SETREF(*object, copy); + Py_XSETREF(*object, copy); return 1; /* success */ } diff --git a/Modules/_ssl.c b/Modules/_ssl.c --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -1589,7 +1589,7 @@ return -1; #else Py_INCREF(value); - Py_SETREF(self->ctx, (PySSLContext *)value); + Py_XSETREF(self->ctx, (PySSLContext *)value); SSL_set_SSL_CTX(self->ssl, self->ctx->ctx); #endif } else { @@ -1646,7 +1646,7 @@ static int PySSL_set_owner(PySSLSocket *self, PyObject *value, void *c) { - Py_SETREF(self->owner, PyWeakref_NewRef(value, NULL)); + Py_XSETREF(self->owner, PyWeakref_NewRef(value, NULL)); if (self->owner == NULL) return -1; return 0; diff --git a/Modules/_struct.c b/Modules/_struct.c --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1437,7 +1437,7 @@ return -1; } - Py_SETREF(soself->s_format, o_format); + Py_XSETREF(soself->s_format, o_format); ret = prepare_s(soself); return ret; diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -793,7 +793,7 @@ ctx->errors, final ? MBENC_FLUSH | MBENC_RESET : 0); if (r == NULL) { /* recover the original pending buffer */ - Py_SETREF(ctx->pending, origpending); + Py_XSETREF(ctx->pending, origpending); origpending = NULL; goto errorexit; } diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -488,7 +488,7 @@ return NULL; Py_XINCREF(file); - Py_SETREF(fatal_error.file, file); + Py_XSETREF(fatal_error.file, file); fatal_error.fd = fd; fatal_error.all_threads = all_threads; fatal_error.interp = tstate->interp; @@ -668,7 +668,7 @@ cancel_dump_traceback_later(); Py_XINCREF(file); - Py_SETREF(thread.file, file); + Py_XSETREF(thread.file, file); thread.fd = fd; thread.timeout_us = timeout_us; thread.repeat = repeat; @@ -846,7 +846,7 @@ } Py_XINCREF(file); - Py_SETREF(user->file, file); + Py_XSETREF(user->file, file); user->fd = fd; user->all_threads = all_threads; user->chain = chain; diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -108,12 +108,12 @@ } } - Py_SETREF(gbo->currkey, newkey); - Py_SETREF(gbo->currvalue, newvalue); + Py_XSETREF(gbo->currkey, newkey); + Py_XSETREF(gbo->currvalue, newvalue); } Py_INCREF(gbo->currkey); - Py_SETREF(gbo->tgtkey, gbo->currkey); + Py_XSETREF(gbo->tgtkey, gbo->currkey); grouper = _grouper_create(gbo, gbo->tgtkey); if (grouper == NULL) @@ -150,11 +150,11 @@ if (!PyArg_ParseTuple(state, "OOO", &currkey, &currvalue, &tgtkey)) return NULL; Py_INCREF(currkey); - Py_SETREF(lz->currkey, currkey); + Py_XSETREF(lz->currkey, currkey); Py_INCREF(currvalue); - Py_SETREF(lz->currvalue, currvalue); + Py_XSETREF(lz->currvalue, currvalue); Py_INCREF(tgtkey); - Py_SETREF(lz->tgtkey, tgtkey); + Py_XSETREF(lz->tgtkey, tgtkey); Py_RETURN_NONE; } @@ -622,7 +622,7 @@ link = teedataobject_jumplink(to->dataobj); if (link == NULL) return NULL; - Py_SETREF(to->dataobj, (teedataobject *)link); + Py_XSETREF(to->dataobj, (teedataobject *)link); to->index = 0; } value = teedataobject_getitem(to->dataobj, to->index); @@ -734,7 +734,7 @@ return NULL; } Py_INCREF(tdo); - Py_SETREF(to->dataobj, tdo); + Py_XSETREF(to->dataobj, tdo); to->index = index; Py_RETURN_NONE; } @@ -975,7 +975,7 @@ if (!PyArg_ParseTuple(state, "O!i", &PyList_Type, &saved, &firstpass)) return NULL; Py_INCREF(saved); - Py_SETREF(lz->saved, saved); + Py_XSETREF(lz->saved, saved); lz->firstpass = firstpass != 0; lz->index = 0; Py_RETURN_NONE; @@ -1907,9 +1907,9 @@ return NULL; Py_INCREF(source); - Py_SETREF(lz->source, source); + Py_XSETREF(lz->source, source); Py_XINCREF(active); - Py_SETREF(lz->active, active); + Py_XSETREF(lz->active, active); Py_RETURN_NONE; } @@ -2266,7 +2266,7 @@ Py_INCREF(element); PyTuple_SET_ITEM(result, i, element); } - Py_SETREF(lz->result, result); + Py_XSETREF(lz->result, result); Py_RETURN_NONE; } @@ -2587,7 +2587,7 @@ PyTuple_SET_ITEM(result, i, element); } - Py_SETREF(lz->result, result); + Py_XSETREF(lz->result, result); Py_RETURN_NONE; } @@ -2917,7 +2917,7 @@ Py_INCREF(element); PyTuple_SET_ITEM(result, i, element); } - Py_SETREF(lz->result, result); + Py_XSETREF(lz->result, result); Py_RETURN_NONE; } @@ -3305,7 +3305,7 @@ Py_INCREF(element); PyTuple_SET_ITEM(result, i, element); } - Py_SETREF(po->result, result); + Py_XSETREF(po->result, result); Py_RETURN_NONE; } @@ -3457,7 +3457,7 @@ return NULL; Py_INCREF(newtotal); - Py_SETREF(lz->total, newtotal); + Py_XSETREF(lz->total, newtotal); return newtotal; } @@ -3490,7 +3490,7 @@ accumulate_setstate(accumulateobject *lz, PyObject *state) { Py_INCREF(state); - Py_SETREF(lz->total, state); + Py_XSETREF(lz->total, state); Py_RETURN_NONE; } @@ -4469,7 +4469,7 @@ zip_longest_setstate(ziplongestobject *lz, PyObject *state) { Py_INCREF(state); - Py_SETREF(lz->fillvalue, state); + Py_XSETREF(lz->fillvalue, state); Py_RETURN_NONE; } diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1362,7 +1362,7 @@ Py_INCREF(v); c_handler = handler_info[handlernum].handler; } - Py_SETREF(self->handlers[handlernum], v); + Py_XSETREF(self->handlers[handlernum], v); handler_info[handlernum].setter(self->itself, c_handler); return 1; } diff --git a/Modules/readline.c b/Modules/readline.c --- a/Modules/readline.c +++ b/Modules/readline.c @@ -324,7 +324,7 @@ } else if (PyCallable_Check(function)) { Py_INCREF(function); - Py_SETREF(*hook_var, function); + Py_XSETREF(*hook_var, function); } else { PyErr_Format(PyExc_TypeError, diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -1266,7 +1266,7 @@ if (Handlers[SIGINT].func == DefaultHandler) { /* Install default int handler */ Py_INCREF(IntHandler); - Py_SETREF(Handlers[SIGINT].func, IntHandler); + Py_XSETREF(Handlers[SIGINT].func, IntHandler); old_siginthandler = PyOS_setsig(SIGINT, signal_handler); } diff --git a/Modules/zipimport.c b/Modules/zipimport.c --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -155,7 +155,7 @@ tmp = PyUnicode_FromFormat("%U%c", self->prefix, SEP); if (tmp == NULL) goto error; - Py_SETREF(self->prefix, tmp); + Py_XSETREF(self->prefix, tmp); } } else diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -667,7 +667,7 @@ PyBytes_AS_STRING(self->unused_data), old_size); Py_MEMCPY(PyBytes_AS_STRING(new_data) + old_size, self->zst.next_in, self->zst.avail_in); - Py_SETREF(self->unused_data, new_data); + Py_XSETREF(self->unused_data, new_data); self->zst.avail_in = 0; } } @@ -679,7 +679,7 @@ (char *)self->zst.next_in, self->zst.avail_in); if (new_data == NULL) return -1; - Py_SETREF(self->unconsumed_tail, new_data); + Py_XSETREF(self->unconsumed_tail, new_data); } return 0; } @@ -961,11 +961,11 @@ goto error; } Py_INCREF(self->unused_data); - Py_SETREF(retval->unused_data, self->unused_data); + Py_XSETREF(retval->unused_data, self->unused_data); Py_INCREF(self->unconsumed_tail); - Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail); + Py_XSETREF(retval->unconsumed_tail, self->unconsumed_tail); Py_XINCREF(self->zdict); - Py_SETREF(retval->zdict, self->zdict); + Py_XSETREF(retval->zdict, self->zdict); retval->eof = self->eof; /* Mark it as being initialized */ @@ -1017,11 +1017,11 @@ } Py_INCREF(self->unused_data); - Py_SETREF(retval->unused_data, self->unused_data); + Py_XSETREF(retval->unused_data, self->unused_data); Py_INCREF(self->unconsumed_tail); - Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail); + Py_XSETREF(retval->unconsumed_tail, self->unconsumed_tail); Py_XINCREF(self->zdict); - Py_SETREF(retval->zdict, self->zdict); + Py_XSETREF(retval->zdict, self->zdict); retval->eof = self->eof; /* Mark it as being initialized */ diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3698,7 +3698,7 @@ /* Multiple references, need to create new object */ PyObject *v; v = bytes_concat(*pv, w); - Py_SETREF(*pv, v); + Py_XSETREF(*pv, v); } } diff --git a/Objects/descrobject.c b/Objects/descrobject.c --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1509,7 +1509,7 @@ PyObject *get_doc = _PyObject_GetAttrId(get, &PyId___doc__); if (get_doc) { if (Py_TYPE(self) == &PyProperty_Type) { - Py_SETREF(prop->prop_doc, get_doc); + Py_XSETREF(prop->prop_doc, get_doc); } else { /* If this is a property subclass, put __doc__ diff --git a/Objects/exceptions.c b/Objects/exceptions.c --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -63,7 +63,7 @@ return -1; Py_INCREF(args); - Py_SETREF(self->args, args); + Py_XSETREF(self->args, args); return 0; } @@ -202,7 +202,7 @@ seq = PySequence_Tuple(val); if (!seq) return -1; - Py_SETREF(self->args, seq); + Py_XSETREF(self->args, seq); return 0; } @@ -231,7 +231,7 @@ } Py_XINCREF(tb); - Py_SETREF(self->traceback, tb); + Py_XSETREF(self->traceback, tb); return 0; } @@ -327,7 +327,7 @@ PyException_SetCause(PyObject *self, PyObject *cause) { ((PyBaseExceptionObject *)self)->suppress_context = 1; - Py_SETREF(((PyBaseExceptionObject *)self)->cause, cause); + Py_XSETREF(((PyBaseExceptionObject *)self)->cause, cause); } PyObject * @@ -341,7 +341,7 @@ void PyException_SetContext(PyObject *self, PyObject *context) { - Py_SETREF(((PyBaseExceptionObject *)self)->context, context); + Py_XSETREF(((PyBaseExceptionObject *)self)->context, context); } @@ -557,11 +557,11 @@ return 0; if (size == 1) { Py_INCREF(PyTuple_GET_ITEM(args, 0)); - Py_SETREF(self->code, PyTuple_GET_ITEM(args, 0)); + Py_XSETREF(self->code, PyTuple_GET_ITEM(args, 0)); } else { /* size > 1 */ Py_INCREF(args); - Py_SETREF(self->code, args); + Py_XSETREF(self->code, args); } return 0; } @@ -622,7 +622,7 @@ kwd = PyDict_GetItemString(kwds, #kwd); \ if (kwd) { \ Py_INCREF(kwd); \ - Py_SETREF(self->kwd, kwd); \ + Py_XSETREF(self->kwd, kwd); \ if (PyDict_DelItemString(kwds, #kwd)) \ return -1; \ } \ @@ -641,7 +641,7 @@ return -1; Py_INCREF(msg); - Py_SETREF(self->msg, msg); + Py_XSETREF(self->msg, msg); return 0; } @@ -851,7 +851,7 @@ #endif /* Steals the reference to args */ - Py_SETREF(self->args, args); + Py_XSETREF(self->args, args); *p_args = args = NULL; return 0; @@ -1271,7 +1271,7 @@ if (lenargs >= 1) { Py_INCREF(PyTuple_GET_ITEM(args, 0)); - Py_SETREF(self->msg, PyTuple_GET_ITEM(args, 0)); + Py_XSETREF(self->msg, PyTuple_GET_ITEM(args, 0)); } if (lenargs == 2) { info = PyTuple_GET_ITEM(args, 1); @@ -1287,16 +1287,16 @@ } Py_INCREF(PyTuple_GET_ITEM(info, 0)); - Py_SETREF(self->filename, PyTuple_GET_ITEM(info, 0)); + Py_XSETREF(self->filename, PyTuple_GET_ITEM(info, 0)); Py_INCREF(PyTuple_GET_ITEM(info, 1)); - Py_SETREF(self->lineno, PyTuple_GET_ITEM(info, 1)); + Py_XSETREF(self->lineno, PyTuple_GET_ITEM(info, 1)); Py_INCREF(PyTuple_GET_ITEM(info, 2)); - Py_SETREF(self->offset, PyTuple_GET_ITEM(info, 2)); + Py_XSETREF(self->offset, PyTuple_GET_ITEM(info, 2)); Py_INCREF(PyTuple_GET_ITEM(info, 3)); - Py_SETREF(self->text, PyTuple_GET_ITEM(info, 3)); + Py_XSETREF(self->text, PyTuple_GET_ITEM(info, 3)); Py_DECREF(info); @@ -1541,7 +1541,7 @@ PyObject *obj = PyUnicode_FromString(value); if (!obj) return -1; - Py_SETREF(*attr, obj); + Py_XSETREF(*attr, obj); return 0; } @@ -1947,7 +1947,7 @@ Py_buffer view; if (PyObject_GetBuffer(ude->object, &view, PyBUF_SIMPLE) != 0) goto error; - Py_SETREF(ude->object, PyBytes_FromStringAndSize(view.buf, view.len)); + Py_XSETREF(ude->object, PyBytes_FromStringAndSize(view.buf, view.len)); PyBuffer_Release(&view); if (!ude->object) goto error; @@ -2856,7 +2856,7 @@ } if (PyUnicode_Tailmatch(self->text, print_prefix, start, text_len, -1)) { - Py_SETREF(self->msg, + Py_XSETREF(self->msg, PyUnicode_FromString("Missing parentheses in call to 'print'")); return 1; } @@ -2870,7 +2870,7 @@ } if (PyUnicode_Tailmatch(self->text, exec_prefix, start, text_len, -1)) { - Py_SETREF(self->msg, + Py_XSETREF(self->msg, PyUnicode_FromString("Missing parentheses in call to 'exec'")); return 1; } diff --git a/Objects/floatobject.c b/Objects/floatobject.c --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -1494,13 +1494,13 @@ /* fold in 2**exponent */ if (exponent > 0) { - Py_SETREF(numerator, + Py_XSETREF(numerator, long_methods->nb_lshift(numerator, py_exponent)); if (numerator == NULL) goto error; } else { - Py_SETREF(denominator, + Py_XSETREF(denominator, long_methods->nb_lshift(denominator, py_exponent)); if (denominator == NULL) goto error; diff --git a/Objects/frameobject.c b/Objects/frameobject.c --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -353,7 +353,7 @@ f->f_lineno = PyFrame_GetLineNumber(f); Py_XINCREF(v); - Py_SETREF(f->f_trace, v); + Py_XSETREF(f->f_trace, v); return 0; } @@ -853,7 +853,7 @@ } } else if (values[j] != value) { Py_XINCREF(value); - Py_SETREF(values[j], value); + Py_XSETREF(values[j], value); } Py_XDECREF(value); } diff --git a/Objects/funcobject.c b/Objects/funcobject.c --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -127,7 +127,7 @@ PyErr_SetString(PyExc_SystemError, "non-tuple default args"); return -1; } - Py_SETREF(((PyFunctionObject *)op)->func_defaults, defaults); + Py_XSETREF(((PyFunctionObject *)op)->func_defaults, defaults); return 0; } @@ -158,7 +158,7 @@ "non-dict keyword only default args"); return -1; } - Py_SETREF(((PyFunctionObject *)op)->func_kwdefaults, defaults); + Py_XSETREF(((PyFunctionObject *)op)->func_kwdefaults, defaults); return 0; } @@ -190,7 +190,7 @@ closure->ob_type->tp_name); return -1; } - Py_SETREF(((PyFunctionObject *)op)->func_closure, closure); + Py_XSETREF(((PyFunctionObject *)op)->func_closure, closure); return 0; } @@ -221,7 +221,7 @@ "non-dict annotations"); return -1; } - Py_SETREF(((PyFunctionObject *)op)->func_annotations, annotations); + Py_XSETREF(((PyFunctionObject *)op)->func_annotations, annotations); return 0; } @@ -270,7 +270,7 @@ return -1; } Py_INCREF(value); - Py_SETREF(op->func_code, value); + Py_XSETREF(op->func_code, value); return 0; } @@ -292,7 +292,7 @@ return -1; } Py_INCREF(value); - Py_SETREF(op->func_name, value); + Py_XSETREF(op->func_name, value); return 0; } @@ -314,7 +314,7 @@ return -1; } Py_INCREF(value); - Py_SETREF(op->func_qualname, value); + Py_XSETREF(op->func_qualname, value); return 0; } @@ -342,7 +342,7 @@ return -1; } Py_XINCREF(value); - Py_SETREF(op->func_defaults, value); + Py_XSETREF(op->func_defaults, value); return 0; } @@ -370,7 +370,7 @@ return -1; } Py_XINCREF(value); - Py_SETREF(op->func_kwdefaults, value); + Py_XSETREF(op->func_kwdefaults, value); return 0; } @@ -400,7 +400,7 @@ return -1; } Py_XINCREF(value); - Py_SETREF(op->func_annotations, value); + Py_XSETREF(op->func_annotations, value); return 0; } @@ -504,7 +504,7 @@ if (name != Py_None) { Py_INCREF(name); - Py_SETREF(newfunc->func_name, name); + Py_XSETREF(newfunc->func_name, name); } if (defaults != Py_None) { Py_INCREF(defaults); diff --git a/Objects/genobject.c b/Objects/genobject.c --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -527,7 +527,7 @@ return -1; } Py_INCREF(value); - Py_SETREF(op->gi_name, value); + Py_XSETREF(op->gi_name, value); return 0; } @@ -549,7 +549,7 @@ return -1; } Py_INCREF(value); - Py_SETREF(op->gi_qualname, value); + Py_XSETREF(op->gi_qualname, value); return 0; } diff --git a/Objects/listobject.c b/Objects/listobject.c --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -229,7 +229,7 @@ return -1; } p = ((PyListObject *)op) -> ob_item + i; - Py_SETREF(*p, newitem); + Py_XSETREF(*p, newitem); return 0; } @@ -735,7 +735,7 @@ if (v == NULL) return list_ass_slice(a, i, i+1, v); Py_INCREF(v); - Py_SETREF(a->ob_item[i], v); + Py_XSETREF(a->ob_item[i], v); return 0; } diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -69,7 +69,7 @@ return -1; if (PyUnicode_CheckExact(name)) { Py_INCREF(name); - Py_SETREF(mod->md_name, name); + Py_XSETREF(mod->md_name, name); } return 0; diff --git a/Objects/object.c b/Objects/object.c --- a/Objects/object.c +++ b/Objects/object.c @@ -1220,7 +1220,7 @@ return -1; } Py_INCREF(value); - Py_SETREF(*dictptr, value); + Py_XSETREF(*dictptr, value); return 0; } diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -1001,7 +1001,7 @@ return NULL; cmp = PyObject_RichCompareBool(state, zero, Py_LT); if (cmp > 0) { - Py_SETREF(r->index, zero); + Py_XSETREF(r->index, zero); Py_RETURN_NONE; } Py_DECREF(zero); @@ -1015,7 +1015,7 @@ state = r->len; Py_INCREF(state); - Py_SETREF(r->index, state); + Py_XSETREF(r->index, state); Py_RETURN_NONE; } @@ -1064,7 +1064,7 @@ result = PyNumber_Add(r->start, product); Py_DECREF(product); if (result) { - Py_SETREF(r->index, new_index); + Py_XSETREF(r->index, new_index); } else { Py_DECREF(new_index); diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -162,7 +162,7 @@ return -1; } p = ((PyTupleObject *)op) -> ob_item + i; - Py_SETREF(*p, newitem); + Py_XSETREF(*p, newitem); return 0; } diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -316,7 +316,7 @@ for (i = 0; i < (1 << MCACHE_SIZE_EXP); i++) { method_cache[i].value = NULL; Py_INCREF(Py_None); - Py_SETREF(method_cache[i].name, Py_None); + Py_XSETREF(method_cache[i].name, Py_None); } /* mark all version tags as invalid */ PyType_Modified(&PyBaseObject_Type); @@ -424,7 +424,7 @@ type->tp_name = tp_name; Py_INCREF(value); - Py_SETREF(((PyHeapTypeObject*)type)->ht_name, value); + Py_XSETREF(((PyHeapTypeObject*)type)->ht_name, value); return 0; } @@ -445,7 +445,7 @@ et = (PyHeapTypeObject*)type; Py_INCREF(value); - Py_SETREF(et->ht_qualname, value); + Py_XSETREF(et->ht_qualname, value); return 0; } @@ -2124,7 +2124,7 @@ return -1; } Py_XINCREF(value); - Py_SETREF(*dictptr, value); + Py_XSETREF(*dictptr, value); return 0; } @@ -2903,7 +2903,7 @@ else method_cache_misses++; #endif - Py_SETREF(method_cache[h].name, name); + Py_XSETREF(method_cache[h].name, name); } return res; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1830,7 +1830,7 @@ _Py_INCREF_UNICODE_EMPTY(); if (!unicode_empty) return -1; - Py_SETREF(*p_unicode, unicode_empty); + Py_XSETREF(*p_unicode, unicode_empty); return 0; } @@ -1838,7 +1838,7 @@ PyObject *copy = resize_copy(unicode, length); if (copy == NULL) return -1; - Py_SETREF(*p_unicode, copy); + Py_XSETREF(*p_unicode, copy); return 0; } @@ -13547,7 +13547,7 @@ return -1; _PyUnicode_FastCopyCharacters(newbuffer, 0, writer->buffer, 0, writer->pos); - Py_SETREF(writer->buffer, newbuffer); + Py_XSETREF(writer->buffer, newbuffer); } _PyUnicodeWriter_Update(writer); return 0; @@ -15264,7 +15264,7 @@ if (t) { Py_INCREF(t); - Py_SETREF(*p, t); + Py_XSETREF(*p, t); return; } diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -526,7 +526,7 @@ goto cleanup; readline = _PyObject_GetAttrId(stream, &PyId_readline); - Py_SETREF(tok->decoding_readline, readline); + Py_XSETREF(tok->decoding_readline, readline); if (pos > 0) { if (PyObject_CallObject(readline, NULL) == NULL) { readline = NULL; diff --git a/Python/_warnings.c b/Python/_warnings.c --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -730,7 +730,7 @@ goto handle_error; } else if (!is_true) { - Py_SETREF(*filename, PyUnicode_FromString("__main__")); + Py_XSETREF(*filename, PyUnicode_FromString("__main__")); if (*filename == NULL) goto handle_error; } diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3236,7 +3236,7 @@ Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); - Py_SETREF(*pfunc, self); + Py_XSETREF(*pfunc, self); na++; /* n++; */ } else @@ -4491,7 +4491,7 @@ PyThreadState *tstate = PyThreadState_GET(); Py_XINCREF(wrapper); - Py_SETREF(tstate->coroutine_wrapper, wrapper); + Py_XSETREF(tstate->coroutine_wrapper, wrapper); } PyObject * @@ -4747,7 +4747,7 @@ Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); - Py_SETREF(*pfunc, self); + Py_XSETREF(*pfunc, self); na++; n++; } else diff --git a/Python/compile.c b/Python/compile.c --- a/Python/compile.c +++ b/Python/compile.c @@ -1756,7 +1756,7 @@ { /* use the class name for name mangling */ Py_INCREF(s->v.ClassDef.name); - Py_SETREF(c->u->u_private, s->v.ClassDef.name); + Py_XSETREF(c->u->u_private, s->v.ClassDef.name); /* load (global) __name__ ... */ str = PyUnicode_InternFromString("__name__"); if (!str || !compiler_nameop(c, str, Load)) { diff --git a/Python/errors.c b/Python/errors.c --- a/Python/errors.c +++ b/Python/errors.c @@ -311,9 +311,9 @@ --tstate->recursion_depth; /* throw away the old exception and use the recursion error instead */ Py_INCREF(PyExc_RecursionError); - Py_SETREF(*exc, PyExc_RecursionError); + Py_XSETREF(*exc, PyExc_RecursionError); Py_INCREF(PyExc_RecursionErrorInst); - Py_SETREF(*val, PyExc_RecursionErrorInst); + Py_XSETREF(*val, PyExc_RecursionErrorInst); /* just keeping the old traceback */ return; } diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -884,7 +884,7 @@ return; Py_INCREF(newname); - Py_SETREF(co->co_filename, newname); + Py_XSETREF(co->co_filename, newname); constants = co->co_consts; n = PyTuple_GET_SIZE(constants); @@ -1330,7 +1330,7 @@ PyUnicode_CompareWithASCIIString(code->co_name, remove_frames) == 0)) { Py_XINCREF(next); - Py_SETREF(*outer_link, next); + Py_XSETREF(*outer_link, next); prev_link = outer_link; } else { diff --git a/Python/peephole.c b/Python/peephole.c --- a/Python/peephole.c +++ b/Python/peephole.c @@ -118,7 +118,7 @@ /* If it's a BUILD_SET, use the PyTuple we just built to create a PyFrozenSet, and use that as the constant instead: */ if (codestr[0] == BUILD_SET) { - Py_SETREF(newconst, PyFrozenSet_New(newconst)); + Py_XSETREF(newconst, PyFrozenSet_New(newconst)); if (newconst == NULL) return 0; } diff --git a/Python/sysmodule.c b/Python/sysmodule.c --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -436,7 +436,7 @@ return -1; } if (result != Py_None) { - Py_SETREF(frame->f_trace, result); + Py_XSETREF(frame->f_trace, result); } else { Py_DECREF(result); -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 6 02:51:59 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 06 Apr 2016 06:51:59 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzIyNTcw?= =?utf-8?q?=3A_Renamed_Py=5FSETREF_to_Py=5FXSETREF=2E?= Message-ID: <20160406065158.49897.35068.B65A8B34@psf.io> https://hg.python.org/cpython/rev/d0c8b2c1544e changeset: 100857:d0c8b2c1544e branch: 3.5 parent: 100855:2577a3684f90 user: Serhiy Storchaka date: Wed Apr 06 09:45:48 2016 +0300 summary: Issue #22570: Renamed Py_SETREF to Py_XSETREF. files: Include/object.h | 4 +- Modules/_bz2module.c | 2 +- Modules/_csv.c | 4 +- Modules/_ctypes/_ctypes.c | 28 +++++++------- Modules/_curses_panel.c | 2 +- Modules/_elementtree.c | 22 ++++++------ Modules/_functoolsmodule.c | 8 ++-- Modules/_io/bufferedio.c | 8 ++-- Modules/_io/bytesio.c | 2 +- Modules/_io/textio.c | 8 ++-- Modules/_lzmamodule.c | 2 +- Modules/_pickle.c | 4 +- Modules/_sqlite/connection.c | 8 ++-- Modules/_sqlite/cursor.c | 10 ++-- Modules/_sre.c | 2 +- Modules/_ssl.c | 4 +- Modules/_struct.c | 2 +- Modules/cjkcodecs/multibytecodec.c | 2 +- Modules/faulthandler.c | 6 +- Modules/itertoolsmodule.c | 28 +++++++------- Modules/signalmodule.c | 2 +- Modules/zipimport.c | 2 +- Modules/zlibmodule.c | 16 ++++---- Objects/bytesobject.c | 2 +- Objects/descrobject.c | 2 +- Objects/exceptions.c | 32 +++++++++--------- Objects/frameobject.c | 2 +- Objects/funcobject.c | 10 ++-- Objects/moduleobject.c | 2 +- Objects/rangeobject.c | 6 +- Objects/typeobject.c | 8 ++-- Objects/unicodeobject.c | 8 ++-- Parser/tokenizer.c | 2 +- Python/_warnings.c | 2 +- Python/ceval.c | 6 +- Python/compile.c | 2 +- Python/errors.c | 4 +- 37 files changed, 132 insertions(+), 132 deletions(-) diff --git a/Include/object.h b/Include/object.h --- a/Include/object.h +++ b/Include/object.h @@ -856,14 +856,14 @@ * * The safe way is: * - * Py_SETREF(op, op2); + * Py_XSETREF(op, op2); * * That arranges to set `op` to `op2` _before_ decref'ing, so that any code * triggered as a side-effect of `op` getting torn down no longer believes * `op` points to a valid object. */ -#define Py_SETREF(op, op2) \ +#define Py_XSETREF(op, op2) \ do { \ PyObject *_py_tmp = (PyObject *)(op); \ (op) = (op2); \ diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c --- a/Modules/_bz2module.c +++ b/Modules/_bz2module.c @@ -540,7 +540,7 @@ if (d->eof) { d->needs_input = 0; if (d->bzs_avail_in_real > 0) { - Py_SETREF(d->unused_data, + Py_XSETREF(d->unused_data, PyBytes_FromStringAndSize(bzs->next_in, d->bzs_avail_in_real)); if (d->unused_data == NULL) goto error; diff --git a/Modules/_csv.c b/Modules/_csv.c --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -277,7 +277,7 @@ if (PyUnicode_READY(src) == -1) return -1; Py_INCREF(src); - Py_SETREF(*target, src); + Py_XSETREF(*target, src); } } return 0; @@ -783,7 +783,7 @@ static int parse_reset(ReaderObj *self) { - Py_SETREF(self->fields, PyList_New(0)); + Py_XSETREF(self->fields, PyList_New(0)); if (self->fields == NULL) return -1; self->field_len = 0; diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -391,7 +391,7 @@ Py_DECREF((PyObject *)dict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)dict); + Py_XSETREF(result->tp_dict, (PyObject *)dict); dict->format = _ctypes_alloc_format_string(NULL, "B"); if (dict->format == NULL) { Py_DECREF(result); @@ -870,7 +870,7 @@ return -1; } Py_INCREF(proto); - Py_SETREF(stgdict->proto, proto); + Py_XSETREF(stgdict->proto, proto); return 0; } @@ -960,7 +960,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); return (PyObject *)result; } @@ -1403,7 +1403,7 @@ /* replace the class dict by our updated spam dict */ if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) goto error; - Py_SETREF(result->tp_dict, (PyObject *)stgdict); /* steal the reference */ + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); /* steal the reference */ stgdict = NULL; /* Special case for character arrays. @@ -1816,7 +1816,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); return (PyObject *)result; } @@ -1944,7 +1944,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); /* Install from_param class methods in ctypes base classes. Overrides the PyCSimpleType_from_param generic method. @@ -2307,7 +2307,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); if (-1 == make_funcptrtype_dict(stgdict)) { Py_DECREF(result); @@ -2451,7 +2451,7 @@ return -1; } if (ob->b_objects == NULL || !PyDict_CheckExact(ob->b_objects)) { - Py_SETREF(ob->b_objects, keep); /* refcount consumed */ + Py_XSETREF(ob->b_objects, keep); /* refcount consumed */ return 0; } key = unique_key(target, index); @@ -2955,7 +2955,7 @@ return -1; } Py_XINCREF(ob); - Py_SETREF(self->errcheck, ob); + Py_XSETREF(self->errcheck, ob); return 0; } @@ -2984,8 +2984,8 @@ return -1; } Py_INCREF(ob); - Py_SETREF(self->restype, ob); - Py_SETREF(self->checker, PyObject_GetAttrString(ob, "_check_retval_")); + Py_XSETREF(self->restype, ob); + Py_XSETREF(self->checker, PyObject_GetAttrString(ob, "_check_retval_")); if (self->checker == NULL) PyErr_Clear(); return 0; @@ -3022,9 +3022,9 @@ converters = converters_from_argtypes(ob); if (!converters) return -1; - Py_SETREF(self->converters, converters); + Py_XSETREF(self->converters, converters); Py_INCREF(ob); - Py_SETREF(self->argtypes, ob); + Py_XSETREF(self->argtypes, ob); } return 0; } @@ -5152,7 +5152,7 @@ bself = (PyBaseExceptionObject *)self; Py_INCREF(args); - Py_SETREF(bself->args, args); + Py_XSETREF(bself->args, args); return 0; } diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -313,7 +313,7 @@ return NULL; } Py_INCREF(temp); - Py_SETREF(po->wo, temp); + Py_XSETREF(po->wo, temp); Py_INCREF(Py_None); return Py_None; } diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -936,7 +936,7 @@ } Py_INCREF(tag); - Py_SETREF(self->tag, tag); + Py_XSETREF(self->tag, tag); _clear_joined_ptr(&self->text); self->text = text ? JOIN_SET(text, PyList_CheckExact(text)) : Py_None; @@ -980,7 +980,7 @@ /* Stash attrib. */ if (attrib) { Py_INCREF(attrib); - Py_SETREF(self->extra->attrib, attrib); + Py_XSETREF(self->extra->attrib, attrib); } Py_RETURN_NONE; @@ -1943,7 +1943,7 @@ if (strcmp(name, "tag") == 0) { Py_INCREF(value); - Py_SETREF(self->tag, value); + Py_XSETREF(self->tag, value); } else if (strcmp(name, "text") == 0) { Py_DECREF(JOIN_OBJ(self->text)); self->text = value; @@ -1958,7 +1958,7 @@ return -1; } Py_INCREF(value); - Py_SETREF(self->extra->attrib, value); + Py_XSETREF(self->extra->attrib, value); } else { PyErr_SetString(PyExc_AttributeError, "Can't set arbitrary attributes on Element"); @@ -2551,9 +2551,9 @@ self->index++; Py_INCREF(node); - Py_SETREF(self->this, node); + Py_XSETREF(self->this, node); Py_INCREF(node); - Py_SETREF(self->last, node); + Py_XSETREF(self->last, node); if (treebuilder_append_event(self, self->start_event_obj, node) < 0) goto error; @@ -3604,7 +3604,7 @@ target = (TreeBuilderObject*) self->target; Py_INCREF(events_queue); - Py_SETREF(target->events, events_queue); + Py_XSETREF(target->events, events_queue); /* clear out existing events */ Py_CLEAR(target->start_event_obj); @@ -3639,18 +3639,18 @@ Py_INCREF(event_name_obj); if (strcmp(event_name, "start") == 0) { - Py_SETREF(target->start_event_obj, event_name_obj); + Py_XSETREF(target->start_event_obj, event_name_obj); } else if (strcmp(event_name, "end") == 0) { - Py_SETREF(target->end_event_obj, event_name_obj); + Py_XSETREF(target->end_event_obj, event_name_obj); } else if (strcmp(event_name, "start-ns") == 0) { - Py_SETREF(target->start_ns_event_obj, event_name_obj); + Py_XSETREF(target->start_ns_event_obj, event_name_obj); EXPAT(SetNamespaceDeclHandler)( self->parser, (XML_StartNamespaceDeclHandler) expat_start_ns_handler, (XML_EndNamespaceDeclHandler) expat_end_ns_handler ); } else if (strcmp(event_name, "end-ns") == 0) { - Py_SETREF(target->end_ns_event_obj, event_name_obj); + Py_XSETREF(target->end_ns_event_obj, event_name_obj); EXPAT(SetNamespaceDeclHandler)( self->parser, (XML_StartNamespaceDeclHandler) expat_start_ns_handler, diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -294,10 +294,10 @@ else Py_INCREF(dict); - Py_SETREF(pto->fn, fn); - Py_SETREF(pto->args, fnargs); - Py_SETREF(pto->kw, kw); - Py_SETREF(pto->dict, dict); + Py_XSETREF(pto->fn, fn); + Py_XSETREF(pto->args, fnargs); + Py_XSETREF(pto->kw, kw); + Py_XSETREF(pto->dict, dict); Py_RETURN_NONE; } diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -1196,7 +1196,7 @@ Py_CLEAR(res); goto end; } - Py_SETREF(res, _PyBytes_Join(_PyIO_empty_bytes, chunks)); + Py_XSETREF(res, _PyBytes_Join(_PyIO_empty_bytes, chunks)); end: LEAVE_BUFFERED(self) @@ -1452,7 +1452,7 @@ return -1; Py_INCREF(raw); - Py_SETREF(self->raw, raw); + Py_XSETREF(self->raw, raw); self->buffer_size = buffer_size; self->readable = 1; self->writable = 0; @@ -1804,7 +1804,7 @@ return -1; Py_INCREF(raw); - Py_SETREF(self->raw, raw); + Py_XSETREF(self->raw, raw); self->readable = 0; self->writable = 1; @@ -2307,7 +2307,7 @@ return -1; Py_INCREF(raw); - Py_SETREF(self->raw, raw); + Py_XSETREF(self->raw, raw); self->buffer_size = buffer_size; self->readable = 1; self->writable = 1; diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -969,7 +969,7 @@ if (initvalue && initvalue != Py_None) { if (PyBytes_CheckExact(initvalue)) { Py_INCREF(initvalue); - Py_SETREF(self->buf, initvalue); + Py_XSETREF(self->buf, initvalue); self->string_size = PyBytes_GET_SIZE(initvalue); } else { diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -995,7 +995,7 @@ "Oi", self->decoder, (int)self->readtranslate); if (incrementalDecoder == NULL) goto error; - Py_SETREF(self->decoder, incrementalDecoder); + Py_XSETREF(self->decoder, incrementalDecoder); } } @@ -1373,7 +1373,7 @@ static void textiowrapper_set_decoded_chars(textio *self, PyObject *chars) { - Py_SETREF(self->decoded_chars, chars); + Py_XSETREF(self->decoded_chars, chars); self->decoded_chars_used = 0; } @@ -1521,7 +1521,7 @@ dec_buffer = NULL; /* Reference lost to PyBytes_Concat */ goto fail; } - Py_SETREF(self->snapshot, Py_BuildValue("NN", dec_flags, next_input)); + Py_XSETREF(self->snapshot, Py_BuildValue("NN", dec_flags, next_input)); } Py_DECREF(input_chunk); @@ -1627,7 +1627,7 @@ if (chunks != NULL) { if (result != NULL && PyList_Append(chunks, result) < 0) goto fail; - Py_SETREF(result, PyUnicode_Join(_PyIO_empty_str, chunks)); + Py_XSETREF(result, PyUnicode_Join(_PyIO_empty_str, chunks)); if (result == NULL) goto fail; Py_CLEAR(chunks); diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c --- a/Modules/_lzmamodule.c +++ b/Modules/_lzmamodule.c @@ -1011,7 +1011,7 @@ if (d->eof) { d->needs_input = 0; if (lzs->avail_in > 0) { - Py_SETREF(d->unused_data, + Py_XSETREF(d->unused_data, PyBytes_FromStringAndSize((char *)lzs->next_in, lzs->avail_in)); if (d->unused_data == NULL) goto error; diff --git a/Modules/_pickle.c b/Modules/_pickle.c --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -846,7 +846,7 @@ static int _Pickler_ClearBuffer(PicklerObject *self) { - Py_SETREF(self->output_buffer, + Py_XSETREF(self->output_buffer, PyBytes_FromStringAndSize(NULL, self->max_output_len)); if (self->output_buffer == NULL) return -1; @@ -3089,7 +3089,7 @@ return -1; } Py_INCREF(item); - Py_SETREF(*module_name, item); + Py_XSETREF(*module_name, item); } else if (PyErr_Occurred()) { return -1; diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -204,7 +204,7 @@ node = node->next; } - Py_SETREF(self->statement_cache, + Py_XSETREF(self->statement_cache, (pysqlite_Cache *)PyObject_CallFunction((PyObject *)&pysqlite_CacheType, "O", self)); Py_DECREF(self); self->statement_cache->decref_factory = 0; @@ -319,7 +319,7 @@ if (cursor && self->row_factory != Py_None) { Py_INCREF(self->row_factory); - Py_SETREF(((pysqlite_Cursor *)cursor)->row_factory, self->row_factory); + Py_XSETREF(((pysqlite_Cursor *)cursor)->row_factory, self->row_factory); } return cursor; @@ -794,7 +794,7 @@ } } - Py_SETREF(self->statements, new_list); + Py_XSETREF(self->statements, new_list); } static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) @@ -825,7 +825,7 @@ } } - Py_SETREF(self->cursors, new_list); + Py_XSETREF(self->cursors, new_list); } PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -170,7 +170,7 @@ return 0; } - Py_SETREF(self->row_cast_map, PyList_New(0)); + Py_XSETREF(self->row_cast_map, PyList_New(0)); for (i = 0; i < sqlite3_column_count(self->statement->st); i++) { converter = NULL; @@ -510,7 +510,7 @@ /* reset description and rowcount */ Py_INCREF(Py_None); - Py_SETREF(self->description, Py_None); + Py_XSETREF(self->description, Py_None); self->rowcount = -1L; func_args = PyTuple_New(1); @@ -526,7 +526,7 @@ (void)pysqlite_statement_reset(self->statement); } - Py_SETREF(self->statement, + Py_XSETREF(self->statement, (pysqlite_Statement *)pysqlite_cache_get(self->connection->statement_cache, func_args)); Py_DECREF(func_args); @@ -535,7 +535,7 @@ } if (self->statement->in_use) { - Py_SETREF(self->statement, + Py_XSETREF(self->statement, PyObject_New(pysqlite_Statement, &pysqlite_StatementType)); if (!self->statement) { goto error; @@ -652,7 +652,7 @@ numcols = sqlite3_column_count(self->statement->st); Py_END_ALLOW_THREADS - Py_SETREF(self->description, PyTuple_New(numcols)); + Py_XSETREF(self->description, PyTuple_New(numcols)); if (!self->description) { goto error; } diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -756,7 +756,7 @@ if (!copy) return 0; - Py_SETREF(*object, copy); + Py_XSETREF(*object, copy); return 1; /* success */ } diff --git a/Modules/_ssl.c b/Modules/_ssl.c --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -1589,7 +1589,7 @@ return -1; #else Py_INCREF(value); - Py_SETREF(self->ctx, (PySSLContext *)value); + Py_XSETREF(self->ctx, (PySSLContext *)value); SSL_set_SSL_CTX(self->ssl, self->ctx->ctx); #endif } else { @@ -1646,7 +1646,7 @@ static int PySSL_set_owner(PySSLSocket *self, PyObject *value, void *c) { - Py_SETREF(self->owner, PyWeakref_NewRef(value, NULL)); + Py_XSETREF(self->owner, PyWeakref_NewRef(value, NULL)); if (self->owner == NULL) return -1; return 0; diff --git a/Modules/_struct.c b/Modules/_struct.c --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1437,7 +1437,7 @@ return -1; } - Py_SETREF(soself->s_format, o_format); + Py_XSETREF(soself->s_format, o_format); ret = prepare_s(soself); return ret; diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -793,7 +793,7 @@ ctx->errors, final ? MBENC_FLUSH | MBENC_RESET : 0); if (r == NULL) { /* recover the original pending buffer */ - Py_SETREF(ctx->pending, origpending); + Py_XSETREF(ctx->pending, origpending); origpending = NULL; goto errorexit; } diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -381,7 +381,7 @@ return NULL; Py_XINCREF(file); - Py_SETREF(fatal_error.file, file); + Py_XSETREF(fatal_error.file, file); fatal_error.fd = fd; fatal_error.all_threads = all_threads; fatal_error.interp = tstate->interp; @@ -599,7 +599,7 @@ cancel_dump_traceback_later(); Py_XINCREF(file); - Py_SETREF(thread.file, file); + Py_XSETREF(thread.file, file); thread.fd = fd; thread.timeout_us = timeout_us; thread.repeat = repeat; @@ -777,7 +777,7 @@ } Py_XINCREF(file); - Py_SETREF(user->file, file); + Py_XSETREF(user->file, file); user->fd = fd; user->all_threads = all_threads; user->chain = chain; diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -158,11 +158,11 @@ if (!PyArg_ParseTuple(state, "OOO", &currkey, &currvalue, &tgtkey)) return NULL; Py_INCREF(currkey); - Py_SETREF(lz->currkey, currkey); + Py_XSETREF(lz->currkey, currkey); Py_INCREF(currvalue); - Py_SETREF(lz->currvalue, currvalue); + Py_XSETREF(lz->currvalue, currvalue); Py_INCREF(tgtkey); - Py_SETREF(lz->tgtkey, tgtkey); + Py_XSETREF(lz->tgtkey, tgtkey); Py_RETURN_NONE; } @@ -631,7 +631,7 @@ link = teedataobject_jumplink(to->dataobj); if (link == NULL) return NULL; - Py_SETREF(to->dataobj, (teedataobject *)link); + Py_XSETREF(to->dataobj, (teedataobject *)link); to->index = 0; } value = teedataobject_getitem(to->dataobj, to->index); @@ -743,7 +743,7 @@ return NULL; } Py_INCREF(tdo); - Py_SETREF(to->dataobj, tdo); + Py_XSETREF(to->dataobj, tdo); to->index = index; Py_RETURN_NONE; } @@ -969,7 +969,7 @@ if (!PyArg_ParseTuple(state, "Oi", &saved, &firstpass)) return NULL; Py_XINCREF(saved); - Py_SETREF(lz->saved, saved); + Py_XSETREF(lz->saved, saved); lz->firstpass = firstpass != 0; Py_RETURN_NONE; } @@ -1895,9 +1895,9 @@ return NULL; Py_INCREF(source); - Py_SETREF(lz->source, source); + Py_XSETREF(lz->source, source); Py_XINCREF(active); - Py_SETREF(lz->active, active); + Py_XSETREF(lz->active, active); Py_RETURN_NONE; } @@ -2253,7 +2253,7 @@ Py_INCREF(element); PyTuple_SET_ITEM(result, i, element); } - Py_SETREF(lz->result, result); + Py_XSETREF(lz->result, result); Py_RETURN_NONE; } @@ -2575,7 +2575,7 @@ PyTuple_SET_ITEM(result, i, element); } - Py_SETREF(lz->result, result); + Py_XSETREF(lz->result, result); Py_RETURN_NONE; } @@ -2905,7 +2905,7 @@ Py_INCREF(element); PyTuple_SET_ITEM(result, i, element); } - Py_SETREF(lz->result, result); + Py_XSETREF(lz->result, result); Py_RETURN_NONE; } @@ -3298,7 +3298,7 @@ Py_INCREF(element); PyTuple_SET_ITEM(result, i, element); } - Py_SETREF(po->result, result); + Py_XSETREF(po->result, result); Py_RETURN_NONE; } @@ -3486,7 +3486,7 @@ accumulate_setstate(accumulateobject *lz, PyObject *state) { Py_INCREF(state); - Py_SETREF(lz->total, state); + Py_XSETREF(lz->total, state); Py_RETURN_NONE; } @@ -4468,7 +4468,7 @@ zip_longest_setstate(ziplongestobject *lz, PyObject *state) { Py_INCREF(state); - Py_SETREF(lz->fillvalue, state); + Py_XSETREF(lz->fillvalue, state); Py_RETURN_NONE; } diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -1266,7 +1266,7 @@ if (Handlers[SIGINT].func == DefaultHandler) { /* Install default int handler */ Py_INCREF(IntHandler); - Py_SETREF(Handlers[SIGINT].func, IntHandler); + Py_XSETREF(Handlers[SIGINT].func, IntHandler); old_siginthandler = PyOS_setsig(SIGINT, signal_handler); } diff --git a/Modules/zipimport.c b/Modules/zipimport.c --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -155,7 +155,7 @@ tmp = PyUnicode_FromFormat("%U%c", self->prefix, SEP); if (tmp == NULL) goto error; - Py_SETREF(self->prefix, tmp); + Py_XSETREF(self->prefix, tmp); } } else diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -668,7 +668,7 @@ PyBytes_AS_STRING(self->unused_data), old_size); Py_MEMCPY(PyBytes_AS_STRING(new_data) + old_size, self->zst.next_in, self->zst.avail_in); - Py_SETREF(self->unused_data, new_data); + Py_XSETREF(self->unused_data, new_data); self->zst.avail_in = 0; } } @@ -680,7 +680,7 @@ (char *)self->zst.next_in, self->zst.avail_in); if (new_data == NULL) return -1; - Py_SETREF(self->unconsumed_tail, new_data); + Py_XSETREF(self->unconsumed_tail, new_data); } return 0; } @@ -962,11 +962,11 @@ goto error; } Py_INCREF(self->unused_data); - Py_SETREF(retval->unused_data, self->unused_data); + Py_XSETREF(retval->unused_data, self->unused_data); Py_INCREF(self->unconsumed_tail); - Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail); + Py_XSETREF(retval->unconsumed_tail, self->unconsumed_tail); Py_XINCREF(self->zdict); - Py_SETREF(retval->zdict, self->zdict); + Py_XSETREF(retval->zdict, self->zdict); retval->eof = self->eof; /* Mark it as being initialized */ @@ -1018,11 +1018,11 @@ } Py_INCREF(self->unused_data); - Py_SETREF(retval->unused_data, self->unused_data); + Py_XSETREF(retval->unused_data, self->unused_data); Py_INCREF(self->unconsumed_tail); - Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail); + Py_XSETREF(retval->unconsumed_tail, self->unconsumed_tail); Py_XINCREF(self->zdict); - Py_SETREF(retval->zdict, self->zdict); + Py_XSETREF(retval->zdict, self->zdict); retval->eof = self->eof; /* Mark it as being initialized */ diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3520,7 +3520,7 @@ /* Multiple references, need to create new object */ PyObject *v; v = bytes_concat(*pv, w); - Py_SETREF(*pv, v); + Py_XSETREF(*pv, v); } } diff --git a/Objects/descrobject.c b/Objects/descrobject.c --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1509,7 +1509,7 @@ PyObject *get_doc = _PyObject_GetAttrId(get, &PyId___doc__); if (get_doc) { if (Py_TYPE(self) == &PyProperty_Type) { - Py_SETREF(prop->prop_doc, get_doc); + Py_XSETREF(prop->prop_doc, get_doc); } else { /* If this is a property subclass, put __doc__ diff --git a/Objects/exceptions.c b/Objects/exceptions.c --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -206,7 +206,7 @@ seq = PySequence_Tuple(val); if (!seq) return -1; - Py_SETREF(self->args, seq); + Py_XSETREF(self->args, seq); return 0; } @@ -235,7 +235,7 @@ } Py_XINCREF(tb); - Py_SETREF(self->traceback, tb); + Py_XSETREF(self->traceback, tb); return 0; } @@ -563,11 +563,11 @@ return 0; if (size == 1) { Py_INCREF(PyTuple_GET_ITEM(args, 0)); - Py_SETREF(self->code, PyTuple_GET_ITEM(args, 0)); + Py_XSETREF(self->code, PyTuple_GET_ITEM(args, 0)); } else { /* size > 1 */ Py_INCREF(args); - Py_SETREF(self->code, args); + Py_XSETREF(self->code, args); } return 0; } @@ -628,7 +628,7 @@ kwd = PyDict_GetItemString(kwds, #kwd); \ if (kwd) { \ Py_INCREF(kwd); \ - Py_SETREF(self->kwd, kwd); \ + Py_XSETREF(self->kwd, kwd); \ if (PyDict_DelItemString(kwds, #kwd)) \ return -1; \ } \ @@ -647,7 +647,7 @@ return -1; Py_INCREF(msg); - Py_SETREF(self->msg, msg); + Py_XSETREF(self->msg, msg); return 0; } @@ -857,7 +857,7 @@ #endif /* Steals the reference to args */ - Py_SETREF(self->args, args); + Py_XSETREF(self->args, args); *p_args = args = NULL; return 0; @@ -1277,7 +1277,7 @@ if (lenargs >= 1) { Py_INCREF(PyTuple_GET_ITEM(args, 0)); - Py_SETREF(self->msg, PyTuple_GET_ITEM(args, 0)); + Py_XSETREF(self->msg, PyTuple_GET_ITEM(args, 0)); } if (lenargs == 2) { info = PyTuple_GET_ITEM(args, 1); @@ -1293,16 +1293,16 @@ } Py_INCREF(PyTuple_GET_ITEM(info, 0)); - Py_SETREF(self->filename, PyTuple_GET_ITEM(info, 0)); + Py_XSETREF(self->filename, PyTuple_GET_ITEM(info, 0)); Py_INCREF(PyTuple_GET_ITEM(info, 1)); - Py_SETREF(self->lineno, PyTuple_GET_ITEM(info, 1)); + Py_XSETREF(self->lineno, PyTuple_GET_ITEM(info, 1)); Py_INCREF(PyTuple_GET_ITEM(info, 2)); - Py_SETREF(self->offset, PyTuple_GET_ITEM(info, 2)); + Py_XSETREF(self->offset, PyTuple_GET_ITEM(info, 2)); Py_INCREF(PyTuple_GET_ITEM(info, 3)); - Py_SETREF(self->text, PyTuple_GET_ITEM(info, 3)); + Py_XSETREF(self->text, PyTuple_GET_ITEM(info, 3)); Py_DECREF(info); @@ -1547,7 +1547,7 @@ PyObject *obj = PyUnicode_FromString(value); if (!obj) return -1; - Py_SETREF(*attr, obj); + Py_XSETREF(*attr, obj); return 0; } @@ -1953,7 +1953,7 @@ Py_buffer view; if (PyObject_GetBuffer(ude->object, &view, PyBUF_SIMPLE) != 0) goto error; - Py_SETREF(ude->object, PyBytes_FromStringAndSize(view.buf, view.len)); + Py_XSETREF(ude->object, PyBytes_FromStringAndSize(view.buf, view.len)); PyBuffer_Release(&view); if (!ude->object) goto error; @@ -2862,7 +2862,7 @@ } if (PyUnicode_Tailmatch(self->text, print_prefix, start, text_len, -1)) { - Py_SETREF(self->msg, + Py_XSETREF(self->msg, PyUnicode_FromString("Missing parentheses in call to 'print'")); return 1; } @@ -2876,7 +2876,7 @@ } if (PyUnicode_Tailmatch(self->text, exec_prefix, start, text_len, -1)) { - Py_SETREF(self->msg, + Py_XSETREF(self->msg, PyUnicode_FromString("Missing parentheses in call to 'exec'")); return 1; } diff --git a/Objects/frameobject.c b/Objects/frameobject.c --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -857,7 +857,7 @@ } } else if (values[j] != value) { Py_XINCREF(value); - Py_SETREF(values[j], value); + Py_XSETREF(values[j], value); } Py_XDECREF(value); } diff --git a/Objects/funcobject.c b/Objects/funcobject.c --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -127,7 +127,7 @@ PyErr_SetString(PyExc_SystemError, "non-tuple default args"); return -1; } - Py_SETREF(((PyFunctionObject *)op)->func_defaults, defaults); + Py_XSETREF(((PyFunctionObject *)op)->func_defaults, defaults); return 0; } @@ -158,7 +158,7 @@ "non-dict keyword only default args"); return -1; } - Py_SETREF(((PyFunctionObject *)op)->func_kwdefaults, defaults); + Py_XSETREF(((PyFunctionObject *)op)->func_kwdefaults, defaults); return 0; } @@ -190,7 +190,7 @@ closure->ob_type->tp_name); return -1; } - Py_SETREF(((PyFunctionObject *)op)->func_closure, closure); + Py_XSETREF(((PyFunctionObject *)op)->func_closure, closure); return 0; } @@ -221,7 +221,7 @@ "non-dict annotations"); return -1; } - Py_SETREF(((PyFunctionObject *)op)->func_annotations, annotations); + Py_XSETREF(((PyFunctionObject *)op)->func_annotations, annotations); return 0; } @@ -527,7 +527,7 @@ if (name != Py_None) { Py_INCREF(name); - Py_SETREF(newfunc->func_name, name); + Py_XSETREF(newfunc->func_name, name); } if (defaults != Py_None) { Py_INCREF(defaults); diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -69,7 +69,7 @@ return -1; if (PyUnicode_CheckExact(name)) { Py_INCREF(name); - Py_SETREF(mod->md_name, name); + Py_XSETREF(mod->md_name, name); } return 0; diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -1001,7 +1001,7 @@ return NULL; cmp = PyObject_RichCompareBool(state, zero, Py_LT); if (cmp > 0) { - Py_SETREF(r->index, zero); + Py_XSETREF(r->index, zero); Py_RETURN_NONE; } Py_DECREF(zero); @@ -1015,7 +1015,7 @@ state = r->len; Py_INCREF(state); - Py_SETREF(r->index, state); + Py_XSETREF(r->index, state); Py_RETURN_NONE; } @@ -1064,7 +1064,7 @@ result = PyNumber_Add(r->start, product); Py_DECREF(product); if (result) { - Py_SETREF(r->index, new_index); + Py_XSETREF(r->index, new_index); } else { Py_DECREF(new_index); diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -316,7 +316,7 @@ for (i = 0; i < (1 << MCACHE_SIZE_EXP); i++) { method_cache[i].value = NULL; Py_INCREF(Py_None); - Py_SETREF(method_cache[i].name, Py_None); + Py_XSETREF(method_cache[i].name, Py_None); } /* mark all version tags as invalid */ PyType_Modified(&PyBaseObject_Type); @@ -424,7 +424,7 @@ type->tp_name = tp_name; Py_INCREF(value); - Py_SETREF(((PyHeapTypeObject*)type)->ht_name, value); + Py_XSETREF(((PyHeapTypeObject*)type)->ht_name, value); return 0; } @@ -445,7 +445,7 @@ et = (PyHeapTypeObject*)type; Py_INCREF(value); - Py_SETREF(et->ht_qualname, value); + Py_XSETREF(et->ht_qualname, value); return 0; } @@ -2897,7 +2897,7 @@ else method_cache_misses++; #endif - Py_SETREF(method_cache[h].name, name); + Py_XSETREF(method_cache[h].name, name); } return res; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1667,7 +1667,7 @@ _Py_INCREF_UNICODE_EMPTY(); if (!unicode_empty) return -1; - Py_SETREF(*p_unicode, unicode_empty); + Py_XSETREF(*p_unicode, unicode_empty); return 0; } @@ -1675,7 +1675,7 @@ PyObject *copy = resize_copy(unicode, length); if (copy == NULL) return -1; - Py_SETREF(*p_unicode, copy); + Py_XSETREF(*p_unicode, copy); return 0; } @@ -13326,7 +13326,7 @@ return -1; _PyUnicode_FastCopyCharacters(newbuffer, 0, writer->buffer, 0, writer->pos); - Py_SETREF(writer->buffer, newbuffer); + Py_XSETREF(writer->buffer, newbuffer); } _PyUnicodeWriter_Update(writer); return 0; @@ -15012,7 +15012,7 @@ if (t) { Py_INCREF(t); - Py_SETREF(*p, t); + Py_XSETREF(*p, t); return; } diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -526,7 +526,7 @@ goto cleanup; readline = _PyObject_GetAttrId(stream, &PyId_readline); - Py_SETREF(tok->decoding_readline, readline); + Py_XSETREF(tok->decoding_readline, readline); if (pos > 0) { if (PyObject_CallObject(readline, NULL) == NULL) { readline = NULL; diff --git a/Python/_warnings.c b/Python/_warnings.c --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -680,7 +680,7 @@ goto handle_error; } else if (!is_true) { - Py_SETREF(*filename, PyUnicode_FromString("__main__")); + Py_XSETREF(*filename, PyUnicode_FromString("__main__")); if (*filename == NULL) goto handle_error; } diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3229,7 +3229,7 @@ Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); - Py_SETREF(*pfunc, self); + Py_XSETREF(*pfunc, self); na++; /* n++; */ } else @@ -4426,7 +4426,7 @@ PyThreadState *tstate = PyThreadState_GET(); Py_XINCREF(wrapper); - Py_SETREF(tstate->coroutine_wrapper, wrapper); + Py_XSETREF(tstate->coroutine_wrapper, wrapper); } PyObject * @@ -4682,7 +4682,7 @@ Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); - Py_SETREF(*pfunc, self); + Py_XSETREF(*pfunc, self); na++; n++; } else diff --git a/Python/compile.c b/Python/compile.c --- a/Python/compile.c +++ b/Python/compile.c @@ -1756,7 +1756,7 @@ { /* use the class name for name mangling */ Py_INCREF(s->v.ClassDef.name); - Py_SETREF(c->u->u_private, s->v.ClassDef.name); + Py_XSETREF(c->u->u_private, s->v.ClassDef.name); /* load (global) __name__ ... */ str = PyUnicode_InternFromString("__name__"); if (!str || !compiler_nameop(c, str, Load)) { diff --git a/Python/errors.c b/Python/errors.c --- a/Python/errors.c +++ b/Python/errors.c @@ -311,9 +311,9 @@ --tstate->recursion_depth; /* throw away the old exception and use the recursion error instead */ Py_INCREF(PyExc_RecursionError); - Py_SETREF(*exc, PyExc_RecursionError); + Py_XSETREF(*exc, PyExc_RecursionError); Py_INCREF(PyExc_RecursionErrorInst); - Py_SETREF(*val, PyExc_RecursionErrorInst); + Py_XSETREF(*val, PyExc_RecursionErrorInst); /* just keeping the old traceback */ return; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 6 02:51:59 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 06 Apr 2016 06:51:59 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzIyNTcw?= =?utf-8?q?=3A_Renamed_Py=5FSETREF_to_Py=5FXSETREF=2E?= Message-ID: <20160406065159.32761.44110.ED802A25@psf.io> https://hg.python.org/cpython/rev/7197809a7428 changeset: 100859:7197809a7428 branch: 2.7 parent: 100850:6137c46cb8df user: Serhiy Storchaka date: Wed Apr 06 09:51:18 2016 +0300 summary: Issue #22570: Renamed Py_SETREF to Py_XSETREF. files: Include/object.h | 4 +- Modules/_bsddb.c | 10 +++--- Modules/_csv.c | 4 +- Modules/_ctypes/_ctypes.c | 24 ++++++++-------- Modules/_curses_panel.c | 2 +- Modules/_elementtree.c | 18 ++++++------ Modules/_functoolsmodule.c | 8 ++-- Modules/_io/bufferedio.c | 8 ++-- Modules/_io/textio.c | 10 +++--- Modules/_json.c | 2 +- Modules/_sqlite/connection.c | 8 ++-- Modules/_sqlite/cursor.c | 10 +++--- Modules/_sre.c | 2 +- Modules/_ssl.c | 2 +- Modules/_struct.c | 4 +- Modules/bz2module.c | 2 +- Modules/cPickle.c | 16 +++++----- Modules/cdmodule.c | 4 +- Modules/itertoolsmodule.c | 2 +- Modules/signalmodule.c | 2 +- Modules/zlibmodule.c | 12 ++++---- Objects/descrobject.c | 2 +- Objects/exceptions.c | 34 ++++++++++++------------ Objects/fileobject.c | 4 +- Objects/frameobject.c | 2 +- Objects/funcobject.c | 6 ++-- Objects/stringobject.c | 4 +- Objects/typeobject.c | 2 +- Objects/unicodeobject.c | 2 +- Python/_warnings.c | 2 +- Python/ceval.c | 2 +- Python/compile.c | 2 +- Python/errors.c | 4 +- 33 files changed, 110 insertions(+), 110 deletions(-) diff --git a/Include/object.h b/Include/object.h --- a/Include/object.h +++ b/Include/object.h @@ -833,14 +833,14 @@ * * The safe way is: * - * Py_SETREF(op, op2); + * Py_XSETREF(op, op2); * * That arranges to set `op` to `op2` _before_ decref'ing, so that any code * triggered as a side-effect of `op` getting torn down no longer believes * `op` points to a valid object. */ -#define Py_SETREF(op, op2) \ +#define Py_XSETREF(op, op2) \ do { \ PyObject *_py_tmp = (PyObject *)(op); \ (op) = (op2); \ diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c --- a/Modules/_bsddb.c +++ b/Modules/_bsddb.c @@ -1608,7 +1608,7 @@ /* Save a reference to the callback in the secondary DB. */ Py_XINCREF(callback); - Py_SETREF(secondaryDB->associateCallback, callback); + Py_XSETREF(secondaryDB->associateCallback, callback); secondaryDB->primaryDBType = _DB_get_type(self); /* PyEval_InitThreads is called here due to a quirk in python 1.5 @@ -2498,7 +2498,7 @@ { /* We can set the private field even if db is closed */ Py_INCREF(private_obj); - Py_SETREF(self->private_obj, private_obj); + Py_XSETREF(self->private_obj, private_obj); RETURN_NONE(); } @@ -6997,7 +6997,7 @@ { /* We can set the private field even if dbenv is closed */ Py_INCREF(private_obj); - Py_SETREF(self->private_obj, private_obj); + Py_XSETREF(self->private_obj, private_obj); RETURN_NONE(); } @@ -7251,7 +7251,7 @@ } Py_INCREF(notifyFunc); - Py_SETREF(self->event_notifyCallback, notifyFunc); + Py_XSETREF(self->event_notifyCallback, notifyFunc); /* This is to workaround a problem with un-initialized threads (see comment in DB_associate) */ @@ -7410,7 +7410,7 @@ RETURN_IF_ERR(); Py_INCREF(rep_transport); - Py_SETREF(self->rep_transport, rep_transport); + Py_XSETREF(self->rep_transport, rep_transport); RETURN_NONE(); } diff --git a/Modules/_csv.c b/Modules/_csv.c --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -277,7 +277,7 @@ } else { Py_INCREF(src); - Py_SETREF(*target, src); + Py_XSETREF(*target, src); } } return 0; @@ -769,7 +769,7 @@ static int parse_reset(ReaderObj *self) { - Py_SETREF(self->fields, PyList_New(0)); + Py_XSETREF(self->fields, PyList_New(0)); if (self->fields == NULL) return -1; self->field_len = 0; diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -424,7 +424,7 @@ Py_DECREF((PyObject *)dict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)dict); + Py_XSETREF(result->tp_dict, (PyObject *)dict); dict->format = _ctypes_alloc_format_string(NULL, "B"); if (dict->format == NULL) { Py_DECREF(result); @@ -902,7 +902,7 @@ return -1; } Py_INCREF(proto); - Py_SETREF(stgdict->proto, proto); + Py_XSETREF(stgdict->proto, proto); return 0; } @@ -992,7 +992,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); return (PyObject *)result; } @@ -1457,7 +1457,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); /* Special case for character arrays. A permanent annoyance: char arrays are also strings! @@ -1880,7 +1880,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); return (PyObject *)result; } @@ -2388,7 +2388,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_SETREF(result->tp_dict, (PyObject *)stgdict); + Py_XSETREF(result->tp_dict, (PyObject *)stgdict); if (-1 == make_funcptrtype_dict(stgdict)) { Py_DECREF(result); @@ -2530,7 +2530,7 @@ } ob = PyCData_GetContainer(target); if (ob->b_objects == NULL || !PyDict_CheckExact(ob->b_objects)) { - Py_SETREF(ob->b_objects, keep); /* refcount consumed */ + Py_XSETREF(ob->b_objects, keep); /* refcount consumed */ return 0; } key = unique_key(target, index); @@ -3053,7 +3053,7 @@ return -1; } Py_XINCREF(ob); - Py_SETREF(self->errcheck, ob); + Py_XSETREF(self->errcheck, ob); return 0; } @@ -3082,8 +3082,8 @@ return -1; } Py_INCREF(ob); - Py_SETREF(self->restype, ob); - Py_SETREF(self->checker, PyObject_GetAttrString(ob, "_check_retval_")); + Py_XSETREF(self->restype, ob); + Py_XSETREF(self->checker, PyObject_GetAttrString(ob, "_check_retval_")); if (self->checker == NULL) PyErr_Clear(); return 0; @@ -3120,9 +3120,9 @@ converters = converters_from_argtypes(ob); if (!converters) return -1; - Py_SETREF(self->converters, converters); + Py_XSETREF(self->converters, converters); Py_INCREF(ob); - Py_SETREF(self->argtypes, ob); + Py_XSETREF(self->argtypes, ob); } return 0; } diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -284,7 +284,7 @@ return NULL; } Py_INCREF(temp); - Py_SETREF(po->wo, temp); + Py_XSETREF(po->wo, temp); Py_INCREF(Py_None); return Py_None; } diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1574,7 +1574,7 @@ if (strcmp(name, "tag") == 0) { Py_INCREF(value); - Py_SETREF(self->tag, value); + Py_XSETREF(self->tag, value); } else if (strcmp(name, "text") == 0) { Py_DECREF(JOIN_OBJ(self->text)); self->text = value; @@ -1587,7 +1587,7 @@ if (!self->extra) element_new_extra(self, NULL); Py_INCREF(value); - Py_SETREF(self->extra->attrib, value); + Py_XSETREF(self->extra->attrib, value); } else { PyErr_SetString(PyExc_AttributeError, name); return -1; @@ -1799,10 +1799,10 @@ self->index++; Py_INCREF(node); - Py_SETREF(self->this, (ElementObject*) node); + Py_XSETREF(self->this, (ElementObject*) node); Py_INCREF(node); - Py_SETREF(self->last, (ElementObject*) node); + Py_XSETREF(self->last, (ElementObject*) node); if (treebuilder_append_event(self, self->start_event_obj, node) < 0) goto error; @@ -2744,7 +2744,7 @@ target = (TreeBuilderObject*) self->target; Py_INCREF(events); - Py_SETREF(target->events, events); + Py_XSETREF(target->events, events); /* clear out existing events */ Py_CLEAR(target->start_event_obj); @@ -2769,18 +2769,18 @@ Py_INCREF(item); event = PyString_AS_STRING(item); if (strcmp(event, "start") == 0) { - Py_SETREF(target->start_event_obj, item); + Py_XSETREF(target->start_event_obj, item); } else if (strcmp(event, "end") == 0) { - Py_SETREF(target->end_event_obj, item); + Py_XSETREF(target->end_event_obj, item); } else if (strcmp(event, "start-ns") == 0) { - Py_SETREF(target->start_ns_event_obj, item); + Py_XSETREF(target->start_ns_event_obj, item); EXPAT(SetNamespaceDeclHandler)( self->parser, (XML_StartNamespaceDeclHandler) expat_start_ns_handler, (XML_EndNamespaceDeclHandler) expat_end_ns_handler ); } else if (strcmp(event, "end-ns") == 0) { - Py_SETREF(target->end_ns_event_obj, item); + Py_XSETREF(target->end_ns_event_obj, item); EXPAT(SetNamespaceDeclHandler)( self->parser, (XML_StartNamespaceDeclHandler) expat_start_ns_handler, diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -320,10 +320,10 @@ else Py_INCREF(dict); - Py_SETREF(pto->fn, fn); - Py_SETREF(pto->args, fnargs); - Py_SETREF(pto->kw, kw); - Py_SETREF(pto->dict, dict); + Py_XSETREF(pto->fn, fn); + Py_XSETREF(pto->args, fnargs); + Py_XSETREF(pto->kw, kw); + Py_XSETREF(pto->dict, dict); Py_RETURN_NONE; } diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -1028,7 +1028,7 @@ Py_CLEAR(res); goto end; } - Py_SETREF(res, _PyBytes_Join(_PyIO_empty_bytes, chunks)); + Py_XSETREF(res, _PyBytes_Join(_PyIO_empty_bytes, chunks)); end: LEAVE_BUFFERED(self) @@ -1264,7 +1264,7 @@ return -1; Py_INCREF(raw); - Py_SETREF(self->raw, raw); + Py_XSETREF(self->raw, raw); self->buffer_size = buffer_size; self->readable = 1; self->writable = 0; @@ -1686,7 +1686,7 @@ return -1; Py_INCREF(raw); - Py_SETREF(self->raw, raw); + Py_XSETREF(self->raw, raw); self->readable = 0; self->writable = 1; @@ -2342,7 +2342,7 @@ return -1; Py_INCREF(raw); - Py_SETREF(self->raw, raw); + Py_XSETREF(self->raw, raw); self->buffer_size = buffer_size; self->readable = 1; self->writable = 1; diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -966,7 +966,7 @@ "Oi", self->decoder, (int)self->readtranslate); if (incrementalDecoder == NULL) goto error; - Py_SETREF(self->decoder, incrementalDecoder); + Py_XSETREF(self->decoder, incrementalDecoder); } } @@ -1346,7 +1346,7 @@ static void textiowrapper_set_decoded_chars(textio *self, PyObject *chars) { - Py_SETREF(self->decoded_chars, chars); + Py_XSETREF(self->decoded_chars, chars); self->decoded_chars_used = 0; } @@ -1475,7 +1475,7 @@ goto fail; } Py_DECREF(dec_buffer); - Py_SETREF(self->snapshot, Py_BuildValue("NN", dec_flags, next_input)); + Py_XSETREF(self->snapshot, Py_BuildValue("NN", dec_flags, next_input)); } Py_DECREF(input_chunk); @@ -1575,7 +1575,7 @@ if (chunks != NULL) { if (result != NULL && PyList_Append(chunks, result) < 0) goto fail; - Py_SETREF(result, PyUnicode_Join(_PyIO_empty_str, chunks)); + Py_XSETREF(result, PyUnicode_Join(_PyIO_empty_str, chunks)); if (result == NULL) goto fail; Py_CLEAR(chunks); @@ -1832,7 +1832,7 @@ if (chunks != NULL) { if (line != NULL && PyList_Append(chunks, line) < 0) goto error; - Py_SETREF(line, PyUnicode_Join(_PyIO_empty_str, chunks)); + Py_XSETREF(line, PyUnicode_Join(_PyIO_empty_str, chunks)); if (line == NULL) goto error; Py_DECREF(chunks); diff --git a/Modules/_json.c b/Modules/_json.c --- a/Modules/_json.c +++ b/Modules/_json.c @@ -1717,7 +1717,7 @@ } else if (PyUnicode_Check(s->encoding)) { PyObject *tmp = PyUnicode_AsEncodedString(s->encoding, NULL, NULL); - Py_SETREF(s->encoding, tmp); + Py_XSETREF(s->encoding, tmp); } if (s->encoding == NULL) goto bail; diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -228,7 +228,7 @@ node = node->next; } - Py_SETREF(self->statement_cache, + Py_XSETREF(self->statement_cache, (pysqlite_Cache *)PyObject_CallFunction((PyObject *)&pysqlite_CacheType, "O", self)); Py_DECREF(self); self->statement_cache->decref_factory = 0; @@ -347,7 +347,7 @@ if (cursor && self->row_factory != Py_None) { Py_INCREF(self->row_factory); - Py_SETREF(((pysqlite_Cursor *)cursor)->row_factory, self->row_factory); + Py_XSETREF(((pysqlite_Cursor *)cursor)->row_factory, self->row_factory); } return cursor; @@ -815,7 +815,7 @@ } } - Py_SETREF(self->statements, new_list); + Py_XSETREF(self->statements, new_list); } static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) @@ -846,7 +846,7 @@ } } - Py_SETREF(self->cursors, new_list); + Py_XSETREF(self->cursors, new_list); } PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -172,7 +172,7 @@ return 0; } - Py_SETREF(self->row_cast_map, PyList_New(0)); + Py_XSETREF(self->row_cast_map, PyList_New(0)); for (i = 0; i < sqlite3_column_count(self->statement->st); i++) { converter = NULL; @@ -544,7 +544,7 @@ /* reset description and rowcount */ Py_INCREF(Py_None); - Py_SETREF(self->description, Py_None); + Py_XSETREF(self->description, Py_None); self->rowcount = -1L; func_args = PyTuple_New(1); @@ -560,7 +560,7 @@ (void)pysqlite_statement_reset(self->statement); } - Py_SETREF(self->statement, + Py_XSETREF(self->statement, (pysqlite_Statement *)pysqlite_cache_get(self->connection->statement_cache, func_args)); Py_DECREF(func_args); @@ -569,7 +569,7 @@ } if (self->statement->in_use) { - Py_SETREF(self->statement, + Py_XSETREF(self->statement, PyObject_New(pysqlite_Statement, &pysqlite_StatementType)); if (!self->statement) { goto error; @@ -681,7 +681,7 @@ numcols = sqlite3_column_count(self->statement->st); Py_END_ALLOW_THREADS - Py_SETREF(self->description, PyTuple_New(numcols)); + Py_XSETREF(self->description, PyTuple_New(numcols)); if (!self->description) { goto error; } diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2054,7 +2054,7 @@ if (!copy) return 0; - Py_SETREF(*object, copy); + Py_XSETREF(*object, copy); return 1; /* success */ } diff --git a/Modules/_ssl.c b/Modules/_ssl.c --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -1467,7 +1467,7 @@ return -1; #else Py_INCREF(value); - Py_SETREF(self->ctx, (PySSLContext *)value); + Py_XSETREF(self->ctx, (PySSLContext *)value); SSL_set_SSL_CTX(self->ssl, self->ctx->ctx); #endif } else { diff --git a/Modules/_struct.c b/Modules/_struct.c --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1377,13 +1377,13 @@ if (PyString_Check(o_format)) { Py_INCREF(o_format); - Py_SETREF(soself->s_format, o_format); + Py_XSETREF(soself->s_format, o_format); } else if (PyUnicode_Check(o_format)) { PyObject *str = PyUnicode_AsEncodedString(o_format, "ascii", NULL); if (str == NULL) return -1; - Py_SETREF(soself->s_format, str); + Py_XSETREF(soself->s_format, str); } else { PyErr_Format(PyExc_TypeError, diff --git a/Modules/bz2module.c b/Modules/bz2module.c --- a/Modules/bz2module.c +++ b/Modules/bz2module.c @@ -1953,7 +1953,7 @@ self->running = 0; input_left += bzs->avail_in; if (input_left != 0) { - Py_SETREF(self->unused_data, + Py_XSETREF(self->unused_data, PyString_FromStringAndSize(bzs->next_in, input_left)); if (self->unused_data == NULL) goto error; diff --git a/Modules/cPickle.c b/Modules/cPickle.c --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -689,7 +689,7 @@ } if (! str) return -1; - Py_SETREF(self->last_string, str); + Py_XSETREF(self->last_string, str); if (! (*s = PyString_AsString(str))) return -1; @@ -715,7 +715,7 @@ if ((str_size = PyString_Size(str)) < 0) return -1; - Py_SETREF(self->last_string, str); + Py_XSETREF(self->last_string, str); if (! (*s = PyString_AsString(str))) return -1; @@ -3227,7 +3227,7 @@ return -1; } Py_INCREF(v); - Py_SETREF(p->pers_func, v); + Py_XSETREF(p->pers_func, v); return 0; } @@ -3240,7 +3240,7 @@ return -1; } Py_INCREF(v); - Py_SETREF(p->inst_pers_func, v); + Py_XSETREF(p->inst_pers_func, v); return 0; } @@ -3267,7 +3267,7 @@ return -1; } Py_INCREF(v); - Py_SETREF(p->memo, v); + Py_XSETREF(p->memo, v); return 0; } @@ -5663,13 +5663,13 @@ if (!strcmp(name, "persistent_load")) { Py_XINCREF(value); - Py_SETREF(self->pers_func, value); + Py_XSETREF(self->pers_func, value); return 0; } if (!strcmp(name, "find_global")) { Py_XINCREF(value); - Py_SETREF(self->find_class, value); + Py_XSETREF(self->find_class, value); return 0; } @@ -5686,7 +5686,7 @@ return -1; } Py_INCREF(value); - Py_SETREF(self->memo, value); + Py_XSETREF(self->memo, value); return 0; } diff --git a/Modules/cdmodule.c b/Modules/cdmodule.c --- a/Modules/cdmodule.c +++ b/Modules/cdmodule.c @@ -629,9 +629,9 @@ (void *) self); #endif Py_INCREF(func); - Py_SETREF(self->ob_cdcallbacks[type].ob_cdcallback, func); + Py_XSETREF(self->ob_cdcallbacks[type].ob_cdcallback, func); Py_INCREF(funcarg); - Py_SETREF(self->ob_cdcallbacks[type].ob_cdcallbackarg, funcarg); + Py_XSETREF(self->ob_cdcallbacks[type].ob_cdcallbackarg, funcarg); /* if (type == cd_audio) { diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -492,7 +492,7 @@ link = teedataobject_jumplink(to->dataobj); if (link == NULL) return NULL; - Py_SETREF(to->dataobj, (teedataobject *)link); + Py_XSETREF(to->dataobj, (teedataobject *)link); to->index = 0; } value = teedataobject_getitem(to->dataobj, to->index); diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -621,7 +621,7 @@ if (Handlers[SIGINT].func == DefaultHandler) { /* Install default int handler */ Py_INCREF(IntHandler); - Py_SETREF(Handlers[SIGINT].func, IntHandler); + Py_XSETREF(Handlers[SIGINT].func, IntHandler); old_siginthandler = PyOS_setsig(SIGINT, signal_handler); } diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -491,7 +491,7 @@ PyString_AS_STRING(self->unused_data), old_size); Py_MEMCPY(PyString_AS_STRING(new_data) + old_size, self->zst.next_in, self->zst.avail_in); - Py_SETREF(self->unused_data, new_data); + Py_XSETREF(self->unused_data, new_data); self->zst.avail_in = 0; } } @@ -503,7 +503,7 @@ (char *)self->zst.next_in, self->zst.avail_in); if (new_data == NULL) return -1; - Py_SETREF(self->unconsumed_tail, new_data); + Py_XSETREF(self->unconsumed_tail, new_data); } return 0; } @@ -731,9 +731,9 @@ } Py_INCREF(self->unused_data); - Py_SETREF(retval->unused_data, self->unused_data); + Py_XSETREF(retval->unused_data, self->unused_data); Py_INCREF(self->unconsumed_tail); - Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail); + Py_XSETREF(retval->unconsumed_tail, self->unconsumed_tail); /* Mark it as being initialized */ retval->is_initialised = 1; @@ -780,9 +780,9 @@ } Py_INCREF(self->unused_data); - Py_SETREF(retval->unused_data, self->unused_data); + Py_XSETREF(retval->unused_data, self->unused_data); Py_INCREF(self->unconsumed_tail); - Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail); + Py_XSETREF(retval->unconsumed_tail, self->unconsumed_tail); /* Mark it as being initialized */ retval->is_initialised = 1; diff --git a/Objects/descrobject.c b/Objects/descrobject.c --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1332,7 +1332,7 @@ PyObject *get_doc = PyObject_GetAttrString(get, "__doc__"); if (get_doc) { if (Py_TYPE(self) == &PyProperty_Type) { - Py_SETREF(prop->prop_doc, get_doc); + Py_XSETREF(prop->prop_doc, get_doc); } else { /* If this is a property subclass, put __doc__ diff --git a/Objects/exceptions.c b/Objects/exceptions.c --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -59,11 +59,11 @@ return -1; Py_INCREF(args); - Py_SETREF(self->args, args); + Py_XSETREF(self->args, args); if (PyTuple_GET_SIZE(self->args) == 1) { Py_INCREF(PyTuple_GET_ITEM(self->args, 0)); - Py_SETREF(self->message, PyTuple_GET_ITEM(self->args, 0)); + Py_XSETREF(self->message, PyTuple_GET_ITEM(self->args, 0)); } return 0; } @@ -279,7 +279,7 @@ return -1; } Py_INCREF(val); - Py_SETREF(self->dict, val); + Py_XSETREF(self->dict, val); return 0; } @@ -305,7 +305,7 @@ seq = PySequence_Tuple(val); if (!seq) return -1; - Py_SETREF(self->args, seq); + Py_XSETREF(self->args, seq); return 0; } @@ -519,11 +519,11 @@ return 0; if (size == 1) { Py_INCREF(PyTuple_GET_ITEM(args, 0)); - Py_SETREF(self->code, PyTuple_GET_ITEM(args, 0)); + Py_XSETREF(self->code, PyTuple_GET_ITEM(args, 0)); } else { /* size > 1 */ Py_INCREF(args); - Py_SETREF(self->code, args); + Py_XSETREF(self->code, args); } return 0; } @@ -608,21 +608,21 @@ return -1; } Py_INCREF(myerrno); - Py_SETREF(self->myerrno, myerrno); + Py_XSETREF(self->myerrno, myerrno); Py_INCREF(strerror); - Py_SETREF(self->strerror, strerror); + Py_XSETREF(self->strerror, strerror); /* self->filename will remain Py_None otherwise */ if (filename != NULL) { Py_INCREF(filename); - Py_SETREF(self->filename, filename); + Py_XSETREF(self->filename, filename); subslice = PyTuple_GetSlice(args, 0, 2); if (!subslice) return -1; - Py_SETREF(self->args, subslice); + Py_XSETREF(self->args, subslice); } return 0; } @@ -873,7 +873,7 @@ return -1; posix_errno = winerror_to_errno(errcode); - Py_SETREF(self->winerror, self->myerrno); + Py_XSETREF(self->winerror, self->myerrno); o_errcode = PyInt_FromLong(posix_errno); if (!o_errcode) @@ -1059,7 +1059,7 @@ if (lenargs >= 1) { Py_INCREF(PyTuple_GET_ITEM(args, 0)); - Py_SETREF(self->msg, PyTuple_GET_ITEM(args, 0)); + Py_XSETREF(self->msg, PyTuple_GET_ITEM(args, 0)); } if (lenargs == 2) { info = PyTuple_GET_ITEM(args, 1); @@ -1075,16 +1075,16 @@ } Py_INCREF(PyTuple_GET_ITEM(info, 0)); - Py_SETREF(self->filename, PyTuple_GET_ITEM(info, 0)); + Py_XSETREF(self->filename, PyTuple_GET_ITEM(info, 0)); Py_INCREF(PyTuple_GET_ITEM(info, 1)); - Py_SETREF(self->lineno, PyTuple_GET_ITEM(info, 1)); + Py_XSETREF(self->lineno, PyTuple_GET_ITEM(info, 1)); Py_INCREF(PyTuple_GET_ITEM(info, 2)); - Py_SETREF(self->offset, PyTuple_GET_ITEM(info, 2)); + Py_XSETREF(self->offset, PyTuple_GET_ITEM(info, 2)); Py_INCREF(PyTuple_GET_ITEM(info, 3)); - Py_SETREF(self->text, PyTuple_GET_ITEM(info, 3)); + Py_XSETREF(self->text, PyTuple_GET_ITEM(info, 3)); Py_DECREF(info); } @@ -1317,7 +1317,7 @@ PyObject *obj = PyString_FromString(value); if (!obj) return -1; - Py_SETREF(*attr, obj); + Py_XSETREF(*attr, obj); return 0; } diff --git a/Objects/fileobject.c b/Objects/fileobject.c --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -574,8 +574,8 @@ oerrors = Py_None; Py_INCREF(Py_None); } - Py_SETREF(file->f_encoding, str); - Py_SETREF(file->f_errors, oerrors); + Py_XSETREF(file->f_encoding, str); + Py_XSETREF(file->f_errors, oerrors); return 1; } diff --git a/Objects/frameobject.c b/Objects/frameobject.c --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -859,7 +859,7 @@ } } else if (values[j] != value) { Py_XINCREF(value); - Py_SETREF(values[j], value); + Py_XSETREF(values[j], value); } Py_XDECREF(value); } diff --git a/Objects/funcobject.c b/Objects/funcobject.c --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -116,7 +116,7 @@ PyErr_SetString(PyExc_SystemError, "non-tuple default args"); return -1; } - Py_SETREF(((PyFunctionObject *)op)->func_defaults, defaults); + Py_XSETREF(((PyFunctionObject *)op)->func_defaults, defaults); return 0; } @@ -148,7 +148,7 @@ closure->ob_type->tp_name); return -1; } - Py_SETREF(((PyFunctionObject *)op)->func_closure, closure); + Py_XSETREF(((PyFunctionObject *)op)->func_closure, closure); return 0; } @@ -428,7 +428,7 @@ if (name != Py_None) { Py_INCREF(name); - Py_SETREF(newfunc->func_name, name); + Py_XSETREF(newfunc->func_name, name); } if (defaults != Py_None) { Py_INCREF(defaults); diff --git a/Objects/stringobject.c b/Objects/stringobject.c --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -3865,7 +3865,7 @@ return; } v = string_concat((PyStringObject *) *pv, w); - Py_SETREF(*pv, v); + Py_XSETREF(*pv, v); } void @@ -4750,7 +4750,7 @@ t = PyDict_GetItem(interned, (PyObject *)s); if (t) { Py_INCREF(t); - Py_SETREF(*p, t); + Py_XSETREF(*p, t); return; } diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -188,7 +188,7 @@ for (i = 0; i < (1 << MCACHE_SIZE_EXP); i++) { method_cache[i].value = NULL; Py_INCREF(Py_None); - Py_SETREF(method_cache[i].name, Py_None); + Py_XSETREF(method_cache[i].name, Py_None); } /* mark all version tags as invalid */ PyType_Modified(&PyBaseObject_Type); diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -436,7 +436,7 @@ return -1; Py_UNICODE_COPY(w->str, v->str, length < v->length ? length : v->length); - Py_SETREF(*unicode, w); + Py_XSETREF(*unicode, w); return 0; } diff --git a/Python/_warnings.c b/Python/_warnings.c --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -528,7 +528,7 @@ goto handle_error; } else if (!is_true) { - Py_SETREF(*filename, PyString_FromString("__main__")); + Py_XSETREF(*filename, PyString_FromString("__main__")); if (*filename == NULL) goto handle_error; } diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4360,7 +4360,7 @@ Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); - Py_SETREF(*pfunc, self); + Py_XSETREF(*pfunc, self); na++; n++; } else diff --git a/Python/compile.c b/Python/compile.c --- a/Python/compile.c +++ b/Python/compile.c @@ -1415,7 +1415,7 @@ s->lineno)) return 0; Py_INCREF(s->v.ClassDef.name); - Py_SETREF(c->u->u_private, s->v.ClassDef.name); + Py_XSETREF(c->u->u_private, s->v.ClassDef.name); str = PyString_InternFromString("__name__"); if (!str || !compiler_nameop(c, str, Load)) { Py_XDECREF(str); diff --git a/Python/errors.c b/Python/errors.c --- a/Python/errors.c +++ b/Python/errors.c @@ -229,9 +229,9 @@ --tstate->recursion_depth; /* throw away the old exception and use the recursion error instead */ Py_INCREF(PyExc_RuntimeError); - Py_SETREF(*exc, PyExc_RuntimeError); + Py_XSETREF(*exc, PyExc_RuntimeError); Py_INCREF(PyExc_RecursionErrorInst); - Py_SETREF(*val, PyExc_RecursionErrorInst); + Py_XSETREF(*val, PyExc_RecursionErrorInst); /* just keeping the old traceback */ return; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 6 15:19:12 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 06 Apr 2016 19:19:12 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326671=3A_Enhanced?= =?utf-8?q?_path=5Fconverter=2E?= Message-ID: <20160406191910.32759.97948.DF001EEF@psf.io> https://hg.python.org/cpython/rev/a866f5727b7f changeset: 100860:a866f5727b7f parent: 100858:719c11b6b6ff user: Serhiy Storchaka date: Wed Apr 06 22:17:52 2016 +0300 summary: Issue #26671: Enhanced path_converter. Exceptions raised during converting argument of correct type are no longer overridded with TypeError. Some error messages are now more detailed. files: Modules/posixmodule.c | 116 ++++++++++++++--------------- 1 files changed, 55 insertions(+), 61 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -669,21 +669,20 @@ #endif static int -_fd_converter(PyObject *o, int *p, const char *allowed) +_fd_converter(PyObject *o, int *p) { int overflow; long long_value; PyObject *index = PyNumber_Index(o); if (index == NULL) { - PyErr_Format(PyExc_TypeError, - "argument should be %s, not %.200s", - allowed, Py_TYPE(o)->tp_name); return 0; } + assert(PyLong_Check(index)); long_value = PyLong_AsLongAndOverflow(index, &overflow); Py_DECREF(index); + assert(!PyErr_Occurred()); if (overflow > 0 || long_value > INT_MAX) { PyErr_SetString(PyExc_OverflowError, "fd is greater than maximum"); @@ -706,7 +705,15 @@ *(int *)p = DEFAULT_DIR_FD; return 1; } - return _fd_converter(o, (int *)p, "integer"); + else if (PyIndex_Check(o)) { + return _fd_converter(o, (int *)p); + } + else { + PyErr_Format(PyExc_TypeError, + "argument should be integer or None, not %.200s", + Py_TYPE(o)->tp_name); + return 0; + } } @@ -816,9 +823,10 @@ } static int -path_converter(PyObject *o, void *p) { +path_converter(PyObject *o, void *p) +{ path_t *path = (path_t *)p; - PyObject *unicode, *bytes; + PyObject *bytes; Py_ssize_t length; char *narrow; @@ -837,12 +845,7 @@ /* ensure it's always safe to call path_cleanup() */ path->cleanup = NULL; - if (o == Py_None) { - if (!path->nullable) { - FORMAT_EXCEPTION(PyExc_TypeError, - "can't specify None for %s argument"); - return 0; - } + if ((o == Py_None) && path->nullable) { path->wide = NULL; path->narrow = NULL; path->length = 0; @@ -851,24 +854,20 @@ return 1; } - unicode = PyUnicode_FromObject(o); - if (unicode) { + if (PyUnicode_Check(o)) { #ifdef MS_WINDOWS wchar_t *wide; - wide = PyUnicode_AsUnicodeAndSize(unicode, &length); + wide = PyUnicode_AsUnicodeAndSize(o, &length); if (!wide) { - Py_DECREF(unicode); return 0; } if (length > 32767) { FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows"); - Py_DECREF(unicode); return 0; } if (wcslen(wide) != length) { - FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character"); - Py_DECREF(unicode); + FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character in %s"); return 0; } @@ -877,52 +876,47 @@ path->length = length; path->object = o; path->fd = -1; - path->cleanup = unicode; - return Py_CLEANUP_SUPPORTED; -#else - int converted = PyUnicode_FSConverter(unicode, &bytes); - Py_DECREF(unicode); - if (!converted) - bytes = NULL; -#endif + return 1; +#else + if (!PyUnicode_FSConverter(o, &bytes)) { + return 0; + } +#endif + } + else if (PyObject_CheckBuffer(o)) { +# ifdef MS_WINDOWS + if (win32_warn_bytes_api()) { + return 0; + } +# endif + bytes = PyBytes_FromObject(o); + if (!bytes) { + return 0; + } + } + else if (path->allow_fd && PyIndex_Check(o)) { + if (!_fd_converter(o, &path->fd)) { + return 0; + } + path->wide = NULL; + path->narrow = NULL; + path->length = 0; + path->object = o; + return 1; } else { - PyErr_Clear(); - if (PyObject_CheckBuffer(o)) - bytes = PyBytes_FromObject(o); - else - bytes = NULL; - if (!bytes) { - PyErr_Clear(); - if (path->allow_fd) { - int fd; - int result = _fd_converter(o, &fd, - "string, bytes or integer"); - if (result) { - path->wide = NULL; - path->narrow = NULL; - path->length = 0; - path->object = o; - path->fd = fd; - return result; - } - } - } - } - - if (!bytes) { - if (!PyErr_Occurred()) - FORMAT_EXCEPTION(PyExc_TypeError, "illegal type for %s parameter"); + PyErr_Format(PyExc_TypeError, "%s%s%s should be %s, not %.200s", + path->function_name ? path->function_name : "", + path->function_name ? ": " : "", + path->argument_name ? path->argument_name : "path", + path->allow_fd && path->nullable ? "string, bytes, integer or None" : + path->allow_fd ? "string, bytes or integer" : + path->nullable ? "string, bytes or None" : + "string or bytes", + Py_TYPE(o)->tp_name); return 0; } -#ifdef MS_WINDOWS - if (win32_warn_bytes_api()) { - Py_DECREF(bytes); - return 0; - } -#endif - length = PyBytes_GET_SIZE(bytes); #ifdef MS_WINDOWS if (length > MAX_PATH-1) { -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 6 15:37:04 2016 From: python-checkins at python.org (steve.dower) Date: Wed, 06 Apr 2016 19:37:04 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Adds_version_info_to_all_signed_binaries_on_Windows?= Message-ID: <20160406193703.32741.82383.F27542AA@psf.io> https://hg.python.org/cpython/rev/1abb34d98b01 changeset: 100862:1abb34d98b01 parent: 100860:a866f5727b7f parent: 100861:f191c438d108 user: Steve Dower date: Wed Apr 06 12:36:23 2016 -0700 summary: Adds version info to all signed binaries on Windows files: PC/bdist_wininst/bdist_wininst.vcxproj | 1 - PC/python_ver_rc.h | 4 +- PC/sqlite3.rc | 49 ++++++++++++++ PCbuild/_bz2.vcxproj | 3 + PCbuild/_ctypes.vcxproj | 3 + PCbuild/_ctypes_test.vcxproj | 3 + PCbuild/_decimal.vcxproj | 3 + PCbuild/_elementtree.vcxproj | 3 + PCbuild/_hashlib.vcxproj | 3 + PCbuild/_lzma.vcxproj | 3 + PCbuild/_msi.vcxproj | 3 + PCbuild/_multiprocessing.vcxproj | 3 + PCbuild/_overlapped.vcxproj | 3 + PCbuild/_socket.vcxproj | 3 + PCbuild/_sqlite3.vcxproj | 3 + PCbuild/_ssl.vcxproj | 3 + PCbuild/_testbuffer.vcxproj | 3 + PCbuild/_testcapi.vcxproj | 3 + PCbuild/_testembed.vcxproj | 3 + PCbuild/_testimportmultiple.vcxproj | 3 + PCbuild/_testmultiphase.vcxproj | 3 + PCbuild/_tkinter.vcxproj | 3 + PCbuild/pyexpat.vcxproj | 3 + PCbuild/pylauncher.vcxproj | 1 - PCbuild/pyproject.props | 14 ++-- PCbuild/python.vcxproj | 1 - PCbuild/python3dll.vcxproj | 1 - PCbuild/pythoncore.vcxproj | 1 - PCbuild/pythonw.vcxproj | 1 - PCbuild/pywlauncher.vcxproj | 1 - PCbuild/select.vcxproj | 3 + PCbuild/sqlite3.vcxproj | 12 +++ PCbuild/unicodedata.vcxproj | 3 + PCbuild/winsound.vcxproj | 3 + 34 files changed, 139 insertions(+), 16 deletions(-) diff --git a/PC/bdist_wininst/bdist_wininst.vcxproj b/PC/bdist_wininst/bdist_wininst.vcxproj --- a/PC/bdist_wininst/bdist_wininst.vcxproj +++ b/PC/bdist_wininst/bdist_wininst.vcxproj @@ -37,7 +37,6 @@ {EB1C19C1-1F18-421E-9735-CAEE69DC6A3C} wininst - ClCompile false diff --git a/PC/python_ver_rc.h b/PC/python_ver_rc.h --- a/PC/python_ver_rc.h +++ b/PC/python_ver_rc.h @@ -10,10 +10,10 @@ #include "modsupport.h" #include "patchlevel.h" #ifdef _DEBUG -# include "pythonnt_rc_d.h" +# include # define PYTHON_DEBUG_EXT "_d" #else -# include "pythonnt_rc.h" +# include # define PYTHON_DEBUG_EXT #endif diff --git a/PC/sqlite3.rc b/PC/sqlite3.rc new file mode 100644 --- /dev/null +++ b/PC/sqlite3.rc @@ -0,0 +1,49 @@ +// Resource script for Sqlite DLL. + +#include + +// Include the manifest file that indicates we support all +// current versions of Windows. +#include +2 RT_MANIFEST "python.manifest" + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#define _S(x) #x +#define S(x) _S(x) + +VS_VERSION_INFO VERSIONINFO + FILEVERSION SQLITE_MAJOR_VERSION, SQLITE_MINOR_VERSION, SQLITE_MICRO_VERSION, SQLITE_PATCH_VERSION + PRODUCTVERSION SQLITE_MAJOR_VERSION, SQLITE_MINOR_VERSION, SQLITE_MICRO_VERSION, SQLITE_PATCH_VERSION + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "CompanyName", "SQLite3\0" + VALUE "FileDescription", "SQLite3\0" + VALUE "FileVersion", S(SQLITE_VERSION) "\0" + VALUE "InternalName", "SQLite3 DLL\0" + VALUE "LegalCopyright", "Unspecified\0" + VALUE "OriginalFilename", "sqlite3.dll\0" + VALUE "ProductName", "SQLite3\0" + VALUE "ProductVersion", S(SQLITE_VERSION) "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END diff --git a/PCbuild/_bz2.vcxproj b/PCbuild/_bz2.vcxproj --- a/PCbuild/_bz2.vcxproj +++ b/PCbuild/_bz2.vcxproj @@ -84,6 +84,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_ctypes.vcxproj b/PCbuild/_ctypes.vcxproj --- a/PCbuild/_ctypes.vcxproj +++ b/PCbuild/_ctypes.vcxproj @@ -97,6 +97,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} diff --git a/PCbuild/_ctypes_test.vcxproj b/PCbuild/_ctypes_test.vcxproj --- a/PCbuild/_ctypes_test.vcxproj +++ b/PCbuild/_ctypes_test.vcxproj @@ -67,6 +67,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} diff --git a/PCbuild/_decimal.vcxproj b/PCbuild/_decimal.vcxproj --- a/PCbuild/_decimal.vcxproj +++ b/PCbuild/_decimal.vcxproj @@ -114,6 +114,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} diff --git a/PCbuild/_elementtree.vcxproj b/PCbuild/_elementtree.vcxproj --- a/PCbuild/_elementtree.vcxproj +++ b/PCbuild/_elementtree.vcxproj @@ -92,6 +92,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_hashlib.vcxproj b/PCbuild/_hashlib.vcxproj --- a/PCbuild/_hashlib.vcxproj +++ b/PCbuild/_hashlib.vcxproj @@ -71,6 +71,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_lzma.vcxproj b/PCbuild/_lzma.vcxproj --- a/PCbuild/_lzma.vcxproj +++ b/PCbuild/_lzma.vcxproj @@ -74,6 +74,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_msi.vcxproj b/PCbuild/_msi.vcxproj --- a/PCbuild/_msi.vcxproj +++ b/PCbuild/_msi.vcxproj @@ -69,6 +69,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_multiprocessing.vcxproj b/PCbuild/_multiprocessing.vcxproj --- a/PCbuild/_multiprocessing.vcxproj +++ b/PCbuild/_multiprocessing.vcxproj @@ -73,6 +73,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_overlapped.vcxproj b/PCbuild/_overlapped.vcxproj --- a/PCbuild/_overlapped.vcxproj +++ b/PCbuild/_overlapped.vcxproj @@ -69,6 +69,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_socket.vcxproj b/PCbuild/_socket.vcxproj --- a/PCbuild/_socket.vcxproj +++ b/PCbuild/_socket.vcxproj @@ -72,6 +72,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_sqlite3.vcxproj b/PCbuild/_sqlite3.vcxproj --- a/PCbuild/_sqlite3.vcxproj +++ b/PCbuild/_sqlite3.vcxproj @@ -91,6 +91,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_ssl.vcxproj b/PCbuild/_ssl.vcxproj --- a/PCbuild/_ssl.vcxproj +++ b/PCbuild/_ssl.vcxproj @@ -71,6 +71,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_testbuffer.vcxproj b/PCbuild/_testbuffer.vcxproj --- a/PCbuild/_testbuffer.vcxproj +++ b/PCbuild/_testbuffer.vcxproj @@ -69,6 +69,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} diff --git a/PCbuild/_testcapi.vcxproj b/PCbuild/_testcapi.vcxproj --- a/PCbuild/_testcapi.vcxproj +++ b/PCbuild/_testcapi.vcxproj @@ -69,6 +69,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_testembed.vcxproj b/PCbuild/_testembed.vcxproj --- a/PCbuild/_testembed.vcxproj +++ b/PCbuild/_testembed.vcxproj @@ -66,6 +66,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_testimportmultiple.vcxproj b/PCbuild/_testimportmultiple.vcxproj --- a/PCbuild/_testimportmultiple.vcxproj +++ b/PCbuild/_testimportmultiple.vcxproj @@ -69,6 +69,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_testmultiphase.vcxproj b/PCbuild/_testmultiphase.vcxproj --- a/PCbuild/_testmultiphase.vcxproj +++ b/PCbuild/_testmultiphase.vcxproj @@ -69,6 +69,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_tkinter.vcxproj b/PCbuild/_tkinter.vcxproj --- a/PCbuild/_tkinter.vcxproj +++ b/PCbuild/_tkinter.vcxproj @@ -74,6 +74,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/pyexpat.vcxproj b/PCbuild/pyexpat.vcxproj --- a/PCbuild/pyexpat.vcxproj +++ b/PCbuild/pyexpat.vcxproj @@ -73,6 +73,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/pylauncher.vcxproj b/PCbuild/pylauncher.vcxproj --- a/PCbuild/pylauncher.vcxproj +++ b/PCbuild/pylauncher.vcxproj @@ -38,7 +38,6 @@ {7B2727B5-5A3F-40EE-A866-43A13CD31446} pylauncher py - ClCompile false diff --git a/PCbuild/pyproject.props b/PCbuild/pyproject.props --- a/PCbuild/pyproject.props +++ b/PCbuild/pyproject.props @@ -75,7 +75,7 @@ true - $(PySourcePath)PC;$(PySourcePath)Include;%(AdditionalIncludeDirectories) + $(PySourcePath)PC;$(PySourcePath)Include;$(IntDir);%(AdditionalIncludeDirectories) $(_DebugPreprocessorDefinition)%(PreprocessorDefinitions) 0x0409 @@ -92,17 +92,17 @@ - - + diff --git a/PCbuild/python.vcxproj b/PCbuild/python.vcxproj --- a/PCbuild/python.vcxproj +++ b/PCbuild/python.vcxproj @@ -36,7 +36,6 @@ {B11D750F-CD1F-4A96-85CE-E69A5C5259F9} - ClCompile diff --git a/PCbuild/python3dll.vcxproj b/PCbuild/python3dll.vcxproj --- a/PCbuild/python3dll.vcxproj +++ b/PCbuild/python3dll.vcxproj @@ -39,7 +39,6 @@ python3dll Win32Proj python3 - ClCompile false diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -48,7 +48,6 @@ - ClCompile true diff --git a/PCbuild/pythonw.vcxproj b/PCbuild/pythonw.vcxproj --- a/PCbuild/pythonw.vcxproj +++ b/PCbuild/pythonw.vcxproj @@ -36,7 +36,6 @@ {F4229CC3-873C-49AE-9729-DD308ED4CD4A} - ClCompile false diff --git a/PCbuild/pywlauncher.vcxproj b/PCbuild/pywlauncher.vcxproj --- a/PCbuild/pywlauncher.vcxproj +++ b/PCbuild/pywlauncher.vcxproj @@ -38,7 +38,6 @@ {1D4B18D3-7C12-4ECB-9179-8531FF876CE6} pywlauncher pyw - ClCompile false diff --git a/PCbuild/select.vcxproj b/PCbuild/select.vcxproj --- a/PCbuild/select.vcxproj +++ b/PCbuild/select.vcxproj @@ -68,6 +68,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/sqlite3.vcxproj b/PCbuild/sqlite3.vcxproj --- a/PCbuild/sqlite3.vcxproj +++ b/PCbuild/sqlite3.vcxproj @@ -56,6 +56,12 @@ <_ProjectFileVersion>10.0.30319.1 + <_SqliteVersion>$([System.Text.RegularExpressions.Regex]::Match(`$(sqlite3Dir)`, `((\d+)\.(\d+)\.(\d+)\.(\d+))\\?$`).Groups) + $(_SqliteVersion.Split(`;`)[1]) + $(_SqliteVersion.Split(`;`)[2]) + $(_SqliteVersion.Split(`;`)[3]) + $(_SqliteVersion.Split(`;`)[4]) + $(_SqliteVersion.Split(`;`)[5]) @@ -63,6 +69,9 @@ SQLITE_API=__declspec(dllexport);%(PreprocessorDefinitions) Level1 + + SQLITE_VERSION=$(SqliteVersion);SQLITE_MAJOR_VERSION=$(SqliteMajorVersion);SQLITE_MINOR_VERSION=$(SqliteMinorVersion);SQLITE_MICRO_VERSION=$(SqliteMicroVersion);SQLITE_PATCH_VERSION=$(SqlitePatchVersion);%(PreprocessorDefinitions) + @@ -71,6 +80,9 @@ + + + diff --git a/PCbuild/unicodedata.vcxproj b/PCbuild/unicodedata.vcxproj --- a/PCbuild/unicodedata.vcxproj +++ b/PCbuild/unicodedata.vcxproj @@ -72,6 +72,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/winsound.vcxproj b/PCbuild/winsound.vcxproj --- a/PCbuild/winsound.vcxproj +++ b/PCbuild/winsound.vcxproj @@ -68,6 +68,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 6 15:37:04 2016 From: python-checkins at python.org (steve.dower) Date: Wed, 06 Apr 2016 19:37:04 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Adds_version_i?= =?utf-8?q?nfo_to_all_signed_binaries_on_Windows=2E?= Message-ID: <20160406193703.9980.44902.F2206B11@psf.io> https://hg.python.org/cpython/rev/f191c438d108 changeset: 100861:f191c438d108 branch: 3.5 parent: 100857:d0c8b2c1544e user: Steve Dower date: Wed Apr 06 12:35:24 2016 -0700 summary: Adds version info to all signed binaries on Windows. files: PC/bdist_wininst/bdist_wininst.vcxproj | 1 - PC/python_ver_rc.h | 4 +- PC/sqlite3.rc | 49 ++++++++++++++ PCbuild/_bz2.vcxproj | 3 + PCbuild/_ctypes.vcxproj | 3 + PCbuild/_ctypes_test.vcxproj | 3 + PCbuild/_decimal.vcxproj | 3 + PCbuild/_elementtree.vcxproj | 3 + PCbuild/_hashlib.vcxproj | 3 + PCbuild/_lzma.vcxproj | 3 + PCbuild/_msi.vcxproj | 3 + PCbuild/_multiprocessing.vcxproj | 3 + PCbuild/_overlapped.vcxproj | 3 + PCbuild/_socket.vcxproj | 3 + PCbuild/_sqlite3.vcxproj | 3 + PCbuild/_ssl.vcxproj | 3 + PCbuild/_testbuffer.vcxproj | 3 + PCbuild/_testcapi.vcxproj | 3 + PCbuild/_testembed.vcxproj | 3 + PCbuild/_testimportmultiple.vcxproj | 3 + PCbuild/_testmultiphase.vcxproj | 3 + PCbuild/_tkinter.vcxproj | 3 + PCbuild/pyexpat.vcxproj | 3 + PCbuild/pylauncher.vcxproj | 1 - PCbuild/pyproject.props | 14 ++-- PCbuild/python.vcxproj | 1 - PCbuild/python3dll.vcxproj | 1 - PCbuild/pythoncore.vcxproj | 1 - PCbuild/pythonw.vcxproj | 1 - PCbuild/pywlauncher.vcxproj | 1 - PCbuild/select.vcxproj | 3 + PCbuild/sqlite3.vcxproj | 12 +++ PCbuild/unicodedata.vcxproj | 3 + PCbuild/winsound.vcxproj | 3 + 34 files changed, 139 insertions(+), 16 deletions(-) diff --git a/PC/bdist_wininst/bdist_wininst.vcxproj b/PC/bdist_wininst/bdist_wininst.vcxproj --- a/PC/bdist_wininst/bdist_wininst.vcxproj +++ b/PC/bdist_wininst/bdist_wininst.vcxproj @@ -37,7 +37,6 @@ {EB1C19C1-1F18-421E-9735-CAEE69DC6A3C} wininst - ClCompile false diff --git a/PC/python_ver_rc.h b/PC/python_ver_rc.h --- a/PC/python_ver_rc.h +++ b/PC/python_ver_rc.h @@ -10,10 +10,10 @@ #include "modsupport.h" #include "patchlevel.h" #ifdef _DEBUG -# include "pythonnt_rc_d.h" +# include # define PYTHON_DEBUG_EXT "_d" #else -# include "pythonnt_rc.h" +# include # define PYTHON_DEBUG_EXT #endif diff --git a/PC/sqlite3.rc b/PC/sqlite3.rc new file mode 100644 --- /dev/null +++ b/PC/sqlite3.rc @@ -0,0 +1,49 @@ +// Resource script for Sqlite DLL. + +#include + +// Include the manifest file that indicates we support all +// current versions of Windows. +#include +2 RT_MANIFEST "python.manifest" + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#define _S(x) #x +#define S(x) _S(x) + +VS_VERSION_INFO VERSIONINFO + FILEVERSION SQLITE_MAJOR_VERSION, SQLITE_MINOR_VERSION, SQLITE_MICRO_VERSION, SQLITE_PATCH_VERSION + PRODUCTVERSION SQLITE_MAJOR_VERSION, SQLITE_MINOR_VERSION, SQLITE_MICRO_VERSION, SQLITE_PATCH_VERSION + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "CompanyName", "SQLite3\0" + VALUE "FileDescription", "SQLite3\0" + VALUE "FileVersion", S(SQLITE_VERSION) "\0" + VALUE "InternalName", "SQLite3 DLL\0" + VALUE "LegalCopyright", "Unspecified\0" + VALUE "OriginalFilename", "sqlite3.dll\0" + VALUE "ProductName", "SQLite3\0" + VALUE "ProductVersion", S(SQLITE_VERSION) "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END diff --git a/PCbuild/_bz2.vcxproj b/PCbuild/_bz2.vcxproj --- a/PCbuild/_bz2.vcxproj +++ b/PCbuild/_bz2.vcxproj @@ -84,6 +84,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_ctypes.vcxproj b/PCbuild/_ctypes.vcxproj --- a/PCbuild/_ctypes.vcxproj +++ b/PCbuild/_ctypes.vcxproj @@ -97,6 +97,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} diff --git a/PCbuild/_ctypes_test.vcxproj b/PCbuild/_ctypes_test.vcxproj --- a/PCbuild/_ctypes_test.vcxproj +++ b/PCbuild/_ctypes_test.vcxproj @@ -67,6 +67,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} diff --git a/PCbuild/_decimal.vcxproj b/PCbuild/_decimal.vcxproj --- a/PCbuild/_decimal.vcxproj +++ b/PCbuild/_decimal.vcxproj @@ -114,6 +114,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} diff --git a/PCbuild/_elementtree.vcxproj b/PCbuild/_elementtree.vcxproj --- a/PCbuild/_elementtree.vcxproj +++ b/PCbuild/_elementtree.vcxproj @@ -92,6 +92,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_hashlib.vcxproj b/PCbuild/_hashlib.vcxproj --- a/PCbuild/_hashlib.vcxproj +++ b/PCbuild/_hashlib.vcxproj @@ -71,6 +71,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_lzma.vcxproj b/PCbuild/_lzma.vcxproj --- a/PCbuild/_lzma.vcxproj +++ b/PCbuild/_lzma.vcxproj @@ -74,6 +74,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_msi.vcxproj b/PCbuild/_msi.vcxproj --- a/PCbuild/_msi.vcxproj +++ b/PCbuild/_msi.vcxproj @@ -69,6 +69,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_multiprocessing.vcxproj b/PCbuild/_multiprocessing.vcxproj --- a/PCbuild/_multiprocessing.vcxproj +++ b/PCbuild/_multiprocessing.vcxproj @@ -73,6 +73,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_overlapped.vcxproj b/PCbuild/_overlapped.vcxproj --- a/PCbuild/_overlapped.vcxproj +++ b/PCbuild/_overlapped.vcxproj @@ -69,6 +69,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_socket.vcxproj b/PCbuild/_socket.vcxproj --- a/PCbuild/_socket.vcxproj +++ b/PCbuild/_socket.vcxproj @@ -72,6 +72,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_sqlite3.vcxproj b/PCbuild/_sqlite3.vcxproj --- a/PCbuild/_sqlite3.vcxproj +++ b/PCbuild/_sqlite3.vcxproj @@ -91,6 +91,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_ssl.vcxproj b/PCbuild/_ssl.vcxproj --- a/PCbuild/_ssl.vcxproj +++ b/PCbuild/_ssl.vcxproj @@ -71,6 +71,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_testbuffer.vcxproj b/PCbuild/_testbuffer.vcxproj --- a/PCbuild/_testbuffer.vcxproj +++ b/PCbuild/_testbuffer.vcxproj @@ -69,6 +69,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} diff --git a/PCbuild/_testcapi.vcxproj b/PCbuild/_testcapi.vcxproj --- a/PCbuild/_testcapi.vcxproj +++ b/PCbuild/_testcapi.vcxproj @@ -69,6 +69,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_testembed.vcxproj b/PCbuild/_testembed.vcxproj --- a/PCbuild/_testembed.vcxproj +++ b/PCbuild/_testembed.vcxproj @@ -66,6 +66,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_testimportmultiple.vcxproj b/PCbuild/_testimportmultiple.vcxproj --- a/PCbuild/_testimportmultiple.vcxproj +++ b/PCbuild/_testimportmultiple.vcxproj @@ -69,6 +69,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_testmultiphase.vcxproj b/PCbuild/_testmultiphase.vcxproj --- a/PCbuild/_testmultiphase.vcxproj +++ b/PCbuild/_testmultiphase.vcxproj @@ -69,6 +69,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/_tkinter.vcxproj b/PCbuild/_tkinter.vcxproj --- a/PCbuild/_tkinter.vcxproj +++ b/PCbuild/_tkinter.vcxproj @@ -74,6 +74,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/pyexpat.vcxproj b/PCbuild/pyexpat.vcxproj --- a/PCbuild/pyexpat.vcxproj +++ b/PCbuild/pyexpat.vcxproj @@ -73,6 +73,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/pylauncher.vcxproj b/PCbuild/pylauncher.vcxproj --- a/PCbuild/pylauncher.vcxproj +++ b/PCbuild/pylauncher.vcxproj @@ -38,7 +38,6 @@ {7B2727B5-5A3F-40EE-A866-43A13CD31446} pylauncher py - ClCompile false diff --git a/PCbuild/pyproject.props b/PCbuild/pyproject.props --- a/PCbuild/pyproject.props +++ b/PCbuild/pyproject.props @@ -75,7 +75,7 @@ true - $(PySourcePath)PC;$(PySourcePath)Include;%(AdditionalIncludeDirectories) + $(PySourcePath)PC;$(PySourcePath)Include;$(IntDir);%(AdditionalIncludeDirectories) $(_DebugPreprocessorDefinition)%(PreprocessorDefinitions) 0x0409 @@ -92,17 +92,17 @@ - - + diff --git a/PCbuild/python.vcxproj b/PCbuild/python.vcxproj --- a/PCbuild/python.vcxproj +++ b/PCbuild/python.vcxproj @@ -36,7 +36,6 @@ {B11D750F-CD1F-4A96-85CE-E69A5C5259F9} - ClCompile diff --git a/PCbuild/python3dll.vcxproj b/PCbuild/python3dll.vcxproj --- a/PCbuild/python3dll.vcxproj +++ b/PCbuild/python3dll.vcxproj @@ -39,7 +39,6 @@ python3dll Win32Proj python3 - ClCompile false diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -48,7 +48,6 @@ - ClCompile true diff --git a/PCbuild/pythonw.vcxproj b/PCbuild/pythonw.vcxproj --- a/PCbuild/pythonw.vcxproj +++ b/PCbuild/pythonw.vcxproj @@ -36,7 +36,6 @@ {F4229CC3-873C-49AE-9729-DD308ED4CD4A} - ClCompile false diff --git a/PCbuild/pywlauncher.vcxproj b/PCbuild/pywlauncher.vcxproj --- a/PCbuild/pywlauncher.vcxproj +++ b/PCbuild/pywlauncher.vcxproj @@ -38,7 +38,6 @@ {1D4B18D3-7C12-4ECB-9179-8531FF876CE6} pywlauncher pyw - ClCompile false diff --git a/PCbuild/select.vcxproj b/PCbuild/select.vcxproj --- a/PCbuild/select.vcxproj +++ b/PCbuild/select.vcxproj @@ -68,6 +68,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/sqlite3.vcxproj b/PCbuild/sqlite3.vcxproj --- a/PCbuild/sqlite3.vcxproj +++ b/PCbuild/sqlite3.vcxproj @@ -56,6 +56,12 @@ <_ProjectFileVersion>10.0.30319.1 + <_SqliteVersion>$([System.Text.RegularExpressions.Regex]::Match(`$(sqlite3Dir)`, `((\d+)\.(\d+)\.(\d+)\.(\d+))\\?$`).Groups) + $(_SqliteVersion.Split(`;`)[1]) + $(_SqliteVersion.Split(`;`)[2]) + $(_SqliteVersion.Split(`;`)[3]) + $(_SqliteVersion.Split(`;`)[4]) + $(_SqliteVersion.Split(`;`)[5]) @@ -63,6 +69,9 @@ SQLITE_API=__declspec(dllexport);%(PreprocessorDefinitions) Level1 + + SQLITE_VERSION=$(SqliteVersion);SQLITE_MAJOR_VERSION=$(SqliteMajorVersion);SQLITE_MINOR_VERSION=$(SqliteMinorVersion);SQLITE_MICRO_VERSION=$(SqliteMicroVersion);SQLITE_PATCH_VERSION=$(SqlitePatchVersion);%(PreprocessorDefinitions) + @@ -71,6 +80,9 @@ + + + diff --git a/PCbuild/unicodedata.vcxproj b/PCbuild/unicodedata.vcxproj --- a/PCbuild/unicodedata.vcxproj +++ b/PCbuild/unicodedata.vcxproj @@ -72,6 +72,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false diff --git a/PCbuild/winsound.vcxproj b/PCbuild/winsound.vcxproj --- a/PCbuild/winsound.vcxproj +++ b/PCbuild/winsound.vcxproj @@ -68,6 +68,9 @@ + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 6 15:55:50 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 06 Apr 2016 19:55:50 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326671=3A_Fixed_?= =?utf-8?q?=23ifdef_indentation=2E?= Message-ID: <20160406195549.32751.46477.582B2E03@psf.io> https://hg.python.org/cpython/rev/8dc144e47252 changeset: 100863:8dc144e47252 user: Serhiy Storchaka date: Wed Apr 06 22:55:31 2016 +0300 summary: Issue #26671: Fixed #ifdef indentation. files: Modules/posixmodule.c | 28 ++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -884,11 +884,11 @@ #endif } else if (PyObject_CheckBuffer(o)) { -# ifdef MS_WINDOWS +#ifdef MS_WINDOWS if (win32_warn_bytes_api()) { return 0; } -# endif +#endif bytes = PyBytes_FromObject(o); if (!bytes) { return 0; @@ -905,6 +905,30 @@ return 1; } else { + PyObject *pathattr; + _Py_IDENTIFIER(path); + + pathattr = _PyObject_GetAttrId(o, &PyId_path); + if (pathattr == NULL) { + PyErr_Clear(); + } + else if (PyUnicode_Check(pathattr) || PyObject_CheckBuffer(pathattr)) { + if (!path_converter(pathattr, path)) { + Py_DECREF(pathattr); + return 0; + } + if (path->cleanup == NULL) { + path->cleanup = pathattr; + } + else { + Py_DECREF(pathattr); + } + return Py_CLEANUP_SUPPORTED; + } + else { + Py_DECREF(pathattr); + } + PyErr_Format(PyExc_TypeError, "%s%s%s should be %s, not %.200s", path->function_name ? path->function_name : "", path->function_name ? ": " : "", -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 6 16:03:05 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 06 Apr 2016 20:03:05 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326671=3A_Fixed_?= =?utf-8?q?=23ifdef_indentation=2E?= Message-ID: <20160406200305.9106.70690.836C1C96@psf.io> https://hg.python.org/cpython/rev/4acdb324a430 changeset: 100865:4acdb324a430 user: Serhiy Storchaka date: Wed Apr 06 23:02:46 2016 +0300 summary: Issue #26671: Fixed #ifdef indentation. files: Modules/posixmodule.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -884,11 +884,11 @@ #endif } else if (PyObject_CheckBuffer(o)) { -# ifdef MS_WINDOWS +#ifdef MS_WINDOWS if (win32_warn_bytes_api()) { return 0; } -# endif +#endif bytes = PyBytes_FromObject(o); if (!bytes) { return 0; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 6 16:03:07 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 06 Apr 2016 20:03:07 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Backed_out_changeset_8dc14?= =?utf-8?q?4e47252?= Message-ID: <20160406200305.52261.25480.BD291F60@psf.io> https://hg.python.org/cpython/rev/47b2cdd6c186 changeset: 100864:47b2cdd6c186 user: Serhiy Storchaka date: Wed Apr 06 23:02:25 2016 +0300 summary: Backed out changeset 8dc144e47252 files: Modules/posixmodule.c | 28 ++-------------------------- 1 files changed, 2 insertions(+), 26 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -884,11 +884,11 @@ #endif } else if (PyObject_CheckBuffer(o)) { -#ifdef MS_WINDOWS +# ifdef MS_WINDOWS if (win32_warn_bytes_api()) { return 0; } -#endif +# endif bytes = PyBytes_FromObject(o); if (!bytes) { return 0; @@ -905,30 +905,6 @@ return 1; } else { - PyObject *pathattr; - _Py_IDENTIFIER(path); - - pathattr = _PyObject_GetAttrId(o, &PyId_path); - if (pathattr == NULL) { - PyErr_Clear(); - } - else if (PyUnicode_Check(pathattr) || PyObject_CheckBuffer(pathattr)) { - if (!path_converter(pathattr, path)) { - Py_DECREF(pathattr); - return 0; - } - if (path->cleanup == NULL) { - path->cleanup = pathattr; - } - else { - Py_DECREF(pathattr); - } - return Py_CLEANUP_SUPPORTED; - } - else { - Py_DECREF(pathattr); - } - PyErr_Format(PyExc_TypeError, "%s%s%s should be %s, not %.200s", path->function_name ? path->function_name : "", path->function_name ? ": " : "", -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Thu Apr 7 05:46:07 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 07 Apr 2016 09:46:07 +0000 Subject: [Python-checkins] Daily reference leaks (4acdb324a430): sum=49 Message-ID: <20160407094607.80206.72348.CA7FEE3C@psf.io> results for 4acdb324a430 on branch "default" -------------------------------------------- test_asyncio leaked [34, 0, 0] references, sum=34 test_asyncio leaked [11, 0, 0] memory blocks, sum=11 test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogbEx2f0', '--timeout', '7200'] From python-checkins at python.org Fri Apr 8 01:32:33 2016 From: python-checkins at python.org (martin.panter) Date: Fri, 08 Apr 2016 05:32:33 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2MjU3?= =?utf-8?q?=3A_Eliminate_buffer=5Ftests=2Epy_and_fix_ByteArrayAsStringTest?= Message-ID: <20160408053232.24980.88382.ED5E339A@psf.io> https://hg.python.org/cpython/rev/197e1f8b28b7 changeset: 100866:197e1f8b28b7 branch: 3.5 parent: 100861:f191c438d108 user: Martin Panter date: Wed Apr 06 06:37:17 2016 +0000 summary: Issue #26257: Eliminate buffer_tests.py and fix ByteArrayAsStringTest ByteArrayAsStringTest.fixtype() was converting test data to bytes, not byte- array, therefore many of the test cases inherited in this class were not actually being run on the bytearray type. The tests in buffer_tests.py were redundant with methods in string_tests .MixinStrUnicodeUserStringTest and string_tests.CommonTest. These methods are now moved into string_tests.BaseTest, where they will also get run for bytes and bytearray. This change also moves test_additional_split(), test_additional_rsplit(), and test_strip() from CommonTest to BaseTest, meaning these tests are now run for bytes and bytearray. I plan to eliminate redundancies with existing tests in test_bytes.py soon. files: Lib/test/buffer_tests.py | 176 --------------------------- Lib/test/string_tests.py | 76 ++++++----- Lib/test/test_bytes.py | 15 +- Lib/test/test_unicode.py | 16 +- 4 files changed, 54 insertions(+), 229 deletions(-) diff --git a/Lib/test/buffer_tests.py b/Lib/test/buffer_tests.py deleted file mode 100644 --- a/Lib/test/buffer_tests.py +++ /dev/null @@ -1,176 +0,0 @@ -# Tests that work for bytearray objects. Could be merged into string_tests. -# See PEP 3137. - -class MixinBytesBufferCommonTests(object): - """Tests that work for bytearray objects. - See PEP 3137. - """ - - def marshal(self, x): - """Convert x into the appropriate type for these tests.""" - raise RuntimeError('test class must provide a marshal method') - - def test_islower(self): - self.assertFalse(self.marshal(b'').islower()) - self.assertTrue(self.marshal(b'a').islower()) - self.assertFalse(self.marshal(b'A').islower()) - self.assertFalse(self.marshal(b'\n').islower()) - self.assertTrue(self.marshal(b'abc').islower()) - self.assertFalse(self.marshal(b'aBc').islower()) - self.assertTrue(self.marshal(b'abc\n').islower()) - self.assertRaises(TypeError, self.marshal(b'abc').islower, 42) - - def test_isupper(self): - self.assertFalse(self.marshal(b'').isupper()) - self.assertFalse(self.marshal(b'a').isupper()) - self.assertTrue(self.marshal(b'A').isupper()) - self.assertFalse(self.marshal(b'\n').isupper()) - self.assertTrue(self.marshal(b'ABC').isupper()) - self.assertFalse(self.marshal(b'AbC').isupper()) - self.assertTrue(self.marshal(b'ABC\n').isupper()) - self.assertRaises(TypeError, self.marshal(b'abc').isupper, 42) - - def test_istitle(self): - self.assertFalse(self.marshal(b'').istitle()) - self.assertFalse(self.marshal(b'a').istitle()) - self.assertTrue(self.marshal(b'A').istitle()) - self.assertFalse(self.marshal(b'\n').istitle()) - self.assertTrue(self.marshal(b'A Titlecased Line').istitle()) - self.assertTrue(self.marshal(b'A\nTitlecased Line').istitle()) - self.assertTrue(self.marshal(b'A Titlecased, Line').istitle()) - self.assertFalse(self.marshal(b'Not a capitalized String').istitle()) - self.assertFalse(self.marshal(b'Not\ta Titlecase String').istitle()) - self.assertFalse(self.marshal(b'Not--a Titlecase String').istitle()) - self.assertFalse(self.marshal(b'NOT').istitle()) - self.assertRaises(TypeError, self.marshal(b'abc').istitle, 42) - - def test_isspace(self): - self.assertFalse(self.marshal(b'').isspace()) - self.assertFalse(self.marshal(b'a').isspace()) - self.assertTrue(self.marshal(b' ').isspace()) - self.assertTrue(self.marshal(b'\t').isspace()) - self.assertTrue(self.marshal(b'\r').isspace()) - self.assertTrue(self.marshal(b'\n').isspace()) - self.assertTrue(self.marshal(b' \t\r\n').isspace()) - self.assertFalse(self.marshal(b' \t\r\na').isspace()) - self.assertRaises(TypeError, self.marshal(b'abc').isspace, 42) - - def test_isalpha(self): - self.assertFalse(self.marshal(b'').isalpha()) - self.assertTrue(self.marshal(b'a').isalpha()) - self.assertTrue(self.marshal(b'A').isalpha()) - self.assertFalse(self.marshal(b'\n').isalpha()) - self.assertTrue(self.marshal(b'abc').isalpha()) - self.assertFalse(self.marshal(b'aBc123').isalpha()) - self.assertFalse(self.marshal(b'abc\n').isalpha()) - self.assertRaises(TypeError, self.marshal(b'abc').isalpha, 42) - - def test_isalnum(self): - self.assertFalse(self.marshal(b'').isalnum()) - self.assertTrue(self.marshal(b'a').isalnum()) - self.assertTrue(self.marshal(b'A').isalnum()) - self.assertFalse(self.marshal(b'\n').isalnum()) - self.assertTrue(self.marshal(b'123abc456').isalnum()) - self.assertTrue(self.marshal(b'a1b3c').isalnum()) - self.assertFalse(self.marshal(b'aBc000 ').isalnum()) - self.assertFalse(self.marshal(b'abc\n').isalnum()) - self.assertRaises(TypeError, self.marshal(b'abc').isalnum, 42) - - def test_isdigit(self): - self.assertFalse(self.marshal(b'').isdigit()) - self.assertFalse(self.marshal(b'a').isdigit()) - self.assertTrue(self.marshal(b'0').isdigit()) - self.assertTrue(self.marshal(b'0123456789').isdigit()) - self.assertFalse(self.marshal(b'0123456789a').isdigit()) - - self.assertRaises(TypeError, self.marshal(b'abc').isdigit, 42) - - def test_capitalize(self): - self.assertEqual(b' hello ', self.marshal(b' hello ').capitalize()) - self.assertEqual(b'Hello ', self.marshal(b'Hello ').capitalize()) - self.assertEqual(b'Hello ', self.marshal(b'hello ').capitalize()) - self.assertEqual(b'Aaaa', self.marshal(b'aaaa').capitalize()) - self.assertEqual(b'Aaaa', self.marshal(b'AaAa').capitalize()) - - self.assertRaises(TypeError, self.marshal(b'hello').capitalize, 42) - - def test_ljust(self): - self.assertEqual(b'abc ', self.marshal(b'abc').ljust(10)) - self.assertEqual(b'abc ', self.marshal(b'abc').ljust(6)) - self.assertEqual(b'abc', self.marshal(b'abc').ljust(3)) - self.assertEqual(b'abc', self.marshal(b'abc').ljust(2)) - self.assertEqual(b'abc*******', self.marshal(b'abc').ljust(10, b'*')) - self.assertRaises(TypeError, self.marshal(b'abc').ljust) - - def test_rjust(self): - self.assertEqual(b' abc', self.marshal(b'abc').rjust(10)) - self.assertEqual(b' abc', self.marshal(b'abc').rjust(6)) - self.assertEqual(b'abc', self.marshal(b'abc').rjust(3)) - self.assertEqual(b'abc', self.marshal(b'abc').rjust(2)) - self.assertEqual(b'*******abc', self.marshal(b'abc').rjust(10, b'*')) - self.assertRaises(TypeError, self.marshal(b'abc').rjust) - - def test_center(self): - self.assertEqual(b' abc ', self.marshal(b'abc').center(10)) - self.assertEqual(b' abc ', self.marshal(b'abc').center(6)) - self.assertEqual(b'abc', self.marshal(b'abc').center(3)) - self.assertEqual(b'abc', self.marshal(b'abc').center(2)) - self.assertEqual(b'***abc****', self.marshal(b'abc').center(10, b'*')) - self.assertRaises(TypeError, self.marshal(b'abc').center) - - def test_swapcase(self): - self.assertEqual(b'hEllO CoMPuTErS', - self.marshal(b'HeLLo cOmpUteRs').swapcase()) - - self.assertRaises(TypeError, self.marshal(b'hello').swapcase, 42) - - def test_zfill(self): - self.assertEqual(b'123', self.marshal(b'123').zfill(2)) - self.assertEqual(b'123', self.marshal(b'123').zfill(3)) - self.assertEqual(b'0123', self.marshal(b'123').zfill(4)) - self.assertEqual(b'+123', self.marshal(b'+123').zfill(3)) - self.assertEqual(b'+123', self.marshal(b'+123').zfill(4)) - self.assertEqual(b'+0123', self.marshal(b'+123').zfill(5)) - self.assertEqual(b'-123', self.marshal(b'-123').zfill(3)) - self.assertEqual(b'-123', self.marshal(b'-123').zfill(4)) - self.assertEqual(b'-0123', self.marshal(b'-123').zfill(5)) - self.assertEqual(b'000', self.marshal(b'').zfill(3)) - self.assertEqual(b'34', self.marshal(b'34').zfill(1)) - self.assertEqual(b'0034', self.marshal(b'34').zfill(4)) - - self.assertRaises(TypeError, self.marshal(b'123').zfill) - - def test_title(self): - self.assertEqual(b' Hello ', self.marshal(b' hello ').title()) - self.assertEqual(b'Hello ', self.marshal(b'hello ').title()) - self.assertEqual(b'Hello ', self.marshal(b'Hello ').title()) - self.assertEqual(b'Format This As Title String', - self.marshal(b'fOrMaT thIs aS titLe String').title()) - self.assertEqual(b'Format,This-As*Title;String', - self.marshal(b'fOrMaT,thIs-aS*titLe;String').title()) - self.assertEqual(b'Getint', self.marshal(b'getInt').title()) - self.assertRaises(TypeError, self.marshal(b'hello').title, 42) - - def test_splitlines(self): - self.assertEqual([b'abc', b'def', b'', b'ghi'], - self.marshal(b'abc\ndef\n\rghi').splitlines()) - self.assertEqual([b'abc', b'def', b'', b'ghi'], - self.marshal(b'abc\ndef\n\r\nghi').splitlines()) - self.assertEqual([b'abc', b'def', b'ghi'], - self.marshal(b'abc\ndef\r\nghi').splitlines()) - self.assertEqual([b'abc', b'def', b'ghi'], - self.marshal(b'abc\ndef\r\nghi\n').splitlines()) - self.assertEqual([b'abc', b'def', b'ghi', b''], - self.marshal(b'abc\ndef\r\nghi\n\r').splitlines()) - self.assertEqual([b'', b'abc', b'def', b'ghi', b''], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines()) - self.assertEqual([b'', b'abc', b'def', b'ghi', b''], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(False)) - self.assertEqual([b'\n', b'abc\n', b'def\r\n', b'ghi\n', b'\r'], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(True)) - self.assertEqual([b'', b'abc', b'def', b'ghi', b''], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(keepends=False)) - self.assertEqual([b'\n', b'abc\n', b'def\r\n', b'ghi\n', b'\r'], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(keepends=True)) - - self.assertRaises(TypeError, self.marshal(b'abc').splitlines, 42, 42) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -51,6 +51,9 @@ else: return obj + def test_fixtype(self): + self.assertIs(type(self.fixtype("123")), self.type2test) + # check that obj.method(*args) returns result def checkequal(self, result, obj, methodname, *args, **kwargs): result = self.fixtype(result) @@ -682,21 +685,6 @@ self.checkraises(OverflowError, A2_16, "replace", "A", A2_16) self.checkraises(OverflowError, A2_16, "replace", "AA", A2_16+A2_16) - - -class CommonTest(BaseTest): - # This testcase contains tests that can be used in all - # stringlike classes. Currently this is str and UserString. - - def test_hash(self): - # SF bug 1054139: += optimization was not invalidating cached hash value - a = self.type2test('DNSSEC') - b = self.type2test('') - for c in a: - b += c - hash(b) - self.assertEqual(hash(a), hash(b)) - def test_capitalize(self): self.checkequal(' hello ', ' hello ', 'capitalize') self.checkequal('Hello ', 'Hello ','capitalize') @@ -704,23 +692,6 @@ self.checkequal('Aaaa', 'aaaa', 'capitalize') self.checkequal('Aaaa', 'AaAa', 'capitalize') - # check that titlecased chars are lowered correctly - # \u1ffc is the titlecased char - self.checkequal('\u03a9\u0399\u1ff3\u1ff3\u1ff3', - '\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize') - # check with cased non-letter chars - self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', - '\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize') - self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', - '\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize') - self.checkequal('\u2160\u2171\u2172', - '\u2160\u2161\u2162', 'capitalize') - self.checkequal('\u2160\u2171\u2172', - '\u2170\u2171\u2172', 'capitalize') - # check with Ll chars with no upper - nothing changes here - self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7', - '\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize') - self.checkraises(TypeError, 'hello', 'capitalize', 42) def test_additional_split(self): @@ -854,10 +825,6 @@ self.checkraises(TypeError, '123', 'zfill') -class MixinStrUnicodeUserStringTest: - # additional tests that only work for - # stringlike objects, i.e. str, UserString - def test_islower(self): self.checkequal(False, '', 'islower') self.checkequal(True, 'a', 'islower') @@ -960,6 +927,43 @@ self.checkraises(TypeError, 'abc', 'splitlines', 42, 42) + +class CommonTest(BaseTest): + # This testcase contains tests that can be used in all + # stringlike classes. Currently this is str and UserString. + + def test_hash(self): + # SF bug 1054139: += optimization was not invalidating cached hash value + a = self.type2test('DNSSEC') + b = self.type2test('') + for c in a: + b += c + hash(b) + self.assertEqual(hash(a), hash(b)) + + def test_capitalize_nonascii(self): + # check that titlecased chars are lowered correctly + # \u1ffc is the titlecased char + self.checkequal('\u03a9\u0399\u1ff3\u1ff3\u1ff3', + '\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize') + # check with cased non-letter chars + self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', + '\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize') + self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', + '\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize') + self.checkequal('\u2160\u2171\u2172', + '\u2160\u2161\u2162', 'capitalize') + self.checkequal('\u2160\u2171\u2172', + '\u2170\u2171\u2172', 'capitalize') + # check with Ll chars with no upper - nothing changes here + self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7', + '\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize') + + +class MixinStrUnicodeUserStringTest: + # additional tests that only work for + # stringlike objects, i.e. str, UserString + def test_startswith(self): self.checkequal(True, 'hello', 'startswith', 'he') self.checkequal(True, 'hello', 'startswith', 'hello') diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -1,8 +1,7 @@ """Unit tests for the bytes and bytearray types. -XXX This is a mess. Common tests should be moved to buffer_tests.py, -which itself ought to be unified with string_tests.py (and the latter -should be modernized). +XXX This is a mess. Common tests should be unified with string_tests.py (and +the latter should be modernized). """ import os @@ -16,7 +15,6 @@ import test.support import test.string_tests -import test.buffer_tests import test.list_tests from test.support import bigaddrspacetest, MAX_Py_ssize_t @@ -1480,8 +1478,7 @@ # the rest that make sense (the code can be cleaned up to use modern # unittest methods at the same time). -class BytearrayPEP3137Test(unittest.TestCase, - test.buffer_tests.MixinBytesBufferCommonTests): +class BytearrayPEP3137Test(unittest.TestCase): def marshal(self, x): return bytearray(x) @@ -1511,16 +1508,16 @@ class FixedStringTest(test.string_tests.BaseTest): def fixtype(self, obj): if isinstance(obj, str): - return obj.encode("utf-8") + return self.type2test(obj.encode("utf-8")) return super().fixtype(obj) + contains_bytes = True + class ByteArrayAsStringTest(FixedStringTest, unittest.TestCase): type2test = bytearray - contains_bytes = True class BytesAsStringTest(FixedStringTest, unittest.TestCase): type2test = bytes - contains_bytes = True class SubclassTest: diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -565,7 +565,7 @@ self.assertTrue('\ud800\udc02' < '\ud84d\udc56') def test_islower(self): - string_tests.MixinStrUnicodeUserStringTest.test_islower(self) + super().test_islower() self.checkequalnofix(False, '\u1FFc', 'islower') self.assertFalse('\u2167'.islower()) self.assertTrue('\u2177'.islower()) @@ -580,7 +580,7 @@ self.assertFalse('\U0001F46F'.islower()) def test_isupper(self): - string_tests.MixinStrUnicodeUserStringTest.test_isupper(self) + super().test_isupper() if not sys.platform.startswith('java'): self.checkequalnofix(False, '\u1FFc', 'isupper') self.assertTrue('\u2167'.isupper()) @@ -596,7 +596,7 @@ self.assertFalse('\U0001F46F'.isupper()) def test_istitle(self): - string_tests.MixinStrUnicodeUserStringTest.test_istitle(self) + super().test_istitle() self.checkequalnofix(True, '\u1FFc', 'istitle') self.checkequalnofix(True, 'Greek \u1FFcitlecases ...', 'istitle') @@ -608,7 +608,7 @@ self.assertFalse(ch.istitle(), '{!a} is not title'.format(ch)) def test_isspace(self): - string_tests.MixinStrUnicodeUserStringTest.test_isspace(self) + super().test_isspace() self.checkequalnofix(True, '\u2000', 'isspace') self.checkequalnofix(True, '\u200a', 'isspace') self.checkequalnofix(False, '\u2014', 'isspace') @@ -618,13 +618,13 @@ self.assertFalse(ch.isspace(), '{!a} is not space.'.format(ch)) def test_isalnum(self): - string_tests.MixinStrUnicodeUserStringTest.test_isalnum(self) + super().test_isalnum() for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E', '\U0001D7F6', '\U00011066', '\U000104A0', '\U0001F107']: self.assertTrue(ch.isalnum(), '{!a} is alnum.'.format(ch)) def test_isalpha(self): - string_tests.MixinStrUnicodeUserStringTest.test_isalpha(self) + super().test_isalpha() self.checkequalnofix(True, '\u1FFc', 'isalpha') # non-BMP, cased self.assertTrue('\U00010401'.isalpha()) @@ -654,7 +654,7 @@ self.assertTrue(ch.isdecimal(), '{!a} is decimal.'.format(ch)) def test_isdigit(self): - string_tests.MixinStrUnicodeUserStringTest.test_isdigit(self) + super().test_isdigit() self.checkequalnofix(True, '\u2460', 'isdigit') self.checkequalnofix(False, '\xbc', 'isdigit') self.checkequalnofix(True, '\u0660', 'isdigit') @@ -807,7 +807,7 @@ self.assertEqual('A\u0345\u03a3'.capitalize(), 'A\u0345\u03c2') def test_title(self): - string_tests.MixinStrUnicodeUserStringTest.test_title(self) + super().test_title() self.assertEqual('\U0001044F'.title(), '\U00010427') self.assertEqual('\U0001044F\U0001044F'.title(), '\U00010427\U0001044F') -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 8 01:32:34 2016 From: python-checkins at python.org (martin.panter) Date: Fri, 08 Apr 2016 05:32:34 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2MjU3?= =?utf-8?q?=3A_Eliminate_buffer=5Ftests=2Epy_and_fix_ByteArrayAsStringTest?= Message-ID: <20160408053233.24954.2310.FB61EA36@psf.io> https://hg.python.org/cpython/rev/26f1543e806c changeset: 100868:26f1543e806c branch: 2.7 parent: 100859:7197809a7428 user: Martin Panter date: Wed Apr 06 06:37:17 2016 +0000 summary: Issue #26257: Eliminate buffer_tests.py and fix ByteArrayAsStringTest ByteArrayAsStringTest.fixtype() was converting test data to bytes, not byte- array, therefore many of the test cases inherited in this class were not actually being run on the bytearray type. The tests in buffer_tests.py were redundant with methods in string_tests .MixinStrUnicodeUserStringTest and string_tests.CommonTest. Moved some tests into a new base class string_tests.NonStringModuleTest, and run them for bytearray. files: Lib/test/buffer_tests.py | 206 --------------------------- Lib/test/string_tests.py | 47 ++++- Lib/test/test_bytes.py | 22 +-- 3 files changed, 41 insertions(+), 234 deletions(-) diff --git a/Lib/test/buffer_tests.py b/Lib/test/buffer_tests.py deleted file mode 100644 --- a/Lib/test/buffer_tests.py +++ /dev/null @@ -1,206 +0,0 @@ -# Tests that work for both bytes and buffer objects. -# See PEP 3137. - -import struct -import sys - -class MixinBytesBufferCommonTests(object): - """Tests that work for both bytes and buffer objects. - See PEP 3137. - """ - - def marshal(self, x): - """Convert x into the appropriate type for these tests.""" - raise RuntimeError('test class must provide a marshal method') - - def test_islower(self): - self.assertFalse(self.marshal(b'').islower()) - self.assertTrue(self.marshal(b'a').islower()) - self.assertFalse(self.marshal(b'A').islower()) - self.assertFalse(self.marshal(b'\n').islower()) - self.assertTrue(self.marshal(b'abc').islower()) - self.assertFalse(self.marshal(b'aBc').islower()) - self.assertTrue(self.marshal(b'abc\n').islower()) - self.assertRaises(TypeError, self.marshal(b'abc').islower, 42) - - def test_isupper(self): - self.assertFalse(self.marshal(b'').isupper()) - self.assertFalse(self.marshal(b'a').isupper()) - self.assertTrue(self.marshal(b'A').isupper()) - self.assertFalse(self.marshal(b'\n').isupper()) - self.assertTrue(self.marshal(b'ABC').isupper()) - self.assertFalse(self.marshal(b'AbC').isupper()) - self.assertTrue(self.marshal(b'ABC\n').isupper()) - self.assertRaises(TypeError, self.marshal(b'abc').isupper, 42) - - def test_istitle(self): - self.assertFalse(self.marshal(b'').istitle()) - self.assertFalse(self.marshal(b'a').istitle()) - self.assertTrue(self.marshal(b'A').istitle()) - self.assertFalse(self.marshal(b'\n').istitle()) - self.assertTrue(self.marshal(b'A Titlecased Line').istitle()) - self.assertTrue(self.marshal(b'A\nTitlecased Line').istitle()) - self.assertTrue(self.marshal(b'A Titlecased, Line').istitle()) - self.assertFalse(self.marshal(b'Not a capitalized String').istitle()) - self.assertFalse(self.marshal(b'Not\ta Titlecase String').istitle()) - self.assertFalse(self.marshal(b'Not--a Titlecase String').istitle()) - self.assertFalse(self.marshal(b'NOT').istitle()) - self.assertRaises(TypeError, self.marshal(b'abc').istitle, 42) - - def test_isspace(self): - self.assertFalse(self.marshal(b'').isspace()) - self.assertFalse(self.marshal(b'a').isspace()) - self.assertTrue(self.marshal(b' ').isspace()) - self.assertTrue(self.marshal(b'\t').isspace()) - self.assertTrue(self.marshal(b'\r').isspace()) - self.assertTrue(self.marshal(b'\n').isspace()) - self.assertTrue(self.marshal(b' \t\r\n').isspace()) - self.assertFalse(self.marshal(b' \t\r\na').isspace()) - self.assertRaises(TypeError, self.marshal(b'abc').isspace, 42) - - def test_isalpha(self): - self.assertFalse(self.marshal(b'').isalpha()) - self.assertTrue(self.marshal(b'a').isalpha()) - self.assertTrue(self.marshal(b'A').isalpha()) - self.assertFalse(self.marshal(b'\n').isalpha()) - self.assertTrue(self.marshal(b'abc').isalpha()) - self.assertFalse(self.marshal(b'aBc123').isalpha()) - self.assertFalse(self.marshal(b'abc\n').isalpha()) - self.assertRaises(TypeError, self.marshal(b'abc').isalpha, 42) - - def test_isalnum(self): - self.assertFalse(self.marshal(b'').isalnum()) - self.assertTrue(self.marshal(b'a').isalnum()) - self.assertTrue(self.marshal(b'A').isalnum()) - self.assertFalse(self.marshal(b'\n').isalnum()) - self.assertTrue(self.marshal(b'123abc456').isalnum()) - self.assertTrue(self.marshal(b'a1b3c').isalnum()) - self.assertFalse(self.marshal(b'aBc000 ').isalnum()) - self.assertFalse(self.marshal(b'abc\n').isalnum()) - self.assertRaises(TypeError, self.marshal(b'abc').isalnum, 42) - - def test_isdigit(self): - self.assertFalse(self.marshal(b'').isdigit()) - self.assertFalse(self.marshal(b'a').isdigit()) - self.assertTrue(self.marshal(b'0').isdigit()) - self.assertTrue(self.marshal(b'0123456789').isdigit()) - self.assertFalse(self.marshal(b'0123456789a').isdigit()) - - self.assertRaises(TypeError, self.marshal(b'abc').isdigit, 42) - - def test_lower(self): - self.assertEqual(b'hello', self.marshal(b'HeLLo').lower()) - self.assertEqual(b'hello', self.marshal(b'hello').lower()) - self.assertRaises(TypeError, self.marshal(b'hello').lower, 42) - - def test_upper(self): - self.assertEqual(b'HELLO', self.marshal(b'HeLLo').upper()) - self.assertEqual(b'HELLO', self.marshal(b'HELLO').upper()) - self.assertRaises(TypeError, self.marshal(b'hello').upper, 42) - - def test_capitalize(self): - self.assertEqual(b' hello ', self.marshal(b' hello ').capitalize()) - self.assertEqual(b'Hello ', self.marshal(b'Hello ').capitalize()) - self.assertEqual(b'Hello ', self.marshal(b'hello ').capitalize()) - self.assertEqual(b'Aaaa', self.marshal(b'aaaa').capitalize()) - self.assertEqual(b'Aaaa', self.marshal(b'AaAa').capitalize()) - - self.assertRaises(TypeError, self.marshal(b'hello').capitalize, 42) - - def test_ljust(self): - self.assertEqual(b'abc ', self.marshal(b'abc').ljust(10)) - self.assertEqual(b'abc ', self.marshal(b'abc').ljust(6)) - self.assertEqual(b'abc', self.marshal(b'abc').ljust(3)) - self.assertEqual(b'abc', self.marshal(b'abc').ljust(2)) - self.assertEqual(b'abc*******', self.marshal(b'abc').ljust(10, '*')) - self.assertRaises(TypeError, self.marshal(b'abc').ljust) - - def test_rjust(self): - self.assertEqual(b' abc', self.marshal(b'abc').rjust(10)) - self.assertEqual(b' abc', self.marshal(b'abc').rjust(6)) - self.assertEqual(b'abc', self.marshal(b'abc').rjust(3)) - self.assertEqual(b'abc', self.marshal(b'abc').rjust(2)) - self.assertEqual(b'*******abc', self.marshal(b'abc').rjust(10, '*')) - self.assertRaises(TypeError, self.marshal(b'abc').rjust) - - def test_center(self): - self.assertEqual(b' abc ', self.marshal(b'abc').center(10)) - self.assertEqual(b' abc ', self.marshal(b'abc').center(6)) - self.assertEqual(b'abc', self.marshal(b'abc').center(3)) - self.assertEqual(b'abc', self.marshal(b'abc').center(2)) - self.assertEqual(b'***abc****', self.marshal(b'abc').center(10, '*')) - self.assertRaises(TypeError, self.marshal(b'abc').center) - - def test_swapcase(self): - self.assertEqual(b'hEllO CoMPuTErS', - self.marshal(b'HeLLo cOmpUteRs').swapcase()) - - self.assertRaises(TypeError, self.marshal(b'hello').swapcase, 42) - - def test_zfill(self): - self.assertEqual(b'123', self.marshal(b'123').zfill(2)) - self.assertEqual(b'123', self.marshal(b'123').zfill(3)) - self.assertEqual(b'0123', self.marshal(b'123').zfill(4)) - self.assertEqual(b'+123', self.marshal(b'+123').zfill(3)) - self.assertEqual(b'+123', self.marshal(b'+123').zfill(4)) - self.assertEqual(b'+0123', self.marshal(b'+123').zfill(5)) - self.assertEqual(b'-123', self.marshal(b'-123').zfill(3)) - self.assertEqual(b'-123', self.marshal(b'-123').zfill(4)) - self.assertEqual(b'-0123', self.marshal(b'-123').zfill(5)) - self.assertEqual(b'000', self.marshal(b'').zfill(3)) - self.assertEqual(b'34', self.marshal(b'34').zfill(1)) - self.assertEqual(b'0034', self.marshal(b'34').zfill(4)) - - self.assertRaises(TypeError, self.marshal(b'123').zfill) - - def test_expandtabs(self): - self.assertEqual(b'abc\rab def\ng hi', - self.marshal(b'abc\rab\tdef\ng\thi').expandtabs()) - self.assertEqual(b'abc\rab def\ng hi', - self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(8)) - self.assertEqual(b'abc\rab def\ng hi', - self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(4)) - self.assertEqual(b'abc\r\nab def\ng hi', - self.marshal(b'abc\r\nab\tdef\ng\thi').expandtabs(4)) - self.assertEqual(b'abc\rab def\ng hi', - self.marshal(b'abc\rab\tdef\ng\thi').expandtabs()) - self.assertEqual(b'abc\rab def\ng hi', - self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(8)) - self.assertEqual(b'abc\r\nab\r\ndef\ng\r\nhi', - self.marshal(b'abc\r\nab\r\ndef\ng\r\nhi').expandtabs(4)) - self.assertEqual(b' a\n b', self.marshal(b' \ta\n\tb').expandtabs(1)) - - self.assertRaises(TypeError, self.marshal(b'hello').expandtabs, 42, 42) - # This test is only valid when sizeof(int) == sizeof(void*) == 4. - if sys.maxint < (1 << 32) and struct.calcsize('P') == 4: - self.assertRaises(OverflowError, - self.marshal(b'\ta\n\tb').expandtabs, sys.maxint) - - def test_title(self): - self.assertEqual(b' Hello ', self.marshal(b' hello ').title()) - self.assertEqual(b'Hello ', self.marshal(b'hello ').title()) - self.assertEqual(b'Hello ', self.marshal(b'Hello ').title()) - self.assertEqual(b'Format This As Title String', - self.marshal(b'fOrMaT thIs aS titLe String').title()) - self.assertEqual(b'Format,This-As*Title;String', - self.marshal(b'fOrMaT,thIs-aS*titLe;String').title()) - self.assertEqual(b'Getint', self.marshal(b'getInt').title()) - self.assertRaises(TypeError, self.marshal(b'hello').title, 42) - - def test_splitlines(self): - self.assertEqual([b'abc', b'def', b'', b'ghi'], - self.marshal(b'abc\ndef\n\rghi').splitlines()) - self.assertEqual([b'abc', b'def', b'', b'ghi'], - self.marshal(b'abc\ndef\n\r\nghi').splitlines()) - self.assertEqual([b'abc', b'def', b'ghi'], - self.marshal(b'abc\ndef\r\nghi').splitlines()) - self.assertEqual([b'abc', b'def', b'ghi'], - self.marshal(b'abc\ndef\r\nghi\n').splitlines()) - self.assertEqual([b'abc', b'def', b'ghi', b''], - self.marshal(b'abc\ndef\r\nghi\n\r').splitlines()) - self.assertEqual([b'', b'abc', b'def', b'ghi', b''], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines()) - self.assertEqual([b'\n', b'abc\n', b'def\r\n', b'ghi\n', b'\r'], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(1)) - - self.assertRaises(TypeError, self.marshal(b'abc').splitlines, 42, 42) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -45,6 +45,9 @@ else: return obj + def test_fixtype(self): + self.assertIs(type(self.fixtype("123")), self.type2test) + # check that object.method(*args) returns result def checkequal(self, result, object, methodname, *args): result = self.fixtype(result) @@ -404,7 +407,9 @@ 'split', 'BLAH', 18) # mixed use of str and unicode - self.checkequal([u'a', u'b', u'c d'], 'a b c d', 'split', u' ', 2) + if self.type2test is not bytearray: + result = [u'a', u'b', u'c d'] + self.checkequal(result, 'a b c d', 'split', u' ', 2) # argument type self.checkraises(TypeError, 'hello', 'split', 42, 42, 42) @@ -494,7 +499,9 @@ 'rsplit', 'BLAH', 18) # mixed use of str and unicode - self.checkequal([u'a b', u'c', u'd'], 'a b c d', 'rsplit', u' ', 2) + if self.type2test is not bytearray: + result = [u'a b', u'c', u'd'] + self.checkequal(result, 'a b c d', 'rsplit', u' ', 2) # argument type self.checkraises(TypeError, 'hello', 'rsplit', 42, 42, 42) @@ -522,7 +529,7 @@ self.checkequal('hello', 'hello', 'strip', 'xyz') # strip/lstrip/rstrip with unicode arg - if test_support.have_unicode: + if self.type2test is not bytearray and test_support.have_unicode: self.checkequal(unicode('hello', 'ascii'), 'xyzzyhelloxyzzy', 'strip', unicode('xyz', 'ascii')) self.checkequal(unicode('helloxyzzy', 'ascii'), 'xyzzyhelloxyzzy', @@ -542,7 +549,11 @@ self.checkequal('abc ', 'abc', 'ljust', 6) self.checkequal('abc', 'abc', 'ljust', 3) self.checkequal('abc', 'abc', 'ljust', 2) - self.checkequal('abc*******', 'abc', 'ljust', 10, '*') + if self.type2test is bytearray: + # Special case because bytearray argument is not accepted + self.assertEqual(b'abc*******', bytearray(b'abc').ljust(10, '*')) + else: + self.checkequal('abc*******', 'abc', 'ljust', 10, '*') self.checkraises(TypeError, 'abc', 'ljust') def test_rjust(self): @@ -550,7 +561,11 @@ self.checkequal(' abc', 'abc', 'rjust', 6) self.checkequal('abc', 'abc', 'rjust', 3) self.checkequal('abc', 'abc', 'rjust', 2) - self.checkequal('*******abc', 'abc', 'rjust', 10, '*') + if self.type2test is bytearray: + # Special case because bytearray argument is not accepted + self.assertEqual(b'*******abc', bytearray(b'abc').rjust(10, '*')) + else: + self.checkequal('*******abc', 'abc', 'rjust', 10, '*') self.checkraises(TypeError, 'abc', 'rjust') def test_center(self): @@ -558,7 +573,12 @@ self.checkequal(' abc ', 'abc', 'center', 6) self.checkequal('abc', 'abc', 'center', 3) self.checkequal('abc', 'abc', 'center', 2) - self.checkequal('***abc****', 'abc', 'center', 10, '*') + if self.type2test is bytearray: + # Special case because bytearray argument is not accepted + result = bytearray(b'abc').center(10, '*') + self.assertEqual(b'***abc****', result) + else: + self.checkequal('***abc****', 'abc', 'center', 10, '*') self.checkraises(TypeError, 'abc', 'center') def test_swapcase(self): @@ -772,13 +792,10 @@ self.checkraises(TypeError, '123', 'zfill') -# XXX alias for py3k forward compatibility -BaseTest = CommonTest -class MixinStrUnicodeUserStringTest: - # additional tests that only work for - # stringlike objects, i.e. str, unicode, UserString - # (but not the string module) +class NonStringModuleTest: + # additional test cases for all string classes from bytearray to + # UserString, but not valid for the "string" module def test_islower(self): self.checkequal(False, '', 'islower') @@ -875,6 +892,12 @@ self.checkraises(TypeError, 'abc', 'splitlines', 42, 42) + +class MixinStrUnicodeUserStringTest(NonStringModuleTest): + # additional tests that only work for + # stringlike objects, i.e. str, unicode, UserString + # (but not the string module) + def test_startswith(self): self.checkequal(True, 'hello', 'startswith', 'he') self.checkequal(True, 'hello', 'startswith', 'hello') diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -1,8 +1,7 @@ """Unit tests for the bytes and bytearray types. -XXX This is a mess. Common tests should be moved to buffer_tests.py, -which itself ought to be unified with string_tests.py (and the latter -should be modernized). +XXX This is a mess. Common tests should be unified with string_tests.py (and +the latter should be modernized). """ import os @@ -15,7 +14,6 @@ import unittest import test.test_support import test.string_tests -import test.buffer_tests if sys.flags.bytes_warning: @@ -1030,8 +1028,7 @@ # the rest that make sense (the code can be cleaned up to use modern # unittest methods at the same time). -class BytearrayPEP3137Test(unittest.TestCase, - test.buffer_tests.MixinBytesBufferCommonTests): +class BytearrayPEP3137Test(unittest.TestCase): def marshal(self, x): return bytearray(x) @@ -1053,12 +1050,10 @@ self.assertTrue(val is not newval, expr+' returned val on a mutable object') -class FixedStringTest(test.string_tests.BaseTest): - def fixtype(self, obj): - if isinstance(obj, str): - return obj.encode("utf-8") - return super(FixedStringTest, self).fixtype(obj) +class ByteArrayAsStringTest(test.string_tests.CommonTest, + test.string_tests.NonStringModuleTest): + type2test = bytearray # Currently the bytes containment testing uses a single integer # value. This may not be the final design, but until then the @@ -1076,10 +1071,6 @@ pass -class ByteArrayAsStringTest(FixedStringTest): - type2test = bytearray - - class ByteArraySubclass(bytearray): pass @@ -1160,7 +1151,6 @@ def test_main(): #test.test_support.run_unittest(BytesTest) #test.test_support.run_unittest(AssortedBytesTest) - #test.test_support.run_unittest(BytesAsStringTest) test.test_support.run_unittest( ByteArrayTest, ByteArrayAsStringTest, -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 8 01:32:34 2016 From: python-checkins at python.org (martin.panter) Date: Fri, 08 Apr 2016 05:32:34 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326257=3A_Merge_buffer=5Ftests_cleanup_from_3=2E?= =?utf-8?q?5?= Message-ID: <20160408053232.834.86104.60140F80@psf.io> https://hg.python.org/cpython/rev/ea598d69b7d3 changeset: 100867:ea598d69b7d3 parent: 100865:4acdb324a430 parent: 100866:197e1f8b28b7 user: Martin Panter date: Fri Apr 08 00:16:33 2016 +0000 summary: Issue #26257: Merge buffer_tests cleanup from 3.5 files: Lib/test/buffer_tests.py | 176 --------------------------- Lib/test/string_tests.py | 76 ++++++----- Lib/test/test_bytes.py | 15 +- Lib/test/test_unicode.py | 16 +- 4 files changed, 54 insertions(+), 229 deletions(-) diff --git a/Lib/test/buffer_tests.py b/Lib/test/buffer_tests.py deleted file mode 100644 --- a/Lib/test/buffer_tests.py +++ /dev/null @@ -1,176 +0,0 @@ -# Tests that work for bytearray objects. Could be merged into string_tests. -# See PEP 3137. - -class MixinBytesBufferCommonTests(object): - """Tests that work for bytearray objects. - See PEP 3137. - """ - - def marshal(self, x): - """Convert x into the appropriate type for these tests.""" - raise RuntimeError('test class must provide a marshal method') - - def test_islower(self): - self.assertFalse(self.marshal(b'').islower()) - self.assertTrue(self.marshal(b'a').islower()) - self.assertFalse(self.marshal(b'A').islower()) - self.assertFalse(self.marshal(b'\n').islower()) - self.assertTrue(self.marshal(b'abc').islower()) - self.assertFalse(self.marshal(b'aBc').islower()) - self.assertTrue(self.marshal(b'abc\n').islower()) - self.assertRaises(TypeError, self.marshal(b'abc').islower, 42) - - def test_isupper(self): - self.assertFalse(self.marshal(b'').isupper()) - self.assertFalse(self.marshal(b'a').isupper()) - self.assertTrue(self.marshal(b'A').isupper()) - self.assertFalse(self.marshal(b'\n').isupper()) - self.assertTrue(self.marshal(b'ABC').isupper()) - self.assertFalse(self.marshal(b'AbC').isupper()) - self.assertTrue(self.marshal(b'ABC\n').isupper()) - self.assertRaises(TypeError, self.marshal(b'abc').isupper, 42) - - def test_istitle(self): - self.assertFalse(self.marshal(b'').istitle()) - self.assertFalse(self.marshal(b'a').istitle()) - self.assertTrue(self.marshal(b'A').istitle()) - self.assertFalse(self.marshal(b'\n').istitle()) - self.assertTrue(self.marshal(b'A Titlecased Line').istitle()) - self.assertTrue(self.marshal(b'A\nTitlecased Line').istitle()) - self.assertTrue(self.marshal(b'A Titlecased, Line').istitle()) - self.assertFalse(self.marshal(b'Not a capitalized String').istitle()) - self.assertFalse(self.marshal(b'Not\ta Titlecase String').istitle()) - self.assertFalse(self.marshal(b'Not--a Titlecase String').istitle()) - self.assertFalse(self.marshal(b'NOT').istitle()) - self.assertRaises(TypeError, self.marshal(b'abc').istitle, 42) - - def test_isspace(self): - self.assertFalse(self.marshal(b'').isspace()) - self.assertFalse(self.marshal(b'a').isspace()) - self.assertTrue(self.marshal(b' ').isspace()) - self.assertTrue(self.marshal(b'\t').isspace()) - self.assertTrue(self.marshal(b'\r').isspace()) - self.assertTrue(self.marshal(b'\n').isspace()) - self.assertTrue(self.marshal(b' \t\r\n').isspace()) - self.assertFalse(self.marshal(b' \t\r\na').isspace()) - self.assertRaises(TypeError, self.marshal(b'abc').isspace, 42) - - def test_isalpha(self): - self.assertFalse(self.marshal(b'').isalpha()) - self.assertTrue(self.marshal(b'a').isalpha()) - self.assertTrue(self.marshal(b'A').isalpha()) - self.assertFalse(self.marshal(b'\n').isalpha()) - self.assertTrue(self.marshal(b'abc').isalpha()) - self.assertFalse(self.marshal(b'aBc123').isalpha()) - self.assertFalse(self.marshal(b'abc\n').isalpha()) - self.assertRaises(TypeError, self.marshal(b'abc').isalpha, 42) - - def test_isalnum(self): - self.assertFalse(self.marshal(b'').isalnum()) - self.assertTrue(self.marshal(b'a').isalnum()) - self.assertTrue(self.marshal(b'A').isalnum()) - self.assertFalse(self.marshal(b'\n').isalnum()) - self.assertTrue(self.marshal(b'123abc456').isalnum()) - self.assertTrue(self.marshal(b'a1b3c').isalnum()) - self.assertFalse(self.marshal(b'aBc000 ').isalnum()) - self.assertFalse(self.marshal(b'abc\n').isalnum()) - self.assertRaises(TypeError, self.marshal(b'abc').isalnum, 42) - - def test_isdigit(self): - self.assertFalse(self.marshal(b'').isdigit()) - self.assertFalse(self.marshal(b'a').isdigit()) - self.assertTrue(self.marshal(b'0').isdigit()) - self.assertTrue(self.marshal(b'0123456789').isdigit()) - self.assertFalse(self.marshal(b'0123456789a').isdigit()) - - self.assertRaises(TypeError, self.marshal(b'abc').isdigit, 42) - - def test_capitalize(self): - self.assertEqual(b' hello ', self.marshal(b' hello ').capitalize()) - self.assertEqual(b'Hello ', self.marshal(b'Hello ').capitalize()) - self.assertEqual(b'Hello ', self.marshal(b'hello ').capitalize()) - self.assertEqual(b'Aaaa', self.marshal(b'aaaa').capitalize()) - self.assertEqual(b'Aaaa', self.marshal(b'AaAa').capitalize()) - - self.assertRaises(TypeError, self.marshal(b'hello').capitalize, 42) - - def test_ljust(self): - self.assertEqual(b'abc ', self.marshal(b'abc').ljust(10)) - self.assertEqual(b'abc ', self.marshal(b'abc').ljust(6)) - self.assertEqual(b'abc', self.marshal(b'abc').ljust(3)) - self.assertEqual(b'abc', self.marshal(b'abc').ljust(2)) - self.assertEqual(b'abc*******', self.marshal(b'abc').ljust(10, b'*')) - self.assertRaises(TypeError, self.marshal(b'abc').ljust) - - def test_rjust(self): - self.assertEqual(b' abc', self.marshal(b'abc').rjust(10)) - self.assertEqual(b' abc', self.marshal(b'abc').rjust(6)) - self.assertEqual(b'abc', self.marshal(b'abc').rjust(3)) - self.assertEqual(b'abc', self.marshal(b'abc').rjust(2)) - self.assertEqual(b'*******abc', self.marshal(b'abc').rjust(10, b'*')) - self.assertRaises(TypeError, self.marshal(b'abc').rjust) - - def test_center(self): - self.assertEqual(b' abc ', self.marshal(b'abc').center(10)) - self.assertEqual(b' abc ', self.marshal(b'abc').center(6)) - self.assertEqual(b'abc', self.marshal(b'abc').center(3)) - self.assertEqual(b'abc', self.marshal(b'abc').center(2)) - self.assertEqual(b'***abc****', self.marshal(b'abc').center(10, b'*')) - self.assertRaises(TypeError, self.marshal(b'abc').center) - - def test_swapcase(self): - self.assertEqual(b'hEllO CoMPuTErS', - self.marshal(b'HeLLo cOmpUteRs').swapcase()) - - self.assertRaises(TypeError, self.marshal(b'hello').swapcase, 42) - - def test_zfill(self): - self.assertEqual(b'123', self.marshal(b'123').zfill(2)) - self.assertEqual(b'123', self.marshal(b'123').zfill(3)) - self.assertEqual(b'0123', self.marshal(b'123').zfill(4)) - self.assertEqual(b'+123', self.marshal(b'+123').zfill(3)) - self.assertEqual(b'+123', self.marshal(b'+123').zfill(4)) - self.assertEqual(b'+0123', self.marshal(b'+123').zfill(5)) - self.assertEqual(b'-123', self.marshal(b'-123').zfill(3)) - self.assertEqual(b'-123', self.marshal(b'-123').zfill(4)) - self.assertEqual(b'-0123', self.marshal(b'-123').zfill(5)) - self.assertEqual(b'000', self.marshal(b'').zfill(3)) - self.assertEqual(b'34', self.marshal(b'34').zfill(1)) - self.assertEqual(b'0034', self.marshal(b'34').zfill(4)) - - self.assertRaises(TypeError, self.marshal(b'123').zfill) - - def test_title(self): - self.assertEqual(b' Hello ', self.marshal(b' hello ').title()) - self.assertEqual(b'Hello ', self.marshal(b'hello ').title()) - self.assertEqual(b'Hello ', self.marshal(b'Hello ').title()) - self.assertEqual(b'Format This As Title String', - self.marshal(b'fOrMaT thIs aS titLe String').title()) - self.assertEqual(b'Format,This-As*Title;String', - self.marshal(b'fOrMaT,thIs-aS*titLe;String').title()) - self.assertEqual(b'Getint', self.marshal(b'getInt').title()) - self.assertRaises(TypeError, self.marshal(b'hello').title, 42) - - def test_splitlines(self): - self.assertEqual([b'abc', b'def', b'', b'ghi'], - self.marshal(b'abc\ndef\n\rghi').splitlines()) - self.assertEqual([b'abc', b'def', b'', b'ghi'], - self.marshal(b'abc\ndef\n\r\nghi').splitlines()) - self.assertEqual([b'abc', b'def', b'ghi'], - self.marshal(b'abc\ndef\r\nghi').splitlines()) - self.assertEqual([b'abc', b'def', b'ghi'], - self.marshal(b'abc\ndef\r\nghi\n').splitlines()) - self.assertEqual([b'abc', b'def', b'ghi', b''], - self.marshal(b'abc\ndef\r\nghi\n\r').splitlines()) - self.assertEqual([b'', b'abc', b'def', b'ghi', b''], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines()) - self.assertEqual([b'', b'abc', b'def', b'ghi', b''], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(False)) - self.assertEqual([b'\n', b'abc\n', b'def\r\n', b'ghi\n', b'\r'], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(True)) - self.assertEqual([b'', b'abc', b'def', b'ghi', b''], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(keepends=False)) - self.assertEqual([b'\n', b'abc\n', b'def\r\n', b'ghi\n', b'\r'], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(keepends=True)) - - self.assertRaises(TypeError, self.marshal(b'abc').splitlines, 42, 42) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -51,6 +51,9 @@ else: return obj + def test_fixtype(self): + self.assertIs(type(self.fixtype("123")), self.type2test) + # check that obj.method(*args) returns result def checkequal(self, result, obj, methodname, *args, **kwargs): result = self.fixtype(result) @@ -682,21 +685,6 @@ self.checkraises(OverflowError, A2_16, "replace", "A", A2_16) self.checkraises(OverflowError, A2_16, "replace", "AA", A2_16+A2_16) - - -class CommonTest(BaseTest): - # This testcase contains tests that can be used in all - # stringlike classes. Currently this is str and UserString. - - def test_hash(self): - # SF bug 1054139: += optimization was not invalidating cached hash value - a = self.type2test('DNSSEC') - b = self.type2test('') - for c in a: - b += c - hash(b) - self.assertEqual(hash(a), hash(b)) - def test_capitalize(self): self.checkequal(' hello ', ' hello ', 'capitalize') self.checkequal('Hello ', 'Hello ','capitalize') @@ -704,23 +692,6 @@ self.checkequal('Aaaa', 'aaaa', 'capitalize') self.checkequal('Aaaa', 'AaAa', 'capitalize') - # check that titlecased chars are lowered correctly - # \u1ffc is the titlecased char - self.checkequal('\u03a9\u0399\u1ff3\u1ff3\u1ff3', - '\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize') - # check with cased non-letter chars - self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', - '\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize') - self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', - '\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize') - self.checkequal('\u2160\u2171\u2172', - '\u2160\u2161\u2162', 'capitalize') - self.checkequal('\u2160\u2171\u2172', - '\u2170\u2171\u2172', 'capitalize') - # check with Ll chars with no upper - nothing changes here - self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7', - '\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize') - self.checkraises(TypeError, 'hello', 'capitalize', 42) def test_additional_split(self): @@ -854,10 +825,6 @@ self.checkraises(TypeError, '123', 'zfill') -class MixinStrUnicodeUserStringTest: - # additional tests that only work for - # stringlike objects, i.e. str, UserString - def test_islower(self): self.checkequal(False, '', 'islower') self.checkequal(True, 'a', 'islower') @@ -960,6 +927,43 @@ self.checkraises(TypeError, 'abc', 'splitlines', 42, 42) + +class CommonTest(BaseTest): + # This testcase contains tests that can be used in all + # stringlike classes. Currently this is str and UserString. + + def test_hash(self): + # SF bug 1054139: += optimization was not invalidating cached hash value + a = self.type2test('DNSSEC') + b = self.type2test('') + for c in a: + b += c + hash(b) + self.assertEqual(hash(a), hash(b)) + + def test_capitalize_nonascii(self): + # check that titlecased chars are lowered correctly + # \u1ffc is the titlecased char + self.checkequal('\u03a9\u0399\u1ff3\u1ff3\u1ff3', + '\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize') + # check with cased non-letter chars + self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', + '\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize') + self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', + '\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize') + self.checkequal('\u2160\u2171\u2172', + '\u2160\u2161\u2162', 'capitalize') + self.checkequal('\u2160\u2171\u2172', + '\u2170\u2171\u2172', 'capitalize') + # check with Ll chars with no upper - nothing changes here + self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7', + '\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize') + + +class MixinStrUnicodeUserStringTest: + # additional tests that only work for + # stringlike objects, i.e. str, UserString + def test_startswith(self): self.checkequal(True, 'hello', 'startswith', 'he') self.checkequal(True, 'hello', 'startswith', 'hello') diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -1,8 +1,7 @@ """Unit tests for the bytes and bytearray types. -XXX This is a mess. Common tests should be moved to buffer_tests.py, -which itself ought to be unified with string_tests.py (and the latter -should be modernized). +XXX This is a mess. Common tests should be unified with string_tests.py (and +the latter should be modernized). """ import os @@ -16,7 +15,6 @@ import test.support import test.string_tests -import test.buffer_tests import test.list_tests from test.support import bigaddrspacetest, MAX_Py_ssize_t @@ -1575,8 +1573,7 @@ # the rest that make sense (the code can be cleaned up to use modern # unittest methods at the same time). -class BytearrayPEP3137Test(unittest.TestCase, - test.buffer_tests.MixinBytesBufferCommonTests): +class BytearrayPEP3137Test(unittest.TestCase): def marshal(self, x): return bytearray(x) @@ -1606,16 +1603,16 @@ class FixedStringTest(test.string_tests.BaseTest): def fixtype(self, obj): if isinstance(obj, str): - return obj.encode("utf-8") + return self.type2test(obj.encode("utf-8")) return super().fixtype(obj) + contains_bytes = True + class ByteArrayAsStringTest(FixedStringTest, unittest.TestCase): type2test = bytearray - contains_bytes = True class BytesAsStringTest(FixedStringTest, unittest.TestCase): type2test = bytes - contains_bytes = True class SubclassTest: diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -565,7 +565,7 @@ self.assertTrue('\ud800\udc02' < '\ud84d\udc56') def test_islower(self): - string_tests.MixinStrUnicodeUserStringTest.test_islower(self) + super().test_islower() self.checkequalnofix(False, '\u1FFc', 'islower') self.assertFalse('\u2167'.islower()) self.assertTrue('\u2177'.islower()) @@ -580,7 +580,7 @@ self.assertFalse('\U0001F46F'.islower()) def test_isupper(self): - string_tests.MixinStrUnicodeUserStringTest.test_isupper(self) + super().test_isupper() if not sys.platform.startswith('java'): self.checkequalnofix(False, '\u1FFc', 'isupper') self.assertTrue('\u2167'.isupper()) @@ -596,7 +596,7 @@ self.assertFalse('\U0001F46F'.isupper()) def test_istitle(self): - string_tests.MixinStrUnicodeUserStringTest.test_istitle(self) + super().test_istitle() self.checkequalnofix(True, '\u1FFc', 'istitle') self.checkequalnofix(True, 'Greek \u1FFcitlecases ...', 'istitle') @@ -608,7 +608,7 @@ self.assertFalse(ch.istitle(), '{!a} is not title'.format(ch)) def test_isspace(self): - string_tests.MixinStrUnicodeUserStringTest.test_isspace(self) + super().test_isspace() self.checkequalnofix(True, '\u2000', 'isspace') self.checkequalnofix(True, '\u200a', 'isspace') self.checkequalnofix(False, '\u2014', 'isspace') @@ -618,13 +618,13 @@ self.assertFalse(ch.isspace(), '{!a} is not space.'.format(ch)) def test_isalnum(self): - string_tests.MixinStrUnicodeUserStringTest.test_isalnum(self) + super().test_isalnum() for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E', '\U0001D7F6', '\U00011066', '\U000104A0', '\U0001F107']: self.assertTrue(ch.isalnum(), '{!a} is alnum.'.format(ch)) def test_isalpha(self): - string_tests.MixinStrUnicodeUserStringTest.test_isalpha(self) + super().test_isalpha() self.checkequalnofix(True, '\u1FFc', 'isalpha') # non-BMP, cased self.assertTrue('\U00010401'.isalpha()) @@ -654,7 +654,7 @@ self.assertTrue(ch.isdecimal(), '{!a} is decimal.'.format(ch)) def test_isdigit(self): - string_tests.MixinStrUnicodeUserStringTest.test_isdigit(self) + super().test_isdigit() self.checkequalnofix(True, '\u2460', 'isdigit') self.checkequalnofix(False, '\xbc', 'isdigit') self.checkequalnofix(True, '\u0660', 'isdigit') @@ -807,7 +807,7 @@ self.assertEqual('A\u0345\u03a3'.capitalize(), 'A\u0345\u03c2') def test_title(self): - string_tests.MixinStrUnicodeUserStringTest.test_title(self) + super().test_title() self.assertEqual('\U0001044F'.title(), '\U00010427') self.assertEqual('\U0001044F\U0001044F'.title(), '\U00010427\U0001044F') -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 8 01:48:47 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 08 Apr 2016 05:48:47 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326671=3A_Fixed_te?= =?utf-8?q?sts_for_changed_error_messages=2E?= Message-ID: <20160408054846.21700.6957.1D52B45F@psf.io> https://hg.python.org/cpython/rev/633bb190fb76 changeset: 100869:633bb190fb76 parent: 100867:ea598d69b7d3 user: Serhiy Storchaka date: Fri Apr 08 08:48:20 2016 +0300 summary: Issue #26671: Fixed tests for changed error messages. files: Lib/test/test_posix.py | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -411,7 +411,7 @@ self.assertTrue(posix.stat(bytearray(os.fsencode(support.TESTFN)))) self.assertRaisesRegex(TypeError, - 'can\'t specify None for path argument', + 'should be string, bytes or integer, not', posix.stat, None) self.assertRaisesRegex(TypeError, 'should be string, bytes or integer, not', @@ -863,9 +863,9 @@ self.assertEqual(s1, s2) s2 = posix.stat(support.TESTFN, dir_fd=None) self.assertEqual(s1, s2) - self.assertRaisesRegex(TypeError, 'should be integer, not', + self.assertRaisesRegex(TypeError, 'should be integer or None, not', posix.stat, support.TESTFN, dir_fd=posix.getcwd()) - self.assertRaisesRegex(TypeError, 'should be integer, not', + self.assertRaisesRegex(TypeError, 'should be integer or None, not', posix.stat, support.TESTFN, dir_fd=float(f)) self.assertRaises(OverflowError, posix.stat, support.TESTFN, dir_fd=10**20) -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Fri Apr 8 05:44:03 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 08 Apr 2016 09:44:03 +0000 Subject: [Python-checkins] Daily reference leaks (ea598d69b7d3): sum=4 Message-ID: <20160408094403.22863.57678.1BF50B55@psf.io> results for ea598d69b7d3 on branch "default" -------------------------------------------- test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogNGsY7a', '--timeout', '7200'] From python-checkins at python.org Fri Apr 8 08:00:55 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 08 Apr 2016 12:00:55 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326709=3A_Fixed_Y2038_problem_in_loading_binary_?= =?utf-8?q?PLists=2E?= Message-ID: <20160408120050.46372.25081.A47F5424@psf.io> https://hg.python.org/cpython/rev/778ccbe3cf74 changeset: 100871:778ccbe3cf74 parent: 100869:633bb190fb76 parent: 100870:ba35b0404163 user: Serhiy Storchaka date: Fri Apr 08 15:00:33 2016 +0300 summary: Issue #26709: Fixed Y2038 problem in loading binary PLists. files: Lib/plistlib.py | 2 +- Lib/test/test_plistlib.py | 9 +++++++++ Misc/NEWS | 2 ++ 3 files changed, 12 insertions(+), 1 deletions(-) diff --git a/Lib/plistlib.py b/Lib/plistlib.py --- a/Lib/plistlib.py +++ b/Lib/plistlib.py @@ -685,7 +685,7 @@ f = struct.unpack('>d', self._fp.read(8))[0] # timestamp 0 of binary plists corresponds to 1/1/2001 # (year of Mac OS X 10.0), instead of 1/1/1970. - return datetime.datetime.utcfromtimestamp(f + (31 * 365 + 8) * 86400) + return datetime.datetime(2001, 1, 1) + datetime.timedelta(seconds=f) elif tokenH == 0x40: # data s = self._get_size(tokenL) diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -428,6 +428,15 @@ b'\x00\x00\x00\x00\x00\x00\x00\x13') self.assertEqual(plistlib.loads(data), {'a': 'b'}) + def test_large_timestamp(self): + # Issue #26709: 32-bit timestamp out of range + for ts in -2**31-1, 2**31: + with self.subTest(ts=ts): + d = (datetime.datetime.utcfromtimestamp(0) + + datetime.timedelta(seconds=ts)) + data = plistlib.dumps(d, fmt=plistlib.FMT_BINARY) + self.assertEqual(plistlib.loads(data), d) + class TestPlistlibDeprecated(unittest.TestCase): def test_io_deprecated(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -237,6 +237,8 @@ Library ------- +- Issue #26709: Fixed Y2038 problem in loading binary PLists. + - Issue #23735: Handle terminal resizing with Readline 6.3+ by installing our own SIGWINCH handler. Patch by Eric Price. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 8 08:00:57 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 08 Apr 2016 12:00:57 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NzA5?= =?utf-8?q?=3A_Fixed_Y2038_problem_in_loading_binary_PLists=2E?= Message-ID: <20160408120050.12632.75039.548A04BB@psf.io> https://hg.python.org/cpython/rev/ba35b0404163 changeset: 100870:ba35b0404163 branch: 3.5 parent: 100866:197e1f8b28b7 user: Serhiy Storchaka date: Fri Apr 08 15:00:02 2016 +0300 summary: Issue #26709: Fixed Y2038 problem in loading binary PLists. files: Lib/plistlib.py | 2 +- Lib/test/test_plistlib.py | 9 +++++++++ Misc/NEWS | 2 ++ 3 files changed, 12 insertions(+), 1 deletions(-) diff --git a/Lib/plistlib.py b/Lib/plistlib.py --- a/Lib/plistlib.py +++ b/Lib/plistlib.py @@ -685,7 +685,7 @@ f = struct.unpack('>d', self._fp.read(8))[0] # timestamp 0 of binary plists corresponds to 1/1/2001 # (year of Mac OS X 10.0), instead of 1/1/1970. - return datetime.datetime.utcfromtimestamp(f + (31 * 365 + 8) * 86400) + return datetime.datetime(2001, 1, 1) + datetime.timedelta(seconds=f) elif tokenH == 0x40: # data s = self._get_size(tokenL) diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -428,6 +428,15 @@ b'\x00\x00\x00\x00\x00\x00\x00\x13') self.assertEqual(plistlib.loads(data), {'a': 'b'}) + def test_large_timestamp(self): + # Issue #26709: 32-bit timestamp out of range + for ts in -2**31-1, 2**31: + with self.subTest(ts=ts): + d = (datetime.datetime.utcfromtimestamp(0) + + datetime.timedelta(seconds=ts)) + data = plistlib.dumps(d, fmt=plistlib.FMT_BINARY) + self.assertEqual(plistlib.loads(data), d) + class TestPlistlibDeprecated(unittest.TestCase): def test_io_deprecated(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -99,6 +99,8 @@ Library ------- +- Issue #26709: Fixed Y2038 problem in loading binary PLists. + - Issue #23735: Handle terminal resizing with Readline 6.3+ by installing our own SIGWINCH handler. Patch by Eric Price. -- Repository URL: https://hg.python.org/cpython From lp_benchmark_robot at intel.com Fri Apr 8 09:24:35 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Fri, 8 Apr 2016 14:24:35 +0100 Subject: [Python-checkins] GOOD Benchmark Results for Python 2.7 2016-04-08 Message-ID: <4efa09b5-c27b-4223-9d69-4fad747453ba@irsmsx101.ger.corp.intel.com> No new revisions. Here are the previous results: Results for project Python 2.7, build date 2016-04-08 02:07:25 +0000 commit: 7197809a7428 previous commit: 6137c46cb8df revision date: 2016-04-06 06:51:18 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.16% 2.83% 6.35% 3.62% :-) pybench 0.12% -0.04% 5.95% 4.25% :-( regex_v8 0.78% -0.03% -2.58% 11.16% :-) nbody 0.09% 3.14% 7.00% 5.08% :-) json_dump_v2 0.29% -0.27% 3.68% 11.11% :-( normal_startup 1.95% -0.22% -5.50% 2.70% :-) ssbench 0.23% -0.57% 2.00% 1.34% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/good-benchmark-results-for-python-2-7-2016-04-08/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Fri Apr 8 09:22:20 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Fri, 8 Apr 2016 14:22:20 +0100 Subject: [Python-checkins] BAD Benchmark Results for Python Default 2016-04-08 Message-ID: <88f34d8f-dff3-475e-b389-7dc9f729eb79@irsmsx101.ger.corp.intel.com> No new revisions. Here are the previous results: Results for project Python default, build date 2016-04-08 02:05:31 +0000 commit: 4acdb324a430 previous commit: a94c2ddfd855 revision date: 2016-04-06 20:02:46 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.19% -0.16% 11.05% 12.85% :-| pybench 0.14% -0.89% -0.31% 5.99% :-( regex_v8 2.56% 0.38% -5.78% 4.28% :-( nbody 0.17% -2.85% -1.13% 9.73% :-| json_dump_v2 0.30% 0.25% -1.90% 11.53% :-| normal_startup 0.86% -0.74% -0.30% 5.75% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/bad-benchmark-results-for-python-default-2016-04-08/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Fri Apr 8 15:16:27 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 08 Apr 2016 19:16:27 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Normalize_whitespace?= Message-ID: <20160408191626.33352.63344.CBADC373@psf.io> https://hg.python.org/cpython/rev/8e8a86f3b236 changeset: 100873:8e8a86f3b236 user: Brett Cannon date: Fri Apr 08 12:16:16 2016 -0700 summary: Normalize whitespace files: Lib/contextlib.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/contextlib.py b/Lib/contextlib.py --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -27,7 +27,7 @@ if cls is AbstractContextManager: if (any("__enter__" in B.__dict__ for B in C.__mro__) and any("__exit__" in B.__dict__ for B in C.__mro__)): - return True + return True return NotImplemented -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 8 15:16:27 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 08 Apr 2016 19:16:27 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2325609=3A_Introduc?= =?utf-8?q?e_contextlib=2EAbstractContextManager_and?= Message-ID: <20160408191626.125101.92654.25B05866@psf.io> https://hg.python.org/cpython/rev/841a263c0c56 changeset: 100872:841a263c0c56 user: Brett Cannon date: Fri Apr 08 12:15:27 2016 -0700 summary: Issue #25609: Introduce contextlib.AbstractContextManager and typing.ContextManager. files: Doc/library/contextlib.rst | 16 ++++++++- Doc/library/typing.rst | 12 +++++- Doc/whatsnew/3.6.rst | 26 +++++++++++++- Lib/contextlib.py | 42 ++++++++++++++++++------ Lib/test/test_contextlib.py | 33 +++++++++++++++++++ Lib/test/test_typing.py | 18 ++++++++++ Lib/typing.py | 7 ++++ Misc/NEWS | 3 + 8 files changed, 138 insertions(+), 19 deletions(-) diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -18,6 +18,18 @@ Functions and classes provided: +.. class:: AbstractContextManager + + An abstract base class for classes that implement + :meth:`object.__enter__` and :meth:`object.__exit__`. A default + implementation for :meth:`object.__enter__` is provided which returns + ``self`` while :meth:`object.__exit__` is an abstract method which by default + returns ``None``. See also the definition of :ref:`typecontextmanager`. + + .. versionadded:: 3.6 + + + .. decorator:: contextmanager This function is a :term:`decorator` that can be used to define a factory @@ -447,9 +459,9 @@ acquisition and release functions, along with an optional validation function, and maps them to the context management protocol:: - from contextlib import contextmanager, ExitStack + from contextlib import contextmanager, AbstractContextManager, ExitStack - class ResourceManager: + class ResourceManager(AbstractContextManager): def __init__(self, acquire_resource, release_resource, check_resource_ok=None): self.acquire_resource = acquire_resource diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -345,15 +345,15 @@ .. class:: Iterable(Generic[T_co]) - A generic version of the :class:`collections.abc.Iterable`. + A generic version of :class:`collections.abc.Iterable`. .. class:: Iterator(Iterable[T_co]) - A generic version of the :class:`collections.abc.Iterator`. + A generic version of :class:`collections.abc.Iterator`. .. class:: Reversible(Iterable[T_co]) - A generic version of the :class:`collections.abc.Reversible`. + A generic version of :class:`collections.abc.Reversible`. .. class:: SupportsInt @@ -448,6 +448,12 @@ A generic version of :class:`collections.abc.ValuesView`. +.. class:: ContextManager(Generic[T_co]) + + A generic version of :class:`contextlib.AbstractContextManager`. + + .. versionadded:: 3.6 + .. class:: Dict(dict, MutableMapping[KT, VT]) A generic version of :class:`dict`. diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -190,6 +190,18 @@ Improved Modules ================ +contextlib +---------- + +The :class:`contextlib.AbstractContextManager` class has been added to +provide an abstract base class for context managers. It provides a +sensible default implementation for `__enter__()` which returns +`self` and leaves `__exit__()` an abstract method. A matching +class has been added to the :mod:`typing` module as +:class:`typing.ContextManager`. +(Contributed by Brett Cannon in :issue:`25609`.) + + datetime -------- @@ -246,6 +258,14 @@ St?phane Wirtel in :issue:`25485`). +typing +------ + +The :class:`typing.ContextManager` class has been added for +representing :class:`contextlib.AbstractContextManager`. +(Contributed by Brett Cannon in :issue:`25609`.) + + unittest.mock ------------- @@ -372,9 +392,9 @@ Deprecated Python modules, functions and methods ------------------------------------------------ -* :meth:`importlib.machinery.SourceFileLoader` and - :meth:`importlib.machinery.SourcelessFileLoader` are now deprecated. They - were the only remaining implementations of +* :meth:`importlib.machinery.SourceFileLoader.load_module` and + :meth:`importlib.machinery.SourcelessFileLoader.load_module` are now + deprecated. They were the only remaining implementations of :meth:`importlib.abc.Loader.load_module` in :mod:`importlib` that had not been deprecated in previous versions of Python in favour of :meth:`importlib.abc.Loader.exec_module`. diff --git a/Lib/contextlib.py b/Lib/contextlib.py --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -1,11 +1,34 @@ """Utilities for with-statement contexts. See PEP 343.""" - +import abc import sys from collections import deque from functools import wraps -__all__ = ["contextmanager", "closing", "ContextDecorator", "ExitStack", - "redirect_stdout", "redirect_stderr", "suppress"] +__all__ = ["contextmanager", "closing", "AbstractContextManager", + "ContextDecorator", "ExitStack", "redirect_stdout", + "redirect_stderr", "suppress"] + + +class AbstractContextManager(abc.ABC): + + """An abstract base class for context managers.""" + + def __enter__(self): + """Return `self` upon entering the runtime context.""" + return self + + @abc.abstractmethod + def __exit__(self, exc_type, exc_value, traceback): + """Raise any exception triggered within the runtime context.""" + return None + + @classmethod + def __subclasshook__(cls, C): + if cls is AbstractContextManager: + if (any("__enter__" in B.__dict__ for B in C.__mro__) and + any("__exit__" in B.__dict__ for B in C.__mro__)): + return True + return NotImplemented class ContextDecorator(object): @@ -31,7 +54,7 @@ return inner -class _GeneratorContextManager(ContextDecorator): +class _GeneratorContextManager(ContextDecorator, AbstractContextManager): """Helper for @contextmanager decorator.""" def __init__(self, func, args, kwds): @@ -134,7 +157,7 @@ return helper -class closing(object): +class closing(AbstractContextManager): """Context to automatically close something at the end of a block. Code like this: @@ -159,7 +182,7 @@ self.thing.close() -class _RedirectStream: +class _RedirectStream(AbstractContextManager): _stream = None @@ -199,7 +222,7 @@ _stream = "stderr" -class suppress: +class suppress(AbstractContextManager): """Context manager to suppress specified exceptions After the exception is suppressed, execution proceeds with the next @@ -230,7 +253,7 @@ # Inspired by discussions on http://bugs.python.org/issue13585 -class ExitStack(object): +class ExitStack(AbstractContextManager): """Context manager for dynamic management of a stack of exit callbacks For example: @@ -309,9 +332,6 @@ """Immediately unwind the context stack""" self.__exit__(None, None, None) - def __enter__(self): - return self - def __exit__(self, *exc_details): received_exc = exc_details[0] is not None diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -12,6 +12,39 @@ threading = None +class TestAbstractContextManager(unittest.TestCase): + + def test_enter(self): + class DefaultEnter(AbstractContextManager): + def __exit__(self, *args): + super().__exit__(*args) + + manager = DefaultEnter() + self.assertIs(manager.__enter__(), manager) + + def test_exit_is_abstract(self): + class MissingExit(AbstractContextManager): + pass + + with self.assertRaises(TypeError): + MissingExit() + + def test_structural_subclassing(self): + class ManagerFromScratch: + def __enter__(self): + return self + def __exit__(self, exc_type, exc_value, traceback): + return None + + self.assertTrue(issubclass(ManagerFromScratch, AbstractContextManager)) + + class DefaultEnter(AbstractContextManager): + def __exit__(self, *args): + super().__exit__(*args) + + self.assertTrue(issubclass(DefaultEnter, AbstractContextManager)) + + class ContextManagerTestCase(unittest.TestCase): def test_contextmanager_plain(self): diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1,3 +1,4 @@ +import contextlib import pickle import re import sys @@ -1309,6 +1310,21 @@ assert len(MMB[KT, VT]()) == 0 +class OtherABCTests(TestCase): + + @skipUnless(hasattr(typing, 'ContextManager'), + 'requires typing.ContextManager') + def test_contextmanager(self): + @contextlib.contextmanager + def manager(): + yield 42 + + cm = manager() + assert isinstance(cm, typing.ContextManager) + assert isinstance(cm, typing.ContextManager[int]) + assert not isinstance(42, typing.ContextManager) + + class NamedTupleTests(TestCase): def test_basics(self): @@ -1447,6 +1463,8 @@ assert 'ValuesView' in a assert 'cast' in a assert 'overload' in a + if hasattr(contextlib, 'AbstractContextManager'): + assert 'ContextManager' in a # Check that io and re are not exported. assert 'io' not in a assert 're' not in a diff --git a/Lib/typing.py b/Lib/typing.py --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1,6 +1,7 @@ import abc from abc import abstractmethod, abstractproperty import collections +import contextlib import functools import re as stdlib_re # Avoid confusion with the re we export. import sys @@ -1530,6 +1531,12 @@ pass +if hasattr(contextlib, 'AbstractContextManager'): + class ContextManager(Generic[T_co], extra=contextlib.AbstractContextManager): + __slots__ = () + __all__.append('ContextManager') + + class Dict(dict, MutableMapping[KT, VT]): def __new__(cls, *args, **kwds): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -237,6 +237,9 @@ Library ------- +- Issue #25609: Introduce contextlib.AbstractContextManager and + typing.ContextManager. + - Issue #26709: Fixed Y2038 problem in loading binary PLists. - Issue #23735: Handle terminal resizing with Readline 6.3+ by installing our -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 8 15:29:10 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 08 Apr 2016 19:29:10 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326668=3A_Remove_t?= =?utf-8?q?he_redundant_Lib/test/test=5Fimportlib/regrtest=2Epy?= Message-ID: <20160408192910.80210.12254.68603ECB@psf.io> https://hg.python.org/cpython/rev/d214b30e8ef0 changeset: 100874:d214b30e8ef0 user: Brett Cannon date: Fri Apr 08 12:29:05 2016 -0700 summary: Issue #26668: Remove the redundant Lib/test/test_importlib/regrtest.py files: Lib/test/test_importlib/regrtest.py | 17 ----------------- 1 files changed, 0 insertions(+), 17 deletions(-) diff --git a/Lib/test/test_importlib/regrtest.py b/Lib/test/test_importlib/regrtest.py deleted file mode 100644 --- a/Lib/test/test_importlib/regrtest.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Run Python's standard test suite using importlib.__import__. - -Tests known to fail because of assumptions that importlib (properly) -invalidates are automatically skipped if the entire test suite is run. -Otherwise all command-line options valid for test.regrtest are also valid for -this script. - -""" -import importlib -import sys -from test import libregrtest - -if __name__ == '__main__': - __builtins__.__import__ = importlib.__import__ - sys.path_importer_cache.clear() - - libregrtest.main(quiet=True, verbose2=True) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 8 18:04:34 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 08 Apr 2016 22:04:34 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326587=3A_Allow_?= =?utf-8?q?=2Epth_files_to_specify_file_paths_as_well_as?= Message-ID: <20160408220434.32910.90644.6C9D89F8@psf.io> https://hg.python.org/cpython/rev/bd1af1a97c2e changeset: 100875:bd1af1a97c2e user: Brett Cannon date: Fri Apr 08 15:04:28 2016 -0700 summary: Issue #26587: Allow .pth files to specify file paths as well as directories. Thanks to Wolfgang Langner for the bug report and initial version of the patch. files: Doc/whatsnew/3.6.rst | 8 ++++++++ Lib/site.py | 18 +++++++++--------- Lib/test/test_site.py | 2 +- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -251,6 +251,14 @@ an instance were excluded. (Contributed by Martin Panter in :issue:`25590`.) +site +---- + +When specifying paths to add to :attr:`sys.path` in a `.pth` file, +you may now specify file paths on top of directories (e.g. zip files). +(Contributed by Wolfgang Langner in :issue:`26587`). + + telnetlib --------- diff --git a/Lib/site.py b/Lib/site.py --- a/Lib/site.py +++ b/Lib/site.py @@ -131,13 +131,13 @@ def _init_pathinfo(): - """Return a set containing all existing directory entries from sys.path""" + """Return a set containing all existing file system items from sys.path.""" d = set() - for dir in sys.path: + for item in sys.path: try: - if os.path.isdir(dir): - dir, dircase = makepath(dir) - d.add(dircase) + if os.path.exists(item): + _, itemcase = makepath(item) + d.add(itemcase) except TypeError: continue return d @@ -150,9 +150,9 @@ """ if known_paths is None: known_paths = _init_pathinfo() - reset = 1 + reset = True else: - reset = 0 + reset = False fullname = os.path.join(sitedir, name) try: f = open(fullname, "r") @@ -190,9 +190,9 @@ 'sitedir'""" if known_paths is None: known_paths = _init_pathinfo() - reset = 1 + reset = True else: - reset = 0 + reset = False sitedir, sitedircase = makepath(sitedir) if not sitedircase in known_paths: sys.path.append(sitedir) # Add path component diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -75,7 +75,7 @@ def test_init_pathinfo(self): dir_set = site._init_pathinfo() for entry in [site.makepath(path)[1] for path in sys.path - if path and os.path.isdir(path)]: + if path and os.path.exists(path)]: self.assertIn(entry, dir_set, "%s from sys.path not found in set returned " "by _init_pathinfo(): %s" % (entry, dir_set)) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -815,6 +815,7 @@ Tino Lange Glenn Langford Andrew Langmead +Wolfgang Langner Detlef Lannert Soren Larsen Amos Latteier diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -237,6 +237,9 @@ Library ------- +- Issue #26587: the site module now allows .pth files to specify files to be + added to sys.path (e.g. zip files). + - Issue #25609: Introduce contextlib.AbstractContextManager and typing.ContextManager. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 8 18:08:06 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 08 Apr 2016 22:08:06 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_w/_3=2E5_for_issue_=2326587?= Message-ID: <20160408220806.104434.20916.086097B5@psf.io> https://hg.python.org/cpython/rev/94d5c57ee835 changeset: 100877:94d5c57ee835 parent: 100875:bd1af1a97c2e parent: 100876:09dc97edf454 user: Brett Cannon date: Fri Apr 08 15:08:01 2016 -0700 summary: Merge w/ 3.5 for issue #26587 files: -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 8 18:08:07 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 08 Apr 2016 22:08:07 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NTg3?= =?utf-8?q?=3A_Remove_an_incorrect_statement_from_the_docs?= Message-ID: <20160408220806.104432.18318.1A61BAA3@psf.io> https://hg.python.org/cpython/rev/09dc97edf454 changeset: 100876:09dc97edf454 branch: 3.5 parent: 100870:ba35b0404163 user: Brett Cannon date: Fri Apr 08 15:06:54 2016 -0700 summary: Issue #26587: Remove an incorrect statement from the docs files: Doc/library/site.rst | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Doc/library/site.rst b/Doc/library/site.rst --- a/Doc/library/site.rst +++ b/Doc/library/site.rst @@ -52,8 +52,7 @@ A path configuration file is a file whose name has the form :file:`{name}.pth` and exists in one of the four directories mentioned above; its contents are additional items (one per line) to be added to ``sys.path``. Non-existing items -are never added to ``sys.path``, and no check is made that the item refers to a -directory rather than a file. No item is added to ``sys.path`` more than +are never added to ``sys.path``. No item is added to ``sys.path`` more than once. Blank lines and lines beginning with ``#`` are skipped. Lines starting with ``import`` (followed by space or tab) are executed. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 00:34:03 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 09 Apr 2016 04:34:03 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326687=3A_Use_Py?= =?utf-8?q?=5FRETURN=5FNONE_macro_in_sqlite3_module?= Message-ID: <20160409043403.31776.16620.1A5571A8@psf.io> https://hg.python.org/cpython/rev/b72f2d699563 changeset: 100878:b72f2d699563 user: Berker Peksag date: Sat Apr 09 07:34:39 2016 +0300 summary: Issue #26687: Use Py_RETURN_NONE macro in sqlite3 module files: Modules/_sqlite/cache.c | 3 +-- Modules/_sqlite/connection.c | 24 ++++++++---------------- Modules/_sqlite/cursor.c | 12 ++++-------- Modules/_sqlite/module.c | 9 +++------ 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/Modules/_sqlite/cache.c b/Modules/_sqlite/cache.c --- a/Modules/_sqlite/cache.c +++ b/Modules/_sqlite/cache.c @@ -244,8 +244,7 @@ ptr = ptr->next; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyMethodDef cache_methods[] = { diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -348,8 +348,7 @@ } } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* @@ -857,8 +856,7 @@ if (PyDict_SetItem(self->function_pinboard, func, Py_None) == -1) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } @@ -889,8 +887,7 @@ if (PyDict_SetItem(self->function_pinboard, aggregate_class, Py_None) == -1) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } @@ -1025,8 +1022,7 @@ if (PyDict_SetItem(self->function_pinboard, authorizer_cb, Py_None) == -1) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } @@ -1055,8 +1051,7 @@ return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject* pysqlite_connection_set_trace_callback(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) @@ -1083,8 +1078,7 @@ sqlite3_trace(self->db, _trace_callback, trace_callback); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } #ifdef HAVE_LOAD_EXTENSION @@ -1107,8 +1101,7 @@ PyErr_SetString(pysqlite_OperationalError, "Error enabling load extension"); return NULL; } else { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } @@ -1131,8 +1124,7 @@ PyErr_SetString(pysqlite_OperationalError, errmsg); return NULL; } else { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } #endif diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -242,8 +242,7 @@ const char* pos; if (!colname) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } for (pos = colname;; pos++) { @@ -914,8 +913,7 @@ row = pysqlite_cursor_iternext(self); if (!row && !PyErr_Occurred()) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return row; @@ -996,8 +994,7 @@ PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args) { /* don't care, return None */ - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args) @@ -1013,8 +1010,7 @@ self->closed = 1; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyMethodDef cursor_methods[] = { diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c --- a/Modules/_sqlite/module.c +++ b/Modules/_sqlite/module.c @@ -139,8 +139,7 @@ PyErr_SetString(pysqlite_OperationalError, "Changing the shared_cache flag failed"); return NULL; } else { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } @@ -172,8 +171,7 @@ if (rc == -1) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(module_register_adapter_doc, @@ -221,8 +219,7 @@ return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(enable_callback_tracebacks_doc, -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 00:52:26 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 09 Apr 2016 04:52:26 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzEzOTUy?= =?utf-8?q?=3A_Add_=2Ecsv_to_mimetypes=2Etypes=5Fmap?= Message-ID: <20160409045226.15162.5962.E799B3E3@psf.io> https://hg.python.org/cpython/rev/711672506b40 changeset: 100879:711672506b40 branch: 3.5 parent: 100876:09dc97edf454 user: Berker Peksag date: Sat Apr 09 07:52:05 2016 +0300 summary: Issue #13952: Add .csv to mimetypes.types_map Patch by Geoff Wilson. files: Lib/mimetypes.py | 1 + Misc/NEWS | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -416,6 +416,7 @@ '.cpio' : 'application/x-cpio', '.csh' : 'application/x-csh', '.css' : 'text/css', + '.csv' : 'text/csv', '.dll' : 'application/octet-stream', '.doc' : 'application/msword', '.dot' : 'application/msword', diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -99,6 +99,8 @@ Library ------- +- Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson. + - Issue #26709: Fixed Y2038 problem in loading binary PLists. - Issue #23735: Handle terminal resizing with Readline 6.3+ by installing our -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 00:52:26 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 09 Apr 2016 04:52:26 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2313952=3A_Add_=2Ecsv_to_mimetypes=2Etypes=5Fmap?= Message-ID: <20160409045226.13543.21295.A462B273@psf.io> https://hg.python.org/cpython/rev/5143f86ffe57 changeset: 100880:5143f86ffe57 parent: 100878:b72f2d699563 parent: 100879:711672506b40 user: Berker Peksag date: Sat Apr 09 07:53:00 2016 +0300 summary: Issue #13952: Add .csv to mimetypes.types_map Patch by Geoff Wilson. files: Lib/mimetypes.py | 1 + Misc/NEWS | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -416,6 +416,7 @@ '.cpio' : 'application/x-cpio', '.csh' : 'application/x-csh', '.css' : 'text/css', + '.csv' : 'text/csv', '.dll' : 'application/octet-stream', '.doc' : 'application/msword', '.dot' : 'application/msword', diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -237,6 +237,8 @@ Library ------- +- Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson. + - Issue #26587: the site module now allows .pth files to specify files to be added to sys.path (e.g. zip files). -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 01:00:20 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 09 Apr 2016 05:00:20 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzE2MzI5?= =?utf-8?q?=3A_Add_=2Ewebm_to_mimetypes=2Etypes=5Fmap?= Message-ID: <20160409050018.98080.9326.C11FA6EC@psf.io> https://hg.python.org/cpython/rev/0327a5a11108 changeset: 100881:0327a5a11108 branch: 3.5 parent: 100879:711672506b40 user: Berker Peksag date: Sat Apr 09 08:00:20 2016 +0300 summary: Issue #16329: Add .webm to mimetypes.types_map Patch by Giampaolo Rodola'. files: Lib/mimetypes.py | 1 + Misc/NEWS | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -514,6 +514,7 @@ '.ustar' : 'application/x-ustar', '.vcf' : 'text/x-vcard', '.wav' : 'audio/x-wav', + '.webm' : 'video/webm', '.wiz' : 'application/msword', '.wsdl' : 'application/xml', '.xbm' : 'image/x-xbitmap', diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -99,6 +99,8 @@ Library ------- +- Issue #16329: Add .webm to mimetypes.types_map. Patch by Giampaolo Rodola'. + - Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson. - Issue #26709: Fixed Y2038 problem in loading binary PLists. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 01:00:20 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 09 Apr 2016 05:00:20 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316329=3A_Add_=2Ewebm_to_mimetypes=2Etypes=5Fmap?= Message-ID: <20160409050018.73278.58244.20EEF5F7@psf.io> https://hg.python.org/cpython/rev/f92e6785b9f0 changeset: 100882:f92e6785b9f0 parent: 100880:5143f86ffe57 parent: 100881:0327a5a11108 user: Berker Peksag date: Sat Apr 09 08:00:53 2016 +0300 summary: Issue #16329: Add .webm to mimetypes.types_map Patch by Giampaolo Rodola'. files: Lib/mimetypes.py | 1 + Misc/NEWS | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -514,6 +514,7 @@ '.ustar' : 'application/x-ustar', '.vcf' : 'text/x-vcard', '.wav' : 'audio/x-wav', + '.webm' : 'video/webm', '.wiz' : 'application/msword', '.wsdl' : 'application/xml', '.xbm' : 'image/x-xbitmap', diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -237,6 +237,8 @@ Library ------- +- Issue #16329: Add .webm to mimetypes.types_map. Patch by Giampaolo Rodola'. + - Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson. - Issue #26587: the site module now allows .pth files to specify files to be -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 01:06:17 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 09 Apr 2016 05:06:17 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2MzI5?= =?utf-8?q?=3A_Add_=2Ewebm_to_mimetypes=2Etypes=5Fmap?= Message-ID: <20160409050617.28648.82369.E1BDA72B@psf.io> https://hg.python.org/cpython/rev/6ed3cb699be6 changeset: 100883:6ed3cb699be6 branch: 2.7 parent: 100868:26f1543e806c user: Berker Peksag date: Sat Apr 09 08:05:18 2016 +0300 summary: Issue #16329: Add .webm to mimetypes.types_map Patch by Giampaolo Rodola'. files: Lib/mimetypes.py | 1 + Misc/NEWS | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -514,6 +514,7 @@ '.ustar' : 'application/x-ustar', '.vcf' : 'text/x-vcard', '.wav' : 'audio/x-wav', + '.webm' : 'video/webm', '.wiz' : 'application/msword', '.wsdl' : 'application/xml', '.xbm' : 'image/x-xbitmap', diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -65,6 +65,8 @@ Library ------- +- Issue #16329: Add .webm to mimetypes.types_map. Patch by Giampaolo Rodola'. + - Issue #23735: Handle terminal resizing with Readline 6.3+ by installing our own SIGWINCH handler. Patch by Eric Price. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 01:06:17 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 09 Apr 2016 05:06:17 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzEzOTUy?= =?utf-8?q?=3A_Add_=2Ecsv_to_mimetypes=2Etypes=5Fmap?= Message-ID: <20160409050617.31772.94347.BBA9AB5A@psf.io> https://hg.python.org/cpython/rev/e704e0786332 changeset: 100884:e704e0786332 branch: 2.7 user: Berker Peksag date: Sat Apr 09 08:06:15 2016 +0300 summary: Issue #13952: Add .csv to mimetypes.types_map Patch by Geoff Wilson. files: Lib/mimetypes.py | 1 + Misc/NEWS | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -420,6 +420,7 @@ '.cpio' : 'application/x-cpio', '.csh' : 'application/x-csh', '.css' : 'text/css', + '.csv' : 'text/csv', '.dll' : 'application/octet-stream', '.doc' : 'application/msword', '.dot' : 'application/msword', diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -65,6 +65,8 @@ Library ------- +- Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson. + - Issue #16329: Add .webm to mimetypes.types_map. Patch by Giampaolo Rodola'. - Issue #23735: Handle terminal resizing with Readline 6.3+ by installing our -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 01:17:17 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 09 Apr 2016 05:17:17 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE5Mzc3?= =?utf-8?q?=3A_Add_=2Esvg_to_mimetypes=2Etypes=5Fmap?= Message-ID: <20160409051717.699.60793.A07FAB0D@psf.io> https://hg.python.org/cpython/rev/43a6e7104b78 changeset: 100885:43a6e7104b78 branch: 2.7 user: Berker Peksag date: Sat Apr 09 08:17:53 2016 +0300 summary: Issue #19377: Add .svg to mimetypes.types_map This is a backport of caf89a6a17a7. files: Lib/mimetypes.py | 2 ++ Misc/NEWS | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -382,6 +382,7 @@ global common_types suffix_map = { + '.svgz': '.svg.gz', '.tgz': '.tar.gz', '.taz': '.tar.gz', '.tz': '.tar.gz', @@ -500,6 +501,7 @@ '.src' : 'application/x-wais-source', '.sv4cpio': 'application/x-sv4cpio', '.sv4crc' : 'application/x-sv4crc', + '.svg' : 'image/svg+xml', '.swf' : 'application/x-shockwave-flash', '.t' : 'application/x-troff', '.tar' : 'application/x-tar', diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -65,6 +65,8 @@ Library ------- +- Issue #19377: Add .svg to mimetypes.types_map. + - Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson. - Issue #16329: Add .webm to mimetypes.types_map. Patch by Giampaolo Rodola'. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 02:07:51 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 09 Apr 2016 06:07:51 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2317264=3A_Fix_cross_refs_and_a_markup_error_in_e?= =?utf-8?q?xtending/building=2Erst?= Message-ID: <20160409060751.21758.77973.F9B91B5B@psf.io> https://hg.python.org/cpython/rev/7f7988ea908f changeset: 100887:7f7988ea908f parent: 100882:f92e6785b9f0 parent: 100886:ca6f174f5932 user: Berker Peksag date: Sat Apr 09 09:08:26 2016 +0300 summary: Issue #17264: Fix cross refs and a markup error in extending/building.rst files: Doc/extending/building.rst | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Doc/extending/building.rst b/Doc/extending/building.rst --- a/Doc/extending/building.rst +++ b/Doc/extending/building.rst @@ -40,7 +40,7 @@ defining multiple initialization functions. However, importing them requires using symbolic links or a custom importer, because by default only the function corresponding to the filename is found. -See :PEP:`489#multiple-modules-in-one-library` for details. +See the *"Multiple modules in one library"* section in :pep:`489` for details. .. highlightlang:: c @@ -88,7 +88,8 @@ It is common to pre-compute arguments to :func:`setup`, to better structure the driver script. In the example above, the ``ext_modules`` argument to -:func:`setup` is a list of extension modules, each of which is an instance of +:func:`~distutils.core.setup` is a list of extension modules, each of which is +an instance of the :class:`~distutils.extension.Extension`. In the example, the instance defines an extension named ``demo`` which is build by compiling a single source file, :file:`demo.c`. @@ -119,7 +120,8 @@ ext_modules = [module1]) -In this example, :func:`setup` is called with additional meta-information, which +In this example, :func:`~distutils.core.setup` is called with additional +meta-information, which is recommended when distribution packages have to be built. For the extension itself, it specifies preprocessor defines, include directories, library directories, and libraries. Depending on the compiler, distutils passes this @@ -150,8 +152,7 @@ python setup.py sdist In some cases, additional files need to be included in a source distribution; -this is done through a :file:`MANIFEST.in` file; see the distutils documentation -for details. +this is done through a :file:`MANIFEST.in` file; see :ref:`manifest` for details. If the source distribution has been build successfully, maintainers can also create binary distributions. Depending on the platform, one of the following -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 02:07:51 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 09 Apr 2016 06:07:51 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzE3MjY0?= =?utf-8?q?=3A_Fix_cross_refs_and_a_markup_error_in_extending/building=2Er?= =?utf-8?q?st?= Message-ID: <20160409060751.16611.59667.7A6FC482@psf.io> https://hg.python.org/cpython/rev/ca6f174f5932 changeset: 100886:ca6f174f5932 branch: 3.5 parent: 100881:0327a5a11108 user: Berker Peksag date: Sat Apr 09 09:08:05 2016 +0300 summary: Issue #17264: Fix cross refs and a markup error in extending/building.rst files: Doc/extending/building.rst | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Doc/extending/building.rst b/Doc/extending/building.rst --- a/Doc/extending/building.rst +++ b/Doc/extending/building.rst @@ -40,7 +40,7 @@ defining multiple initialization functions. However, importing them requires using symbolic links or a custom importer, because by default only the function corresponding to the filename is found. -See :PEP:`489#multiple-modules-in-one-library` for details. +See the *"Multiple modules in one library"* section in :pep:`489` for details. .. highlightlang:: c @@ -88,7 +88,8 @@ It is common to pre-compute arguments to :func:`setup`, to better structure the driver script. In the example above, the ``ext_modules`` argument to -:func:`setup` is a list of extension modules, each of which is an instance of +:func:`~distutils.core.setup` is a list of extension modules, each of which is +an instance of the :class:`~distutils.extension.Extension`. In the example, the instance defines an extension named ``demo`` which is build by compiling a single source file, :file:`demo.c`. @@ -119,7 +120,8 @@ ext_modules = [module1]) -In this example, :func:`setup` is called with additional meta-information, which +In this example, :func:`~distutils.core.setup` is called with additional +meta-information, which is recommended when distribution packages have to be built. For the extension itself, it specifies preprocessor defines, include directories, library directories, and libraries. Depending on the compiler, distutils passes this @@ -150,8 +152,7 @@ python setup.py sdist In some cases, additional files need to be included in a source distribution; -this is done through a :file:`MANIFEST.in` file; see the distutils documentation -for details. +this is done through a :file:`MANIFEST.in` file; see :ref:`manifest` for details. If the source distribution has been build successfully, maintainers can also create binary distributions. Depending on the platform, one of the following -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 05:52:19 2016 From: python-checkins at python.org (victor.stinner) Date: Sat, 09 Apr 2016 09:52:19 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Update_fcntl_d?= =?utf-8?q?oc=3A_replace_IOError_with_OSError?= Message-ID: <20160409095219.15614.11670.4E374628@psf.io> https://hg.python.org/cpython/rev/60ac28b612af changeset: 100888:60ac28b612af branch: 3.5 parent: 100886:ca6f174f5932 user: Victor Stinner date: Sat Apr 09 11:32:58 2016 +0200 summary: Update fcntl doc: replace IOError with OSError Issue #26716. IOError is a deprecated alias to OSError since Python 3.3. files: Doc/library/fcntl.rst | 4 ++-- Modules/fcntlmodule.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/fcntl.rst b/Doc/library/fcntl.rst --- a/Doc/library/fcntl.rst +++ b/Doc/library/fcntl.rst @@ -83,7 +83,7 @@ buffer 1024 bytes long which is then passed to :func:`ioctl` and copied back into the supplied buffer. - If the :c:func:`ioctl` fails, an :exc:`IOError` exception is raised. + If the :c:func:`ioctl` fails, an :exc:`OSError` exception is raised. An example:: @@ -106,7 +106,7 @@ :manpage:`flock(2)` for details. (On some systems, this function is emulated using :c:func:`fcntl`.) - If the :c:func:`flock` fails, an :exc:`IOError` exception is raised. + If the :c:func:`flock` fails, an :exc:`OSError` exception is raised. .. function:: lockf(fd, cmd, len=0, start=0, whence=0) diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -344,7 +344,7 @@ When operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and the -lock cannot be acquired, an IOError will be raised and the exception will +lock cannot be acquired, an OSError will be raised and the exception will have an errno attribute set to EACCES or EAGAIN (depending on the operating system -- for portability, check for either value). -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 05:52:20 2016 From: python-checkins at python.org (victor.stinner) Date: Sat, 09 Apr 2016 09:52:20 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_3=2E5=3A_fcntl_doc?= Message-ID: <20160409095219.90806.8801.46CA8A48@psf.io> https://hg.python.org/cpython/rev/8160786d0295 changeset: 100889:8160786d0295 parent: 100887:7f7988ea908f parent: 100888:60ac28b612af user: Victor Stinner date: Sat Apr 09 11:33:53 2016 +0200 summary: Merge 3.5: fcntl doc files: Doc/library/fcntl.rst | 4 ++-- Modules/fcntlmodule.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/fcntl.rst b/Doc/library/fcntl.rst --- a/Doc/library/fcntl.rst +++ b/Doc/library/fcntl.rst @@ -83,7 +83,7 @@ buffer 1024 bytes long which is then passed to :func:`ioctl` and copied back into the supplied buffer. - If the :c:func:`ioctl` fails, an :exc:`IOError` exception is raised. + If the :c:func:`ioctl` fails, an :exc:`OSError` exception is raised. An example:: @@ -106,7 +106,7 @@ :manpage:`flock(2)` for details. (On some systems, this function is emulated using :c:func:`fcntl`.) - If the :c:func:`flock` fails, an :exc:`IOError` exception is raised. + If the :c:func:`flock` fails, an :exc:`OSError` exception is raised. .. function:: lockf(fd, cmd, len=0, start=0, whence=0) diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -344,7 +344,7 @@ When operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and the -lock cannot be acquired, an IOError will be raised and the exception will +lock cannot be acquired, an OSError will be raised and the exception will have an errno attribute set to EACCES or EAGAIN (depending on the operating system -- for portability, check for either value). -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 09:44:35 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 09 Apr 2016 13:44:35 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NjA5?= =?utf-8?q?=3A_Fix_HTTP_server_tests_to_request_an_absolute_URL_path?= Message-ID: <20160409134435.27668.95627.23C5A6E1@psf.io> https://hg.python.org/cpython/rev/0e19f421dc9e changeset: 100890:0e19f421dc9e branch: 3.5 parent: 100888:60ac28b612af user: Martin Panter date: Sat Apr 09 04:56:10 2016 +0000 summary: Issue #26609: Fix HTTP server tests to request an absolute URL path files: Lib/test/test_httpservers.py | 41 ++++++++++++++++------- 1 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -284,6 +284,7 @@ self.data = b'We are the knights who say Ni!' self.tempdir = tempfile.mkdtemp(dir=basetempdir) self.tempdir_name = os.path.basename(self.tempdir) + self.base_url = '/' + self.tempdir_name with open(os.path.join(self.tempdir, 'test'), 'wb') as temp: temp.write(self.data) @@ -330,7 +331,7 @@ filename = os.fsdecode(support.TESTFN_UNDECODABLE) + '.txt' with open(os.path.join(self.tempdir, filename), 'wb') as f: f.write(support.TESTFN_UNDECODABLE) - response = self.request(self.tempdir_name + '/') + response = self.request(self.base_url + '/') if sys.platform == 'darwin': # On Mac OS the HFS+ filesystem replaces bytes that aren't valid # UTF-8 into a percent-encoded value. @@ -344,27 +345,27 @@ .encode(enc, 'surrogateescape'), body) self.assertIn(('>%s<' % html.escape(filename)) .encode(enc, 'surrogateescape'), body) - response = self.request(self.tempdir_name + '/' + quotedname) + response = self.request(self.base_url + '/' + quotedname) self.check_status_and_reason(response, HTTPStatus.OK, data=support.TESTFN_UNDECODABLE) def test_get(self): #constructs the path relative to the root directory of the HTTPServer - response = self.request(self.tempdir_name + '/test') + response = self.request(self.base_url + '/test') self.check_status_and_reason(response, HTTPStatus.OK, data=self.data) # check for trailing "/" which should return 404. See Issue17324 - response = self.request(self.tempdir_name + '/test/') + response = self.request(self.base_url + '/test/') self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) - response = self.request(self.tempdir_name + '/') + response = self.request(self.base_url + '/') self.check_status_and_reason(response, HTTPStatus.OK) - response = self.request(self.tempdir_name) + response = self.request(self.base_url) self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) - response = self.request(self.tempdir_name + '/?hi=2') + response = self.request(self.base_url + '/?hi=2') self.check_status_and_reason(response, HTTPStatus.OK) - response = self.request(self.tempdir_name + '?hi=1') + response = self.request(self.base_url + '?hi=1') self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) self.assertEqual(response.getheader("Location"), - self.tempdir_name + "/?hi=1") + self.base_url + "/?hi=1") response = self.request('/ThisDoesNotExist') self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) response = self.request('/' + 'ThisDoesNotExist' + '/') @@ -373,7 +374,7 @@ data = b"Dummy index file\r\n" with open(os.path.join(self.tempdir_name, 'index.html'), 'wb') as f: f.write(data) - response = self.request('/' + self.tempdir_name + '/') + response = self.request(self.base_url + '/') self.check_status_and_reason(response, HTTPStatus.OK, data) # chmod() doesn't work as expected on Windows, and filesystem @@ -381,14 +382,14 @@ if os.name == 'posix' and os.geteuid() != 0: os.chmod(self.tempdir, 0) try: - response = self.request(self.tempdir_name + '/') + response = self.request(self.base_url + '/') self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) finally: os.chmod(self.tempdir, 0o755) def test_head(self): response = self.request( - self.tempdir_name + '/test', method='HEAD') + self.base_url + '/test', method='HEAD') self.check_status_and_reason(response, HTTPStatus.OK) self.assertEqual(response.getheader('content-length'), str(len(self.data))) @@ -404,6 +405,22 @@ response = self.request('/', method='GETs') self.check_status_and_reason(response, HTTPStatus.NOT_IMPLEMENTED) + def test_path_without_leading_slash(self): + response = self.request(self.tempdir_name + '/test') + self.check_status_and_reason(response, HTTPStatus.OK, data=self.data) + response = self.request(self.tempdir_name + '/test/') + self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) + response = self.request(self.tempdir_name + '/') + self.check_status_and_reason(response, HTTPStatus.OK) + response = self.request(self.tempdir_name) + self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) + response = self.request(self.tempdir_name + '/?hi=2') + self.check_status_and_reason(response, HTTPStatus.OK) + response = self.request(self.tempdir_name + '?hi=1') + self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) + self.assertEqual(response.getheader("Location"), + self.tempdir_name + "/?hi=1") + cgi_file1 = """\ #!%s -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 09:44:36 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 09 Apr 2016 13:44:36 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2NjA5?= =?utf-8?q?=3A_Fix_HTTP_server_tests_to_request_an_absolute_URL_path?= Message-ID: <20160409134436.90808.95900.D50C642C@psf.io> https://hg.python.org/cpython/rev/2691f81a89a7 changeset: 100892:2691f81a89a7 branch: 2.7 parent: 100885:43a6e7104b78 user: Martin Panter date: Sat Apr 09 04:56:10 2016 +0000 summary: Issue #26609: Fix HTTP server tests to request an absolute URL path files: Lib/test/test_httpservers.py | 37 +++++++++++++++++------ 1 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -288,6 +288,7 @@ self.data = 'We are the knights who say Ni!' self.tempdir = tempfile.mkdtemp(dir=basetempdir) self.tempdir_name = os.path.basename(self.tempdir) + self.base_url = '/' + self.tempdir_name temp = open(os.path.join(self.tempdir, 'test'), 'wb') temp.write(self.data) temp.close() @@ -312,39 +313,39 @@ def test_get(self): #constructs the path relative to the root directory of the HTTPServer - response = self.request(self.tempdir_name + '/test') + response = self.request(self.base_url + '/test') self.check_status_and_reason(response, 200, data=self.data) # check for trailing "/" which should return 404. See Issue17324 - response = self.request(self.tempdir_name + '/test/') + response = self.request(self.base_url + '/test/') self.check_status_and_reason(response, 404) - response = self.request(self.tempdir_name + '/') + response = self.request(self.base_url + '/') self.check_status_and_reason(response, 200) - response = self.request(self.tempdir_name) + response = self.request(self.base_url) self.check_status_and_reason(response, 301) - response = self.request(self.tempdir_name + '/?hi=2') + response = self.request(self.base_url + '/?hi=2') self.check_status_and_reason(response, 200) - response = self.request(self.tempdir_name + '?hi=1') + response = self.request(self.base_url + '?hi=1') self.check_status_and_reason(response, 301) self.assertEqual(response.getheader("Location"), - self.tempdir_name + "/?hi=1") + self.base_url + "/?hi=1") response = self.request('/ThisDoesNotExist') self.check_status_and_reason(response, 404) response = self.request('/' + 'ThisDoesNotExist' + '/') self.check_status_and_reason(response, 404) with open(os.path.join(self.tempdir_name, 'index.html'), 'w') as fp: - response = self.request('/' + self.tempdir_name + '/') + response = self.request(self.base_url + '/') self.check_status_and_reason(response, 200) # chmod() doesn't work as expected on Windows, and filesystem # permissions are ignored by root on Unix. if os.name == 'posix' and os.geteuid() != 0: os.chmod(self.tempdir, 0) - response = self.request(self.tempdir_name + '/') + response = self.request(self.base_url + '/') self.check_status_and_reason(response, 404) os.chmod(self.tempdir, 0755) def test_head(self): response = self.request( - self.tempdir_name + '/test', method='HEAD') + self.base_url + '/test', method='HEAD') self.check_status_and_reason(response, 200) self.assertEqual(response.getheader('content-length'), str(len(self.data))) @@ -360,6 +361,22 @@ response = self.request('/', method='GETs') self.check_status_and_reason(response, 501) + def test_path_without_leading_slash(self): + response = self.request(self.tempdir_name + '/test') + self.check_status_and_reason(response, HTTPStatus.OK, data=self.data) + response = self.request(self.tempdir_name + '/test/') + self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) + response = self.request(self.tempdir_name + '/') + self.check_status_and_reason(response, HTTPStatus.OK) + response = self.request(self.tempdir_name) + self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) + response = self.request(self.tempdir_name + '/?hi=2') + self.check_status_and_reason(response, HTTPStatus.OK) + response = self.request(self.tempdir_name + '?hi=1') + self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) + self.assertEqual(response.getheader("Location"), + self.tempdir_name + "/?hi=1") + cgi_file1 = """\ #!%s -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 09:44:36 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 09 Apr 2016 13:44:36 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326609=3A_Merge_HTTP_tests_from_3=2E5?= Message-ID: <20160409134435.110000.74445.1A107372@psf.io> https://hg.python.org/cpython/rev/34ebf79acd78 changeset: 100891:34ebf79acd78 parent: 100889:8160786d0295 parent: 100890:0e19f421dc9e user: Martin Panter date: Sat Apr 09 12:51:41 2016 +0000 summary: Issue #26609: Merge HTTP tests from 3.5 files: Lib/test/test_httpservers.py | 41 ++++++++++++++++------- 1 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -285,6 +285,7 @@ self.data = b'We are the knights who say Ni!' self.tempdir = tempfile.mkdtemp(dir=basetempdir) self.tempdir_name = os.path.basename(self.tempdir) + self.base_url = '/' + self.tempdir_name with open(os.path.join(self.tempdir, 'test'), 'wb') as temp: temp.write(self.data) @@ -331,7 +332,7 @@ filename = os.fsdecode(support.TESTFN_UNDECODABLE) + '.txt' with open(os.path.join(self.tempdir, filename), 'wb') as f: f.write(support.TESTFN_UNDECODABLE) - response = self.request(self.tempdir_name + '/') + response = self.request(self.base_url + '/') if sys.platform == 'darwin': # On Mac OS the HFS+ filesystem replaces bytes that aren't valid # UTF-8 into a percent-encoded value. @@ -345,27 +346,27 @@ .encode(enc, 'surrogateescape'), body) self.assertIn(('>%s<' % html.escape(filename)) .encode(enc, 'surrogateescape'), body) - response = self.request(self.tempdir_name + '/' + quotedname) + response = self.request(self.base_url + '/' + quotedname) self.check_status_and_reason(response, HTTPStatus.OK, data=support.TESTFN_UNDECODABLE) def test_get(self): #constructs the path relative to the root directory of the HTTPServer - response = self.request(self.tempdir_name + '/test') + response = self.request(self.base_url + '/test') self.check_status_and_reason(response, HTTPStatus.OK, data=self.data) # check for trailing "/" which should return 404. See Issue17324 - response = self.request(self.tempdir_name + '/test/') + response = self.request(self.base_url + '/test/') self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) - response = self.request(self.tempdir_name + '/') + response = self.request(self.base_url + '/') self.check_status_and_reason(response, HTTPStatus.OK) - response = self.request(self.tempdir_name) + response = self.request(self.base_url) self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) - response = self.request(self.tempdir_name + '/?hi=2') + response = self.request(self.base_url + '/?hi=2') self.check_status_and_reason(response, HTTPStatus.OK) - response = self.request(self.tempdir_name + '?hi=1') + response = self.request(self.base_url + '?hi=1') self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) self.assertEqual(response.getheader("Location"), - self.tempdir_name + "/?hi=1") + self.base_url + "/?hi=1") response = self.request('/ThisDoesNotExist') self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) response = self.request('/' + 'ThisDoesNotExist' + '/') @@ -374,7 +375,7 @@ data = b"Dummy index file\r\n" with open(os.path.join(self.tempdir_name, 'index.html'), 'wb') as f: f.write(data) - response = self.request('/' + self.tempdir_name + '/') + response = self.request(self.base_url + '/') self.check_status_and_reason(response, HTTPStatus.OK, data) # chmod() doesn't work as expected on Windows, and filesystem @@ -382,14 +383,14 @@ if os.name == 'posix' and os.geteuid() != 0: os.chmod(self.tempdir, 0) try: - response = self.request(self.tempdir_name + '/') + response = self.request(self.base_url + '/') self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) finally: os.chmod(self.tempdir, 0o755) def test_head(self): response = self.request( - self.tempdir_name + '/test', method='HEAD') + self.base_url + '/test', method='HEAD') self.check_status_and_reason(response, HTTPStatus.OK) self.assertEqual(response.getheader('content-length'), str(len(self.data))) @@ -405,6 +406,22 @@ response = self.request('/', method='GETs') self.check_status_and_reason(response, HTTPStatus.NOT_IMPLEMENTED) + def test_path_without_leading_slash(self): + response = self.request(self.tempdir_name + '/test') + self.check_status_and_reason(response, HTTPStatus.OK, data=self.data) + response = self.request(self.tempdir_name + '/test/') + self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) + response = self.request(self.tempdir_name + '/') + self.check_status_and_reason(response, HTTPStatus.OK) + response = self.request(self.tempdir_name) + self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) + response = self.request(self.tempdir_name + '/?hi=2') + self.check_status_and_reason(response, HTTPStatus.OK) + response = self.request(self.tempdir_name + '?hi=1') + self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) + self.assertEqual(response.getheader("Location"), + self.tempdir_name + "/?hi=1") + cgi_file1 = """\ #!%s -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 09:46:07 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 09 Apr 2016 13:46:07 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2NjA5?= =?utf-8?q?=3A_Fix_up_Python_2_port?= Message-ID: <20160409134606.34593.91254.938E9DD2@psf.io> https://hg.python.org/cpython/rev/4f64b1c87a56 changeset: 100893:4f64b1c87a56 branch: 2.7 user: Martin Panter date: Sat Apr 09 13:45:52 2016 +0000 summary: Issue #26609: Fix up Python 2 port files: Lib/test/test_httpservers.py | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -363,17 +363,17 @@ def test_path_without_leading_slash(self): response = self.request(self.tempdir_name + '/test') - self.check_status_and_reason(response, HTTPStatus.OK, data=self.data) + self.check_status_and_reason(response, 200, data=self.data) response = self.request(self.tempdir_name + '/test/') - self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) + self.check_status_and_reason(response, 404) response = self.request(self.tempdir_name + '/') - self.check_status_and_reason(response, HTTPStatus.OK) + self.check_status_and_reason(response, 200) response = self.request(self.tempdir_name) - self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) + self.check_status_and_reason(response, 301) response = self.request(self.tempdir_name + '/?hi=2') - self.check_status_and_reason(response, HTTPStatus.OK) + self.check_status_and_reason(response, 200) response = self.request(self.tempdir_name + '?hi=1') - self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) + self.check_status_and_reason(response, 301) self.assertEqual(response.getheader("Location"), self.tempdir_name + "/?hi=1") -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 10:12:50 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 09 Apr 2016 14:12:50 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzIxMDY5?= =?utf-8?q?=3A_Move_test=5Ffileno=28=29_from_test=5Furllibnet_and_rewrite_?= =?utf-8?q?it?= Message-ID: <20160409141250.18843.6211.BF944778@psf.io> https://hg.python.org/cpython/rev/00240ddce1d0 changeset: 100894:00240ddce1d0 branch: 3.5 parent: 100890:0e19f421dc9e user: Martin Panter date: Sat Apr 09 14:03:17 2016 +0000 summary: Issue #21069: Move test_fileno() from test_urllibnet and rewrite it * No longer attempts to close already freed socket file descriptor * Use socket object to be compatible with Windows * Do not use a timeout to avoid complication with non-blocking mode * Use internal localhost server rather than depending on a third party * Avoid trouble with buffered HTTP data by testing tunnelled CONNECT data files: Lib/test/test_httplib.py | 41 ++++++++++++++++++++++++++ Lib/test/test_urllibnet.py | 11 ------ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -915,6 +915,47 @@ self.assertEqual(sock.file.read(), extradata) #we read to the end resp.close() + def test_response_fileno(self): + # Make sure fd returned by fileno is valid. + threading = support.import_module("threading") + + serv = socket.socket( + socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) + self.addCleanup(serv.close) + serv.bind((HOST, 0)) + serv.listen() + + result = None + def run_server(): + [conn, address] = serv.accept() + with conn, conn.makefile("rb") as reader: + # Read the request header until a blank line + while True: + line = reader.readline() + if not line.rstrip(b"\r\n"): + break + conn.sendall(b"HTTP/1.1 200 Connection established\r\n\r\n") + nonlocal result + result = reader.read() + + thread = threading.Thread(target=run_server) + thread.start() + conn = client.HTTPConnection(*serv.getsockname()) + conn.request("CONNECT", "dummy:1234") + response = conn.getresponse() + try: + self.assertEqual(response.status, client.OK) + s = socket.socket(fileno=response.fileno()) + try: + s.sendall(b"proxied data\n") + finally: + s.detach() + finally: + response.close() + conn.close() + thread.join() + self.assertEqual(result, b"proxied data\n") + class ExtendedReadTest(TestCase): """ Test peek(), read1(), readline() diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -99,17 +99,6 @@ open_url.close() self.assertEqual(code, 404) - # On Windows, socket handles are not file descriptors; this - # test can't pass on Windows. - @unittest.skipIf(sys.platform in ('win32',), 'not appropriate for Windows') - def test_fileno(self): - # Make sure fd returned by fileno is valid. - with self.urlopen("http://www.google.com/") as open_url: - fd = open_url.fileno() - with os.fdopen(fd, 'rb') as f: - self.assertTrue(f.read(), "reading from file created using fd " - "returned by fileno failed") - def test_bad_address(self): # Make sure proper exception is raised when connecting to a bogus # address. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 10:12:51 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 09 Apr 2016 14:12:51 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogSXNzdWUgIzIxMDY5OiBNZXJnZSB0ZXN0X2ZpbGVubygpIGZyb20gMy41?= Message-ID: <20160409141250.16625.8868.0A24B57B@psf.io> https://hg.python.org/cpython/rev/4c19396bd4a0 changeset: 100895:4c19396bd4a0 parent: 100891:34ebf79acd78 parent: 100894:00240ddce1d0 user: Martin Panter date: Sat Apr 09 14:05:19 2016 +0000 summary: Issue #21069: Merge test_fileno() from 3.5 files: Lib/test/test_httplib.py | 41 ++++++++++++++++++++++++++ Lib/test/test_urllibnet.py | 11 ------ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -915,6 +915,47 @@ self.assertEqual(sock.file.read(), extradata) #we read to the end resp.close() + def test_response_fileno(self): + # Make sure fd returned by fileno is valid. + threading = support.import_module("threading") + + serv = socket.socket( + socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) + self.addCleanup(serv.close) + serv.bind((HOST, 0)) + serv.listen() + + result = None + def run_server(): + [conn, address] = serv.accept() + with conn, conn.makefile("rb") as reader: + # Read the request header until a blank line + while True: + line = reader.readline() + if not line.rstrip(b"\r\n"): + break + conn.sendall(b"HTTP/1.1 200 Connection established\r\n\r\n") + nonlocal result + result = reader.read() + + thread = threading.Thread(target=run_server) + thread.start() + conn = client.HTTPConnection(*serv.getsockname()) + conn.request("CONNECT", "dummy:1234") + response = conn.getresponse() + try: + self.assertEqual(response.status, client.OK) + s = socket.socket(fileno=response.fileno()) + try: + s.sendall(b"proxied data\n") + finally: + s.detach() + finally: + response.close() + conn.close() + thread.join() + self.assertEqual(result, b"proxied data\n") + class ExtendedReadTest(TestCase): """ Test peek(), read1(), readline() diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -99,17 +99,6 @@ open_url.close() self.assertEqual(code, 404) - # On Windows, socket handles are not file descriptors; this - # test can't pass on Windows. - @unittest.skipIf(sys.platform in ('win32',), 'not appropriate for Windows') - def test_fileno(self): - # Make sure fd returned by fileno is valid. - with self.urlopen("http://www.google.com/") as open_url: - fd = open_url.fileno() - with os.fdopen(fd, 'rb') as f: - self.assertTrue(f.read(), "reading from file created using fd " - "returned by fileno failed") - def test_bad_address(self): # Make sure proper exception is raised when connecting to a bogus # address. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 9 22:44:24 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 10 Apr 2016 02:44:24 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2325609=3A_Double_b?= =?utf-8?q?ack-ticks_to_avoid_=E2=80=9Cmake_check=E2=80=9D_buildbot_failur?= =?utf-8?q?e?= Message-ID: <20160410024424.110010.50888.4683586D@psf.io> https://hg.python.org/cpython/rev/5c0e332988b2 changeset: 100896:5c0e332988b2 user: Martin Panter date: Sun Apr 10 02:41:25 2016 +0000 summary: Issue #25609: Double back-ticks to avoid ?make check? buildbot failure files: Doc/whatsnew/3.6.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -196,7 +196,7 @@ The :class:`contextlib.AbstractContextManager` class has been added to provide an abstract base class for context managers. It provides a sensible default implementation for `__enter__()` which returns -`self` and leaves `__exit__()` an abstract method. A matching +``self`` and leaves `__exit__()` an abstract method. A matching class has been added to the :mod:`typing` module as :class:`typing.ContextManager`. (Contributed by Brett Cannon in :issue:`25609`.) -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Sun Apr 10 05:47:18 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sun, 10 Apr 2016 09:47:18 +0000 Subject: [Python-checkins] Daily reference leaks (5c0e332988b2): sum=4 Message-ID: <20160410094716.110010.86710.60BA7968@psf.io> results for 5c0e332988b2 on branch "default" -------------------------------------------- test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogdLW0mC', '--timeout', '7200'] From python-checkins at python.org Sun Apr 10 06:28:10 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 10 Apr 2016 10:28:10 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NzEy?= =?utf-8?q?=3A_Unify_=28r=29split=2C_=28l/r=29strip_tests_into_string=5Fte?= =?utf-8?q?sts?= Message-ID: <20160410102809.34731.86024.B73438CA@psf.io> https://hg.python.org/cpython/rev/15cbeb389f17 changeset: 100897:15cbeb389f17 branch: 3.5 parent: 100894:00240ddce1d0 user: Martin Panter date: Sun Apr 10 08:45:26 2016 +0000 summary: Issue #26712: Unify (r)split, (l/r)strip tests into string_tests This eliminates a few redundant test cases. files: Lib/test/string_tests.py | 36 +++++++++- Lib/test/test_bytes.py | 91 +-------------------------- Lib/test/test_unicode.py | 4 - 3 files changed, 35 insertions(+), 96 deletions(-) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -368,6 +368,8 @@ sys.maxsize-2) self.checkequal(['a|b|c|d'], 'a|b|c|d', 'split', '|', 0) self.checkequal(['a', '', 'b||c||d'], 'a||b||c||d', 'split', '|', 2) + self.checkequal(['abcd'], 'abcd', 'split', '|') + self.checkequal([''], '', 'split', '|') self.checkequal(['endcase ', ''], 'endcase |', 'split', '|') self.checkequal(['', ' startcase'], '| startcase', 'split', '|') self.checkequal(['', 'bothcase', ''], '|bothcase|', 'split', '|') @@ -435,6 +437,8 @@ sys.maxsize-100) self.checkequal(['a|b|c|d'], 'a|b|c|d', 'rsplit', '|', 0) self.checkequal(['a||b||c', '', 'd'], 'a||b||c||d', 'rsplit', '|', 2) + self.checkequal(['abcd'], 'abcd', 'rsplit', '|') + self.checkequal([''], '', 'rsplit', '|') self.checkequal(['', ' begincase'], '| begincase', 'rsplit', '|') self.checkequal(['endcase ', ''], 'endcase |', 'rsplit', '|') self.checkequal(['', 'bothcase', ''], '|bothcase|', 'rsplit', '|') @@ -714,16 +718,21 @@ self.checkequal(['a'], ' a ', 'split') self.checkequal(['a', 'b'], ' a b ', 'split') self.checkequal(['a', 'b '], ' a b ', 'split', None, 1) + self.checkequal(['a b c '], ' a b c ', 'split', None, 0) self.checkequal(['a', 'b c '], ' a b c ', 'split', None, 1) self.checkequal(['a', 'b', 'c '], ' a b c ', 'split', None, 2) + self.checkequal(['a', 'b', 'c'], ' a b c ', 'split', None, 3) self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'split') aaa = ' a '*20 self.checkequal(['a']*20, aaa, 'split') self.checkequal(['a'] + [aaa[4:]], aaa, 'split', None, 1) self.checkequal(['a']*19 + ['a '], aaa, 'split', None, 19) - # mixed use of str and unicode - self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', ' ', 2) + for b in ('arf\tbarf', 'arf\nbarf', 'arf\rbarf', + 'arf\fbarf', 'arf\vbarf'): + self.checkequal(['arf', 'barf'], b, 'split') + self.checkequal(['arf', 'barf'], b, 'split', None) + self.checkequal(['arf', 'barf'], b, 'split', None, 2) def test_additional_rsplit(self): self.checkequal(['this', 'is', 'the', 'rsplit', 'function'], @@ -745,36 +754,53 @@ self.checkequal(['a'], ' a ', 'rsplit') self.checkequal(['a', 'b'], ' a b ', 'rsplit') self.checkequal([' a', 'b'], ' a b ', 'rsplit', None, 1) + self.checkequal([' a b c'], ' a b c ', 'rsplit', + None, 0) self.checkequal([' a b','c'], ' a b c ', 'rsplit', None, 1) self.checkequal([' a', 'b', 'c'], ' a b c ', 'rsplit', None, 2) + self.checkequal(['a', 'b', 'c'], ' a b c ', 'rsplit', + None, 3) self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'rsplit', None, 88) aaa = ' a '*20 self.checkequal(['a']*20, aaa, 'rsplit') self.checkequal([aaa[:-4]] + ['a'], aaa, 'rsplit', None, 1) self.checkequal([' a a'] + ['a']*18, aaa, 'rsplit', None, 18) - # mixed use of str and unicode - self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', ' ', 2) + for b in ('arf\tbarf', 'arf\nbarf', 'arf\rbarf', + 'arf\fbarf', 'arf\vbarf'): + self.checkequal(['arf', 'barf'], b, 'rsplit') + self.checkequal(['arf', 'barf'], b, 'rsplit', None) + self.checkequal(['arf', 'barf'], b, 'rsplit', None, 2) - def test_strip(self): + def test_strip_whitespace(self): self.checkequal('hello', ' hello ', 'strip') self.checkequal('hello ', ' hello ', 'lstrip') self.checkequal(' hello', ' hello ', 'rstrip') self.checkequal('hello', 'hello', 'strip') + b = ' \t\n\r\f\vabc \t\n\r\f\v' + self.checkequal('abc', b, 'strip') + self.checkequal('abc \t\n\r\f\v', b, 'lstrip') + self.checkequal(' \t\n\r\f\vabc', b, 'rstrip') + # strip/lstrip/rstrip with None arg self.checkequal('hello', ' hello ', 'strip', None) self.checkequal('hello ', ' hello ', 'lstrip', None) self.checkequal(' hello', ' hello ', 'rstrip', None) self.checkequal('hello', 'hello', 'strip', None) + def test_strip(self): # strip/lstrip/rstrip with str arg self.checkequal('hello', 'xyzzyhelloxyzzy', 'strip', 'xyz') self.checkequal('helloxyzzy', 'xyzzyhelloxyzzy', 'lstrip', 'xyz') self.checkequal('xyzzyhello', 'xyzzyhelloxyzzy', 'rstrip', 'xyz') self.checkequal('hello', 'hello', 'strip', 'xyz') + self.checkequal('', 'mississippi', 'strip', 'mississippi') + + # only trim the start and end; does not strip internal characters + self.checkequal('mississipp', 'mississippi', 'strip', 'i') self.checkraises(TypeError, 'hello', 'strip', 42, 42) self.checkraises(TypeError, 'hello', 'lstrip', 42, 42) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -495,68 +495,16 @@ self.assertEqual(b.replace(b'i', b'a'), b'massassappa') self.assertEqual(b.replace(b'ss', b'x'), b'mixixippi') - def test_split(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.split(b'i'), [b'm', b'ss', b'ss', b'pp', b'']) - self.assertEqual(b.split(b'ss'), [b'mi', b'i', b'ippi']) - self.assertEqual(b.split(b'w'), [b]) - # with keyword args - b = self.type2test(b'a|b|c|d') - self.assertEqual(b.split(sep=b'|'), [b'a', b'b', b'c', b'd']) - self.assertEqual(b.split(b'|', maxsplit=1), [b'a', b'b|c|d']) - self.assertEqual(b.split(sep=b'|', maxsplit=1), [b'a', b'b|c|d']) - self.assertEqual(b.split(maxsplit=1, sep=b'|'), [b'a', b'b|c|d']) - b = self.type2test(b'a b c d') - self.assertEqual(b.split(maxsplit=1), [b'a', b'b c d']) - - def test_split_whitespace(self): - for b in (b' arf barf ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf', - b'arf\fbarf', b'arf\vbarf'): - b = self.type2test(b) - self.assertEqual(b.split(), [b'arf', b'barf']) - self.assertEqual(b.split(None), [b'arf', b'barf']) - self.assertEqual(b.split(None, 2), [b'arf', b'barf']) - for b in (b'a\x1Cb', b'a\x1Db', b'a\x1Eb', b'a\x1Fb'): - b = self.type2test(b) - self.assertEqual(b.split(), [b]) - self.assertEqual(self.type2test(b' a bb c ').split(None, 0), [b'a bb c ']) - self.assertEqual(self.type2test(b' a bb c ').split(None, 1), [b'a', b'bb c ']) - self.assertEqual(self.type2test(b' a bb c ').split(None, 2), [b'a', b'bb', b'c ']) - self.assertEqual(self.type2test(b' a bb c ').split(None, 3), [b'a', b'bb', b'c']) - def test_split_string_error(self): self.assertRaises(TypeError, self.type2test(b'a b').split, ' ') def test_split_unicodewhitespace(self): + for b in (b'a\x1Cb', b'a\x1Db', b'a\x1Eb', b'a\x1Fb'): + b = self.type2test(b) + self.assertEqual(b.split(), [b]) b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F") self.assertEqual(b.split(), [b'\x1c\x1d\x1e\x1f']) - def test_rsplit(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.rsplit(b'i'), [b'm', b'ss', b'ss', b'pp', b'']) - self.assertEqual(b.rsplit(b'ss'), [b'mi', b'i', b'ippi']) - self.assertEqual(b.rsplit(b'w'), [b]) - # with keyword args - b = self.type2test(b'a|b|c|d') - self.assertEqual(b.rsplit(sep=b'|'), [b'a', b'b', b'c', b'd']) - self.assertEqual(b.rsplit(b'|', maxsplit=1), [b'a|b|c', b'd']) - self.assertEqual(b.rsplit(sep=b'|', maxsplit=1), [b'a|b|c', b'd']) - self.assertEqual(b.rsplit(maxsplit=1, sep=b'|'), [b'a|b|c', b'd']) - b = self.type2test(b'a b c d') - self.assertEqual(b.rsplit(maxsplit=1), [b'a b c', b'd']) - - def test_rsplit_whitespace(self): - for b in (b' arf barf ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf', - b'arf\fbarf', b'arf\vbarf'): - b = self.type2test(b) - self.assertEqual(b.rsplit(), [b'arf', b'barf']) - self.assertEqual(b.rsplit(None), [b'arf', b'barf']) - self.assertEqual(b.rsplit(None, 2), [b'arf', b'barf']) - self.assertEqual(self.type2test(b' a bb c ').rsplit(None, 0), [b' a bb c']) - self.assertEqual(self.type2test(b' a bb c ').rsplit(None, 1), [b' a bb', b'c']) - self.assertEqual(self.type2test(b' a bb c ').rsplit(None, 2), [b' a', b'bb', b'c']) - self.assertEqual(self.type2test(b' a bb c ').rsplit(None, 3), [b'a', b'bb', b'c']) - def test_rsplit_string_error(self): self.assertRaises(TypeError, self.type2test(b'a b').rsplit, ' ') @@ -601,37 +549,6 @@ it = pickle.loads(d) self.assertEqual(list(it), data[1:]) - def test_strip(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.strip(b'i'), b'mississipp') - self.assertEqual(b.strip(b'm'), b'ississippi') - self.assertEqual(b.strip(b'pi'), b'mississ') - self.assertEqual(b.strip(b'im'), b'ssissipp') - self.assertEqual(b.strip(b'pim'), b'ssiss') - self.assertEqual(b.strip(b), b'') - - def test_lstrip(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.lstrip(b'i'), b'mississippi') - self.assertEqual(b.lstrip(b'm'), b'ississippi') - self.assertEqual(b.lstrip(b'pi'), b'mississippi') - self.assertEqual(b.lstrip(b'im'), b'ssissippi') - self.assertEqual(b.lstrip(b'pim'), b'ssissippi') - - def test_rstrip(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.rstrip(b'i'), b'mississipp') - self.assertEqual(b.rstrip(b'm'), b'mississippi') - self.assertEqual(b.rstrip(b'pi'), b'mississ') - self.assertEqual(b.rstrip(b'im'), b'mississipp') - self.assertEqual(b.rstrip(b'pim'), b'mississ') - - def test_strip_whitespace(self): - b = self.type2test(b' \t\n\r\f\vabc \t\n\r\f\v') - self.assertEqual(b.strip(), b'abc') - self.assertEqual(b.lstrip(), b'abc \t\n\r\f\v') - self.assertEqual(b.rstrip(), b' \t\n\r\f\vabc') - def test_strip_bytearray(self): self.assertEqual(self.type2test(b'abc').strip(memoryview(b'ac')), b'b') self.assertEqual(self.type2test(b'abc').lstrip(memoryview(b'ac')), b'bc') @@ -1470,7 +1387,7 @@ # XXX More string methods? (Those that don't use character properties) # There are tests in string_tests.py that are more - # comprehensive for things like split, partition, etc. + # comprehensive for things like partition, etc. # Unfortunately they are all bundled with tests that # are not appropriate for bytes diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -380,10 +380,6 @@ def test_split(self): string_tests.CommonTest.test_split(self) - # Mixed arguments - self.checkequalnofix(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//') - self.checkequalnofix(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//') - self.checkequalnofix(['endcase ', ''], 'endcase test', 'split', 'test') # test mixed kinds for left, right in ('ba', '\u0101\u0100', '\U00010301\U00010300'): left *= 9 -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 06:28:13 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 10 Apr 2016 10:28:13 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Remove_relics_?= =?utf-8?q?of_str8_=28became_bytes=29_and_buffer_=28bytearray=29_type_test?= =?utf-8?q?s?= Message-ID: <20160410102809.18837.53204.44C7B27B@psf.io> https://hg.python.org/cpython/rev/a4e3ba22fb6d changeset: 100898:a4e3ba22fb6d branch: 3.5 user: Martin Panter date: Sun Apr 10 08:48:51 2016 +0000 summary: Remove relics of str8 (became bytes) and buffer (bytearray) type tests Remove redundant tests now that str is unicode. files: Lib/test/string_tests.py | 33 ---------------------------- 1 files changed, 0 insertions(+), 33 deletions(-) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -645,14 +645,6 @@ EQ("bobobXbobob", "bobobobXbobobob", "replace", "bobob", "bob") EQ("BOBOBOB", "BOBOBOB", "replace", "bob", "bobby") - # XXX Commented out. Is there any reason to support buffer objects - # as arguments for str.replace()? GvR -## ba = bytearray('a') -## bb = bytearray('b') -## EQ("bbc", "abc", "replace", ba, bb) -## EQ("aac", "abc", "replace", bb, ba) - - # self.checkequal('one at two!three!', 'one!two!three!', 'replace', '!', '@', 1) self.checkequal('onetwothree', 'one!two!three!', 'replace', '!', '') self.checkequal('one at two@three!', 'one!two!three!', 'replace', '!', '@', 2) @@ -1389,28 +1381,3 @@ s1 = t("abcd") s2 = t().join([s1]) self.assertIs(s1, s2) - - # Should also test mixed-type join. - if t is str: - s1 = subclass("abcd") - s2 = "".join([s1]) - self.assertIsNot(s1, s2) - self.assertIs(type(s2), t) - - s1 = t("abcd") - s2 = "".join([s1]) - self.assertIs(s1, s2) - -## elif t is str8: -## s1 = subclass("abcd") -## s2 = "".join([s1]) -## self.assertIsNot(s1, s2) -## self.assertIs(type(s2), str) # promotes! - -## s1 = t("abcd") -## s2 = "".join([s1]) -## self.assertIsNot(s1, s2) -## self.assertIs(type(s2), str) # promotes! - - else: - self.fail("unexpected type for MixinStrUnicodeTest %r" % t) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 06:28:14 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 10 Apr 2016 10:28:14 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326712=3A_Merge_string=5Ftests_cleanup_from_3=2E?= =?utf-8?q?5?= Message-ID: <20160410102812.19144.68386.D758700D@psf.io> https://hg.python.org/cpython/rev/bb3cfca9c431 changeset: 100899:bb3cfca9c431 parent: 100896:5c0e332988b2 parent: 100898:a4e3ba22fb6d user: Martin Panter date: Sun Apr 10 09:16:23 2016 +0000 summary: Issue #26712: Merge string_tests cleanup from 3.5 files: Lib/test/string_tests.py | 69 +++++++++----------- Lib/test/test_bytes.py | 91 +-------------------------- Lib/test/test_unicode.py | 4 - 3 files changed, 35 insertions(+), 129 deletions(-) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -368,6 +368,8 @@ sys.maxsize-2) self.checkequal(['a|b|c|d'], 'a|b|c|d', 'split', '|', 0) self.checkequal(['a', '', 'b||c||d'], 'a||b||c||d', 'split', '|', 2) + self.checkequal(['abcd'], 'abcd', 'split', '|') + self.checkequal([''], '', 'split', '|') self.checkequal(['endcase ', ''], 'endcase |', 'split', '|') self.checkequal(['', ' startcase'], '| startcase', 'split', '|') self.checkequal(['', 'bothcase', ''], '|bothcase|', 'split', '|') @@ -435,6 +437,8 @@ sys.maxsize-100) self.checkequal(['a|b|c|d'], 'a|b|c|d', 'rsplit', '|', 0) self.checkequal(['a||b||c', '', 'd'], 'a||b||c||d', 'rsplit', '|', 2) + self.checkequal(['abcd'], 'abcd', 'rsplit', '|') + self.checkequal([''], '', 'rsplit', '|') self.checkequal(['', ' begincase'], '| begincase', 'rsplit', '|') self.checkequal(['endcase ', ''], 'endcase |', 'rsplit', '|') self.checkequal(['', 'bothcase', ''], '|bothcase|', 'rsplit', '|') @@ -641,14 +645,6 @@ EQ("bobobXbobob", "bobobobXbobobob", "replace", "bobob", "bob") EQ("BOBOBOB", "BOBOBOB", "replace", "bob", "bobby") - # XXX Commented out. Is there any reason to support buffer objects - # as arguments for str.replace()? GvR -## ba = bytearray('a') -## bb = bytearray('b') -## EQ("bbc", "abc", "replace", ba, bb) -## EQ("aac", "abc", "replace", bb, ba) - - # self.checkequal('one at two!three!', 'one!two!three!', 'replace', '!', '@', 1) self.checkequal('onetwothree', 'one!two!three!', 'replace', '!', '') self.checkequal('one at two@three!', 'one!two!three!', 'replace', '!', '@', 2) @@ -714,16 +710,21 @@ self.checkequal(['a'], ' a ', 'split') self.checkequal(['a', 'b'], ' a b ', 'split') self.checkequal(['a', 'b '], ' a b ', 'split', None, 1) + self.checkequal(['a b c '], ' a b c ', 'split', None, 0) self.checkequal(['a', 'b c '], ' a b c ', 'split', None, 1) self.checkequal(['a', 'b', 'c '], ' a b c ', 'split', None, 2) + self.checkequal(['a', 'b', 'c'], ' a b c ', 'split', None, 3) self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'split') aaa = ' a '*20 self.checkequal(['a']*20, aaa, 'split') self.checkequal(['a'] + [aaa[4:]], aaa, 'split', None, 1) self.checkequal(['a']*19 + ['a '], aaa, 'split', None, 19) - # mixed use of str and unicode - self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', ' ', 2) + for b in ('arf\tbarf', 'arf\nbarf', 'arf\rbarf', + 'arf\fbarf', 'arf\vbarf'): + self.checkequal(['arf', 'barf'], b, 'split') + self.checkequal(['arf', 'barf'], b, 'split', None) + self.checkequal(['arf', 'barf'], b, 'split', None, 2) def test_additional_rsplit(self): self.checkequal(['this', 'is', 'the', 'rsplit', 'function'], @@ -745,36 +746,53 @@ self.checkequal(['a'], ' a ', 'rsplit') self.checkequal(['a', 'b'], ' a b ', 'rsplit') self.checkequal([' a', 'b'], ' a b ', 'rsplit', None, 1) + self.checkequal([' a b c'], ' a b c ', 'rsplit', + None, 0) self.checkequal([' a b','c'], ' a b c ', 'rsplit', None, 1) self.checkequal([' a', 'b', 'c'], ' a b c ', 'rsplit', None, 2) + self.checkequal(['a', 'b', 'c'], ' a b c ', 'rsplit', + None, 3) self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'rsplit', None, 88) aaa = ' a '*20 self.checkequal(['a']*20, aaa, 'rsplit') self.checkequal([aaa[:-4]] + ['a'], aaa, 'rsplit', None, 1) self.checkequal([' a a'] + ['a']*18, aaa, 'rsplit', None, 18) - # mixed use of str and unicode - self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', ' ', 2) + for b in ('arf\tbarf', 'arf\nbarf', 'arf\rbarf', + 'arf\fbarf', 'arf\vbarf'): + self.checkequal(['arf', 'barf'], b, 'rsplit') + self.checkequal(['arf', 'barf'], b, 'rsplit', None) + self.checkequal(['arf', 'barf'], b, 'rsplit', None, 2) - def test_strip(self): + def test_strip_whitespace(self): self.checkequal('hello', ' hello ', 'strip') self.checkequal('hello ', ' hello ', 'lstrip') self.checkequal(' hello', ' hello ', 'rstrip') self.checkequal('hello', 'hello', 'strip') + b = ' \t\n\r\f\vabc \t\n\r\f\v' + self.checkequal('abc', b, 'strip') + self.checkequal('abc \t\n\r\f\v', b, 'lstrip') + self.checkequal(' \t\n\r\f\vabc', b, 'rstrip') + # strip/lstrip/rstrip with None arg self.checkequal('hello', ' hello ', 'strip', None) self.checkequal('hello ', ' hello ', 'lstrip', None) self.checkequal(' hello', ' hello ', 'rstrip', None) self.checkequal('hello', 'hello', 'strip', None) + def test_strip(self): # strip/lstrip/rstrip with str arg self.checkequal('hello', 'xyzzyhelloxyzzy', 'strip', 'xyz') self.checkequal('helloxyzzy', 'xyzzyhelloxyzzy', 'lstrip', 'xyz') self.checkequal('xyzzyhello', 'xyzzyhelloxyzzy', 'rstrip', 'xyz') self.checkequal('hello', 'hello', 'strip', 'xyz') + self.checkequal('', 'mississippi', 'strip', 'mississippi') + + # only trim the start and end; does not strip internal characters + self.checkequal('mississipp', 'mississippi', 'strip', 'i') self.checkraises(TypeError, 'hello', 'strip', 42, 42) self.checkraises(TypeError, 'hello', 'lstrip', 42, 42) @@ -1363,28 +1381,3 @@ s1 = t("abcd") s2 = t().join([s1]) self.assertIs(s1, s2) - - # Should also test mixed-type join. - if t is str: - s1 = subclass("abcd") - s2 = "".join([s1]) - self.assertIsNot(s1, s2) - self.assertIs(type(s2), t) - - s1 = t("abcd") - s2 = "".join([s1]) - self.assertIs(s1, s2) - -## elif t is str8: -## s1 = subclass("abcd") -## s2 = "".join([s1]) -## self.assertIsNot(s1, s2) -## self.assertIs(type(s2), str) # promotes! - -## s1 = t("abcd") -## s2 = "".join([s1]) -## self.assertIsNot(s1, s2) -## self.assertIs(type(s2), str) # promotes! - - else: - self.fail("unexpected type for MixinStrUnicodeTest %r" % t) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -509,68 +509,16 @@ self.assertEqual(b.replace(b'i', b'a'), b'massassappa') self.assertEqual(b.replace(b'ss', b'x'), b'mixixippi') - def test_split(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.split(b'i'), [b'm', b'ss', b'ss', b'pp', b'']) - self.assertEqual(b.split(b'ss'), [b'mi', b'i', b'ippi']) - self.assertEqual(b.split(b'w'), [b]) - # with keyword args - b = self.type2test(b'a|b|c|d') - self.assertEqual(b.split(sep=b'|'), [b'a', b'b', b'c', b'd']) - self.assertEqual(b.split(b'|', maxsplit=1), [b'a', b'b|c|d']) - self.assertEqual(b.split(sep=b'|', maxsplit=1), [b'a', b'b|c|d']) - self.assertEqual(b.split(maxsplit=1, sep=b'|'), [b'a', b'b|c|d']) - b = self.type2test(b'a b c d') - self.assertEqual(b.split(maxsplit=1), [b'a', b'b c d']) - - def test_split_whitespace(self): - for b in (b' arf barf ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf', - b'arf\fbarf', b'arf\vbarf'): - b = self.type2test(b) - self.assertEqual(b.split(), [b'arf', b'barf']) - self.assertEqual(b.split(None), [b'arf', b'barf']) - self.assertEqual(b.split(None, 2), [b'arf', b'barf']) - for b in (b'a\x1Cb', b'a\x1Db', b'a\x1Eb', b'a\x1Fb'): - b = self.type2test(b) - self.assertEqual(b.split(), [b]) - self.assertEqual(self.type2test(b' a bb c ').split(None, 0), [b'a bb c ']) - self.assertEqual(self.type2test(b' a bb c ').split(None, 1), [b'a', b'bb c ']) - self.assertEqual(self.type2test(b' a bb c ').split(None, 2), [b'a', b'bb', b'c ']) - self.assertEqual(self.type2test(b' a bb c ').split(None, 3), [b'a', b'bb', b'c']) - def test_split_string_error(self): self.assertRaises(TypeError, self.type2test(b'a b').split, ' ') def test_split_unicodewhitespace(self): + for b in (b'a\x1Cb', b'a\x1Db', b'a\x1Eb', b'a\x1Fb'): + b = self.type2test(b) + self.assertEqual(b.split(), [b]) b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F") self.assertEqual(b.split(), [b'\x1c\x1d\x1e\x1f']) - def test_rsplit(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.rsplit(b'i'), [b'm', b'ss', b'ss', b'pp', b'']) - self.assertEqual(b.rsplit(b'ss'), [b'mi', b'i', b'ippi']) - self.assertEqual(b.rsplit(b'w'), [b]) - # with keyword args - b = self.type2test(b'a|b|c|d') - self.assertEqual(b.rsplit(sep=b'|'), [b'a', b'b', b'c', b'd']) - self.assertEqual(b.rsplit(b'|', maxsplit=1), [b'a|b|c', b'd']) - self.assertEqual(b.rsplit(sep=b'|', maxsplit=1), [b'a|b|c', b'd']) - self.assertEqual(b.rsplit(maxsplit=1, sep=b'|'), [b'a|b|c', b'd']) - b = self.type2test(b'a b c d') - self.assertEqual(b.rsplit(maxsplit=1), [b'a b c', b'd']) - - def test_rsplit_whitespace(self): - for b in (b' arf barf ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf', - b'arf\fbarf', b'arf\vbarf'): - b = self.type2test(b) - self.assertEqual(b.rsplit(), [b'arf', b'barf']) - self.assertEqual(b.rsplit(None), [b'arf', b'barf']) - self.assertEqual(b.rsplit(None, 2), [b'arf', b'barf']) - self.assertEqual(self.type2test(b' a bb c ').rsplit(None, 0), [b' a bb c']) - self.assertEqual(self.type2test(b' a bb c ').rsplit(None, 1), [b' a bb', b'c']) - self.assertEqual(self.type2test(b' a bb c ').rsplit(None, 2), [b' a', b'bb', b'c']) - self.assertEqual(self.type2test(b' a bb c ').rsplit(None, 3), [b'a', b'bb', b'c']) - def test_rsplit_string_error(self): self.assertRaises(TypeError, self.type2test(b'a b').rsplit, ' ') @@ -615,37 +563,6 @@ it = pickle.loads(d) self.assertEqual(list(it), data[1:]) - def test_strip(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.strip(b'i'), b'mississipp') - self.assertEqual(b.strip(b'm'), b'ississippi') - self.assertEqual(b.strip(b'pi'), b'mississ') - self.assertEqual(b.strip(b'im'), b'ssissipp') - self.assertEqual(b.strip(b'pim'), b'ssiss') - self.assertEqual(b.strip(b), b'') - - def test_lstrip(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.lstrip(b'i'), b'mississippi') - self.assertEqual(b.lstrip(b'm'), b'ississippi') - self.assertEqual(b.lstrip(b'pi'), b'mississippi') - self.assertEqual(b.lstrip(b'im'), b'ssissippi') - self.assertEqual(b.lstrip(b'pim'), b'ssissippi') - - def test_rstrip(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.rstrip(b'i'), b'mississipp') - self.assertEqual(b.rstrip(b'm'), b'mississippi') - self.assertEqual(b.rstrip(b'pi'), b'mississ') - self.assertEqual(b.rstrip(b'im'), b'mississipp') - self.assertEqual(b.rstrip(b'pim'), b'mississ') - - def test_strip_whitespace(self): - b = self.type2test(b' \t\n\r\f\vabc \t\n\r\f\v') - self.assertEqual(b.strip(), b'abc') - self.assertEqual(b.lstrip(), b'abc \t\n\r\f\v') - self.assertEqual(b.rstrip(), b' \t\n\r\f\vabc') - def test_strip_bytearray(self): self.assertEqual(self.type2test(b'abc').strip(memoryview(b'ac')), b'b') self.assertEqual(self.type2test(b'abc').lstrip(memoryview(b'ac')), b'bc') @@ -1565,7 +1482,7 @@ # XXX More string methods? (Those that don't use character properties) # There are tests in string_tests.py that are more - # comprehensive for things like split, partition, etc. + # comprehensive for things like partition, etc. # Unfortunately they are all bundled with tests that # are not appropriate for bytes diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -380,10 +380,6 @@ def test_split(self): string_tests.CommonTest.test_split(self) - # Mixed arguments - self.checkequalnofix(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//') - self.checkequalnofix(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//') - self.checkequalnofix(['endcase ', ''], 'endcase test', 'split', 'test') # test mixed kinds for left, right in ('ba', '\u0101\u0100', '\U00010301\U00010300'): left *= 9 -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 06:28:14 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 10 Apr 2016 10:28:14 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2NzEy?= =?utf-8?b?OiBVbmlmeSAocilzcGxpdCgpLCAobC9yKXN0cmlwKCkgdGVzdHMgaW50byBz?= =?utf-8?q?tring=5Ftests?= Message-ID: <20160410102814.11627.82612.6B7C8086@psf.io> https://hg.python.org/cpython/rev/4dc347c5c8a8 changeset: 100900:4dc347c5c8a8 branch: 2.7 parent: 100893:4f64b1c87a56 user: Martin Panter date: Sun Apr 10 09:39:07 2016 +0000 summary: Issue #26712: Unify (r)split(), (l/r)strip() tests into string_tests This eliminates a few redundant test cases. files: Lib/test/string_tests.py | 33 +++++++++++- Lib/test/test_bytes.py | 75 +-------------------------- 2 files changed, 36 insertions(+), 72 deletions(-) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -349,14 +349,22 @@ self.checkequal(['a'], ' a ', 'split') self.checkequal(['a', 'b'], ' a b ', 'split') self.checkequal(['a', 'b '], ' a b ', 'split', None, 1) + self.checkequal(['a b c '], ' a b c ', 'split', None, 0) self.checkequal(['a', 'b c '], ' a b c ', 'split', None, 1) self.checkequal(['a', 'b', 'c '], ' a b c ', 'split', None, 2) + self.checkequal(['a', 'b', 'c'], ' a b c ', 'split', None, 3) self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'split') aaa = ' a '*20 self.checkequal(['a']*20, aaa, 'split') self.checkequal(['a'] + [aaa[4:]], aaa, 'split', None, 1) self.checkequal(['a']*19 + ['a '], aaa, 'split', None, 19) + for b in ('arf\tbarf', 'arf\nbarf', 'arf\rbarf', + 'arf\fbarf', 'arf\vbarf'): + self.checkequal(['arf', 'barf'], b, 'split') + self.checkequal(['arf', 'barf'], b, 'split', None) + self.checkequal(['arf', 'barf'], b, 'split', None, 2) + # by a char self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|') self.checkequal(['a|b|c|d'], 'a|b|c|d', 'split', '|', 0) @@ -368,6 +376,8 @@ sys.maxint-2) self.checkequal(['a|b|c|d'], 'a|b|c|d', 'split', '|', 0) self.checkequal(['a', '', 'b||c||d'], 'a||b||c||d', 'split', '|', 2) + self.checkequal(['abcd'], 'abcd', 'split', '|') + self.checkequal([''], '', 'split', '|') self.checkequal(['endcase ', ''], 'endcase |', 'split', '|') self.checkequal(['', ' startcase'], '| startcase', 'split', '|') self.checkequal(['', 'bothcase', ''], '|bothcase|', 'split', '|') @@ -438,16 +448,25 @@ self.checkequal(['a'], ' a ', 'rsplit') self.checkequal(['a', 'b'], ' a b ', 'rsplit') self.checkequal([' a', 'b'], ' a b ', 'rsplit', None, 1) + self.checkequal([' a b c'], ' a b c ', 'rsplit', + None, 0) self.checkequal([' a b','c'], ' a b c ', 'rsplit', None, 1) self.checkequal([' a', 'b', 'c'], ' a b c ', 'rsplit', None, 2) + self.checkequal(['a', 'b', 'c'], ' a b c ', 'rsplit', + None, 3) self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'rsplit', None, 88) aaa = ' a '*20 self.checkequal(['a']*20, aaa, 'rsplit') self.checkequal([aaa[:-4]] + ['a'], aaa, 'rsplit', None, 1) self.checkequal([' a a'] + ['a']*18, aaa, 'rsplit', None, 18) + for b in ('arf\tbarf', 'arf\nbarf', 'arf\rbarf', + 'arf\fbarf', 'arf\vbarf'): + self.checkequal(['arf', 'barf'], b, 'rsplit') + self.checkequal(['arf', 'barf'], b, 'rsplit', None) + self.checkequal(['arf', 'barf'], b, 'rsplit', None, 2) # by a char self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|') @@ -459,6 +478,8 @@ sys.maxint-100) self.checkequal(['a|b|c|d'], 'a|b|c|d', 'rsplit', '|', 0) self.checkequal(['a||b||c', '', 'd'], 'a||b||c||d', 'rsplit', '|', 2) + self.checkequal(['abcd'], 'abcd', 'rsplit', '|') + self.checkequal([''], '', 'rsplit', '|') self.checkequal(['', ' begincase'], '| begincase', 'rsplit', '|') self.checkequal(['endcase ', ''], 'endcase |', 'rsplit', '|') self.checkequal(['', 'bothcase', ''], '|bothcase|', 'rsplit', '|') @@ -510,23 +531,33 @@ self.checkraises(ValueError, 'hello', 'rsplit', '') self.checkraises(ValueError, 'hello', 'rsplit', '', 0) - def test_strip(self): + def test_strip_whitespace(self): self.checkequal('hello', ' hello ', 'strip') self.checkequal('hello ', ' hello ', 'lstrip') self.checkequal(' hello', ' hello ', 'rstrip') self.checkequal('hello', 'hello', 'strip') + b = ' \t\n\r\f\vabc \t\n\r\f\v' + self.checkequal('abc', b, 'strip') + self.checkequal('abc \t\n\r\f\v', b, 'lstrip') + self.checkequal(' \t\n\r\f\vabc', b, 'rstrip') + # strip/lstrip/rstrip with None arg self.checkequal('hello', ' hello ', 'strip', None) self.checkequal('hello ', ' hello ', 'lstrip', None) self.checkequal(' hello', ' hello ', 'rstrip', None) self.checkequal('hello', 'hello', 'strip', None) + def test_strip(self): # strip/lstrip/rstrip with str arg self.checkequal('hello', 'xyzzyhelloxyzzy', 'strip', 'xyz') self.checkequal('helloxyzzy', 'xyzzyhelloxyzzy', 'lstrip', 'xyz') self.checkequal('xyzzyhello', 'xyzzyhelloxyzzy', 'rstrip', 'xyz') self.checkequal('hello', 'hello', 'strip', 'xyz') + self.checkequal('', 'mississippi', 'strip', 'mississippi') + + # only trims the start and end, does not strip internal characters + self.checkequal('mississipp', 'mississippi', 'strip', 'i') # strip/lstrip/rstrip with unicode arg if self.type2test is not bytearray and test_support.have_unicode: diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -336,52 +336,16 @@ self.assertEqual(b.replace(b'i', b'a'), b'massassappa') self.assertEqual(b.replace(b'ss', b'x'), b'mixixippi') - def test_split(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.split(b'i'), [b'm', b'ss', b'ss', b'pp', b'']) - self.assertEqual(b.split(b'ss'), [b'mi', b'i', b'ippi']) - self.assertEqual(b.split(b'w'), [b]) - - def test_split_whitespace(self): - for b in (b' arf barf ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf', - b'arf\fbarf', b'arf\vbarf'): - b = self.type2test(b) - self.assertEqual(b.split(), [b'arf', b'barf']) - self.assertEqual(b.split(None), [b'arf', b'barf']) - self.assertEqual(b.split(None, 2), [b'arf', b'barf']) - for b in (b'a\x1Cb', b'a\x1Db', b'a\x1Eb', b'a\x1Fb'): - b = self.type2test(b) - self.assertEqual(b.split(), [b]) - self.assertEqual(self.type2test(b' a bb c ').split(None, 0), [b'a bb c ']) - self.assertEqual(self.type2test(b' a bb c ').split(None, 1), [b'a', b'bb c ']) - self.assertEqual(self.type2test(b' a bb c ').split(None, 2), [b'a', b'bb', b'c ']) - self.assertEqual(self.type2test(b' a bb c ').split(None, 3), [b'a', b'bb', b'c']) - def test_split_string_error(self): self.assertRaises(TypeError, self.type2test(b'a b').split, u' ') def test_split_unicodewhitespace(self): + for b in (b'a\x1Cb', b'a\x1Db', b'a\x1Eb', b'a\x1Fb'): + b = self.type2test(b) + self.assertEqual(b.split(), [b]) b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F") self.assertEqual(b.split(), [b'\x1c\x1d\x1e\x1f']) - def test_rsplit(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.rsplit(b'i'), [b'm', b'ss', b'ss', b'pp', b'']) - self.assertEqual(b.rsplit(b'ss'), [b'mi', b'i', b'ippi']) - self.assertEqual(b.rsplit(b'w'), [b]) - - def test_rsplit_whitespace(self): - for b in (b' arf barf ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf', - b'arf\fbarf', b'arf\vbarf'): - b = self.type2test(b) - self.assertEqual(b.rsplit(), [b'arf', b'barf']) - self.assertEqual(b.rsplit(None), [b'arf', b'barf']) - self.assertEqual(b.rsplit(None, 2), [b'arf', b'barf']) - self.assertEqual(self.type2test(b' a bb c ').rsplit(None, 0), [b' a bb c']) - self.assertEqual(self.type2test(b' a bb c ').rsplit(None, 1), [b' a bb', b'c']) - self.assertEqual(self.type2test(b' a bb c ').rsplit(None, 2), [b' a', b'bb', b'c']) - self.assertEqual(self.type2test(b' a bb c ').rsplit(None, 3), [b'a', b'bb', b'c']) - def test_rsplit_string_error(self): self.assertRaises(TypeError, self.type2test(b'a b').rsplit, u' ') @@ -408,37 +372,6 @@ q = pickle.loads(ps) self.assertEqual(b, q) - def test_strip(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.strip(b'i'), b'mississipp') - self.assertEqual(b.strip(b'm'), b'ississippi') - self.assertEqual(b.strip(b'pi'), b'mississ') - self.assertEqual(b.strip(b'im'), b'ssissipp') - self.assertEqual(b.strip(b'pim'), b'ssiss') - self.assertEqual(b.strip(b), b'') - - def test_lstrip(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.lstrip(b'i'), b'mississippi') - self.assertEqual(b.lstrip(b'm'), b'ississippi') - self.assertEqual(b.lstrip(b'pi'), b'mississippi') - self.assertEqual(b.lstrip(b'im'), b'ssissippi') - self.assertEqual(b.lstrip(b'pim'), b'ssissippi') - - def test_rstrip(self): - b = self.type2test(b'mississippi') - self.assertEqual(b.rstrip(b'i'), b'mississipp') - self.assertEqual(b.rstrip(b'm'), b'mississippi') - self.assertEqual(b.rstrip(b'pi'), b'mississ') - self.assertEqual(b.rstrip(b'im'), b'mississipp') - self.assertEqual(b.rstrip(b'pim'), b'mississ') - - def test_strip_whitespace(self): - b = self.type2test(b' \t\n\r\f\vabc \t\n\r\f\v') - self.assertEqual(b.strip(), b'abc') - self.assertEqual(b.lstrip(), b'abc \t\n\r\f\v') - self.assertEqual(b.rstrip(), b' \t\n\r\f\vabc') - def test_strip_bytearray(self): self.assertEqual(self.type2test(b'abc').strip(memoryview(b'ac')), b'b') self.assertEqual(self.type2test(b'abc').lstrip(memoryview(b'ac')), b'bc') @@ -1020,7 +953,7 @@ # XXX More string methods? (Those that don't use character properties) # There are tests in string_tests.py that are more - # comprehensive for things like split, partition, etc. + # comprehensive for things like partition, etc. # Unfortunately they are all bundled with tests that # are not appropriate for bytes -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 07:45:41 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 10 Apr 2016 11:45:41 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI1MzM5?= =?utf-8?q?=3A_PYTHONIOENCODING_now_has_priority_over_locale_in_setting_th?= =?utf-8?q?e?= Message-ID: <20160410114541.18859.79191.C4033EA0@psf.io> https://hg.python.org/cpython/rev/56eca1c08738 changeset: 100901:56eca1c08738 branch: 3.5 parent: 100898:a4e3ba22fb6d user: Serhiy Storchaka date: Sun Apr 10 14:34:13 2016 +0300 summary: Issue #25339: PYTHONIOENCODING now has priority over locale in setting the error handler for stdin and stdout. files: Lib/test/test_sys.py | 27 +++++++++++++++++++++++---- Misc/NEWS | 3 +++ Python/pylifecycle.c | 19 +++++++++---------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -691,8 +691,10 @@ args = [sys.executable, "-c", code] if isolated: args.append("-I") - elif encoding: + if encoding is not None: env['PYTHONIOENCODING'] = encoding + else: + env.pop('PYTHONIOENCODING', None) p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, @@ -709,14 +711,31 @@ 'stderr: backslashreplace\n') # replace the default error handler - out = self.c_locale_get_error_handler(encoding=':strict') + out = self.c_locale_get_error_handler(encoding=':ignore') + self.assertEqual(out, + 'stdin: ignore\n' + 'stdout: ignore\n' + 'stderr: backslashreplace\n') + + # force the encoding + out = self.c_locale_get_error_handler(encoding='iso8859-1') + self.assertEqual(out, + 'stdin: strict\n' + 'stdout: strict\n' + 'stderr: backslashreplace\n') + out = self.c_locale_get_error_handler(encoding='iso8859-1:') self.assertEqual(out, 'stdin: strict\n' 'stdout: strict\n' 'stderr: backslashreplace\n') - # force the encoding - out = self.c_locale_get_error_handler(encoding='iso8859-1') + # have no any effect + out = self.c_locale_get_error_handler(encoding=':') + self.assertEqual(out, + 'stdin: surrogateescape\n' + 'stdout: surrogateescape\n' + 'stderr: backslashreplace\n') + out = self.c_locale_get_error_handler(encoding='') self.assertEqual(out, 'stdin: surrogateescape\n' 'stdout: surrogateescape\n' diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #25339: PYTHONIOENCODING now has priority over locale in setting the + error handler for stdin and stdout. + - Issue #26494: Fixed crash on iterating exhausting iterators. Affected classes are generic sequence iterators, iterators of str, bytes, bytearray, list, tuple, set, frozenset, dict, OrderedDict, corresponding diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1135,15 +1135,6 @@ encoding = _Py_StandardStreamEncoding; errors = _Py_StandardStreamErrors; if (!encoding || !errors) { - if (!errors) { - /* When the LC_CTYPE locale is the POSIX locale ("C locale"), - stdin and stdout use the surrogateescape error handler by - default, instead of the strict error handler. */ - char *loc = setlocale(LC_CTYPE, NULL); - if (loc != NULL && strcmp(loc, "C") == 0) - errors = "surrogateescape"; - } - pythonioencoding = Py_GETENV("PYTHONIOENCODING"); if (pythonioencoding) { char *err; @@ -1156,7 +1147,7 @@ if (err) { *err = '\0'; err++; - if (*err && !_Py_StandardStreamErrors) { + if (*err && !errors) { errors = err; } } @@ -1164,6 +1155,14 @@ encoding = pythonioencoding; } } + if (!errors && !(pythonioencoding && *pythonioencoding)) { + /* When the LC_CTYPE locale is the POSIX locale ("C locale"), + stdin and stdout use the surrogateescape error handler by + default, instead of the strict error handler. */ + char *loc = setlocale(LC_CTYPE, NULL); + if (loc != NULL && strcmp(loc, "C") == 0) + errors = "surrogateescape"; + } } /* Set sys.stdin */ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 07:45:43 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 10 Apr 2016 11:45:43 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2317339=3A_Improved?= =?utf-8?q?_TypeError_message_in_bytes_constructor=2E?= Message-ID: <20160410114542.19166.42222.D4F59052@psf.io> https://hg.python.org/cpython/rev/6b16eec56854 changeset: 100905:6b16eec56854 user: Serhiy Storchaka date: Sun Apr 10 14:44:59 2016 +0300 summary: Issue #17339: Improved TypeError message in bytes constructor. files: Objects/bytesobject.c | 31 +++++++++++++++---------------- 1 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3469,31 +3469,24 @@ } static PyObject * -_PyBytes_FromIterator(PyObject *x) +_PyBytes_FromIterator(PyObject *it, PyObject *x) { char *str; - PyObject *it; Py_ssize_t i, size; _PyBytesWriter writer; - _PyBytesWriter_Init(&writer); - /* For iterator version, create a string object and resize as needed */ size = PyObject_LengthHint(x, 64); if (size == -1 && PyErr_Occurred()) return NULL; + _PyBytesWriter_Init(&writer); str = _PyBytesWriter_Alloc(&writer, size); if (str == NULL) return NULL; writer.overallocate = 1; size = writer.allocated; - /* Get the iterator */ - it = PyObject_GetIter(x); - if (it == NULL) - goto error; - /* Run the iterator to exhaustion */ for (i = 0; ; i++) { PyObject *item; @@ -3529,19 +3522,19 @@ } *str++ = (char) value; } - Py_DECREF(it); return _PyBytesWriter_Finish(&writer, str); error: _PyBytesWriter_Dealloc(&writer); - Py_XDECREF(it); return NULL; } PyObject * PyBytes_FromObject(PyObject *x) { + PyObject *it, *result; + if (x == NULL) { PyErr_BadInternalCall(); return NULL; @@ -3562,13 +3555,19 @@ if (PyTuple_CheckExact(x)) return _PyBytes_FromTuple(x); - if (PyUnicode_Check(x)) { - PyErr_SetString(PyExc_TypeError, - "cannot convert unicode object to bytes"); - return NULL; + if (!PyUnicode_Check(x)) { + it = PyObject_GetIter(x); + if (it != NULL) { + result = _PyBytes_FromIterator(it, x); + Py_DECREF(it); + return result; + } } - return _PyBytes_FromIterator(x); + PyErr_Format(PyExc_TypeError, + "cannot convert '%.200s' object to bytes", + x->ob_type->tp_name); + return NULL; } static PyObject * -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 07:45:43 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 10 Apr 2016 11:45:43 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NzE5?= =?utf-8?q?=3A_More_efficient_formatting_of_ints_and_floats_in_json=2E?= Message-ID: <20160410114542.90778.24866.3B5FB9CF@psf.io> https://hg.python.org/cpython/rev/4d4febb76864 changeset: 100903:4d4febb76864 branch: 3.5 parent: 100901:56eca1c08738 user: Serhiy Storchaka date: Sun Apr 10 14:41:19 2016 +0300 summary: Issue #26719: More efficient formatting of ints and floats in json. files: Lib/json/encoder.py | 20 +++++----- Modules/_json.c | 56 ++------------------------------ 2 files changed, 14 insertions(+), 62 deletions(-) diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py --- a/Lib/json/encoder.py +++ b/Lib/json/encoder.py @@ -32,7 +32,6 @@ #ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i,)) INFINITY = float('inf') -FLOAT_REPR = repr def py_encode_basestring(s): """Return a JSON representation of a Python string @@ -221,7 +220,7 @@ _encoder = encode_basestring def floatstr(o, allow_nan=self.allow_nan, - _repr=FLOAT_REPR, _inf=INFINITY, _neginf=-INFINITY): + _repr=float.__repr__, _inf=INFINITY, _neginf=-INFINITY): # Check for specials. Note that this type of test is processor # and/or platform-specific, so do tests which don't depend on the # internals. @@ -268,6 +267,7 @@ list=list, str=str, tuple=tuple, + _intstr=int.__str__, ): if _indent is not None and not isinstance(_indent, str): @@ -309,10 +309,10 @@ # Subclasses of int/float may override __str__, but we still # want to encode them as integers/floats in JSON. One example # within the standard library is IntEnum. - yield buf + str(int(value)) + yield buf + _intstr(value) elif isinstance(value, float): # see comment above for int - yield buf + _floatstr(float(value)) + yield buf + _floatstr(value) else: yield buf if isinstance(value, (list, tuple)): @@ -359,7 +359,7 @@ # also allow them. Many encoders seem to do something like this. elif isinstance(key, float): # see comment for int/float in _make_iterencode - key = _floatstr(float(key)) + key = _floatstr(key) elif key is True: key = 'true' elif key is False: @@ -368,7 +368,7 @@ key = 'null' elif isinstance(key, int): # see comment for int/float in _make_iterencode - key = str(int(key)) + key = _intstr(key) elif _skipkeys: continue else: @@ -389,10 +389,10 @@ yield 'false' elif isinstance(value, int): # see comment for int/float in _make_iterencode - yield str(int(value)) + yield _intstr(value) elif isinstance(value, float): # see comment for int/float in _make_iterencode - yield _floatstr(float(value)) + yield _floatstr(value) else: if isinstance(value, (list, tuple)): chunks = _iterencode_list(value, _current_indent_level) @@ -419,10 +419,10 @@ yield 'false' elif isinstance(o, int): # see comment for int/float in _make_iterencode - yield str(int(o)) + yield _intstr(o) elif isinstance(o, float): # see comment for int/float in _make_iterencode - yield _floatstr(float(o)) + yield _floatstr(o) elif isinstance(o, (list, tuple)): yield from _iterencode_list(o, _current_indent_level) elif isinstance(o, dict): diff --git a/Modules/_json.c b/Modules/_json.c --- a/Modules/_json.c +++ b/Modules/_json.c @@ -116,8 +116,6 @@ static PyObject * encoder_encode_string(PyEncoderObject *s, PyObject *obj); static PyObject * -encoder_encode_long(PyEncoderObject* s UNUSED, PyObject *obj); -static PyObject * encoder_encode_float(PyEncoderObject *s, PyObject *obj); #define S_CHAR(c) (c >= ' ' && c <= '~' && c != '\\' && c != '"') @@ -1445,38 +1443,9 @@ } static PyObject * -encoder_encode_long(PyEncoderObject* s UNUSED, PyObject *obj) -{ - /* Return the JSON representation of a PyLong and PyLong subclasses. - Calls int() on PyLong subclasses in case the str() was changed. - Added specifically to deal with IntEnum. See Issue18264. */ - PyObject *encoded, *longobj; - if (PyLong_CheckExact(obj)) { - encoded = PyObject_Str(obj); - } - else { - longobj = PyNumber_Long(obj); - if (longobj == NULL) { - PyErr_SetString( - PyExc_ValueError, - "Unable to coerce int subclass to int" - ); - return NULL; - } - encoded = PyObject_Str(longobj); - Py_DECREF(longobj); - } - return encoded; -} - - -static PyObject * encoder_encode_float(PyEncoderObject *s, PyObject *obj) { - /* Return the JSON representation of a PyFloat. - Modified to call float() on float subclasses in case the subclass - changes the repr. See Issue18264. */ - PyObject *encoded, *floatobj; + /* Return the JSON representation of a PyFloat. */ double i = PyFloat_AS_DOUBLE(obj); if (!Py_IS_FINITE(i)) { if (!s->allow_nan) { @@ -1496,24 +1465,7 @@ return PyUnicode_FromString("NaN"); } } - /* coerce float subclasses to float (primarily for Enum) */ - if (PyFloat_CheckExact(obj)) { - /* Use a better float format here? */ - encoded = PyObject_Repr(obj); - } - else { - floatobj = PyNumber_Float(obj); - if (floatobj == NULL) { - PyErr_SetString( - PyExc_ValueError, - "Unable to coerce float subclass to float" - ); - return NULL; - } - encoded = PyObject_Repr(floatobj); - Py_DECREF(floatobj); - } - return encoded; + return PyFloat_Type.tp_repr(obj); } static PyObject * @@ -1557,7 +1509,7 @@ return _steal_accumulate(acc, encoded); } else if (PyLong_Check(obj)) { - PyObject *encoded = encoder_encode_long(s, obj); + PyObject *encoded = PyLong_Type.tp_str(obj); if (encoded == NULL) return -1; return _steal_accumulate(acc, encoded); @@ -1722,7 +1674,7 @@ goto bail; } else if (PyLong_Check(key)) { - kstr = encoder_encode_long(s, key); + kstr = PyLong_Type.tp_str(key); if (kstr == NULL) { goto bail; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 07:45:43 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 10 Apr 2016 11:45:43 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326719=3A_More_efficient_formatting_of_ints_and_?= =?utf-8?q?floats_in_json=2E?= Message-ID: <20160410114542.16605.13109.5247EDEA@psf.io> https://hg.python.org/cpython/rev/36b15a9776ae changeset: 100904:36b15a9776ae parent: 100902:9c6623099da1 parent: 100903:4d4febb76864 user: Serhiy Storchaka date: Sun Apr 10 14:43:04 2016 +0300 summary: Issue #26719: More efficient formatting of ints and floats in json. files: Lib/json/encoder.py | 20 +++++----- Modules/_json.c | 56 ++------------------------------ 2 files changed, 14 insertions(+), 62 deletions(-) diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py --- a/Lib/json/encoder.py +++ b/Lib/json/encoder.py @@ -32,7 +32,6 @@ #ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i,)) INFINITY = float('inf') -FLOAT_REPR = repr def py_encode_basestring(s): """Return a JSON representation of a Python string @@ -221,7 +220,7 @@ _encoder = encode_basestring def floatstr(o, allow_nan=self.allow_nan, - _repr=FLOAT_REPR, _inf=INFINITY, _neginf=-INFINITY): + _repr=float.__repr__, _inf=INFINITY, _neginf=-INFINITY): # Check for specials. Note that this type of test is processor # and/or platform-specific, so do tests which don't depend on the # internals. @@ -268,6 +267,7 @@ list=list, str=str, tuple=tuple, + _intstr=int.__str__, ): if _indent is not None and not isinstance(_indent, str): @@ -309,10 +309,10 @@ # Subclasses of int/float may override __str__, but we still # want to encode them as integers/floats in JSON. One example # within the standard library is IntEnum. - yield buf + str(int(value)) + yield buf + _intstr(value) elif isinstance(value, float): # see comment above for int - yield buf + _floatstr(float(value)) + yield buf + _floatstr(value) else: yield buf if isinstance(value, (list, tuple)): @@ -359,7 +359,7 @@ # also allow them. Many encoders seem to do something like this. elif isinstance(key, float): # see comment for int/float in _make_iterencode - key = _floatstr(float(key)) + key = _floatstr(key) elif key is True: key = 'true' elif key is False: @@ -368,7 +368,7 @@ key = 'null' elif isinstance(key, int): # see comment for int/float in _make_iterencode - key = str(int(key)) + key = _intstr(key) elif _skipkeys: continue else: @@ -389,10 +389,10 @@ yield 'false' elif isinstance(value, int): # see comment for int/float in _make_iterencode - yield str(int(value)) + yield _intstr(value) elif isinstance(value, float): # see comment for int/float in _make_iterencode - yield _floatstr(float(value)) + yield _floatstr(value) else: if isinstance(value, (list, tuple)): chunks = _iterencode_list(value, _current_indent_level) @@ -419,10 +419,10 @@ yield 'false' elif isinstance(o, int): # see comment for int/float in _make_iterencode - yield str(int(o)) + yield _intstr(o) elif isinstance(o, float): # see comment for int/float in _make_iterencode - yield _floatstr(float(o)) + yield _floatstr(o) elif isinstance(o, (list, tuple)): yield from _iterencode_list(o, _current_indent_level) elif isinstance(o, dict): diff --git a/Modules/_json.c b/Modules/_json.c --- a/Modules/_json.c +++ b/Modules/_json.c @@ -116,8 +116,6 @@ static PyObject * encoder_encode_string(PyEncoderObject *s, PyObject *obj); static PyObject * -encoder_encode_long(PyEncoderObject* s UNUSED, PyObject *obj); -static PyObject * encoder_encode_float(PyEncoderObject *s, PyObject *obj); #define S_CHAR(c) (c >= ' ' && c <= '~' && c != '\\' && c != '"') @@ -1445,38 +1443,9 @@ } static PyObject * -encoder_encode_long(PyEncoderObject* s UNUSED, PyObject *obj) -{ - /* Return the JSON representation of a PyLong and PyLong subclasses. - Calls int() on PyLong subclasses in case the str() was changed. - Added specifically to deal with IntEnum. See Issue18264. */ - PyObject *encoded, *longobj; - if (PyLong_CheckExact(obj)) { - encoded = PyObject_Str(obj); - } - else { - longobj = PyNumber_Long(obj); - if (longobj == NULL) { - PyErr_SetString( - PyExc_ValueError, - "Unable to coerce int subclass to int" - ); - return NULL; - } - encoded = PyObject_Str(longobj); - Py_DECREF(longobj); - } - return encoded; -} - - -static PyObject * encoder_encode_float(PyEncoderObject *s, PyObject *obj) { - /* Return the JSON representation of a PyFloat. - Modified to call float() on float subclasses in case the subclass - changes the repr. See Issue18264. */ - PyObject *encoded, *floatobj; + /* Return the JSON representation of a PyFloat. */ double i = PyFloat_AS_DOUBLE(obj); if (!Py_IS_FINITE(i)) { if (!s->allow_nan) { @@ -1496,24 +1465,7 @@ return PyUnicode_FromString("NaN"); } } - /* coerce float subclasses to float (primarily for Enum) */ - if (PyFloat_CheckExact(obj)) { - /* Use a better float format here? */ - encoded = PyObject_Repr(obj); - } - else { - floatobj = PyNumber_Float(obj); - if (floatobj == NULL) { - PyErr_SetString( - PyExc_ValueError, - "Unable to coerce float subclass to float" - ); - return NULL; - } - encoded = PyObject_Repr(floatobj); - Py_DECREF(floatobj); - } - return encoded; + return PyFloat_Type.tp_repr(obj); } static PyObject * @@ -1557,7 +1509,7 @@ return _steal_accumulate(acc, encoded); } else if (PyLong_Check(obj)) { - PyObject *encoded = encoder_encode_long(s, obj); + PyObject *encoded = PyLong_Type.tp_str(obj); if (encoded == NULL) return -1; return _steal_accumulate(acc, encoded); @@ -1722,7 +1674,7 @@ goto bail; } else if (PyLong_Check(key)) { - kstr = encoder_encode_long(s, key); + kstr = PyLong_Type.tp_str(key); if (kstr == NULL) { goto bail; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 07:45:43 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 10 Apr 2016 11:45:43 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2325339=3A_PYTHONIOENCODING_now_has_priority_over?= =?utf-8?q?_locale_in_setting_the?= Message-ID: <20160410114541.11583.27623.159049DC@psf.io> https://hg.python.org/cpython/rev/9c6623099da1 changeset: 100902:9c6623099da1 parent: 100899:bb3cfca9c431 parent: 100901:56eca1c08738 user: Serhiy Storchaka date: Sun Apr 10 14:35:21 2016 +0300 summary: Issue #25339: PYTHONIOENCODING now has priority over locale in setting the error handler for stdin and stdout. files: Lib/test/test_sys.py | 27 +++++++++++++++++++++++---- Misc/NEWS | 3 +++ Python/pylifecycle.c | 19 +++++++++---------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -691,8 +691,10 @@ args = [sys.executable, "-c", code] if isolated: args.append("-I") - elif encoding: + if encoding is not None: env['PYTHONIOENCODING'] = encoding + else: + env.pop('PYTHONIOENCODING', None) p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, @@ -709,14 +711,31 @@ 'stderr: backslashreplace\n') # replace the default error handler - out = self.c_locale_get_error_handler(encoding=':strict') + out = self.c_locale_get_error_handler(encoding=':ignore') + self.assertEqual(out, + 'stdin: ignore\n' + 'stdout: ignore\n' + 'stderr: backslashreplace\n') + + # force the encoding + out = self.c_locale_get_error_handler(encoding='iso8859-1') + self.assertEqual(out, + 'stdin: strict\n' + 'stdout: strict\n' + 'stderr: backslashreplace\n') + out = self.c_locale_get_error_handler(encoding='iso8859-1:') self.assertEqual(out, 'stdin: strict\n' 'stdout: strict\n' 'stderr: backslashreplace\n') - # force the encoding - out = self.c_locale_get_error_handler(encoding='iso8859-1') + # have no any effect + out = self.c_locale_get_error_handler(encoding=':') + self.assertEqual(out, + 'stdin: surrogateescape\n' + 'stdout: surrogateescape\n' + 'stderr: backslashreplace\n') + out = self.c_locale_get_error_handler(encoding='') self.assertEqual(out, 'stdin: surrogateescape\n' 'stdout: surrogateescape\n' diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #25339: PYTHONIOENCODING now has priority over locale in setting the + error handler for stdin and stdout. + - Issue #26494: Fixed crash on iterating exhausting iterators. Affected classes are generic sequence iterators, iterators of str, bytes, bytearray, list, tuple, set, frozenset, dict, OrderedDict, corresponding diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1166,15 +1166,6 @@ encoding = _Py_StandardStreamEncoding; errors = _Py_StandardStreamErrors; if (!encoding || !errors) { - if (!errors) { - /* When the LC_CTYPE locale is the POSIX locale ("C locale"), - stdin and stdout use the surrogateescape error handler by - default, instead of the strict error handler. */ - char *loc = setlocale(LC_CTYPE, NULL); - if (loc != NULL && strcmp(loc, "C") == 0) - errors = "surrogateescape"; - } - pythonioencoding = Py_GETENV("PYTHONIOENCODING"); if (pythonioencoding) { char *err; @@ -1187,7 +1178,7 @@ if (err) { *err = '\0'; err++; - if (*err && !_Py_StandardStreamErrors) { + if (*err && !errors) { errors = err; } } @@ -1195,6 +1186,14 @@ encoding = pythonioencoding; } } + if (!errors && !(pythonioencoding && *pythonioencoding)) { + /* When the LC_CTYPE locale is the POSIX locale ("C locale"), + stdin and stdout use the surrogateescape error handler by + default, instead of the strict error handler. */ + char *loc = setlocale(LC_CTYPE, NULL); + if (loc != NULL && strcmp(loc, "C") == 0) + errors = "surrogateescape"; + } } /* Set sys.stdin */ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 08:27:34 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 10 Apr 2016 12:27:34 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzEzNDEw?= =?utf-8?q?=3A_Fixed_a_bug_in_PyUnicode=5FFormat_where_it_failed_to_proper?= =?utf-8?q?ly?= Message-ID: <20160410122734.11583.71886.2D911302@psf.io> https://hg.python.org/cpython/rev/a06654ca0134 changeset: 100906:a06654ca0134 branch: 2.7 parent: 100900:4dc347c5c8a8 user: Serhiy Storchaka date: Sun Apr 10 15:26:52 2016 +0300 summary: Issue #13410: Fixed a bug in PyUnicode_Format where it failed to properly ignore errors from a __int__() method. Patch based on the patch for issue #15516. files: Lib/test/test_format.py | 1 + Misc/NEWS | 3 +++ Objects/unicodeobject.c | 5 ++++- 3 files changed, 8 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -243,6 +243,7 @@ fst = IntFails() testformat("%x", fst, '0') + testformat(u"%x", fst, '0') # Test exception for unknown format characters if verbose: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #13410: Fixed a bug in PyUnicode_Format where it failed to properly + ignore errors from a __int__() method. + - Issue #26494: Fixed crash on iterating exhausting iterators. Affected classes are generic sequence iterators, iterators of bytearray, list, tuple, set, frozenset, dict, OrderedDict and corresponding views. diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8632,7 +8632,10 @@ } else { iobj = PyNumber_Int(v); - if (iobj==NULL) iobj = PyNumber_Long(v); + if (iobj==NULL) { + PyErr_Clear(); + iobj = PyNumber_Long(v); + } } if (iobj!=NULL) { if (PyInt_Check(iobj)) { -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 08:47:11 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 10 Apr 2016 12:47:11 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326623=3A_TypeErro?= =?utf-8?q?r_message_for_JSON_unserializible_object_now_contains?= Message-ID: <20160410124711.18857.30199.1DD9F51B@psf.io> https://hg.python.org/cpython/rev/cb1ad434f10e changeset: 100907:cb1ad434f10e parent: 100905:6b16eec56854 user: Serhiy Storchaka date: Sun Apr 10 15:46:30 2016 +0300 summary: Issue #26623: TypeError message for JSON unserializible object now contains object's type name, not object's representation. Based on patch by Mahmoud Lababidi. files: Lib/json/encoder.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py --- a/Lib/json/encoder.py +++ b/Lib/json/encoder.py @@ -176,7 +176,8 @@ return JSONEncoder.default(self, o) """ - raise TypeError(repr(o) + " is not JSON serializable") + raise TypeError("Object of type '%s' is not JSON serializable" % + o.__class__.__name__) def encode(self, o): """Return a JSON string representation of a Python data structure. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 11:12:35 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 10 Apr 2016 15:12:35 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2MjAw?= =?utf-8?q?=3A_Added_Py=5FSETREF_and_replaced_Py=5FXSETREF_with_Py=5FSETRE?= =?utf-8?q?F?= Message-ID: <20160410151235.15630.69015.5B82E4B2@psf.io> https://hg.python.org/cpython/rev/66fafa13a711 changeset: 100909:66fafa13a711 branch: 3.5 parent: 100903:4d4febb76864 user: Serhiy Storchaka date: Sun Apr 10 18:05:40 2016 +0300 summary: Issue #26200: Added Py_SETREF and replaced Py_XSETREF with Py_SETREF in places where Py_DECREF was used. files: Include/object.h | 14 ++++++++++++-- Modules/_ctypes/_ctypes.c | 14 +++++++------- Modules/_curses_panel.c | 2 +- Modules/_elementtree.c | 8 ++++---- Modules/_sqlite/connection.c | 6 +++--- Modules/_sqlite/cursor.c | 6 +++--- Modules/_sre.c | 2 +- Modules/_ssl.c | 2 +- Modules/itertoolsmodule.c | 2 +- Modules/signalmodule.c | 2 +- Modules/zipimport.c | 2 +- Modules/zlibmodule.c | 4 ++-- Objects/bytesobject.c | 2 +- Objects/funcobject.c | 2 +- Objects/rangeobject.c | 2 +- Objects/typeobject.c | 6 +++--- Objects/unicodeobject.c | 8 ++++---- Python/_warnings.c | 2 +- Python/ceval.c | 4 ++-- Python/errors.c | 4 ++-- 20 files changed, 52 insertions(+), 42 deletions(-) diff --git a/Include/object.h b/Include/object.h --- a/Include/object.h +++ b/Include/object.h @@ -851,18 +851,28 @@ * * As in case of Py_CLEAR "the obvious" code can be deadly: * - * Py_XDECREF(op); + * Py_DECREF(op); * op = op2; * * The safe way is: * - * Py_XSETREF(op, op2); + * Py_SETREF(op, op2); * * That arranges to set `op` to `op2` _before_ decref'ing, so that any code * triggered as a side-effect of `op` getting torn down no longer believes * `op` points to a valid object. + * + * Py_XSETREF is a variant of Py_SETREF that uses Py_XDECREF instead of + * Py_DECREF. */ +#define Py_SETREF(op, op2) \ + do { \ + PyObject *_py_tmp = (PyObject *)(op); \ + (op) = (op2); \ + Py_DECREF(_py_tmp); \ + } while (0) + #define Py_XSETREF(op, op2) \ do { \ PyObject *_py_tmp = (PyObject *)(op); \ diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -391,7 +391,7 @@ Py_DECREF((PyObject *)dict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)dict); + Py_SETREF(result->tp_dict, (PyObject *)dict); dict->format = _ctypes_alloc_format_string(NULL, "B"); if (dict->format == NULL) { Py_DECREF(result); @@ -960,7 +960,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); + Py_SETREF(result->tp_dict, (PyObject *)stgdict); return (PyObject *)result; } @@ -1403,7 +1403,7 @@ /* replace the class dict by our updated spam dict */ if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) goto error; - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); /* steal the reference */ + Py_SETREF(result->tp_dict, (PyObject *)stgdict); /* steal the reference */ stgdict = NULL; /* Special case for character arrays. @@ -1816,7 +1816,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); + Py_SETREF(result->tp_dict, (PyObject *)stgdict); return (PyObject *)result; } @@ -1944,7 +1944,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); + Py_SETREF(result->tp_dict, (PyObject *)stgdict); /* Install from_param class methods in ctypes base classes. Overrides the PyCSimpleType_from_param generic method. @@ -2307,7 +2307,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); + Py_SETREF(result->tp_dict, (PyObject *)stgdict); if (-1 == make_funcptrtype_dict(stgdict)) { Py_DECREF(result); @@ -5152,7 +5152,7 @@ bself = (PyBaseExceptionObject *)self; Py_INCREF(args); - Py_XSETREF(bself->args, args); + Py_SETREF(bself->args, args); return 0; } diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -313,7 +313,7 @@ return NULL; } Py_INCREF(temp); - Py_XSETREF(po->wo, temp); + Py_SETREF(po->wo, temp); Py_INCREF(Py_None); return Py_None; } diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1943,7 +1943,7 @@ if (strcmp(name, "tag") == 0) { Py_INCREF(value); - Py_XSETREF(self->tag, value); + Py_SETREF(self->tag, value); } else if (strcmp(name, "text") == 0) { Py_DECREF(JOIN_OBJ(self->text)); self->text = value; @@ -1958,7 +1958,7 @@ return -1; } Py_INCREF(value); - Py_XSETREF(self->extra->attrib, value); + Py_SETREF(self->extra->attrib, value); } else { PyErr_SetString(PyExc_AttributeError, "Can't set arbitrary attributes on Element"); @@ -2551,9 +2551,9 @@ self->index++; Py_INCREF(node); - Py_XSETREF(self->this, node); + Py_SETREF(self->this, node); Py_INCREF(node); - Py_XSETREF(self->last, node); + Py_SETREF(self->last, node); if (treebuilder_append_event(self, self->start_event_obj, node) < 0) goto error; diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -204,7 +204,7 @@ node = node->next; } - Py_XSETREF(self->statement_cache, + Py_SETREF(self->statement_cache, (pysqlite_Cache *)PyObject_CallFunction((PyObject *)&pysqlite_CacheType, "O", self)); Py_DECREF(self); self->statement_cache->decref_factory = 0; @@ -794,7 +794,7 @@ } } - Py_XSETREF(self->statements, new_list); + Py_SETREF(self->statements, new_list); } static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) @@ -825,7 +825,7 @@ } } - Py_XSETREF(self->cursors, new_list); + Py_SETREF(self->cursors, new_list); } PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -510,7 +510,7 @@ /* reset description and rowcount */ Py_INCREF(Py_None); - Py_XSETREF(self->description, Py_None); + Py_SETREF(self->description, Py_None); self->rowcount = -1L; func_args = PyTuple_New(1); @@ -535,7 +535,7 @@ } if (self->statement->in_use) { - Py_XSETREF(self->statement, + Py_SETREF(self->statement, PyObject_New(pysqlite_Statement, &pysqlite_StatementType)); if (!self->statement) { goto error; @@ -652,7 +652,7 @@ numcols = sqlite3_column_count(self->statement->st); Py_END_ALLOW_THREADS - Py_XSETREF(self->description, PyTuple_New(numcols)); + Py_SETREF(self->description, PyTuple_New(numcols)); if (!self->description) { goto error; } diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -756,7 +756,7 @@ if (!copy) return 0; - Py_XSETREF(*object, copy); + Py_SETREF(*object, copy); return 1; /* success */ } diff --git a/Modules/_ssl.c b/Modules/_ssl.c --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -1589,7 +1589,7 @@ return -1; #else Py_INCREF(value); - Py_XSETREF(self->ctx, (PySSLContext *)value); + Py_SETREF(self->ctx, (PySSLContext *)value); SSL_set_SSL_CTX(self->ssl, self->ctx->ctx); #endif } else { diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -631,7 +631,7 @@ link = teedataobject_jumplink(to->dataobj); if (link == NULL) return NULL; - Py_XSETREF(to->dataobj, (teedataobject *)link); + Py_SETREF(to->dataobj, (teedataobject *)link); to->index = 0; } value = teedataobject_getitem(to->dataobj, to->index); diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -1266,7 +1266,7 @@ if (Handlers[SIGINT].func == DefaultHandler) { /* Install default int handler */ Py_INCREF(IntHandler); - Py_XSETREF(Handlers[SIGINT].func, IntHandler); + Py_SETREF(Handlers[SIGINT].func, IntHandler); old_siginthandler = PyOS_setsig(SIGINT, signal_handler); } diff --git a/Modules/zipimport.c b/Modules/zipimport.c --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -155,7 +155,7 @@ tmp = PyUnicode_FromFormat("%U%c", self->prefix, SEP); if (tmp == NULL) goto error; - Py_XSETREF(self->prefix, tmp); + Py_SETREF(self->prefix, tmp); } } else diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -668,7 +668,7 @@ PyBytes_AS_STRING(self->unused_data), old_size); Py_MEMCPY(PyBytes_AS_STRING(new_data) + old_size, self->zst.next_in, self->zst.avail_in); - Py_XSETREF(self->unused_data, new_data); + Py_SETREF(self->unused_data, new_data); self->zst.avail_in = 0; } } @@ -680,7 +680,7 @@ (char *)self->zst.next_in, self->zst.avail_in); if (new_data == NULL) return -1; - Py_XSETREF(self->unconsumed_tail, new_data); + Py_SETREF(self->unconsumed_tail, new_data); } return 0; } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3520,7 +3520,7 @@ /* Multiple references, need to create new object */ PyObject *v; v = bytes_concat(*pv, w); - Py_XSETREF(*pv, v); + Py_SETREF(*pv, v); } } diff --git a/Objects/funcobject.c b/Objects/funcobject.c --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -527,7 +527,7 @@ if (name != Py_None) { Py_INCREF(name); - Py_XSETREF(newfunc->func_name, name); + Py_SETREF(newfunc->func_name, name); } if (defaults != Py_None) { Py_INCREF(defaults); diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -1064,7 +1064,7 @@ result = PyNumber_Add(r->start, product); Py_DECREF(product); if (result) { - Py_XSETREF(r->index, new_index); + Py_SETREF(r->index, new_index); } else { Py_DECREF(new_index); diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -424,7 +424,7 @@ type->tp_name = tp_name; Py_INCREF(value); - Py_XSETREF(((PyHeapTypeObject*)type)->ht_name, value); + Py_SETREF(((PyHeapTypeObject*)type)->ht_name, value); return 0; } @@ -445,7 +445,7 @@ et = (PyHeapTypeObject*)type; Py_INCREF(value); - Py_XSETREF(et->ht_qualname, value); + Py_SETREF(et->ht_qualname, value); return 0; } @@ -2897,7 +2897,7 @@ else method_cache_misses++; #endif - Py_XSETREF(method_cache[h].name, name); + Py_SETREF(method_cache[h].name, name); } return res; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1667,7 +1667,7 @@ _Py_INCREF_UNICODE_EMPTY(); if (!unicode_empty) return -1; - Py_XSETREF(*p_unicode, unicode_empty); + Py_SETREF(*p_unicode, unicode_empty); return 0; } @@ -1675,7 +1675,7 @@ PyObject *copy = resize_copy(unicode, length); if (copy == NULL) return -1; - Py_XSETREF(*p_unicode, copy); + Py_SETREF(*p_unicode, copy); return 0; } @@ -13326,7 +13326,7 @@ return -1; _PyUnicode_FastCopyCharacters(newbuffer, 0, writer->buffer, 0, writer->pos); - Py_XSETREF(writer->buffer, newbuffer); + Py_SETREF(writer->buffer, newbuffer); } _PyUnicodeWriter_Update(writer); return 0; @@ -15012,7 +15012,7 @@ if (t) { Py_INCREF(t); - Py_XSETREF(*p, t); + Py_SETREF(*p, t); return; } diff --git a/Python/_warnings.c b/Python/_warnings.c --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -680,7 +680,7 @@ goto handle_error; } else if (!is_true) { - Py_XSETREF(*filename, PyUnicode_FromString("__main__")); + Py_SETREF(*filename, PyUnicode_FromString("__main__")); if (*filename == NULL) goto handle_error; } diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3229,7 +3229,7 @@ Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); - Py_XSETREF(*pfunc, self); + Py_SETREF(*pfunc, self); na++; /* n++; */ } else @@ -4682,7 +4682,7 @@ Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); - Py_XSETREF(*pfunc, self); + Py_SETREF(*pfunc, self); na++; n++; } else diff --git a/Python/errors.c b/Python/errors.c --- a/Python/errors.c +++ b/Python/errors.c @@ -311,9 +311,9 @@ --tstate->recursion_depth; /* throw away the old exception and use the recursion error instead */ Py_INCREF(PyExc_RecursionError); - Py_XSETREF(*exc, PyExc_RecursionError); + Py_SETREF(*exc, PyExc_RecursionError); Py_INCREF(PyExc_RecursionErrorInst); - Py_XSETREF(*val, PyExc_RecursionErrorInst); + Py_SETREF(*val, PyExc_RecursionErrorInst); /* just keeping the old traceback */ return; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 11:12:35 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 10 Apr 2016 15:12:35 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2MjAw?= =?utf-8?q?=3A_Added_Py=5FSETREF_and_replaced_Py=5FXSETREF_with_Py=5FSETRE?= =?utf-8?q?F?= Message-ID: <20160410151235.27676.84181.8194FD45@psf.io> https://hg.python.org/cpython/rev/9cf8572abe58 changeset: 100908:9cf8572abe58 branch: 2.7 parent: 100906:a06654ca0134 user: Serhiy Storchaka date: Sun Apr 10 18:05:12 2016 +0300 summary: Issue #26200: Added Py_SETREF and replaced Py_XSETREF with Py_SETREF in places where Py_DECREF was used. files: Include/object.h | 14 ++++++++++++-- Modules/_bsddb.c | 6 +++--- Modules/_ctypes/_ctypes.c | 10 +++++----- Modules/_curses_panel.c | 2 +- Modules/_elementtree.c | 8 ++++---- Modules/_json.c | 2 +- Modules/_sqlite/connection.c | 6 +++--- Modules/_sqlite/cursor.c | 6 +++--- Modules/_sre.c | 2 +- Modules/_ssl.c | 2 +- Modules/bz2module.c | 2 +- Modules/itertoolsmodule.c | 2 +- Modules/signalmodule.c | 2 +- Modules/zlibmodule.c | 4 ++-- Objects/exceptions.c | 4 ++-- Objects/fileobject.c | 4 ++-- Objects/funcobject.c | 2 +- Objects/stringobject.c | 4 ++-- Objects/unicodeobject.c | 2 +- Python/_warnings.c | 2 +- Python/ceval.c | 2 +- Python/errors.c | 4 ++-- 22 files changed, 51 insertions(+), 41 deletions(-) diff --git a/Include/object.h b/Include/object.h --- a/Include/object.h +++ b/Include/object.h @@ -828,18 +828,28 @@ * * As in case of Py_CLEAR "the obvious" code can be deadly: * - * Py_XDECREF(op); + * Py_DECREF(op); * op = op2; * * The safe way is: * - * Py_XSETREF(op, op2); + * Py_SETREF(op, op2); * * That arranges to set `op` to `op2` _before_ decref'ing, so that any code * triggered as a side-effect of `op` getting torn down no longer believes * `op` points to a valid object. + * + * Py_XSETREF is a variant of Py_SETREF that uses Py_XDECREF instead of + * Py_DECREF. */ +#define Py_SETREF(op, op2) \ + do { \ + PyObject *_py_tmp = (PyObject *)(op); \ + (op) = (op2); \ + Py_DECREF(_py_tmp); \ + } while (0) + #define Py_XSETREF(op, op2) \ do { \ PyObject *_py_tmp = (PyObject *)(op); \ diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c --- a/Modules/_bsddb.c +++ b/Modules/_bsddb.c @@ -2498,7 +2498,7 @@ { /* We can set the private field even if db is closed */ Py_INCREF(private_obj); - Py_XSETREF(self->private_obj, private_obj); + Py_SETREF(self->private_obj, private_obj); RETURN_NONE(); } @@ -6997,7 +6997,7 @@ { /* We can set the private field even if dbenv is closed */ Py_INCREF(private_obj); - Py_XSETREF(self->private_obj, private_obj); + Py_SETREF(self->private_obj, private_obj); RETURN_NONE(); } @@ -7410,7 +7410,7 @@ RETURN_IF_ERR(); Py_INCREF(rep_transport); - Py_XSETREF(self->rep_transport, rep_transport); + Py_SETREF(self->rep_transport, rep_transport); RETURN_NONE(); } diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -424,7 +424,7 @@ Py_DECREF((PyObject *)dict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)dict); + Py_SETREF(result->tp_dict, (PyObject *)dict); dict->format = _ctypes_alloc_format_string(NULL, "B"); if (dict->format == NULL) { Py_DECREF(result); @@ -992,7 +992,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); + Py_SETREF(result->tp_dict, (PyObject *)stgdict); return (PyObject *)result; } @@ -1457,7 +1457,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); + Py_SETREF(result->tp_dict, (PyObject *)stgdict); /* Special case for character arrays. A permanent annoyance: char arrays are also strings! @@ -1880,7 +1880,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); + Py_SETREF(result->tp_dict, (PyObject *)stgdict); return (PyObject *)result; } @@ -2388,7 +2388,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); + Py_SETREF(result->tp_dict, (PyObject *)stgdict); if (-1 == make_funcptrtype_dict(stgdict)) { Py_DECREF(result); diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -284,7 +284,7 @@ return NULL; } Py_INCREF(temp); - Py_XSETREF(po->wo, temp); + Py_SETREF(po->wo, temp); Py_INCREF(Py_None); return Py_None; } diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1574,7 +1574,7 @@ if (strcmp(name, "tag") == 0) { Py_INCREF(value); - Py_XSETREF(self->tag, value); + Py_SETREF(self->tag, value); } else if (strcmp(name, "text") == 0) { Py_DECREF(JOIN_OBJ(self->text)); self->text = value; @@ -1587,7 +1587,7 @@ if (!self->extra) element_new_extra(self, NULL); Py_INCREF(value); - Py_XSETREF(self->extra->attrib, value); + Py_SETREF(self->extra->attrib, value); } else { PyErr_SetString(PyExc_AttributeError, name); return -1; @@ -1799,10 +1799,10 @@ self->index++; Py_INCREF(node); - Py_XSETREF(self->this, (ElementObject*) node); + Py_SETREF(self->this, (ElementObject*) node); Py_INCREF(node); - Py_XSETREF(self->last, (ElementObject*) node); + Py_SETREF(self->last, (ElementObject*) node); if (treebuilder_append_event(self, self->start_event_obj, node) < 0) goto error; diff --git a/Modules/_json.c b/Modules/_json.c --- a/Modules/_json.c +++ b/Modules/_json.c @@ -1717,7 +1717,7 @@ } else if (PyUnicode_Check(s->encoding)) { PyObject *tmp = PyUnicode_AsEncodedString(s->encoding, NULL, NULL); - Py_XSETREF(s->encoding, tmp); + Py_SETREF(s->encoding, tmp); } if (s->encoding == NULL) goto bail; diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -228,7 +228,7 @@ node = node->next; } - Py_XSETREF(self->statement_cache, + Py_SETREF(self->statement_cache, (pysqlite_Cache *)PyObject_CallFunction((PyObject *)&pysqlite_CacheType, "O", self)); Py_DECREF(self); self->statement_cache->decref_factory = 0; @@ -815,7 +815,7 @@ } } - Py_XSETREF(self->statements, new_list); + Py_SETREF(self->statements, new_list); } static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) @@ -846,7 +846,7 @@ } } - Py_XSETREF(self->cursors, new_list); + Py_SETREF(self->cursors, new_list); } PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -544,7 +544,7 @@ /* reset description and rowcount */ Py_INCREF(Py_None); - Py_XSETREF(self->description, Py_None); + Py_SETREF(self->description, Py_None); self->rowcount = -1L; func_args = PyTuple_New(1); @@ -569,7 +569,7 @@ } if (self->statement->in_use) { - Py_XSETREF(self->statement, + Py_SETREF(self->statement, PyObject_New(pysqlite_Statement, &pysqlite_StatementType)); if (!self->statement) { goto error; @@ -681,7 +681,7 @@ numcols = sqlite3_column_count(self->statement->st); Py_END_ALLOW_THREADS - Py_XSETREF(self->description, PyTuple_New(numcols)); + Py_SETREF(self->description, PyTuple_New(numcols)); if (!self->description) { goto error; } diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2054,7 +2054,7 @@ if (!copy) return 0; - Py_XSETREF(*object, copy); + Py_SETREF(*object, copy); return 1; /* success */ } diff --git a/Modules/_ssl.c b/Modules/_ssl.c --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -1467,7 +1467,7 @@ return -1; #else Py_INCREF(value); - Py_XSETREF(self->ctx, (PySSLContext *)value); + Py_SETREF(self->ctx, (PySSLContext *)value); SSL_set_SSL_CTX(self->ssl, self->ctx->ctx); #endif } else { diff --git a/Modules/bz2module.c b/Modules/bz2module.c --- a/Modules/bz2module.c +++ b/Modules/bz2module.c @@ -1953,7 +1953,7 @@ self->running = 0; input_left += bzs->avail_in; if (input_left != 0) { - Py_XSETREF(self->unused_data, + Py_SETREF(self->unused_data, PyString_FromStringAndSize(bzs->next_in, input_left)); if (self->unused_data == NULL) goto error; diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -492,7 +492,7 @@ link = teedataobject_jumplink(to->dataobj); if (link == NULL) return NULL; - Py_XSETREF(to->dataobj, (teedataobject *)link); + Py_SETREF(to->dataobj, (teedataobject *)link); to->index = 0; } value = teedataobject_getitem(to->dataobj, to->index); diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -621,7 +621,7 @@ if (Handlers[SIGINT].func == DefaultHandler) { /* Install default int handler */ Py_INCREF(IntHandler); - Py_XSETREF(Handlers[SIGINT].func, IntHandler); + Py_SETREF(Handlers[SIGINT].func, IntHandler); old_siginthandler = PyOS_setsig(SIGINT, signal_handler); } diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -491,7 +491,7 @@ PyString_AS_STRING(self->unused_data), old_size); Py_MEMCPY(PyString_AS_STRING(new_data) + old_size, self->zst.next_in, self->zst.avail_in); - Py_XSETREF(self->unused_data, new_data); + Py_SETREF(self->unused_data, new_data); self->zst.avail_in = 0; } } @@ -503,7 +503,7 @@ (char *)self->zst.next_in, self->zst.avail_in); if (new_data == NULL) return -1; - Py_XSETREF(self->unconsumed_tail, new_data); + Py_SETREF(self->unconsumed_tail, new_data); } return 0; } diff --git a/Objects/exceptions.c b/Objects/exceptions.c --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -59,7 +59,7 @@ return -1; Py_INCREF(args); - Py_XSETREF(self->args, args); + Py_SETREF(self->args, args); if (PyTuple_GET_SIZE(self->args) == 1) { Py_INCREF(PyTuple_GET_ITEM(self->args, 0)); @@ -622,7 +622,7 @@ if (!subslice) return -1; - Py_XSETREF(self->args, subslice); + Py_SETREF(self->args, subslice); } return 0; } diff --git a/Objects/fileobject.c b/Objects/fileobject.c --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -574,8 +574,8 @@ oerrors = Py_None; Py_INCREF(Py_None); } - Py_XSETREF(file->f_encoding, str); - Py_XSETREF(file->f_errors, oerrors); + Py_SETREF(file->f_encoding, str); + Py_SETREF(file->f_errors, oerrors); return 1; } diff --git a/Objects/funcobject.c b/Objects/funcobject.c --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -428,7 +428,7 @@ if (name != Py_None) { Py_INCREF(name); - Py_XSETREF(newfunc->func_name, name); + Py_SETREF(newfunc->func_name, name); } if (defaults != Py_None) { Py_INCREF(defaults); diff --git a/Objects/stringobject.c b/Objects/stringobject.c --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -3865,7 +3865,7 @@ return; } v = string_concat((PyStringObject *) *pv, w); - Py_XSETREF(*pv, v); + Py_SETREF(*pv, v); } void @@ -4750,7 +4750,7 @@ t = PyDict_GetItem(interned, (PyObject *)s); if (t) { Py_INCREF(t); - Py_XSETREF(*p, t); + Py_SETREF(*p, t); return; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -436,7 +436,7 @@ return -1; Py_UNICODE_COPY(w->str, v->str, length < v->length ? length : v->length); - Py_XSETREF(*unicode, w); + Py_SETREF(*unicode, w); return 0; } diff --git a/Python/_warnings.c b/Python/_warnings.c --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -528,7 +528,7 @@ goto handle_error; } else if (!is_true) { - Py_XSETREF(*filename, PyString_FromString("__main__")); + Py_SETREF(*filename, PyString_FromString("__main__")); if (*filename == NULL) goto handle_error; } diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4360,7 +4360,7 @@ Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); - Py_XSETREF(*pfunc, self); + Py_SETREF(*pfunc, self); na++; n++; } else diff --git a/Python/errors.c b/Python/errors.c --- a/Python/errors.c +++ b/Python/errors.c @@ -229,9 +229,9 @@ --tstate->recursion_depth; /* throw away the old exception and use the recursion error instead */ Py_INCREF(PyExc_RuntimeError); - Py_XSETREF(*exc, PyExc_RuntimeError); + Py_SETREF(*exc, PyExc_RuntimeError); Py_INCREF(PyExc_RecursionErrorInst); - Py_XSETREF(*val, PyExc_RecursionErrorInst); + Py_SETREF(*val, PyExc_RecursionErrorInst); /* just keeping the old traceback */ return; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 11:12:36 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 10 Apr 2016 15:12:36 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326200=3A_Added_Py=5FSETREF_and_replaced_Py=5FXS?= =?utf-8?q?ETREF_with_Py=5FSETREF?= Message-ID: <20160410151236.27682.89026.48CD5CA4@psf.io> https://hg.python.org/cpython/rev/d758c5965199 changeset: 100910:d758c5965199 parent: 100907:cb1ad434f10e parent: 100909:66fafa13a711 user: Serhiy Storchaka date: Sun Apr 10 18:12:01 2016 +0300 summary: Issue #26200: Added Py_SETREF and replaced Py_XSETREF with Py_SETREF in places where Py_DECREF was used. files: Include/object.h | 14 ++++++++++++-- Modules/_ctypes/_ctypes.c | 14 +++++++------- Modules/_curses_panel.c | 2 +- Modules/_datetimemodule.c | 6 +++--- Modules/_elementtree.c | 8 ++++---- Modules/_io/bytesio.c | 2 +- Modules/_sqlite/connection.c | 6 +++--- Modules/_sqlite/cursor.c | 6 +++--- Modules/_sre.c | 2 +- Modules/_ssl.c | 2 +- Modules/itertoolsmodule.c | 4 ++-- Modules/signalmodule.c | 2 +- Modules/zipimport.c | 2 +- Modules/zlibmodule.c | 4 ++-- Objects/bytesobject.c | 2 +- Objects/funcobject.c | 2 +- Objects/listobject.c | 2 +- Objects/rangeobject.c | 2 +- Objects/typeobject.c | 6 +++--- Objects/unicodeobject.c | 8 ++++---- Python/_warnings.c | 2 +- Python/ceval.c | 4 ++-- Python/errors.c | 4 ++-- 23 files changed, 58 insertions(+), 48 deletions(-) diff --git a/Include/object.h b/Include/object.h --- a/Include/object.h +++ b/Include/object.h @@ -851,18 +851,28 @@ * * As in case of Py_CLEAR "the obvious" code can be deadly: * - * Py_XDECREF(op); + * Py_DECREF(op); * op = op2; * * The safe way is: * - * Py_XSETREF(op, op2); + * Py_SETREF(op, op2); * * That arranges to set `op` to `op2` _before_ decref'ing, so that any code * triggered as a side-effect of `op` getting torn down no longer believes * `op` points to a valid object. + * + * Py_XSETREF is a variant of Py_SETREF that uses Py_XDECREF instead of + * Py_DECREF. */ +#define Py_SETREF(op, op2) \ + do { \ + PyObject *_py_tmp = (PyObject *)(op); \ + (op) = (op2); \ + Py_DECREF(_py_tmp); \ + } while (0) + #define Py_XSETREF(op, op2) \ do { \ PyObject *_py_tmp = (PyObject *)(op); \ diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -391,7 +391,7 @@ Py_DECREF((PyObject *)dict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)dict); + Py_SETREF(result->tp_dict, (PyObject *)dict); dict->format = _ctypes_alloc_format_string(NULL, "B"); if (dict->format == NULL) { Py_DECREF(result); @@ -960,7 +960,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); + Py_SETREF(result->tp_dict, (PyObject *)stgdict); return (PyObject *)result; } @@ -1403,7 +1403,7 @@ /* replace the class dict by our updated spam dict */ if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) goto error; - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); /* steal the reference */ + Py_SETREF(result->tp_dict, (PyObject *)stgdict); /* steal the reference */ stgdict = NULL; /* Special case for character arrays. @@ -1816,7 +1816,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); + Py_SETREF(result->tp_dict, (PyObject *)stgdict); return (PyObject *)result; } @@ -1944,7 +1944,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); + Py_SETREF(result->tp_dict, (PyObject *)stgdict); /* Install from_param class methods in ctypes base classes. Overrides the PyCSimpleType_from_param generic method. @@ -2307,7 +2307,7 @@ Py_DECREF((PyObject *)stgdict); return NULL; } - Py_XSETREF(result->tp_dict, (PyObject *)stgdict); + Py_SETREF(result->tp_dict, (PyObject *)stgdict); if (-1 == make_funcptrtype_dict(stgdict)) { Py_DECREF(result); @@ -5150,7 +5150,7 @@ return -1; Py_INCREF(args); - Py_XSETREF(((PyBaseExceptionObject *)self)->args, args); + Py_SETREF(((PyBaseExceptionObject *)self)->args, args); return 0; } diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -313,7 +313,7 @@ return NULL; } Py_INCREF(temp); - Py_XSETREF(po->wo, temp); + Py_SETREF(po->wo, temp); Py_INCREF(Py_None); return Py_None; } diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -1058,7 +1058,7 @@ /* Offset is normalized, so it is negative if days < 0 */ if (GET_TD_DAYS(offset) < 0) { sign = '-'; - Py_XSETREF(offset, delta_negative((PyDateTime_Delta *)offset)); + Py_SETREF(offset, delta_negative((PyDateTime_Delta *)offset)); if (offset == NULL) return -1; } @@ -3045,7 +3045,7 @@ if (dst == Py_None) goto Inconsistent; if (delta_bool((PyDateTime_Delta *)dst) != 0) { - Py_XSETREF(result, add_datetime_timedelta((PyDateTime_DateTime *)result, + Py_SETREF(result, add_datetime_timedelta((PyDateTime_DateTime *)result, (PyDateTime_Delta *)dst, 1)); if (result == NULL) goto Fail; @@ -4445,7 +4445,7 @@ return NULL; if (offdiff != NULL) { - Py_XSETREF(result, delta_subtract(result, offdiff)); + Py_SETREF(result, delta_subtract(result, offdiff)); Py_DECREF(offdiff); } } diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1957,7 +1957,7 @@ { _VALIDATE_ATTR_VALUE(value); Py_INCREF(value); - Py_XSETREF(self->tag, value); + Py_SETREF(self->tag, value); return 0; } @@ -1990,7 +1990,7 @@ return -1; } Py_INCREF(value); - Py_XSETREF(self->extra->attrib, value); + Py_SETREF(self->extra->attrib, value); return 0; } @@ -2524,9 +2524,9 @@ self->index++; Py_INCREF(node); - Py_XSETREF(self->this, node); + Py_SETREF(self->this, node); Py_INCREF(node); - Py_XSETREF(self->last, node); + Py_SETREF(self->last, node); if (treebuilder_append_event(self, self->start_event_obj, node) < 0) goto error; diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -96,7 +96,7 @@ return -1; memcpy(PyBytes_AS_STRING(new_buf), PyBytes_AS_STRING(self->buf), self->string_size); - Py_XSETREF(self->buf, new_buf); + Py_SETREF(self->buf, new_buf); return 0; } diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -204,7 +204,7 @@ node = node->next; } - Py_XSETREF(self->statement_cache, + Py_SETREF(self->statement_cache, (pysqlite_Cache *)PyObject_CallFunction((PyObject *)&pysqlite_CacheType, "O", self)); Py_DECREF(self); self->statement_cache->decref_factory = 0; @@ -793,7 +793,7 @@ } } - Py_XSETREF(self->statements, new_list); + Py_SETREF(self->statements, new_list); } static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) @@ -824,7 +824,7 @@ } } - Py_XSETREF(self->cursors, new_list); + Py_SETREF(self->cursors, new_list); } PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -509,7 +509,7 @@ /* reset description and rowcount */ Py_INCREF(Py_None); - Py_XSETREF(self->description, Py_None); + Py_SETREF(self->description, Py_None); self->rowcount = -1L; func_args = PyTuple_New(1); @@ -534,7 +534,7 @@ } if (self->statement->in_use) { - Py_XSETREF(self->statement, + Py_SETREF(self->statement, PyObject_New(pysqlite_Statement, &pysqlite_StatementType)); if (!self->statement) { goto error; @@ -651,7 +651,7 @@ numcols = sqlite3_column_count(self->statement->st); Py_END_ALLOW_THREADS - Py_XSETREF(self->description, PyTuple_New(numcols)); + Py_SETREF(self->description, PyTuple_New(numcols)); if (!self->description) { goto error; } diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -753,7 +753,7 @@ if (!copy) return 0; - Py_XSETREF(*object, copy); + Py_SETREF(*object, copy); return 1; /* success */ } diff --git a/Modules/_ssl.c b/Modules/_ssl.c --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -1589,7 +1589,7 @@ return -1; #else Py_INCREF(value); - Py_XSETREF(self->ctx, (PySSLContext *)value); + Py_SETREF(self->ctx, (PySSLContext *)value); SSL_set_SSL_CTX(self->ssl, self->ctx->ctx); #endif } else { diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -622,7 +622,7 @@ link = teedataobject_jumplink(to->dataobj); if (link == NULL) return NULL; - Py_XSETREF(to->dataobj, (teedataobject *)link); + Py_SETREF(to->dataobj, (teedataobject *)link); to->index = 0; } value = teedataobject_getitem(to->dataobj, to->index); @@ -3457,7 +3457,7 @@ return NULL; Py_INCREF(newtotal); - Py_XSETREF(lz->total, newtotal); + Py_SETREF(lz->total, newtotal); return newtotal; } diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -1266,7 +1266,7 @@ if (Handlers[SIGINT].func == DefaultHandler) { /* Install default int handler */ Py_INCREF(IntHandler); - Py_XSETREF(Handlers[SIGINT].func, IntHandler); + Py_SETREF(Handlers[SIGINT].func, IntHandler); old_siginthandler = PyOS_setsig(SIGINT, signal_handler); } diff --git a/Modules/zipimport.c b/Modules/zipimport.c --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -155,7 +155,7 @@ tmp = PyUnicode_FromFormat("%U%c", self->prefix, SEP); if (tmp == NULL) goto error; - Py_XSETREF(self->prefix, tmp); + Py_SETREF(self->prefix, tmp); } } else diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -667,7 +667,7 @@ PyBytes_AS_STRING(self->unused_data), old_size); Py_MEMCPY(PyBytes_AS_STRING(new_data) + old_size, self->zst.next_in, self->zst.avail_in); - Py_XSETREF(self->unused_data, new_data); + Py_SETREF(self->unused_data, new_data); self->zst.avail_in = 0; } } @@ -679,7 +679,7 @@ (char *)self->zst.next_in, self->zst.avail_in); if (new_data == NULL) return -1; - Py_XSETREF(self->unconsumed_tail, new_data); + Py_SETREF(self->unconsumed_tail, new_data); } return 0; } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3697,7 +3697,7 @@ /* Multiple references, need to create new object */ PyObject *v; v = bytes_concat(*pv, w); - Py_XSETREF(*pv, v); + Py_SETREF(*pv, v); } } diff --git a/Objects/funcobject.c b/Objects/funcobject.c --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -504,7 +504,7 @@ if (name != Py_None) { Py_INCREF(name); - Py_XSETREF(newfunc->func_name, name); + Py_SETREF(newfunc->func_name, name); } if (defaults != Py_None) { Py_INCREF(defaults); diff --git a/Objects/listobject.c b/Objects/listobject.c --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -735,7 +735,7 @@ if (v == NULL) return list_ass_slice(a, i, i+1, v); Py_INCREF(v); - Py_XSETREF(a->ob_item[i], v); + Py_SETREF(a->ob_item[i], v); return 0; } diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -1064,7 +1064,7 @@ result = PyNumber_Add(r->start, product); Py_DECREF(product); if (result) { - Py_XSETREF(r->index, new_index); + Py_SETREF(r->index, new_index); } else { Py_DECREF(new_index); diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -424,7 +424,7 @@ type->tp_name = tp_name; Py_INCREF(value); - Py_XSETREF(((PyHeapTypeObject*)type)->ht_name, value); + Py_SETREF(((PyHeapTypeObject*)type)->ht_name, value); return 0; } @@ -445,7 +445,7 @@ et = (PyHeapTypeObject*)type; Py_INCREF(value); - Py_XSETREF(et->ht_qualname, value); + Py_SETREF(et->ht_qualname, value); return 0; } @@ -2903,7 +2903,7 @@ else method_cache_misses++; #endif - Py_XSETREF(method_cache[h].name, name); + Py_SETREF(method_cache[h].name, name); } return res; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1830,7 +1830,7 @@ _Py_INCREF_UNICODE_EMPTY(); if (!unicode_empty) return -1; - Py_XSETREF(*p_unicode, unicode_empty); + Py_SETREF(*p_unicode, unicode_empty); return 0; } @@ -1838,7 +1838,7 @@ PyObject *copy = resize_copy(unicode, length); if (copy == NULL) return -1; - Py_XSETREF(*p_unicode, copy); + Py_SETREF(*p_unicode, copy); return 0; } @@ -13547,7 +13547,7 @@ return -1; _PyUnicode_FastCopyCharacters(newbuffer, 0, writer->buffer, 0, writer->pos); - Py_XSETREF(writer->buffer, newbuffer); + Py_SETREF(writer->buffer, newbuffer); } _PyUnicodeWriter_Update(writer); return 0; @@ -15264,7 +15264,7 @@ if (t) { Py_INCREF(t); - Py_XSETREF(*p, t); + Py_SETREF(*p, t); return; } diff --git a/Python/_warnings.c b/Python/_warnings.c --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -730,7 +730,7 @@ goto handle_error; } else if (!is_true) { - Py_XSETREF(*filename, PyUnicode_FromString("__main__")); + Py_SETREF(*filename, PyUnicode_FromString("__main__")); if (*filename == NULL) goto handle_error; } diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3236,7 +3236,7 @@ Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); - Py_XSETREF(*pfunc, self); + Py_SETREF(*pfunc, self); na++; /* n++; */ } else @@ -4747,7 +4747,7 @@ Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func); - Py_XSETREF(*pfunc, self); + Py_SETREF(*pfunc, self); na++; n++; } else diff --git a/Python/errors.c b/Python/errors.c --- a/Python/errors.c +++ b/Python/errors.c @@ -311,9 +311,9 @@ --tstate->recursion_depth; /* throw away the old exception and use the recursion error instead */ Py_INCREF(PyExc_RecursionError); - Py_XSETREF(*exc, PyExc_RecursionError); + Py_SETREF(*exc, PyExc_RecursionError); Py_INCREF(PyExc_RecursionErrorInst); - Py_XSETREF(*val, PyExc_RecursionErrorInst); + Py_SETREF(*val, PyExc_RecursionErrorInst); /* just keeping the old traceback */ return; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 21:20:25 2016 From: python-checkins at python.org (martin.panter) Date: Mon, 11 Apr 2016 01:20:25 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326685=3A_Raise_OS?= =?utf-8?q?Error_if_closing_a_socket_fails?= Message-ID: <20160411012025.16607.44050.D3F4E496@psf.io> https://hg.python.org/cpython/rev/bd665613ed67 changeset: 100911:bd665613ed67 user: Martin Panter date: Mon Apr 11 00:38:12 2016 +0000 summary: Issue #26685: Raise OSError if closing a socket fails files: Doc/library/socket.rst | 4 ++++ Doc/whatsnew/3.6.rst | 4 ++++ Lib/test/test_pty.py | 1 - Lib/test/test_socket.py | 11 +++++++++++ Misc/NEWS | 2 ++ Modules/socketmodule.c | 6 +++++- 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -868,6 +868,10 @@ it is recommended to :meth:`close` them explicitly, or to use a :keyword:`with` statement around them. + .. versionchanged:: 3.6 + :exc:`OSError` is now raised if an error occurs when the underlying + :c:func:`close` call is made. + .. note:: :meth:`close()` releases the resource associated with a connection but diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -514,6 +514,10 @@ * :func:`spwd.getspnam` now raises a :exc:`PermissionError` instead of :exc:`KeyError` if the user doesn't have privileges. +* The :meth:`socket.socket.close` method now raises an exception if + an error (e.g. EBADF) was reported by the underlying system call. + See :issue:`26685`. + Changes in the C API -------------------- diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -277,7 +277,6 @@ socketpair = self._socketpair() masters = [s.fileno() for s in socketpair] - os.close(masters[1]) socketpair[1].close() os.close(write_to_stdin_fd) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1161,6 +1161,17 @@ sock.close() self.assertRaises(OSError, sock.send, b"spam") + def testCloseException(self): + sock = socket.socket() + socket.socket(fileno=sock.fileno()).close() + try: + sock.close() + except OSError as err: + # Winsock apparently raises ENOTSOCK + self.assertIn(err.errno, (errno.EBADF, errno.ENOTSOCK)) + else: + self.fail("close() should raise EBADF/ENOTSOCK") + def testNewAttributes(self): # testing .family, .type and .protocol diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -240,6 +240,8 @@ Library ------- +- Issue #26685: Raise OSError if closing a socket fails. + - Issue #16329: Add .webm to mimetypes.types_map. Patch by Giampaolo Rodola'. - Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -2576,6 +2576,7 @@ sock_close(PySocketSockObject *s) { SOCKET_T fd; + int res; fd = s->sock_fd; if (fd != -1) { @@ -2586,8 +2587,11 @@ http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html for more details. */ Py_BEGIN_ALLOW_THREADS - (void) SOCKETCLOSE(fd); + res = SOCKETCLOSE(fd); Py_END_ALLOW_THREADS + if (res < 0) { + return s->errorhandler(); + } } Py_INCREF(Py_None); return Py_None; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 21:20:25 2016 From: python-checkins at python.org (martin.panter) Date: Mon, 11 Apr 2016 01:20:25 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326585=3A_Eliminat?= =?utf-8?q?e_=5Fquote=5Fhtml=28=29_and_use_html=2Eescape=28quote=3DFalse?= =?utf-8?q?=29?= Message-ID: <20160411012025.18853.13205.C9ED06B7@psf.io> https://hg.python.org/cpython/rev/bf44913588b7 changeset: 100912:bf44913588b7 user: Martin Panter date: Mon Apr 11 00:40:08 2016 +0000 summary: Issue #26585: Eliminate _quote_html() and use html.escape(quote=False) Patch by Xiang Zhang. files: Lib/http/server.py | 16 ++++++------ Lib/test/test_httpservers.py | 30 +++++++++++++++++++++++- Misc/NEWS | 3 ++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Lib/http/server.py b/Lib/http/server.py --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -127,9 +127,6 @@ DEFAULT_ERROR_CONTENT_TYPE = "text/html;charset=utf-8" -def _quote_html(html): - return html.replace("&", "&").replace("<", "<").replace(">", ">") - class HTTPServer(socketserver.TCPServer): allow_reuse_address = 1 # Seems to make sense in testing environment @@ -449,9 +446,12 @@ if explain is None: explain = longmsg self.log_error("code %d, message %s", code, message) - # using _quote_html to prevent Cross Site Scripting attacks (see bug #1100201) - content = (self.error_message_format % - {'code': code, 'message': _quote_html(message), 'explain': _quote_html(explain)}) + # HTML encode to prevent Cross Site Scripting attacks (see bug #1100201) + content = (self.error_message_format % { + 'code': code, + 'message': html.escape(message, quote=False), + 'explain': html.escape(explain, quote=False) + }) body = content.encode('UTF-8', 'replace') self.send_response(code, message) self.send_header("Content-Type", self.error_content_type) @@ -710,7 +710,7 @@ errors='surrogatepass') except UnicodeDecodeError: displaypath = urllib.parse.unquote(path) - displaypath = html.escape(displaypath) + displaypath = html.escape(displaypath, quote=False) enc = sys.getfilesystemencoding() title = 'Directory listing for %s' % displaypath r.append('%s' % (urllib.parse.quote(linkname, errors='surrogatepass'), - html.escape(displayname))) + html.escape(displayname, quote=False))) r.append('\n
\n\n\n') encoded = '\n'.join(r).encode(enc, 'surrogateescape') f = io.BytesIO() diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -344,7 +344,7 @@ quotedname = urllib.parse.quote(filename, errors='surrogatepass') self.assertIn(('href="%s"' % quotedname) .encode(enc, 'surrogateescape'), body) - self.assertIn(('>%s<' % html.escape(filename)) + self.assertIn(('>%s<' % html.escape(filename, quote=False)) .encode(enc, 'surrogateescape'), body) response = self.request(self.base_url + '/' + quotedname) self.check_status_and_reason(response, HTTPStatus.OK, @@ -422,6 +422,27 @@ self.assertEqual(response.getheader("Location"), self.tempdir_name + "/?hi=1") + def test_html_escape_filename(self): + filename = '.txt' + fullpath = os.path.join(self.tempdir, filename) + + try: + open(fullpath, 'w').close() + except OSError: + raise unittest.SkipTest('Can not create file %s on current file ' + 'system' % filename) + + try: + response = self.request(self.base_url + '/') + body = self.check_status_and_reason(response, HTTPStatus.OK) + enc = response.headers.get_content_charset() + finally: + os.unlink(fullpath) # avoid affecting test_undecodable_filename + + self.assertIsNotNone(enc) + html_text = '>%s<' % html.escape(filename, quote=False) + self.assertIn(html_text.encode(enc), body) + cgi_file1 = """\ #!%s @@ -883,6 +904,13 @@ self.assertFalse(self.handler.get_called) self.assertEqual(self.handler.requestline, 'GET / HTTP/1.1') + def test_html_escape_on_error(self): + result = self.send_typical_request( + b' / HTTP/1.1') + result = b''.join(result) + text = '' + self.assertIn(html.escape(text, quote=False).encode('ascii'), result) + def test_close_connection(self): # handle_one_request() should be repeatedly called until # it sets close_connection diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -240,6 +240,9 @@ Library ------- +- Issue #26585: Eliminate http.server._quote_html() and use + html.escape(quote=False). Patch by Xiang Zhang. + - Issue #26685: Raise OSError if closing a socket fails. - Issue #16329: Add .webm to mimetypes.types_map. Patch by Giampaolo Rodola'. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 22:47:18 2016 From: python-checkins at python.org (martin.panter) Date: Mon, 11 Apr 2016 02:47:18 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2314456=3A_Merge_signal_doc_fix_from_3=2E5?= Message-ID: <20160411024718.19166.14580.D3C9D6D5@psf.io> https://hg.python.org/cpython/rev/a8dbe6016a31 changeset: 100914:a8dbe6016a31 parent: 100912:bf44913588b7 parent: 100913:73050563053f user: Martin Panter date: Mon Apr 11 02:45:22 2016 +0000 summary: Issue #14456: Merge signal doc fix from 3.5 files: Doc/library/signal.rst | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) diff --git a/Doc/library/signal.rst b/Doc/library/signal.rst --- a/Doc/library/signal.rst +++ b/Doc/library/signal.rst @@ -22,9 +22,6 @@ underlying implementation), with the exception of the handler for :const:`SIGCHLD`, which follows the underlying implementation. -There is no way to "block" signals temporarily from critical sections (since -this is not supported by all Unix flavors). - Execution of Python signal handlers ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 10 22:47:19 2016 From: python-checkins at python.org (martin.panter) Date: Mon, 11 Apr 2016 02:47:19 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzE0NDU2?= =?utf-8?q?=3A_Remove_contradiction_about_blocking_signals_from_bad_merge?= Message-ID: <20160411024718.90786.74270.EA08E184@psf.io> https://hg.python.org/cpython/rev/73050563053f changeset: 100913:73050563053f branch: 3.5 parent: 100909:66fafa13a711 user: Martin Panter date: Mon Apr 11 02:44:34 2016 +0000 summary: Issue #14456: Remove contradiction about blocking signals from bad merge files: Doc/library/signal.rst | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) diff --git a/Doc/library/signal.rst b/Doc/library/signal.rst --- a/Doc/library/signal.rst +++ b/Doc/library/signal.rst @@ -22,9 +22,6 @@ underlying implementation), with the exception of the handler for :const:`SIGCHLD`, which follows the underlying implementation. -There is no way to "block" signals temporarily from critical sections (since -this is not supported by all Unix flavors). - Execution of Python signal handlers ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 02:58:11 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 06:58:11 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2MjAw?= =?utf-8?q?=3A_Restored_more_safe_usages_of_Py=5FSETREF=2E?= Message-ID: <20160411065811.110030.64296.CCE1C669@psf.io> https://hg.python.org/cpython/rev/f21740a1abde changeset: 100916:f21740a1abde branch: 2.7 parent: 100908:9cf8572abe58 user: Serhiy Storchaka date: Mon Apr 11 09:53:37 2016 +0300 summary: Issue #26200: Restored more safe usages of Py_SETREF. files: Modules/_functoolsmodule.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -320,9 +320,9 @@ else Py_INCREF(dict); - Py_XSETREF(pto->fn, fn); - Py_XSETREF(pto->args, fnargs); - Py_XSETREF(pto->kw, kw); + Py_SETREF(pto->fn, fn); + Py_SETREF(pto->args, fnargs); + Py_SETREF(pto->kw, kw); Py_XSETREF(pto->dict, dict); Py_RETURN_NONE; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 02:58:10 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 06:58:10 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2MjAw?= =?utf-8?q?=3A_Restored_more_safe_usages_of_Py=5FSETREF=2E?= Message-ID: <20160411065810.15608.74718.40DBBE41@psf.io> https://hg.python.org/cpython/rev/aa5dbc32d313 changeset: 100915:aa5dbc32d313 branch: 3.5 parent: 100913:73050563053f user: Serhiy Storchaka date: Mon Apr 11 09:53:37 2016 +0300 summary: Issue #26200: Restored more safe usages of Py_SETREF. files: Modules/_functoolsmodule.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -294,9 +294,9 @@ else Py_INCREF(dict); - Py_XSETREF(pto->fn, fn); - Py_XSETREF(pto->args, fnargs); - Py_XSETREF(pto->kw, kw); + Py_SETREF(pto->fn, fn); + Py_SETREF(pto->args, fnargs); + Py_SETREF(pto->kw, kw); Py_XSETREF(pto->dict, dict); Py_RETURN_NONE; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 02:58:11 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 06:58:11 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326200=3A_Restored_more_safe_usages_of_Py=5FSETR?= =?utf-8?b?RUYu?= Message-ID: <20160411065811.90786.24703.B21EA231@psf.io> https://hg.python.org/cpython/rev/144b78ac2077 changeset: 100917:144b78ac2077 parent: 100914:a8dbe6016a31 parent: 100915:aa5dbc32d313 user: Serhiy Storchaka date: Mon Apr 11 09:57:37 2016 +0300 summary: Issue #26200: Restored more safe usages of Py_SETREF. files: Modules/_decimal/_decimal.c | 8 ++++---- Modules/_functoolsmodule.c | 6 +++--- Objects/floatobject.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -3439,14 +3439,14 @@ goto error; } - Py_XSETREF(exponent, long_methods->nb_power(tmp, exponent, Py_None)); + Py_SETREF(exponent, long_methods->nb_power(tmp, exponent, Py_None)); Py_DECREF(tmp); if (exponent == NULL) { goto error; } if (exp >= 0) { - Py_XSETREF(numerator, long_methods->nb_multiply(numerator, exponent)); + Py_SETREF(numerator, long_methods->nb_multiply(numerator, exponent)); if (numerator == NULL) { goto error; } @@ -3462,8 +3462,8 @@ if (tmp == NULL) { goto error; } - Py_XSETREF(numerator, long_methods->nb_floor_divide(numerator, tmp)); - Py_XSETREF(denominator, long_methods->nb_floor_divide(denominator, tmp)); + Py_SETREF(numerator, long_methods->nb_floor_divide(numerator, tmp)); + Py_SETREF(denominator, long_methods->nb_floor_divide(denominator, tmp)); Py_DECREF(tmp); if (numerator == NULL || denominator == NULL) { goto error; diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -294,9 +294,9 @@ else Py_INCREF(dict); - Py_XSETREF(pto->fn, fn); - Py_XSETREF(pto->args, fnargs); - Py_XSETREF(pto->kw, kw); + Py_SETREF(pto->fn, fn); + Py_SETREF(pto->args, fnargs); + Py_SETREF(pto->kw, kw); Py_XSETREF(pto->dict, dict); Py_RETURN_NONE; } diff --git a/Objects/floatobject.c b/Objects/floatobject.c --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -1494,13 +1494,13 @@ /* fold in 2**exponent */ if (exponent > 0) { - Py_XSETREF(numerator, + Py_SETREF(numerator, long_methods->nb_lshift(numerator, py_exponent)); if (numerator == NULL) goto error; } else { - Py_XSETREF(denominator, + Py_SETREF(denominator, long_methods->nb_lshift(denominator, py_exponent)); if (denominator == NULL) goto error; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 05:22:38 2016 From: python-checkins at python.org (berker.peksag) Date: Mon, 11 Apr 2016 09:22:38 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Fix_typos_in_mock_and_exceptions_docs?= Message-ID: <20160411092238.32282.7546.D37CF6C2@psf.io> https://hg.python.org/cpython/rev/16fb032f29cc changeset: 100919:16fb032f29cc parent: 100917:144b78ac2077 parent: 100918:83f267ffb862 user: Berker Peksag date: Mon Apr 11 12:23:25 2016 +0300 summary: Fix typos in mock and exceptions docs The default value of __len__ is 0, not 1: >>> from unittest.mock import MagicMock >>> mock = MagicMock() >>> len(mock) 0 Reported by Alex on docs at p.o. Remove the remaining VMSError reference. VMS support is gone. files: Doc/library/exceptions.rst | 2 +- Doc/library/unittest.mock.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -288,7 +288,7 @@ .. versionchanged:: 3.3 :exc:`EnvironmentError`, :exc:`IOError`, :exc:`WindowsError`, - :exc:`VMSError`, :exc:`socket.error`, :exc:`select.error` and + :exc:`socket.error`, :exc:`select.error` and :exc:`mmap.error` have been merged into :exc:`OSError`, and the constructor may return a subclass. diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -1725,7 +1725,7 @@ * ``__ge__``: NotImplemented * ``__int__``: 1 * ``__contains__``: False -* ``__len__``: 1 +* ``__len__``: 0 * ``__iter__``: iter([]) * ``__exit__``: False * ``__complex__``: 1j -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 05:22:39 2016 From: python-checkins at python.org (berker.peksag) Date: Mon, 11 Apr 2016 09:22:39 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Fix_typos_in_m?= =?utf-8?q?ock_and_exceptions_docs?= Message-ID: <20160411092238.90806.63743.C78E1E11@psf.io> https://hg.python.org/cpython/rev/83f267ffb862 changeset: 100918:83f267ffb862 branch: 3.5 parent: 100915:aa5dbc32d313 user: Berker Peksag date: Mon Apr 11 12:23:04 2016 +0300 summary: Fix typos in mock and exceptions docs The default value of __len__ is 0, not 1: >>> from unittest.mock import MagicMock >>> mock = MagicMock() >>> len(mock) 0 Reported by Alex on docs at p.o. Remove the remaining VMSError reference. VMS support is gone. files: Doc/library/exceptions.rst | 2 +- Doc/library/unittest.mock.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -288,7 +288,7 @@ .. versionchanged:: 3.3 :exc:`EnvironmentError`, :exc:`IOError`, :exc:`WindowsError`, - :exc:`VMSError`, :exc:`socket.error`, :exc:`select.error` and + :exc:`socket.error`, :exc:`select.error` and :exc:`mmap.error` have been merged into :exc:`OSError`, and the constructor may return a subclass. diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -1697,7 +1697,7 @@ * ``__ge__``: NotImplemented * ``__int__``: 1 * ``__contains__``: False -* ``__len__``: 1 +* ``__len__``: 0 * ``__iter__``: iter([]) * ``__exit__``: False * ``__complex__``: 1j -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 05:39:52 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 09:39:52 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI1OTEw?= =?utf-8?q?=3A_Fixed_dead_links_in_the_docs=2E?= Message-ID: <20160411093948.110008.10340.FBB4D469@psf.io> https://hg.python.org/cpython/rev/00addbb47c5c changeset: 100922:00addbb47c5c branch: 2.7 user: Serhiy Storchaka date: Mon Apr 11 12:18:56 2016 +0300 summary: Issue #25910: Fixed dead links in the docs. files: Doc/faq/gui.rst | 2 +- Doc/howto/logging-cookbook.rst | 4 ++-- Doc/whatsnew/2.1.rst | 2 +- Doc/whatsnew/2.2.rst | 6 +++--- Doc/whatsnew/2.3.rst | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/faq/gui.rst b/Doc/faq/gui.rst --- a/Doc/faq/gui.rst +++ b/Doc/faq/gui.rst @@ -49,7 +49,7 @@ There are bindings available for the Qt toolkit (using either `PyQt `_ or `PySide -`_) and for KDE (`PyKDE `__). +`_) and for KDE (`PyKDE4 `__). PyQt is currently more mature than PySide, but you must buy a PyQt license from `Riverbank Computing `_ if you want to write proprietary applications. PySide is free for all applications. diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -705,7 +705,7 @@ ----------------------------------------- Below is an example of a logging configuration dictionary - it's taken from -the `documentation on the Django project `_. +the `documentation on the Django project `_. This dictionary is passed to :func:`~config.dictConfig` to put the configuration into effect:: LOGGING = { @@ -761,7 +761,7 @@ } For more information about this configuration, you can see the `relevant -section `_ +section `_ of the Django documentation. Inserting a BOM into messages sent to a SysLogHandler diff --git a/Doc/whatsnew/2.1.rst b/Doc/whatsnew/2.1.rst --- a/Doc/whatsnew/2.1.rst +++ b/Doc/whatsnew/2.1.rst @@ -731,7 +731,7 @@ ... For a fuller discussion of the line I/O changes, see the python-dev summary for - January 1-15, 2001 at https://www.python.org/dev/summary/2001-01-1/. + January 1-15, 2001 at https://mail.python.org/pipermail/python-dev/2001-January/. * A new method, :meth:`popitem`, was added to dictionaries to enable destructively iterating through the contents of a dictionary; this can be faster diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst --- a/Doc/whatsnew/2.2.rst +++ b/Doc/whatsnew/2.2.rst @@ -24,8 +24,8 @@ This article doesn't attempt to provide a complete specification of the new features, but instead provides a convenient overview. For full details, you should refer to the documentation for Python 2.2, such as the `Python Library -Reference `_ and the `Python -Reference Manual `_. If you want to +Reference `_ and the `Python +Reference Manual `_. If you want to understand the complete implementation and design rationale for a change, refer to the PEP for a particular new feature. @@ -395,7 +395,7 @@ of an explanation to start you programming, but many details have been simplified or ignored. Where should you go to get a more complete picture? -https://www.python.org/2.2/descrintro.html is a lengthy tutorial introduction to +https://docs.python.org/dev/howto/descriptor.html is a lengthy tutorial introduction to the descriptor features, written by Guido van Rossum. If my description has whetted your appetite, go read this tutorial next, because it goes into much more detail about the new features while still remaining quite easy to read. diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -1858,7 +1858,7 @@ .. seealso:: - https://svn.python.org/view/python/trunk/Objects/obmalloc.c + https://hg.python.org/cpython/file/default/Objects/obmalloc.c For the full details of the pymalloc implementation, see the comments at the top of the file :file:`Objects/obmalloc.c` in the Python source code. The above link points to the file within the python.org SVN browser. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 05:39:52 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 09:39:52 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2325910=3A_Fixed_dead_links_in_the_docs=2E?= Message-ID: <20160411093948.11633.54551.7AF0935B@psf.io> https://hg.python.org/cpython/rev/15c4557af8e0 changeset: 100923:15c4557af8e0 parent: 100917:144b78ac2077 parent: 100920:ce721df212cf user: Serhiy Storchaka date: Mon Apr 11 12:34:07 2016 +0300 summary: Issue #25910: Fixed dead links in the docs. files: Doc/faq/gui.rst | 2 +- Doc/howto/logging-cookbook.rst | 4 ++-- Doc/whatsnew/2.1.rst | 2 +- Doc/whatsnew/2.2.rst | 6 +++--- Doc/whatsnew/2.3.rst | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/faq/gui.rst b/Doc/faq/gui.rst --- a/Doc/faq/gui.rst +++ b/Doc/faq/gui.rst @@ -59,7 +59,7 @@ There are bindings available for the Qt toolkit (using either `PyQt `_ or `PySide -`_) and for KDE (`PyKDE `__). +`_) and for KDE (`PyKDE4 `__). PyQt is currently more mature than PySide, but you must buy a PyQt license from `Riverbank Computing `_ if you want to write proprietary applications. PySide is free for all applications. diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -1316,7 +1316,7 @@ ----------------------------------------- Below is an example of a logging configuration dictionary - it's taken from -the `documentation on the Django project `_. +the `documentation on the Django project `_. This dictionary is passed to :func:`~config.dictConfig` to put the configuration into effect:: LOGGING = { @@ -1372,7 +1372,7 @@ } For more information about this configuration, you can see the `relevant -section `_ +section `_ of the Django documentation. .. _cookbook-rotator-namer: diff --git a/Doc/whatsnew/2.1.rst b/Doc/whatsnew/2.1.rst --- a/Doc/whatsnew/2.1.rst +++ b/Doc/whatsnew/2.1.rst @@ -731,7 +731,7 @@ ... For a fuller discussion of the line I/O changes, see the python-dev summary for - January 1-15, 2001 at https://www.python.org/dev/summary/2001-01-1/. + January 1-15, 2001 at https://mail.python.org/pipermail/python-dev/2001-January/. * A new method, :meth:`popitem`, was added to dictionaries to enable destructively iterating through the contents of a dictionary; this can be faster diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst --- a/Doc/whatsnew/2.2.rst +++ b/Doc/whatsnew/2.2.rst @@ -24,8 +24,8 @@ This article doesn't attempt to provide a complete specification of the new features, but instead provides a convenient overview. For full details, you should refer to the documentation for Python 2.2, such as the `Python Library -Reference `_ and the `Python -Reference Manual `_. If you want to +Reference `_ and the `Python +Reference Manual `_. If you want to understand the complete implementation and design rationale for a change, refer to the PEP for a particular new feature. @@ -395,7 +395,7 @@ of an explanation to start you programming, but many details have been simplified or ignored. Where should you go to get a more complete picture? -https://www.python.org/2.2/descrintro.html is a lengthy tutorial introduction to +https://docs.python.org/dev/howto/descriptor.html is a lengthy tutorial introduction to the descriptor features, written by Guido van Rossum. If my description has whetted your appetite, go read this tutorial next, because it goes into much more detail about the new features while still remaining quite easy to read. diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -1858,7 +1858,7 @@ .. seealso:: - https://svn.python.org/view/python/trunk/Objects/obmalloc.c + https://hg.python.org/cpython/file/default/Objects/obmalloc.c For the full details of the pymalloc implementation, see the comments at the top of the file :file:`Objects/obmalloc.c` in the Python source code. The above link points to the file within the python.org SVN browser. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 05:39:52 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 09:39:52 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI1OTEw?= =?utf-8?q?=3A_Fixed_dead_links_in_the_docs=2E?= Message-ID: <20160411093947.34567.79694.2A3C3FD3@psf.io> https://hg.python.org/cpython/rev/ce721df212cf changeset: 100920:ce721df212cf branch: 3.5 parent: 100915:aa5dbc32d313 user: Serhiy Storchaka date: Mon Apr 11 12:18:56 2016 +0300 summary: Issue #25910: Fixed dead links in the docs. files: Doc/faq/gui.rst | 2 +- Doc/howto/logging-cookbook.rst | 4 ++-- Doc/whatsnew/2.1.rst | 2 +- Doc/whatsnew/2.2.rst | 6 +++--- Doc/whatsnew/2.3.rst | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/faq/gui.rst b/Doc/faq/gui.rst --- a/Doc/faq/gui.rst +++ b/Doc/faq/gui.rst @@ -59,7 +59,7 @@ There are bindings available for the Qt toolkit (using either `PyQt `_ or `PySide -`_) and for KDE (`PyKDE `__). +`_) and for KDE (`PyKDE4 `__). PyQt is currently more mature than PySide, but you must buy a PyQt license from `Riverbank Computing `_ if you want to write proprietary applications. PySide is free for all applications. diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -1316,7 +1316,7 @@ ----------------------------------------- Below is an example of a logging configuration dictionary - it's taken from -the `documentation on the Django project `_. +the `documentation on the Django project `_. This dictionary is passed to :func:`~config.dictConfig` to put the configuration into effect:: LOGGING = { @@ -1372,7 +1372,7 @@ } For more information about this configuration, you can see the `relevant -section `_ +section `_ of the Django documentation. .. _cookbook-rotator-namer: diff --git a/Doc/whatsnew/2.1.rst b/Doc/whatsnew/2.1.rst --- a/Doc/whatsnew/2.1.rst +++ b/Doc/whatsnew/2.1.rst @@ -731,7 +731,7 @@ ... For a fuller discussion of the line I/O changes, see the python-dev summary for - January 1-15, 2001 at https://www.python.org/dev/summary/2001-01-1/. + January 1-15, 2001 at https://mail.python.org/pipermail/python-dev/2001-January/. * A new method, :meth:`popitem`, was added to dictionaries to enable destructively iterating through the contents of a dictionary; this can be faster diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst --- a/Doc/whatsnew/2.2.rst +++ b/Doc/whatsnew/2.2.rst @@ -24,8 +24,8 @@ This article doesn't attempt to provide a complete specification of the new features, but instead provides a convenient overview. For full details, you should refer to the documentation for Python 2.2, such as the `Python Library -Reference `_ and the `Python -Reference Manual `_. If you want to +Reference `_ and the `Python +Reference Manual `_. If you want to understand the complete implementation and design rationale for a change, refer to the PEP for a particular new feature. @@ -395,7 +395,7 @@ of an explanation to start you programming, but many details have been simplified or ignored. Where should you go to get a more complete picture? -https://www.python.org/2.2/descrintro.html is a lengthy tutorial introduction to +https://docs.python.org/dev/howto/descriptor.html is a lengthy tutorial introduction to the descriptor features, written by Guido van Rossum. If my description has whetted your appetite, go read this tutorial next, because it goes into much more detail about the new features while still remaining quite easy to read. diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -1858,7 +1858,7 @@ .. seealso:: - https://svn.python.org/view/python/trunk/Objects/obmalloc.c + https://hg.python.org/cpython/file/default/Objects/obmalloc.c For the full details of the pymalloc implementation, see the comments at the top of the file :file:`Objects/obmalloc.c` in the Python source code. The above link points to the file within the python.org SVN browser. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 05:39:52 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 09:39:52 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogQ2xvc2VzICMyNTkx?= =?utf-8?q?0=3A_fix_dead_and_permanently_redirected_links_in_the_docs=2E_T?= =?utf-8?q?hanks_to?= Message-ID: <20160411093948.34585.57955.010F70AF@psf.io> https://hg.python.org/cpython/rev/14e00e7e4d51 changeset: 100921:14e00e7e4d51 branch: 2.7 parent: 100916:f21740a1abde user: Georg Brandl date: Fri Feb 26 19:37:12 2016 +0100 summary: Closes #25910: fix dead and permanently redirected links in the docs. Thanks to SilentGhost for the patch. files: Doc/distributing/index.rst | 16 ++-- Doc/distutils/apiref.rst | 2 +- Doc/extending/extending.rst | 2 +- Doc/faq/extending.rst | 4 +- Doc/faq/general.rst | 12 +- Doc/faq/gui.rst | 8 +- Doc/faq/library.rst | 2 +- Doc/faq/programming.rst | 2 +- Doc/howto/functional.rst | 10 +- Doc/howto/logging-cookbook.rst | 2 +- Doc/howto/logging.rst | 2 +- Doc/howto/sorting.rst | 6 +- Doc/howto/webservers.rst | 34 +++++----- Doc/installing/index.rst | 18 ++-- Doc/library/collections.rst | 5 +- Doc/library/decimal.rst | 3 - Doc/library/email.generator.rst | 2 +- Doc/library/functions.rst | 2 +- Doc/library/heapq.rst | 4 +- Doc/library/json.rst | 2 +- Doc/library/logging.rst | 2 +- Doc/library/mailbox.rst | 4 +- Doc/library/math.rst | 2 +- Doc/library/msilib.rst | 64 ++++++++++---------- Doc/library/othergui.rst | 8 +- Doc/library/shelve.rst | 2 +- Doc/library/socket.rst | 2 +- Doc/library/ssl.rst | 24 +++--- Doc/library/subprocess.rst | 6 +- Doc/library/tkinter.rst | 4 +- Doc/library/wsgiref.rst | 4 +- Doc/library/xml.rst | 10 +- Doc/library/zipfile.rst | 9 +- Doc/library/zipimport.rst | 2 +- Doc/using/mac.rst | 2 +- Doc/using/unix.rst | 8 +- Doc/using/windows.rst | 18 ++-- Doc/whatsnew/2.0.rst | 4 +- Doc/whatsnew/2.1.rst | 2 +- Doc/whatsnew/2.3.rst | 8 +- Doc/whatsnew/2.4.rst | 6 +- Doc/whatsnew/2.5.rst | 6 +- Doc/whatsnew/2.6.rst | 10 +- Doc/whatsnew/2.7.rst | 4 +- 44 files changed, 172 insertions(+), 177 deletions(-) diff --git a/Doc/distributing/index.rst b/Doc/distributing/index.rst --- a/Doc/distributing/index.rst +++ b/Doc/distributing/index.rst @@ -35,7 +35,7 @@ repository of open source licensed packages made available for use by other Python users * the `Python Packaging Authority - `__ are the group of + `__ are the group of developers and documentation authors responsible for the maintenance and evolution of the standard packaging tools and the associated metadata and file format standards. They maintain a variety of tools, documentation @@ -62,7 +62,7 @@ locally. .. _setuptools: https://setuptools.pypa.io/en/latest/setuptools.html -.. _wheel: http://wheel.readthedocs.org +.. _wheel: https://wheel.readthedocs.org Open source licensing and collaboration ======================================= @@ -111,7 +111,7 @@ The Python Packaging User Guide includes more details on the `currently recommended tools`_. -.. _currently recommended tools: https://packaging.python.org/en/latest/current.html#packaging-tool-recommendations +.. _currently recommended tools: https://packaging.python.org/en/latest/current/#packaging-tool-recommendations Reading the guide ================= @@ -124,11 +124,11 @@ * `Uploading the project to the Python Packaging Index`_ .. _Project structure: \ - https://packaging.python.org/en/latest/distributing.html#creating-your-own-project + https://packaging.python.org/en/latest/distributing/ .. _Building and packaging the project: \ - https://packaging.python.org/en/latest/distributing.html#packaging-your-project + https://packaging.python.org/en/latest/distributing/#packaging-your-project .. _Uploading the project to the Python Packaging Index: \ - https://packaging.python.org/en/latest/distributing.html#uploading-your-project-to-pypi + https://packaging.python.org/en/latest/distributing/#uploading-your-project-to-pypi How do I...? @@ -160,11 +160,11 @@ .. seealso:: `Python Packaging User Guide: Binary Extensions - `__ + `__ .. other topics: Once the Development & Deployment part of PPUG is fleshed out, some of those sections should be linked from new questions here (most notably, we should have a question about avoiding depending on PyPI that links to - https://packaging.python.org/en/latest/deployment.html#pypi-mirrors-and-caches) + https://packaging.python.org/en/latest/mirrors/) diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -1816,7 +1816,7 @@ Builds a `Windows Installer`_ (.msi) binary package. - .. _Windows Installer: http://msdn.microsoft.com/en-us/library/cc185688(VS.85).aspx + .. _Windows Installer: https://msdn.microsoft.com/en-us/library/cc185688(VS.85).aspx In most cases, the ``bdist_msi`` installer is a better choice than the ``bdist_wininst`` installer, because it provides better support for diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst --- a/Doc/extending/extending.rst +++ b/Doc/extending/extending.rst @@ -27,7 +27,7 @@ avoid writing C extensions and preserve portability to other implementations. For example, if your use case is calling C library functions or system calls, you should consider using the :mod:`ctypes` module or the `cffi - `_ library rather than writing custom C code. + `_ library rather than writing custom C code. These modules let you write Python code to interface with C code and are more portable between implementations of Python than writing and compiling a C extension module. diff --git a/Doc/faq/extending.rst b/Doc/faq/extending.rst --- a/Doc/faq/extending.rst +++ b/Doc/faq/extending.rst @@ -53,10 +53,10 @@ If you need to interface to some C or C++ library for which no Python extension currently exists, you can try wrapping the library's data types and functions with a tool such as `SWIG `_. `SIP -`__, `CXX +`__, `CXX `_ `Boost `_, or `Weave -`_ are also +`_ are also alternatives for wrapping C++ libraries. diff --git a/Doc/faq/general.rst b/Doc/faq/general.rst --- a/Doc/faq/general.rst +++ b/Doc/faq/general.rst @@ -159,7 +159,7 @@ -------------------------------------------- The latest Python source distribution is always available from python.org, at -https://www.python.org/download/. The latest development sources can be obtained +https://www.python.org/downloads/. The latest development sources can be obtained via anonymous Mercurial access at https://hg.python.org/cpython. The source distribution is a gzipped tar file containing the complete C source, @@ -218,7 +218,7 @@ How do I get a beta test version of Python? ------------------------------------------- -Alpha and beta releases are available from https://www.python.org/download/. All +Alpha and beta releases are available from https://www.python.org/downloads/. All releases are announced on the comp.lang.python and comp.lang.python.announce newsgroups and on the Python home page at https://www.python.org/; an RSS feed of news is available. @@ -273,7 +273,7 @@ `www.python.org `_ is graciously hosted by `Rackspace `_, with CDN caching provided by `Fastly `_. `Upfront Systems -`_ hosts `bugs.python.org +`_ hosts `bugs.python.org `_. Many other Python services like `the Wiki `_ are hosted by `Oregon State University Open Source Lab `_. @@ -284,7 +284,7 @@ When he began implementing Python, Guido van Rossum was also reading the published scripts from `"Monty Python's Flying Circus" -`__, a BBC comedy series from the 1970s. Van Rossum +`__, a BBC comedy series from the 1970s. Van Rossum thought he needed a name that was short, unique, and slightly mysterious, so he decided to call the language Python. @@ -313,7 +313,7 @@ releases. The latest stable releases can always be found on the `Python download page -`_. There are two recommended production-ready +`_. There are two recommended production-ready versions at this point in time, because at the moment there are two branches of stable releases: 2.x and 3.x. Python 3.x may be less useful than 2.x, since currently there is more third party software available for Python 2 than for @@ -345,7 +345,7 @@ High-profile Python projects include `the Mailman mailing list manager `_ and `the Zope application server `_. Several Linux distributions, most notably `Red Hat -`_, have written part or all of their installer and +`_, have written part or all of their installer and system administration software in Python. Companies that use Python internally include Google, Yahoo, and Lucasfilm Ltd. diff --git a/Doc/faq/gui.rst b/Doc/faq/gui.rst --- a/Doc/faq/gui.rst +++ b/Doc/faq/gui.rst @@ -48,14 +48,14 @@ --- There are bindings available for the Qt toolkit (using either `PyQt -`_ or `PySide -`_) and for KDE (`PyKDE `__). +`_ or `PySide +`_) and for KDE (`PyKDE `__). PyQt is currently more mature than PySide, but you must buy a PyQt license from -`Riverbank Computing `_ +`Riverbank Computing `_ if you want to write proprietary applications. PySide is free for all applications. Qt 4.5 upwards is licensed under the LGPL license; also, commercial licenses -are available from `The Qt Company `_. +are available from `The Qt Company `_. Gtk+ ---- diff --git a/Doc/faq/library.rst b/Doc/faq/library.rst --- a/Doc/faq/library.rst +++ b/Doc/faq/library.rst @@ -597,7 +597,7 @@ For Unix, see a Usenet post by Mitch Chapman: - http://groups.google.com/groups?selm=34A04430.CF9 at ohioee.com + https://groups.google.com/groups?selm=34A04430.CF9 at ohioee.com Why doesn't closing sys.stdout (stdin, stderr) really close it? diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -63,7 +63,7 @@ warns about code complexity and style. You can get PyChecker from http://pychecker.sourceforge.net/. -`Pylint `_ is another tool that checks +`Pylint `_ is another tool that checks if a module satisfies a coding standard, and also makes it possible to write plug-ins to add a custom feature. In addition to the bug checking that PyChecker performs, Pylint offers some additional features such as checking line diff --git a/Doc/howto/functional.rst b/Doc/howto/functional.rst --- a/Doc/howto/functional.rst +++ b/Doc/howto/functional.rst @@ -331,7 +331,7 @@ List comprehensions and generator expressions (short form: "listcomps" and "genexps") are a concise notation for such operations, borrowed from the -functional programming language Haskell (http://www.haskell.org/). You can strip +functional programming language Haskell (https://www.haskell.org/). You can strip all the whitespace from a stream of strings with the following code:: line_list = [' line 1\n', 'line 2 \n', ...] @@ -1144,7 +1144,7 @@ **Structure and Interpretation of Computer Programs**, by Harold Abelson and Gerald Jay Sussman with Julie Sussman. Full text at -http://mitpress.mit.edu/sicp/. In this classic textbook of computer science, +https://mitpress.mit.edu/sicp/. In this classic textbook of computer science, chapters 2 and 3 discuss the use of sequences and streams to organize the data flow inside a program. The book uses Scheme for its examples, but many of the design approaches described in these chapters are applicable to functional-style @@ -1153,12 +1153,12 @@ http://www.defmacro.org/ramblings/fp.html: A general introduction to functional programming that uses Java examples and has a lengthy historical introduction. -http://en.wikipedia.org/wiki/Functional_programming: General Wikipedia entry +https://en.wikipedia.org/wiki/Functional_programming: General Wikipedia entry describing functional programming. -http://en.wikipedia.org/wiki/Coroutine: Entry for coroutines. +https://en.wikipedia.org/wiki/Coroutine: Entry for coroutines. -http://en.wikipedia.org/wiki/Currying: Entry for the concept of currying. +https://en.wikipedia.org/wiki/Currying: Entry for the concept of currying. Python-specific --------------- diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -705,7 +705,7 @@ ----------------------------------------- Below is an example of a logging configuration dictionary - it's taken from -the `documentation on the Django project `_. +the `documentation on the Django project `_. This dictionary is passed to :func:`~config.dictConfig` to put the configuration into effect:: LOGGING = { diff --git a/Doc/howto/logging.rst b/Doc/howto/logging.rst --- a/Doc/howto/logging.rst +++ b/Doc/howto/logging.rst @@ -310,7 +310,7 @@ If your logging needs are simple, then use the above examples to incorporate logging into your own scripts, and if you run into problems or don't understand something, please post a question on the comp.lang.python Usenet -group (available at http://groups.google.com/group/comp.lang.python) and you +group (available at https://groups.google.com/group/comp.lang.python) and you should receive help before too long. Still here? You can carry on reading the next few sections, which provide a diff --git a/Doc/howto/sorting.rst b/Doc/howto/sorting.rst --- a/Doc/howto/sorting.rst +++ b/Doc/howto/sorting.rst @@ -137,7 +137,7 @@ ================================ Starting with Python 2.2, sorts are guaranteed to be `stable -`_\. That means that +`_\. That means that when multiple records have the same key, their original order is preserved. >>> data = [('red', 1), ('blue', 1), ('red', 2), ('blue', 2)] @@ -155,7 +155,7 @@ >>> sorted(s, key=attrgetter('grade'), reverse=True) # now sort on primary key, descending [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)] -The `Timsort `_ algorithm used in Python +The `Timsort `_ algorithm used in Python does multiple sorts efficiently because it can take advantage of any ordering already present in a dataset. @@ -194,7 +194,7 @@ directly. Another name for this idiom is -`Schwartzian transform `_\, +`Schwartzian transform `_\, after Randal L. Schwartz, who popularized it among Perl programmers. For large lists and lists where the comparison information is expensive to diff --git a/Doc/howto/webservers.rst b/Doc/howto/webservers.rst --- a/Doc/howto/webservers.rst +++ b/Doc/howto/webservers.rst @@ -267,7 +267,7 @@ Each web server requires a specific module. * Apache has both `mod_fastcgi `_ and `mod_fcgid - `_. ``mod_fastcgi`` is the original one, but it + `_. ``mod_fastcgi`` is the original one, but it has some licensing issues, which is why it is sometimes considered non-free. ``mod_fcgid`` is a smaller, compatible alternative. One of these modules needs to be loaded by Apache. @@ -277,7 +277,7 @@ `SCGI module `_. * `nginx `_ also supports `FastCGI - `_. + `_. Once you have installed and configured the module, you can test it with the following WSGI-application:: @@ -306,8 +306,8 @@ .. seealso:: - There is some documentation on `setting up Django with FastCGI - `_, most of + There is some documentation on `setting up Django with WSGI + `_, most of which can be reused for other WSGI-compliant frameworks and libraries. Only the ``manage.py`` part has to be changed, the example used here can be used instead. Django does more or less the exact same thing. @@ -357,7 +357,7 @@ A really great WSGI feature is middleware. Middleware is a layer around your program which can add various functionality to it. There is quite a bit of -`middleware `_ already +`middleware `_ already available. For example, instead of writing your own session management (HTTP is a stateless protocol, so to associate multiple HTTP requests with a single user your application must create and manage such state via a session), you can @@ -378,7 +378,7 @@ The code that is used to connect to various low level gateways like CGI or mod_python is called a *WSGI server*. One of these servers is ``flup``, which supports FastCGI and SCGI, as well as `AJP -`_. Some of these servers +`_. Some of these servers are written in Python, as ``flup`` is, but there also exist others which are written in C and can be used as drop-in replacements. @@ -389,8 +389,8 @@ .. seealso:: A good overview of WSGI-related code can be found in the `WSGI homepage - `_, which contains an extensive list of `WSGI servers - `_ which can be used by *any* application + `_, which contains an extensive list of `WSGI servers + `_ which can be used by *any* application supporting WSGI. You might be interested in some WSGI-supporting modules already contained in @@ -407,7 +407,7 @@ Python without using WSGI. One of the most widely used wiki software packages is `MoinMoin -`_. It was created in 2000, so it predates WSGI by about +`_. It was created in 2000, so it predates WSGI by about three years. Older versions needed separate code to run on CGI, mod_python, FastCGI and standalone. @@ -459,7 +459,7 @@ .. seealso:: The English Wikipedia has an article about the `Model-View-Controller pattern - `_. It includes a long + `_. It includes a long list of web frameworks for various programming languages. @@ -547,10 +547,10 @@ smaller sites SQLite is just enough. Relational databases are *queried* using a language called `SQL -`_. Python programmers in general do not +`_. Python programmers in general do not like SQL too much, as they prefer to work with objects. It is possible to save Python objects into a database using a technology called `ORM -`_ (Object Relational +`_ (Object Relational Mapping). ORM translates all object-oriented access into SQL code under the hood, so the developer does not need to think about it. Most `frameworks`_ use ORMs, and it works quite well. @@ -583,13 +583,13 @@ helps with choosing a method for saving data * `SQLAlchemy `_, the most powerful OR-Mapper - for Python, and `Elixir `_, which makes + for Python, and `Elixir `_, which makes SQLAlchemy easier to use * `SQLObject `_, another popular OR-Mapper * `ZODB `_ and `Durus - `_, two object oriented + `_, two object oriented databases @@ -675,10 +675,10 @@ example the ORM and template engine can be changed to use packages different from those used by default. -The documentation can be found in the `TurboGears wiki -`_, where links to screencasts can be found. +The documentation can be found in the `TurboGears documentation +`_, where links to screencasts can be found. TurboGears has also an active user community which can respond to most related -questions. There is also a `TurboGears book `_ +questions. There is also a `TurboGears book `_ published, which is a good starting point. The newest version of TurboGears, version 2.0, moves even further in direction diff --git a/Doc/installing/index.rst b/Doc/installing/index.rst --- a/Doc/installing/index.rst +++ b/Doc/installing/index.rst @@ -43,7 +43,7 @@ repository of open source licensed packages made available for use by other Python users * the `Python Packaging Authority - `__ are the group of + `__ are the group of developers and documentation authors responsible for the maintenance and evolution of the standard packaging tools and the associated metadata and file format standards. They maintain a variety of tools, documentation @@ -101,7 +101,7 @@ .. seealso:: `Python Packaging User Guide: Installing Python Distribution Packages - `__ + `__ How do I ...? @@ -118,8 +118,8 @@ .. seealso:: - `Python Packaging User Guide: Setup for Installing Distribution Packages - `__ + `Python Packaging User Guide: Requirements for Installing Packages + `__ .. installing-per-user-installation: @@ -138,13 +138,13 @@ aren't currently easy to install using ``pip`` directly. At this point in time, it will often be easier for users to install these packages by `other means -`__ +`__ rather than attempting to install them with ``pip``. .. seealso:: `Python Packaging User Guide: Installing Scientific Packages - `__ + `__ ... work with multiple versions of Python installed in parallel? @@ -174,7 +174,7 @@ Once the Development & Deployment part of PPUG is fleshed out, some of those sections should be linked from new questions here (most notably, we should have a question about avoiding depending on PyPI that links to - https://packaging.python.org/en/latest/deployment.html#pypi-mirrors-and-caches) + https://packaging.python.org/en/latest/mirrors/) Common installation issues @@ -207,11 +207,11 @@ than needing to build them themselves. Some of the solutions for installing `scientific software -`__ +`__ that is not yet available as pre-built ``wheel`` files may also help with obtaining other binary extensions without needing to build them locally. .. seealso:: `Python Packaging User Guide: Binary Extensions - `__ + `__ diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -200,12 +200,11 @@ adapted for Python 2.5 and an early `Bag recipe `_ for Python 2.4. - * `Bag class `_ in Smalltalk. - * Wikipedia entry for `Multisets `_. + * Wikipedia entry for `Multisets `_. - * `C++ multisets `_ + * `C++ multisets `_ tutorial with examples. * For mathematical operations on multisets and their use cases, see diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -111,9 +111,6 @@ * IBM's General Decimal Arithmetic Specification, `The General Decimal Arithmetic Specification `_. - * IEEE standard 854-1987, `Unofficial IEEE 854 Text - `_. - .. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/Doc/library/email.generator.rst b/Doc/library/email.generator.rst --- a/Doc/library/email.generator.rst +++ b/Doc/library/email.generator.rst @@ -37,7 +37,7 @@ followed by a space at the beginning of the line. This is the only guaranteed portable way to avoid having such lines be mistaken for a Unix mailbox format envelope header separator (see `WHY THE CONTENT-LENGTH FORMAT IS BAD - `_ for details). *mangle_from_* + `_ for details). *mangle_from_* defaults to ``True``, but you might want to set this to ``False`` if you are not writing Unix mailbox format files. diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1447,7 +1447,7 @@ For practical suggestions on how to design cooperative classes using :func:`super`, see `guide to using super() - `_. + `_. .. versionadded:: 2.2 diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst --- a/Doc/library/heapq.rst +++ b/Doc/library/heapq.rst @@ -133,7 +133,7 @@ Basic Examples -------------- -A `heapsort `_ can be implemented by +A `heapsort `_ can be implemented by pushing all values onto a heap and then popping off the smallest values one at a time:: @@ -164,7 +164,7 @@ Priority Queue Implementation Notes ----------------------------------- -A `priority queue `_ is common use +A `priority queue `_ is common use for a heap, and it presents several implementation challenges: * Sort stability: how do you get two tasks with equal priorities to be returned diff --git a/Doc/library/json.rst b/Doc/library/json.rst --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -11,7 +11,7 @@ :rfc:`7159` (which obsoletes :rfc:`4627`) and by `ECMA-404 `_, is a lightweight data interchange format inspired by -`JavaScript `_ object literal syntax +`JavaScript `_ object literal syntax (although it is not a strict subset of JavaScript [#rfc-errata]_ ). :mod:`json` exposes an API familiar to users of the standard library diff --git a/Doc/library/logging.rst b/Doc/library/logging.rst --- a/Doc/library/logging.rst +++ b/Doc/library/logging.rst @@ -1021,7 +1021,7 @@ The proposal which described this feature for inclusion in the Python standard library. - `Original Python logging package `_ + `Original Python logging package `_ This is the original source for the :mod:`logging` package. The version of the package available from this site is suitable for use with Python 1.5.2, 2.1.x and 2.2.x, which do not include the :mod:`logging` package in the standard diff --git a/Doc/library/mailbox.rst b/Doc/library/mailbox.rst --- a/Doc/library/mailbox.rst +++ b/Doc/library/mailbox.rst @@ -471,7 +471,7 @@ `mbox man page from tin `_ Another specification of the format, with details on locking. - `Configuring Netscape Mail on Unix: Why The Content-Length Format is Bad `_ + `Configuring Netscape Mail on Unix: Why The Content-Length Format is Bad `_ An argument for using the original mbox format rather than a variation. `"mbox" is a family of several mutually incompatible mailbox formats `_ @@ -731,7 +731,7 @@ `mmdf man page from tin `_ A specification of MMDF format from the documentation of tin, a newsreader. - `MMDF `_ + `MMDF `_ A Wikipedia article describing the Multichannel Memorandum Distribution Facility. diff --git a/Doc/library/math.rst b/Doc/library/math.rst --- a/Doc/library/math.rst +++ b/Doc/library/math.rst @@ -102,7 +102,7 @@ For further discussion and two alternative approaches, see the `ASPN cookbook recipes for accurate floating point summation - `_\. + `_\. .. versionadded:: 2.6 diff --git a/Doc/library/msilib.rst b/Doc/library/msilib.rst --- a/Doc/library/msilib.rst +++ b/Doc/library/msilib.rst @@ -123,9 +123,9 @@ .. seealso:: - `FCICreateFile `_ - `UuidCreate `_ - `UuidToString `_ + `FCICreateFile `_ + `UuidCreate `_ + `UuidToString `_ .. _database-objects: @@ -154,9 +154,9 @@ .. seealso:: - `MSIDatabaseOpenView `_ - `MSIDatabaseCommit `_ - `MSIGetSummaryInformation `_ + `MSIDatabaseOpenView `_ + `MSIDatabaseCommit `_ + `MSIGetSummaryInformation `_ .. _view-objects: @@ -202,11 +202,11 @@ .. seealso:: - `MsiViewExecute `_ - `MSIViewGetColumnInfo `_ - `MsiViewFetch `_ - `MsiViewModify `_ - `MsiViewClose `_ + `MsiViewExecute `_ + `MSIViewGetColumnInfo `_ + `MsiViewFetch `_ + `MsiViewModify `_ + `MsiViewClose `_ .. _summary-objects: @@ -246,10 +246,10 @@ .. seealso:: - `MsiSummaryInfoGetProperty `_ - `MsiSummaryInfoGetPropertyCount `_ - `MsiSummaryInfoSetProperty `_ - `MsiSummaryInfoPersist `_ + `MsiSummaryInfoGetProperty `_ + `MsiSummaryInfoGetPropertyCount `_ + `MsiSummaryInfoSetProperty `_ + `MsiSummaryInfoPersist `_ .. _record-objects: @@ -300,11 +300,11 @@ .. seealso:: - `MsiRecordGetFieldCount `_ - `MsiRecordSetString `_ - `MsiRecordSetStream `_ - `MsiRecordSetInteger `_ - `MsiRecordClear `_ + `MsiRecordGetFieldCount `_ + `MsiRecordSetString `_ + `MsiRecordSetStream `_ + `MsiRecordSetInteger `_ + `MsiRecordClear `_ .. _msi-errors: @@ -396,10 +396,10 @@ .. seealso:: - `Directory Table `_ - `File Table `_ - `Component Table `_ - `FeatureComponents Table `_ + `Directory Table `_ + `File Table `_ + `Component Table `_ + `FeatureComponents Table `_ .. _features: @@ -424,7 +424,7 @@ .. seealso:: - `Feature Table `_ + `Feature Table `_ .. _msi-gui: @@ -519,13 +519,13 @@ .. seealso:: - `Dialog Table `_ - `Control Table `_ - `Control Types `_ - `ControlCondition Table `_ - `ControlEvent Table `_ - `EventMapping Table `_ - `RadioButton Table `_ + `Dialog Table `_ + `Control Table `_ + `Control Types `_ + `ControlCondition Table `_ + `ControlEvent Table `_ + `EventMapping Table `_ + `RadioButton Table `_ .. _msi-tables: diff --git a/Doc/library/othergui.rst b/Doc/library/othergui.rst --- a/Doc/library/othergui.rst +++ b/Doc/library/othergui.rst @@ -13,17 +13,17 @@ provides an object oriented interface that is slightly higher level than the C one. It comes with many more widgets than Tkinter provides, and has good Python-specific reference documentation. There are also bindings to - `GNOME `_. An online `tutorial + `GNOME `_. An online `tutorial `_ is available. - `PyQt `_ + `PyQt `_ PyQt is a :program:`sip`\ -wrapped binding to the Qt toolkit. Qt is an extensive C++ GUI application development framework that is available for Unix, Windows and Mac OS X. :program:`sip` is a tool for generating bindings for C++ libraries as Python classes, and is specifically designed for Python. The *PyQt3* bindings have a book, `GUI Programming with Python: QT Edition - `_ by Boudewijn + `_ by Boudewijn Rempt. The *PyQt4* bindings also have a book, `Rapid GUI Programming with Python and Qt `_, by Mark Summerfield. @@ -39,7 +39,7 @@ low-level device context drawing, drag and drop, system clipboard access, an XML-based resource format and more, including an ever growing library of user-contributed modules. wxPython has a book, `wxPython in Action - `_, by Noel Rappin and + `_, by Noel Rappin and Robin Dunn. PyGTK, PyQt, and wxPython, all have a modern look and feel and more diff --git a/Doc/library/shelve.rst b/Doc/library/shelve.rst --- a/Doc/library/shelve.rst +++ b/Doc/library/shelve.rst @@ -73,7 +73,7 @@ .. seealso:: - `Persistent dictionary recipe `_ + `Persistent dictionary recipe `_ with widely supported storage formats and having the speed of native dictionaries. diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -640,7 +640,7 @@ The :meth:`ioctl` method is a limited interface to the WSAIoctl system interface. Please refer to the `Win32 documentation - `_ for more + `_ for more information. On other platforms, the generic :func:`fcntl.fcntl` and :func:`fcntl.ioctl` diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst --- a/Doc/library/ssl.rst +++ b/Doc/library/ssl.rst @@ -206,7 +206,7 @@ The *ciphers* parameter sets the available ciphers for this SSL object. It should be a string in the `OpenSSL cipher list format - `_. + `_. The parameter ``do_handshake_on_connect`` specifies whether to do the SSL handshake automatically after doing a :meth:`socket.connect`, or whether the @@ -713,7 +713,7 @@ Whether the OpenSSL library has built-in support for *Next Protocol Negotiation* as described in the `NPN draft specification - `_. When true, + `_. When true, you can use the :meth:`SSLContext.set_npn_protocols` method to advertise which protocols you want to support. @@ -1091,7 +1091,7 @@ Set the available ciphers for sockets created with this context. It should be a string in the `OpenSSL cipher list format - `_. + `_. If no cipher can be selected (because compile-time options or other configuration forbids use of all the specified ciphers), an :class:`SSLError` will be raised. @@ -1120,7 +1120,7 @@ handshake. It should be a list of strings, like ``['http/1.1', 'spdy/2']``, ordered by preference. The selection of a protocol will happen during the handshake, and will play out according to the `NPN draft specification - `_. After a + `_. After a successful handshake, the :meth:`SSLSocket.selected_npn_protocol` method will return the agreed-upon protocol. @@ -1722,7 +1722,7 @@ :meth:`SSLContext.set_ciphers` method. Starting from Python 2.7.9, the ssl module disables certain weak ciphers by default, but you may want to further restrict the cipher choice. Be sure to read OpenSSL's documentation -about the `cipher list format `_. +about the `cipher list format `_. If you want to check which ciphers are enabled by a given cipher list, use the ``openssl ciphers`` command on your system. @@ -1743,25 +1743,25 @@ Class :class:`socket.socket` Documentation of underlying :mod:`socket` class - `SSL/TLS Strong Encryption: An Introduction `_ + `SSL/TLS Strong Encryption: An Introduction `_ Intro from the Apache webserver documentation - `RFC 1422: Privacy Enhancement for Internet Electronic Mail: Part II: Certificate-Based Key Management `_ + `RFC 1422: Privacy Enhancement for Internet Electronic Mail: Part II: Certificate-Based Key Management `_ Steve Kent - `RFC 1750: Randomness Recommendations for Security `_ + `RFC 1750: Randomness Recommendations for Security `_ D. Eastlake et. al. - `RFC 3280: Internet X.509 Public Key Infrastructure Certificate and CRL Profile `_ + `RFC 3280: Internet X.509 Public Key Infrastructure Certificate and CRL Profile `_ Housley et. al. - `RFC 4366: Transport Layer Security (TLS) Extensions `_ + `RFC 4366: Transport Layer Security (TLS) Extensions `_ Blake-Wilson et. al. - `RFC 5246: The Transport Layer Security (TLS) Protocol Version 1.2 `_ + `RFC 5246: The Transport Layer Security (TLS) Protocol Version 1.2 `_ T. Dierks et. al. - `RFC 6066: Transport Layer Security (TLS) Extensions `_ + `RFC 6066: Transport Layer Security (TLS) Extensions `_ D. Eastlake `IANA TLS: Transport Layer Security (TLS) Parameters `_ diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -404,7 +404,7 @@ `side-by-side assembly`_ the specified *env* **must** include a valid :envvar:`SystemRoot`. - .. _side-by-side assembly: http://en.wikipedia.org/wiki/Side-by-Side_Assembly + .. _side-by-side assembly: https://en.wikipedia.org/wiki/Side-by-Side_Assembly If *universal_newlines* is ``True``, the file objects *stdout* and *stderr* are opened as text files in :term:`universal newlines` mode. Lines may be @@ -586,7 +586,7 @@ .. class:: STARTUPINFO() Partial support of the Windows - `STARTUPINFO `__ + `STARTUPINFO `__ structure is used for :class:`Popen` creation. .. attribute:: dwFlags @@ -622,7 +622,7 @@ If :attr:`dwFlags` specifies :data:`STARTF_USESHOWWINDOW`, this attribute can be any of the values that can be specified in the ``nCmdShow`` parameter for the - `ShowWindow `__ + `ShowWindow `__ function, except for ``SW_SHOWDEFAULT``. Otherwise, this attribute is ignored. diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst --- a/Doc/library/tkinter.rst +++ b/Doc/library/tkinter.rst @@ -35,13 +35,13 @@ `Tcl/Tk manual `_ Official manual for the latest tcl/tk version. - `Programming Python `_ + `Programming Python `_ Book by Mark Lutz, has excellent coverage of Tkinter. `Modern Tkinter for Busy Python Developers `_ Book by Mark Rozerman about building attractive and modern graphical user interfaces with Python and Tkinter. - `Python and Tkinter Programming `_ + `Python and Tkinter Programming `_ The book by John Grayson (ISBN 1-884777-81-3). diff --git a/Doc/library/wsgiref.rst b/Doc/library/wsgiref.rst --- a/Doc/library/wsgiref.rst +++ b/Doc/library/wsgiref.rst @@ -26,8 +26,8 @@ and a validation tool that checks WSGI servers and applications for conformance to the WSGI specification (:pep:`333`). -See http://www.wsgi.org for more information about WSGI, and links to tutorials -and other resources. +See https://wsgi.readthedocs.org/ for more information about WSGI, and links to +tutorials and other resources. .. XXX If you're just trying to write a web application... diff --git a/Doc/library/xml.rst b/Doc/library/xml.rst --- a/Doc/library/xml.rst +++ b/Doc/library/xml.rst @@ -62,7 +62,7 @@ billion laughs **Yes** **Yes** **Yes** **Yes** **Yes** quadratic blowup **Yes** **Yes** **Yes** **Yes** **Yes** external entity expansion **Yes** No (1) No (2) **Yes** No (3) -DTD retrieval **Yes** No No **Yes** No +`DTD`_ retrieval **Yes** No No **Yes** No decompression bomb No No No No **Yes** ========================= ======== ========= ========= ======== ========= @@ -94,7 +94,7 @@ parser retrieves the resource with e.g. HTTP or FTP requests and embeds the content into the XML document. -DTD retrieval +`DTD`_ retrieval Some XML libraries like Python's :mod:`xml.dom.pulldom` retrieve document type definitions from remote or local locations. The feature has similar implications as the external entity expansion issue. @@ -131,6 +131,6 @@ .. _defusedxml: https://pypi.python.org/pypi/defusedxml/ .. _defusedexpat: https://pypi.python.org/pypi/defusedexpat/ -.. _Billion Laughs: http://en.wikipedia.org/wiki/Billion_laughs -.. _ZIP bomb: http://en.wikipedia.org/wiki/Zip_bomb -.. _DTD: http://en.wikipedia.org/wiki/Document_Type_Definition +.. _Billion Laughs: https://en.wikipedia.org/wiki/Billion_laughs +.. _ZIP bomb: https://en.wikipedia.org/wiki/Zip_bomb +.. _DTD: https://en.wikipedia.org/wiki/Document_type_definition diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst --- a/Doc/library/zipfile.rst +++ b/Doc/library/zipfile.rst @@ -15,8 +15,7 @@ The ZIP file format is a common archive and compression standard. This module provides tools to create, read, write, append, and list a ZIP file. Any advanced use of this module will require an understanding of the format, as -defined in `PKZIP Application Note -`_. +defined in `PKZIP Application Note`_. This module does not currently handle multi-disk ZIP files. It can handle ZIP files that use the ZIP64 extensions @@ -83,7 +82,7 @@ .. seealso:: - `PKZIP Application Note `_ + `PKZIP Application Note`_ Documentation on the ZIP file format by Phil Katz, the creator of the format and algorithms used. @@ -435,8 +434,7 @@ .. attribute:: ZipInfo.extra - Expansion field data. The `PKZIP Application Note - `_ contains + Expansion field data. The `PKZIP Application Note`_ contains some comments on the internal structure of the data contained in this string. @@ -499,3 +497,4 @@ Size of the uncompressed file. +.. _PKZIP Application Note: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT diff --git a/Doc/library/zipimport.rst b/Doc/library/zipimport.rst --- a/Doc/library/zipimport.rst +++ b/Doc/library/zipimport.rst @@ -37,7 +37,7 @@ .. seealso:: - `PKZIP Application Note `_ + `PKZIP Application Note `_ Documentation on the ZIP file format by Phil Katz, the creator of the format and algorithms used. diff --git a/Doc/using/mac.rst b/Doc/using/mac.rst --- a/Doc/using/mac.rst +++ b/Doc/using/mac.rst @@ -160,7 +160,7 @@ *PyQt* is another popular cross-platform GUI toolkit that runs natively on Mac OS X. More information can be found at -http://www.riverbankcomputing.co.uk/software/pyqt/intro. +https://riverbankcomputing.com/software/pyqt/intro. Distributing Python Applications on the Mac diff --git a/Doc/using/unix.rst b/Doc/using/unix.rst --- a/Doc/using/unix.rst +++ b/Doc/using/unix.rst @@ -26,11 +26,11 @@ .. seealso:: - http://www.debian.org/doc/manuals/maint-guide/first.en.html + https://www.debian.org/doc/manuals/maint-guide/first.en.html for Debian users - http://en.opensuse.org/Portal:Packaging + https://en.opensuse.org/Portal:Packaging for OpenSuse users - http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-creating-rpms.html + https://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-creating-rpms.html for Fedora users http://www.slackbook.org/html/package-management-making-packages.html for Slackware users @@ -65,7 +65,7 @@ =============== If you want to compile CPython yourself, first thing you should do is get the -`source `_. You can download either the +`source `_. You can download either the latest release's source or just grab a fresh `clone `_. (If you want to contribute patches, you will need a clone.) diff --git a/Doc/using/windows.rst b/Doc/using/windows.rst --- a/Doc/using/windows.rst +++ b/Doc/using/windows.rst @@ -42,7 +42,7 @@ .. seealso:: - `Python on XP `_ + `Python on XP `_ "7 Minutes to "Hello World!"" by Richard Dooling, 2006 @@ -65,7 +65,7 @@ additional functionality. The following is a list of popular versions and their key features: -`ActivePython `_ +`ActivePython `_ Installer with multi-platform compatibility, documentation, PyWin32 `Enthought Python Distribution `_ @@ -123,10 +123,10 @@ .. seealso:: - http://support.microsoft.com/kb/100843 + https://support.microsoft.com/kb/100843 Environment variables in Windows NT - http://support.microsoft.com/kb/310519 + https://support.microsoft.com/kb/310519 How To Manage Environment Variables in Windows XP http://www.chem.gla.ac.uk/~louis/software/faq/q1.html @@ -242,18 +242,18 @@ PyWin32 ------- -The `PyWin32 `_ module by Mark Hammond +The `PyWin32 `_ module by Mark Hammond is a collection of modules for advanced Windows-specific support. This includes utilities for: -* `Component Object Model `_ (COM) +* `Component Object Model `_ (COM) * Win32 API calls * Registry * Event log -* `Microsoft Foundation Classes `_ (MFC) +* `Microsoft Foundation Classes `_ (MFC) user interfaces -`PythonWin `_ is a sample MFC application shipped with PyWin32. It is an embeddable IDE with a built-in debugger. @@ -291,7 +291,7 @@ =========================== If you want to compile CPython yourself, first thing you should do is get the -`source `_. You can download either the +`source `_. You can download either the latest release's source or just grab a fresh `checkout `_. diff --git a/Doc/whatsnew/2.0.rst b/Doc/whatsnew/2.0.rst --- a/Doc/whatsnew/2.0.rst +++ b/Doc/whatsnew/2.0.rst @@ -130,7 +130,7 @@ Read the rest of PEP 1 for the details of the PEP editorial process, style, and format. PEPs are kept in the Python CVS tree on SourceForge, though they're not part of the Python 2.0 distribution, and are also available in HTML form from -https://www.python.org/peps/. As of September 2000, there are 25 PEPS, ranging +https://www.python.org/dev/peps/. As of September 2000, there are 25 PEPS, ranging from PEP 201, "Lockstep Iteration", to PEP 225, "Elementwise/Objectwise Operators". @@ -337,7 +337,7 @@ [ (x,y) for x in seq1 for y in seq2] The idea of list comprehensions originally comes from the functional programming -language Haskell (http://www.haskell.org). Greg Ewing argued most effectively +language Haskell (https://www.haskell.org). Greg Ewing argued most effectively for adding them to Python and wrote the initial list comprehension patch, which was then discussed for a seemingly endless time on the python-dev mailing list and kept up-to-date by Skip Montanaro. diff --git a/Doc/whatsnew/2.1.rst b/Doc/whatsnew/2.1.rst --- a/Doc/whatsnew/2.1.rst +++ b/Doc/whatsnew/2.1.rst @@ -562,7 +562,7 @@ using Python 2.1, since a new release of the Distutils will be made for users of earlier Python versions. Version 1.0.2 of the Distutils includes the changes described in PEP 241, as well as various bugfixes and enhancements. It will be -available from the Distutils SIG at https://www.python.org/sigs/distutils-sig/. +available from the Distutils SIG at https://www.python.org/community/sigs/current/distutils-sig/. .. seealso:: diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -1080,9 +1080,9 @@ hierarchy. Classic classes are unaffected by this change. Python 2.2 originally used a topological sort of a class's ancestors, but 2.3 now uses the C3 algorithm as described in the paper `"A Monotonic Superclass Linearization - for Dylan" `_. To + for Dylan" `_. To understand the motivation for this change, read Michele Simionato's article - `"Python 2.3 Method Resolution Order" `_, or + `"Python 2.3 Method Resolution Order" `_, or read the thread on python-dev starting with the message at https://mail.python.org/pipermail/python-dev/2002-October/029035.html. Samuele Pedroni first pointed out the problem and also implemented the fix by coding the @@ -1306,7 +1306,7 @@ partially sorted order such that, for every index *k*, ``heap[k] <= heap[2*k+1]`` and ``heap[k] <= heap[2*k+2]``. This makes it quick to remove the smallest item, and inserting a new item while maintaining the heap property is - O(lg n). (See http://www.nist.gov/dads/HTML/priorityque.html for more + O(lg n). (See https://xlinux.nist.gov/dads//HTML/priorityque.html for more information about the priority queue data structure.) The :mod:`heapq` module provides :func:`heappush` and :func:`heappop` functions @@ -1949,7 +1949,7 @@ source distribution, were updated for 2.3. (Contributed by Sean Reifschneider.) Other new platforms now supported by Python include AtheOS -(http://www.atheos.cx/), GNU/Hurd, and OpenVMS. +(http://atheos.cx/), GNU/Hurd, and OpenVMS. .. ====================================================================== diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -337,7 +337,7 @@ wrote patches implementing function decorators, but the one that was actually checked in was patch #979728, written by Mark Russell. - https://www.python.org/moin/PythonDecoratorLibrary + https://wiki.python.org/moin/PythonDecoratorLibrary This Wiki page contains several examples of decorators. .. ====================================================================== @@ -687,7 +687,7 @@ The article uses Fortran code to illustrate many of the problems that floating- point inaccuracy can cause. - http://www2.hursley.ibm.com/decimal/ + http://speleotrove.com/decimal/ A description of a decimal-based representation. This representation is being proposed as a standard, and underlies the new Python decimal type. Much of this material was written by Mike Cowlishaw, designer of the Rexx language. @@ -756,7 +756,7 @@ :c:type:`double` to an ASCII string. The code for these functions came from the GLib library -(http://library.gnome.org/devel/glib/stable/), whose developers kindly +(https://developer.gnome.org/glib/stable/), whose developers kindly relicensed the relevant functions and donated them to the Python Software Foundation. The :mod:`locale` module can now change the numeric locale, letting extensions such as GTK+ produce the correct results. diff --git a/Doc/whatsnew/2.5.rst b/Doc/whatsnew/2.5.rst --- a/Doc/whatsnew/2.5.rst +++ b/Doc/whatsnew/2.5.rst @@ -330,7 +330,7 @@ :pep:`328` - Imports: Multi-Line and Absolute/Relative PEP written by Aahz; implemented by Thomas Wouters. - http://codespeak.net/py/current/doc/index.html + https://pylib.readthedocs.org/ The py library by Holger Krekel, which contains the :mod:`py.std` package. .. ====================================================================== @@ -547,7 +547,7 @@ Earlier versions of these features were proposed in :pep:`288` by Raymond Hettinger and :pep:`325` by Samuele Pedroni. - http://en.wikipedia.org/wiki/Coroutine + https://en.wikipedia.org/wiki/Coroutine The Wikipedia entry for coroutines. http://www.sidhe.org/~dan/blog/archives/000178.html @@ -2088,7 +2088,7 @@ provided the results of their examination of the Python source code. The analysis found about 60 bugs that were quickly fixed. Many of the bugs were refcounting problems, often occurring in error-handling code. See - http://scan.coverity.com for the statistics. + https://scan.coverity.com for the statistics. * The largest change to the C API came from :pep:`353`, which modifies the interpreter to use a :c:type:`Py_ssize_t` type definition instead of diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -151,8 +151,8 @@ therefore posted a call for issue trackers, asking volunteers to set up different products and import some of the bugs and patches from SourceForge. Four different trackers were examined: `Jira -`__, -`Launchpad `__, +`__, +`Launchpad `__, `Roundup `__, and `Trac `__. The committee eventually settled on Jira @@ -215,7 +215,7 @@ During the 2.6 development cycle, Georg Brandl put a lot of effort into building a new toolchain for processing the documentation. The resulting package is called Sphinx, and is available from -http://sphinx.pocoo.org/. +http://sphinx-doc.org/. Sphinx concentrates on HTML output, producing attractively styled and modern HTML; printed output is still supported through conversion to @@ -1792,7 +1792,7 @@ * The :mod:`bsddb` module also has a new maintainer, Jes?s Cea Avion, and the package is now available as a standalone package. The web page for the package is `www.jcea.es/programacion/pybsddb.htm - `__. + `__. The plan is to remove the package from the standard library in Python 3.0, because its pace of releases is much more frequent than Python's. @@ -1922,7 +1922,7 @@ the left to six places. (Contributed by Skip Montanaro; :issue:`1158`.) * The :mod:`decimal` module was updated to version 1.66 of - `the General Decimal Specification `__. New features + `the General Decimal Specification `__. New features include some methods for some basic mathematical functions such as :meth:`exp` and :meth:`log10`:: diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -1029,7 +1029,7 @@ * Updated module: the :mod:`bsddb` module has been updated from 4.7.2devel9 to version 4.8.4 of - `the pybsddb package `__. + `the pybsddb package `__. The new version features better Python 3.x compatibility, various bug fixes, and adds several new BerkeleyDB flags and methods. (Updated by Jes?s Cea Avi?n; :issue:`8156`. The pybsddb @@ -1513,7 +1513,7 @@ (Contributed by Kristj?n Valur J?nsson; :issue:`6192` and :issue:`6267`.) * Updated module: the :mod:`sqlite3` module has been updated to - version 2.6.0 of the `pysqlite package `__. Version 2.6.0 includes a number of bugfixes, and adds + version 2.6.0 of the `pysqlite package `__. Version 2.6.0 includes a number of bugfixes, and adds the ability to load SQLite extensions from shared libraries. Call the ``enable_load_extension(True)`` method to enable extensions, and then call :meth:`~sqlite3.Connection.load_extension` to load a particular shared library. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 05:39:54 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 09:39:54 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Null_merge?= Message-ID: <20160411093954.15610.37532.157E9EA8@psf.io> https://hg.python.org/cpython/rev/2f41847540dc changeset: 100926:2f41847540dc parent: 100925:8cd2e0bf65e0 parent: 100924:9520682b928d user: Serhiy Storchaka date: Mon Apr 11 12:39:18 2016 +0300 summary: Null merge files: -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 05:39:54 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 09:39:54 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy41IC0+IDMuNSk6?= =?utf-8?q?_Merge_heads?= Message-ID: <20160411093954.14813.21515.030858BC@psf.io> https://hg.python.org/cpython/rev/9520682b928d changeset: 100924:9520682b928d branch: 3.5 parent: 100920:ce721df212cf parent: 100918:83f267ffb862 user: Serhiy Storchaka date: Mon Apr 11 12:38:54 2016 +0300 summary: Merge heads files: Doc/library/exceptions.rst | 2 +- Doc/library/unittest.mock.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -288,7 +288,7 @@ .. versionchanged:: 3.3 :exc:`EnvironmentError`, :exc:`IOError`, :exc:`WindowsError`, - :exc:`VMSError`, :exc:`socket.error`, :exc:`select.error` and + :exc:`socket.error`, :exc:`select.error` and :exc:`mmap.error` have been merged into :exc:`OSError`, and the constructor may return a subclass. diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -1697,7 +1697,7 @@ * ``__ge__``: NotImplemented * ``__int__``: 1 * ``__contains__``: False -* ``__len__``: 1 +* ``__len__``: 0 * ``__iter__``: iter([]) * ``__exit__``: False * ``__complex__``: 1j -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 05:39:57 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 09:39:57 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_Merge_heads?= Message-ID: <20160411093954.34581.78234.855C6EB8@psf.io> https://hg.python.org/cpython/rev/8cd2e0bf65e0 changeset: 100925:8cd2e0bf65e0 parent: 100923:15c4557af8e0 parent: 100919:16fb032f29cc user: Serhiy Storchaka date: Mon Apr 11 12:39:07 2016 +0300 summary: Merge heads files: Doc/library/exceptions.rst | 2 +- Doc/library/unittest.mock.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -288,7 +288,7 @@ .. versionchanged:: 3.3 :exc:`EnvironmentError`, :exc:`IOError`, :exc:`WindowsError`, - :exc:`VMSError`, :exc:`socket.error`, :exc:`select.error` and + :exc:`socket.error`, :exc:`select.error` and :exc:`mmap.error` have been merged into :exc:`OSError`, and the constructor may return a subclass. diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -1725,7 +1725,7 @@ * ``__ge__``: NotImplemented * ``__int__``: 1 * ``__contains__``: False -* ``__len__``: 1 +* ``__len__``: 0 * ``__iter__``: iter([]) * ``__exit__``: False * ``__complex__``: 1j -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Mon Apr 11 05:46:04 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 11 Apr 2016 09:46:04 +0000 Subject: [Python-checkins] Daily reference leaks (a8dbe6016a31): sum=65 Message-ID: <20160411094603.15616.3068.E1A0006B@psf.io> results for a8dbe6016a31 on branch "default" -------------------------------------------- test_asyncio leaked [0, 0, 3] memory blocks, sum=3 test_functools leaked [0, 3, 1] memory blocks, sum=4 test_multiprocessing_spawn leaked [0, 38, 0] references, sum=38 test_multiprocessing_spawn leaked [0, 18, 0] memory blocks, sum=18 test_multiprocessing_spawn leaked [0, 2, 0] file descriptors, sum=2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/refloguLUfew', '--timeout', '7200'] From lp_benchmark_robot at intel.com Mon Apr 11 06:29:52 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Mon, 11 Apr 2016 11:29:52 +0100 Subject: [Python-checkins] GOOD Benchmark Results for Python Default 2016-04-11 Message-ID: Results for project Python default, build date 2016-04-11 02:09:30 +0000 commit: bf44913588b7 previous commit: 4acdb324a430 revision date: 2016-04-11 00:40:08 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.19% -0.18% 10.89% 14.56% :-| pybench 0.21% 0.90% 0.59% 5.36% :-( regex_v8 2.64% 1.64% -4.04% 5.53% :-| nbody 0.22% -0.86% -1.99% 10.09% :-( json_dump_v2 0.23% -0.38% -2.29% 9.75% :-| normal_startup 0.78% 0.02% -0.13% 5.73% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/good-benchmark-results-for-python-default-2016-04-11/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Mon Apr 11 06:35:16 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Mon, 11 Apr 2016 11:35:16 +0100 Subject: [Python-checkins] UGLY Benchmark Results for Python 2.7 2016-04-11 Message-ID: <558ce3db-2ee7-483b-895a-76749d4aabc1@irsmsx106.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-11 03:03:26 +0000 commit: 9cf8572abe58 previous commit: 7197809a7428 revision date: 2016-04-10 15:05:12 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.16% -2.25% 4.24% 2.77% :-) pybench 0.11% 0.51% 6.42% 4.05% :-( regex_v8 0.81% -0.32% -2.90% 10.06% :-) nbody 0.08% 2.58% 9.40% 1.64% :-) json_dump_v2 0.21% 0.05% 3.73% 9.05% :-( normal_startup 1.93% -0.40% -5.92% 1.87% :-) ssbench 0.29% 0.09% 2.10% 1.53% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/ugly-benchmark-results-for-python-2-7-2016-04-11/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Mon Apr 11 06:49:17 2016 From: python-checkins at python.org (berker.peksag) Date: Mon, 11 Apr 2016 10:49:17 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Add_a_versionchanged_directive_to_document_addition_of_t?= =?utf-8?q?he_new_=27namereplace=27?= Message-ID: <20160411104917.18857.73936.1BCACA0F@psf.io> https://hg.python.org/cpython/rev/3ba2eb4d1836 changeset: 100928:3ba2eb4d1836 parent: 100926:2f41847540dc parent: 100927:3735a033791b user: Berker Peksag date: Mon Apr 11 13:50:04 2016 +0300 summary: Add a versionchanged directive to document addition of the new 'namereplace' error handler. Reported by Robert on docs at p.o. files: Doc/library/functions.rst | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1074,6 +1074,8 @@ exception, the function now retries the system call instead of raising an :exc:`InterruptedError` exception (see :pep:`475` for the rationale). + .. versionchanged:: 3.5 + The ``'namereplace'`` error handler was added. .. function:: ord(c) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 06:49:19 2016 From: python-checkins at python.org (berker.peksag) Date: Mon, 11 Apr 2016 10:49:19 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Add_a_versionc?= =?utf-8?q?hanged_directive_to_document_addition_of_the_new_=27namereplace?= =?utf-8?q?=27?= Message-ID: <20160411104917.110000.61365.0B477D5C@psf.io> https://hg.python.org/cpython/rev/3735a033791b changeset: 100927:3735a033791b branch: 3.5 parent: 100924:9520682b928d user: Berker Peksag date: Mon Apr 11 13:49:46 2016 +0300 summary: Add a versionchanged directive to document addition of the new 'namereplace' error handler. Reported by Robert on docs at p.o. files: Doc/library/functions.rst | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1074,6 +1074,8 @@ exception, the function now retries the system call instead of raising an :exc:`InterruptedError` exception (see :pep:`475` for the rationale). + .. versionchanged:: 3.5 + The ``'namereplace'`` error handler was added. .. function:: ord(c) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 10:23:46 2016 From: python-checkins at python.org (victor.stinner) Date: Mon, 11 Apr 2016 14:23:46 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy41?= Message-ID: <20160411142343.15606.55356.E9E55CE5@psf.io> https://hg.python.org/cpython/rev/3a1a19d89bdd changeset: 100930:3a1a19d89bdd parent: 100928:3ba2eb4d1836 parent: 100929:6a26fd505e8e user: Victor Stinner date: Mon Apr 11 16:23:37 2016 +0200 summary: Merge 3.5 files: Doc/library/typing.rst | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -6,6 +6,8 @@ **Source code:** :source:`Lib/typing.py` +.. versionadded:: 3.5 + -------------- This module supports type hints as specified by :pep:`484`. The most -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 10:23:48 2016 From: python-checkins at python.org (victor.stinner) Date: Mon, 11 Apr 2016 14:23:48 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogdHlwaW5nIGRvYzog?= =?utf-8?q?add_versionadded_3=2E5?= Message-ID: <20160411142343.11641.59329.FAE1B456@psf.io> https://hg.python.org/cpython/rev/6a26fd505e8e changeset: 100929:6a26fd505e8e branch: 3.5 parent: 100927:3735a033791b user: Victor Stinner date: Mon Apr 11 16:23:22 2016 +0200 summary: typing doc: add versionadded 3.5 files: Doc/library/typing.rst | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -6,6 +6,8 @@ **Source code:** :source:`Lib/typing.py` +.. versionadded:: 3.5 + -------------- This module supports type hints as specified by :pep:`484`. The most -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 10:38:53 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 14:38:53 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI1OTEw?= =?utf-8?q?=3A_Fixed_more_links_in_the_docs=2E?= Message-ID: <20160411143851.18859.27207.908B2F75@psf.io> https://hg.python.org/cpython/rev/61c7deea9e6a changeset: 100932:61c7deea9e6a branch: 2.7 parent: 100922:00addbb47c5c user: Serhiy Storchaka date: Mon Apr 11 17:32:33 2016 +0300 summary: Issue #25910: Fixed more links in the docs. files: Doc/using/windows.rst | 4 ++-- Doc/whatsnew/2.7.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/using/windows.rst b/Doc/using/windows.rst --- a/Doc/using/windows.rst +++ b/Doc/using/windows.rst @@ -52,9 +52,9 @@ by Mark Pilgrim, 2004, ISBN 1-59059-356-1 - `For Windows users `_ + `For Windows users `_ in "Installing Python" - in "`A Byte of Python `_" + in "`A Byte of Python `_" by Swaroop C H, 2003 diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -1530,7 +1530,7 @@ *ciphers* argument that's a string listing the encryption algorithms to be allowed; the format of the string is described `in the OpenSSL documentation - `__. + `__. (Added by Antoine Pitrou; :issue:`8322`.) Another change makes the extension load all of OpenSSL's ciphers and -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 10:39:56 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 14:39:56 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI1OTEw?= =?utf-8?q?=3A_Fixed_more_links_in_the_docs=2E?= Message-ID: <20160411143851.90798.30219.63FC3F76@psf.io> https://hg.python.org/cpython/rev/bb10867ffe28 changeset: 100931:bb10867ffe28 branch: 3.5 parent: 100929:6a26fd505e8e user: Serhiy Storchaka date: Mon Apr 11 17:32:33 2016 +0300 summary: Issue #25910: Fixed more links in the docs. files: Doc/using/windows.rst | 4 ++-- Doc/whatsnew/2.7.rst | 2 +- Doc/whatsnew/3.2.rst | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/using/windows.rst b/Doc/using/windows.rst --- a/Doc/using/windows.rst +++ b/Doc/using/windows.rst @@ -266,9 +266,9 @@ by Mark Pilgrim, 2004, ISBN 1-59059-356-1 - `For Windows users `_ + `For Windows users `_ in "Installing Python" - in "`A Byte of Python `_" + in "`A Byte of Python `_" by Swaroop C H, 2003 diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -1530,7 +1530,7 @@ *ciphers* argument that's a string listing the encryption algorithms to be allowed; the format of the string is described `in the OpenSSL documentation - `__. + `__. (Added by Antoine Pitrou; :issue:`8322`.) Another change makes the extension load all of OpenSSL's ciphers and diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -1618,7 +1618,7 @@ * The :func:`ssl.wrap_socket` constructor function now takes a *ciphers* argument. The *ciphers* string lists the allowed encryption algorithms using the format described in the `OpenSSL documentation - `__. + `__. * When linked against recent versions of OpenSSL, the :mod:`ssl` module now supports the Server Name Indication extension to the TLS protocol, allowing -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 10:40:04 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 11 Apr 2016 14:40:04 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2325910=3A_Fixed_more_links_in_the_docs=2E?= Message-ID: <20160411143852.90800.67635.C9ABA364@psf.io> https://hg.python.org/cpython/rev/e3c9a47a83fb changeset: 100933:e3c9a47a83fb parent: 100930:3a1a19d89bdd parent: 100931:bb10867ffe28 user: Serhiy Storchaka date: Mon Apr 11 17:33:27 2016 +0300 summary: Issue #25910: Fixed more links in the docs. files: Doc/using/windows.rst | 4 ++-- Doc/whatsnew/2.7.rst | 2 +- Doc/whatsnew/3.2.rst | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/using/windows.rst b/Doc/using/windows.rst --- a/Doc/using/windows.rst +++ b/Doc/using/windows.rst @@ -266,9 +266,9 @@ by Mark Pilgrim, 2004, ISBN 1-59059-356-1 - `For Windows users `_ + `For Windows users `_ in "Installing Python" - in "`A Byte of Python `_" + in "`A Byte of Python `_" by Swaroop C H, 2003 diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -1530,7 +1530,7 @@ *ciphers* argument that's a string listing the encryption algorithms to be allowed; the format of the string is described `in the OpenSSL documentation - `__. + `__. (Added by Antoine Pitrou; :issue:`8322`.) Another change makes the extension load all of OpenSSL's ciphers and diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -1618,7 +1618,7 @@ * The :func:`ssl.wrap_socket` constructor function now takes a *ciphers* argument. The *ciphers* string lists the allowed encryption algorithms using the format described in the `OpenSSL documentation - `__. + `__. * When linked against recent versions of OpenSSL, the :mod:`ssl` module now supports the Server Name Indication extension to the TLS protocol, allowing -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 11 13:27:34 2016 From: python-checkins at python.org (steven.daprano) Date: Mon, 11 Apr 2016 17:27:34 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Make_API_And_Implementation_s?= =?utf-8?q?ection_less_wishy-washy=2E?= Message-ID: <20160411172728.16613.85607.A545A311@psf.io> https://hg.python.org/peps/rev/c14c62e1f6d6 changeset: 6278:c14c62e1f6d6 user: Steven D'Aprano date: Tue Apr 12 03:26:55 2016 +1000 summary: Make API And Implementation section less wishy-washy. Per GvR's request, be more specific about what is included. files: pep-0506.txt | 42 +++++++++++++++++---------------------- 1 files changed, 18 insertions(+), 24 deletions(-) diff --git a/pep-0506.txt b/pep-0506.txt --- a/pep-0506.txt +++ b/pep-0506.txt @@ -113,13 +113,14 @@ API and Implementation ====================== -The contents of the ``secrets`` module is expected to evolve over time, and -likely will evolve between the time of writing this PEP and actual release -in the standard library [#]_. At the time of writing, the following functions -have been suggested: +This PEP proposes the following functions for the ``secrets`` module: -* A high-level function for generating secure tokens suitable for use - in (e.g.) password recovery, as session keys, etc. +* Functions for generating tokens suitable for use in (e.g.) password + recovery, as session keys, etc., in the following formats: + + - as bytes, ``secrets.token_bytes``; + - as text, using hexadecimal digits, ``secrets.token_hex``; + - as text, using URL-safe base-64 encoding, ``secrets.token_urlsafe``. * A limited interface to the system CSPRNG, using either ``os.urandom`` directly or ``random.SystemRandom``. Unlike the ``random`` module, this @@ -128,13 +129,13 @@ following: - A function for choosing items from a sequence, ``secrets.choice``. - - A function for generating an integer within some range, such as - ``secrets.randrange`` or ``secrets.randint`` [#]_. - A function for generating a given number of random bits and/or bytes - as an integer. - - A similar function which returns the value as a hex digit string. + as an integer, ``secrets.randbits``. + - A function for returning a random integer in the half-open range + 0 to the given upper limit, ``secrets.randbelow`` [#]_. -* ``hmac.compare_digest`` under the name ``equal``. +* A function for comparing text or bytes digests for equality while being + resistent to timing attacks, ``secrets.compare_digest``. The consensus appears to be that there is no need to add a new CSPRNG to the ``random`` module to support these uses, ``SystemRandom`` will be @@ -143,16 +144,14 @@ Some illustrative implementations have been given by Nick Coghlan [#]_ and a minimalist API by Tim Peters [#]_. This idea has also been discussed on the issue tracker for the "cryptography" module [#]_. The following -pseudo-code can be taken as a possible starting point for the real +pseudo-code should be taken as the starting point for the real implementation:: from random import SystemRandom - from hmac import compare_digest as equal + from hmac import compare_digest _sysrand = SystemRandom() - randrange = _sysrand.randrange - randint = _sysrand.randint randbits = _sysrand.getrandbits choice = _sysrand.choice @@ -169,7 +168,7 @@ def token_hex(nbytes=None): return binascii.hexlify(token_bytes(nbytes)).decode('ascii') - def token_url(nbytes=None): + def token_urlsafe(nbytes=None): tok = token_bytes(nbytes) return base64.urlsafe_b64encode(tok).rstrip(b'=').decode('ascii') @@ -372,14 +371,9 @@ .. [#] At least those who are motivated to read the source code and documentation. -.. [#] Tim Peters suggests that bike-shedding the contents of the module will - be 10000 times more time consuming than actually implementing the - module. Words do not begin to express how much I am looking forward to - this. - -.. [#] After considerable discussion, Guido ruled that the module will instead - provide a function, ``randbelow``. See - http://code.activestate.com/lists/python-dev/138375/ +.. [#] After considerable discussion, Guido ruled that the module need only + provide ``randbelow``, and not similar functions ``randrange`` or + ``randint``. http://code.activestate.com/lists/python-dev/138375/ .. [#] https://mail.python.org/pipermail/python-ideas/2015-September/036271.html -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Tue Apr 12 01:48:45 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Tue, 12 Apr 2016 05:48:45 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326733=3A_Fixed_formatting_line_numbers_in_test?= =?utf-8?b?X2Rpcy4=?= Message-ID: <20160412054845.11595.30012.E9EBC4D1@psf.io> https://hg.python.org/cpython/rev/e0816ce68952 changeset: 100935:e0816ce68952 parent: 100933:e3c9a47a83fb parent: 100934:b114a0650c44 user: Serhiy Storchaka date: Tue Apr 12 08:47:08 2016 +0300 summary: Issue #26733: Fixed formatting line numbers in test_dis. Based on patch by Xiang Zhang. files: Lib/test/test_dis.py | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -31,7 +31,7 @@ self.x = x == 1 dis_c_instance_method = """\ - %-4d 0 LOAD_FAST 1 (x) +%3d 0 LOAD_FAST 1 (x) 3 LOAD_CONST 1 (1) 6 COMPARE_OP 2 (==) 9 LOAD_FAST 0 (self) @@ -55,12 +55,12 @@ return 1 dis_f = """\ - %-4d 0 LOAD_GLOBAL 0 (print) +%3d 0 LOAD_GLOBAL 0 (print) 3 LOAD_FAST 0 (a) 6 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 9 POP_TOP - %-4d 10 LOAD_CONST 1 (1) +%3d 10 LOAD_CONST 1 (1) 13 RETURN_VALUE """ % (_f.__code__.co_firstlineno + 1, _f.__code__.co_firstlineno + 2) @@ -82,17 +82,17 @@ pass dis_bug708901 = """\ - %-4d 0 SETUP_LOOP 23 (to 26) +%3d 0 SETUP_LOOP 23 (to 26) 3 LOAD_GLOBAL 0 (range) 6 LOAD_CONST 1 (1) - %-4d 9 LOAD_CONST 2 (10) +%3d 9 LOAD_CONST 2 (10) 12 CALL_FUNCTION 2 (2 positional, 0 keyword pair) 15 GET_ITER >> 16 FOR_ITER 6 (to 25) 19 STORE_FAST 0 (res) - %-4d 22 JUMP_ABSOLUTE 16 +%3d 22 JUMP_ABSOLUTE 16 >> 25 POP_BLOCK >> 26 LOAD_CONST 0 (None) 29 RETURN_VALUE @@ -191,16 +191,16 @@ """ dis_traceback = """\ - %-4d 0 SETUP_EXCEPT 12 (to 15) +%3d 0 SETUP_EXCEPT 12 (to 15) - %-4d 3 LOAD_CONST 1 (1) +%3d 3 LOAD_CONST 1 (1) 6 LOAD_CONST 2 (0) --> 9 BINARY_TRUE_DIVIDE 10 POP_TOP 11 POP_BLOCK 12 JUMP_FORWARD 46 (to 61) - %-4d >> 15 DUP_TOP +%3d >> 15 DUP_TOP 16 LOAD_GLOBAL 0 (Exception) 19 COMPARE_OP 10 (exception match) 22 POP_JUMP_IF_FALSE 60 @@ -209,7 +209,7 @@ 29 POP_TOP 30 SETUP_FINALLY 14 (to 47) - %-4d 33 LOAD_FAST 0 (e) +%3d 33 LOAD_FAST 0 (e) 36 LOAD_ATTR 1 (__traceback__) 39 STORE_FAST 1 (tb) 42 POP_BLOCK @@ -222,7 +222,7 @@ 57 JUMP_FORWARD 1 (to 61) >> 60 END_FINALLY - %-4d >> 61 LOAD_FAST 1 (tb) +%3d >> 61 LOAD_FAST 1 (tb) 64 RETURN_VALUE """ % (TRACEBACK_CODE.co_firstlineno + 1, TRACEBACK_CODE.co_firstlineno + 2, -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 01:48:46 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Tue, 12 Apr 2016 05:48:46 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NzMz?= =?utf-8?q?=3A_Fixed_formatting_line_numbers_in_test=5Fdis=2E?= Message-ID: <20160412054845.16621.33769.42D5D6E0@psf.io> https://hg.python.org/cpython/rev/b114a0650c44 changeset: 100934:b114a0650c44 branch: 3.5 parent: 100931:bb10867ffe28 user: Serhiy Storchaka date: Tue Apr 12 08:46:28 2016 +0300 summary: Issue #26733: Fixed formatting line numbers in test_dis. Based on patch by Xiang Zhang. files: Lib/test/test_dis.py | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -31,7 +31,7 @@ self.x = x == 1 dis_c_instance_method = """\ - %-4d 0 LOAD_FAST 1 (x) +%3d 0 LOAD_FAST 1 (x) 3 LOAD_CONST 1 (1) 6 COMPARE_OP 2 (==) 9 LOAD_FAST 0 (self) @@ -55,12 +55,12 @@ return 1 dis_f = """\ - %-4d 0 LOAD_GLOBAL 0 (print) +%3d 0 LOAD_GLOBAL 0 (print) 3 LOAD_FAST 0 (a) 6 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 9 POP_TOP - %-4d 10 LOAD_CONST 1 (1) +%3d 10 LOAD_CONST 1 (1) 13 RETURN_VALUE """ % (_f.__code__.co_firstlineno + 1, _f.__code__.co_firstlineno + 2) @@ -82,17 +82,17 @@ pass dis_bug708901 = """\ - %-4d 0 SETUP_LOOP 23 (to 26) +%3d 0 SETUP_LOOP 23 (to 26) 3 LOAD_GLOBAL 0 (range) 6 LOAD_CONST 1 (1) - %-4d 9 LOAD_CONST 2 (10) +%3d 9 LOAD_CONST 2 (10) 12 CALL_FUNCTION 2 (2 positional, 0 keyword pair) 15 GET_ITER >> 16 FOR_ITER 6 (to 25) 19 STORE_FAST 0 (res) - %-4d 22 JUMP_ABSOLUTE 16 +%3d 22 JUMP_ABSOLUTE 16 >> 25 POP_BLOCK >> 26 LOAD_CONST 0 (None) 29 RETURN_VALUE @@ -191,16 +191,16 @@ """ dis_traceback = """\ - %-4d 0 SETUP_EXCEPT 12 (to 15) +%3d 0 SETUP_EXCEPT 12 (to 15) - %-4d 3 LOAD_CONST 1 (1) +%3d 3 LOAD_CONST 1 (1) 6 LOAD_CONST 2 (0) --> 9 BINARY_TRUE_DIVIDE 10 POP_TOP 11 POP_BLOCK 12 JUMP_FORWARD 46 (to 61) - %-4d >> 15 DUP_TOP +%3d >> 15 DUP_TOP 16 LOAD_GLOBAL 0 (Exception) 19 COMPARE_OP 10 (exception match) 22 POP_JUMP_IF_FALSE 60 @@ -209,7 +209,7 @@ 29 POP_TOP 30 SETUP_FINALLY 14 (to 47) - %-4d 33 LOAD_FAST 0 (e) +%3d 33 LOAD_FAST 0 (e) 36 LOAD_ATTR 1 (__traceback__) 39 STORE_FAST 1 (tb) 42 POP_BLOCK @@ -222,7 +222,7 @@ 57 JUMP_FORWARD 1 (to 61) >> 60 END_FINALLY - %-4d >> 61 LOAD_FAST 1 (tb) +%3d >> 61 LOAD_FAST 1 (tb) 64 RETURN_VALUE """ % (TRACEBACK_CODE.co_firstlineno + 1, TRACEBACK_CODE.co_firstlineno + 2, -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 01:48:46 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Tue, 12 Apr 2016 05:48:46 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2NzMz?= =?utf-8?q?=3A_Fixed_formatting_line_numbers_in_test=5Fdis=2E?= Message-ID: <20160412054845.110014.10503.DAE150D6@psf.io> https://hg.python.org/cpython/rev/16a27e38e9b5 changeset: 100936:16a27e38e9b5 branch: 2.7 parent: 100932:61c7deea9e6a user: Serhiy Storchaka date: Tue Apr 12 08:47:20 2016 +0300 summary: Issue #26733: Fixed formatting line numbers in test_dis. Based on patch by Xiang Zhang. files: Lib/test/test_dis.py | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -12,11 +12,11 @@ return 1 dis_f = """\ - %-4d 0 LOAD_FAST 0 (a) +%3d 0 LOAD_FAST 0 (a) 3 PRINT_ITEM 4 PRINT_NEWLINE - %-4d 5 LOAD_CONST 1 (1) +%3d 5 LOAD_CONST 1 (1) 8 RETURN_VALUE """%(_f.func_code.co_firstlineno + 1, _f.func_code.co_firstlineno + 2) @@ -28,17 +28,17 @@ pass dis_bug708901 = """\ - %-4d 0 SETUP_LOOP 23 (to 26) +%3d 0 SETUP_LOOP 23 (to 26) 3 LOAD_GLOBAL 0 (range) 6 LOAD_CONST 1 (1) - %-4d 9 LOAD_CONST 2 (10) +%3d 9 LOAD_CONST 2 (10) 12 CALL_FUNCTION 2 15 GET_ITER >> 16 FOR_ITER 6 (to 25) 19 STORE_FAST 0 (res) - %-4d 22 JUMP_ABSOLUTE 16 +%3d 22 JUMP_ABSOLUTE 16 >> 25 POP_BLOCK >> 26 LOAD_CONST 0 (None) 29 RETURN_VALUE @@ -53,7 +53,7 @@ pass dis_bug1333982 = """\ - %-4d 0 LOAD_CONST 1 (0) +%3d 0 LOAD_CONST 1 (0) 3 POP_JUMP_IF_TRUE 41 6 LOAD_GLOBAL 0 (AssertionError) 9 BUILD_LIST 0 @@ -65,12 +65,12 @@ 25 LIST_APPEND 2 28 JUMP_ABSOLUTE 16 - %-4d >> 31 LOAD_CONST 2 (1) +%3d >> 31 LOAD_CONST 2 (1) 34 BINARY_ADD 35 CALL_FUNCTION 1 38 RAISE_VARARGS 1 - %-4d >> 41 LOAD_CONST 0 (None) +%3d >> 41 LOAD_CONST 0 (None) 44 RETURN_VALUE """%(bug1333982.func_code.co_firstlineno + 1, bug1333982.func_code.co_firstlineno + 2, -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 01:52:40 2016 From: python-checkins at python.org (georg.brandl) Date: Tue, 12 Apr 2016 05:52:40 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Clarify_greedy?= =?utf-8?q?-qualifier_example=2C_avoid_HTML=2E?= Message-ID: <20160412055240.32282.20075.4C9C83BD@psf.io> https://hg.python.org/cpython/rev/0140eabf226b changeset: 100937:0140eabf226b branch: 3.5 parent: 100934:b114a0650c44 user: Georg Brandl date: Tue Apr 12 07:51:41 2016 +0200 summary: Clarify greedy-qualifier example, avoid HTML. files: Doc/library/re.rst | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/re.rst b/Doc/library/re.rst --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -113,11 +113,11 @@ ``*?``, ``+?``, ``??`` The ``'*'``, ``'+'``, and ``'?'`` qualifiers are all :dfn:`greedy`; they match as much text as possible. Sometimes this behaviour isn't desired; if the RE - ``<.*>`` is matched against ``'

title

'``, it will match the entire - string, and not just ``'

'``. Adding ``'?'`` after the qualifier makes it + ``<.*>`` is matched against `` b ``, it will match the entire + string, and not just ````. Adding ``?`` after the qualifier makes it perform the match in :dfn:`non-greedy` or :dfn:`minimal` fashion; as *few* - characters as possible will be matched. Using ``.*?`` in the previous - expression will match only ``'

'``. + characters as possible will be matched. Using the RE ``<.*?>`` will match + only ````. ``{m}`` Specifies that exactly *m* copies of the previous RE should be matched; fewer -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 01:52:42 2016 From: python-checkins at python.org (georg.brandl) Date: Tue, 12 Apr 2016 05:52:42 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E5?= Message-ID: <20160412055240.34589.59648.47B75327@psf.io> https://hg.python.org/cpython/rev/a5acd7ca8727 changeset: 100938:a5acd7ca8727 parent: 100935:e0816ce68952 parent: 100937:0140eabf226b user: Georg Brandl date: Tue Apr 12 07:52:22 2016 +0200 summary: merge with 3.5 files: Doc/library/re.rst | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/re.rst b/Doc/library/re.rst --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -113,11 +113,11 @@ ``*?``, ``+?``, ``??`` The ``'*'``, ``'+'``, and ``'?'`` qualifiers are all :dfn:`greedy`; they match as much text as possible. Sometimes this behaviour isn't desired; if the RE - ``<.*>`` is matched against ``'

title

'``, it will match the entire - string, and not just ``'

'``. Adding ``'?'`` after the qualifier makes it + ``<.*>`` is matched against `` b ``, it will match the entire + string, and not just ````. Adding ``?`` after the qualifier makes it perform the match in :dfn:`non-greedy` or :dfn:`minimal` fashion; as *few* - characters as possible will be matched. Using ``.*?`` in the previous - expression will match only ``'

'``. + characters as possible will be matched. Using the RE ``<.*?>`` will match + only ````. ``{m}`` Specifies that exactly *m* copies of the previous RE should be matched; fewer -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 01:53:02 2016 From: python-checkins at python.org (georg.brandl) Date: Tue, 12 Apr 2016 05:53:02 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Clarify_greedy?= =?utf-8?q?-qualifier_example=2C_avoid_HTML=2E?= Message-ID: <20160412055300.110012.45506.C29BBD17@psf.io> https://hg.python.org/cpython/rev/c2f57f959c05 changeset: 100939:c2f57f959c05 branch: 2.7 parent: 100936:16a27e38e9b5 user: Georg Brandl date: Tue Apr 12 07:51:41 2016 +0200 summary: Clarify greedy-qualifier example, avoid HTML. files: Doc/library/re.rst | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/re.rst b/Doc/library/re.rst --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -108,11 +108,11 @@ ``*?``, ``+?``, ``??`` The ``'*'``, ``'+'``, and ``'?'`` qualifiers are all :dfn:`greedy`; they match as much text as possible. Sometimes this behaviour isn't desired; if the RE - ``<.*>`` is matched against ``'

title

'``, it will match the entire - string, and not just ``'

'``. Adding ``'?'`` after the qualifier makes it + ``<.*>`` is matched against `` b ``, it will match the entire + string, and not just ````. Adding ``?`` after the qualifier makes it perform the match in :dfn:`non-greedy` or :dfn:`minimal` fashion; as *few* - characters as possible will be matched. Using ``.*?`` in the previous - expression will match only ``'

'``. + characters as possible will be matched. Using the RE ``<.*?>`` will match + only ````. ``{m}`` Specifies that exactly *m* copies of the previous RE should be matched; fewer -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Tue Apr 12 05:19:34 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Tue, 12 Apr 2016 09:19:34 +0000 Subject: [Python-checkins] Daily reference leaks (e3c9a47a83fb): sum=4 Message-ID: <20160412091930.90782.54332.85C11DA6@psf.io> results for e3c9a47a83fb on branch "default" -------------------------------------------- test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogttvEiM', '--timeout', '7200'] From lp_benchmark_robot at intel.com Tue Apr 12 08:57:59 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Tue, 12 Apr 2016 13:57:59 +0100 Subject: [Python-checkins] BAD Benchmark Results for Python Default 2016-04-12 Message-ID: <9a5cadd4-64fa-4ba2-9762-ada8d6dc8fd7@irsmsx102.ger.corp.intel.com> Results for project Python default, build date 2016-04-12 02:08:56 +0000 commit: e3c9a47a83fb previous commit: bf44913588b7 revision date: 2016-04-11 14:33:27 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.43% -2.99% 8.22% 16.89% :-| pybench 0.12% 0.21% 0.80% 5.02% :-( regex_v8 2.64% -0.11% -4.15% 5.04% :-| nbody 0.12% 0.26% -1.73% 8.27% :-( json_dump_v2 0.21% 0.02% -2.27% 9.07% :-| normal_startup 0.83% -0.05% -0.12% 5.16% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/bad-benchmark-results-for-python-default-2016-04-12/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Tue Apr 12 08:58:52 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Tue, 12 Apr 2016 13:58:52 +0100 Subject: [Python-checkins] BAD Benchmark Results for Python 2.7 2016-04-12 Message-ID: <08c7ab11-f75c-4198-b104-1d8f26d1e0c9@irsmsx102.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-12 03:00:37 +0000 commit: 61c7deea9e6a previous commit: 9cf8572abe58 revision date: 2016-04-11 14:32:33 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.15% 0.01% 4.25% 5.56% :-) pybench 0.10% -0.03% 6.39% 4.13% :-( regex_v8 0.86% -0.03% -2.93% 11.51% :-) nbody 0.11% -1.06% 8.44% 1.91% :-) json_dump_v2 0.20% -0.03% 3.70% 9.55% :-( normal_startup 1.95% 0.21% -5.70% 2.40% :-) ssbench 0.18% 0.70% 2.81% 0.78% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/bad-benchmark-results-for-python-2-7-2016-04-12/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Tue Apr 12 12:44:15 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 12 Apr 2016 16:44:15 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NjQ3?= =?utf-8?q?=3A_Fix_typo_in_test=5Fgrammar?= Message-ID: <20160412164415.27664.58266.E5B78AB9@psf.io> https://hg.python.org/cpython/rev/f8398dba48fb changeset: 100942:f8398dba48fb branch: 3.5 parent: 100937:0140eabf226b user: Victor Stinner date: Tue Apr 12 18:33:41 2016 +0200 summary: Issue #26647: Fix typo in test_grammar Patch written by Demur Rumed. files: Lib/test/test_grammar.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -994,7 +994,7 @@ # Test ifelse expressions in various cases def _checkeval(msg, ret): "helper to check that evaluation of expressions is done correctly" - print(x) + print(msg) return ret # the next line is not allowed anymore -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 12:44:47 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 12 Apr 2016 16:44:47 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy41?= Message-ID: <20160412164415.16633.28029.CCC12674@psf.io> https://hg.python.org/cpython/rev/8ac6cc5a0c01 changeset: 100943:8ac6cc5a0c01 parent: 100941:423e2a96189e parent: 100942:f8398dba48fb user: Victor Stinner date: Tue Apr 12 18:33:54 2016 +0200 summary: Merge 3.5 files: Lib/test/test_grammar.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -1032,7 +1032,7 @@ # Test ifelse expressions in various cases def _checkeval(msg, ret): "helper to check that evaluation of expressions is done correctly" - print(x) + print(msg) return ret # the next line is not allowed anymore -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 12:44:47 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 12 Apr 2016 16:44:47 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326647=3A_Cleanup_?= =?utf-8?q?modulefinder?= Message-ID: <20160412164415.110012.32397.E04D543E@psf.io> https://hg.python.org/cpython/rev/423e2a96189e changeset: 100941:423e2a96189e user: Victor Stinner date: Tue Apr 12 18:17:06 2016 +0200 summary: Issue #26647: Cleanup modulefinder Use directly dis.opmap[name] rather than dis.opname.index(name). Patch written by Demur Rumed. files: Lib/modulefinder.py | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py --- a/Lib/modulefinder.py +++ b/Lib/modulefinder.py @@ -14,11 +14,11 @@ import imp # XXX Clean up once str8's cstor matches bytes. -LOAD_CONST = bytes([dis.opname.index('LOAD_CONST')]) -IMPORT_NAME = bytes([dis.opname.index('IMPORT_NAME')]) -STORE_NAME = bytes([dis.opname.index('STORE_NAME')]) -STORE_GLOBAL = bytes([dis.opname.index('STORE_GLOBAL')]) -STORE_OPS = [STORE_NAME, STORE_GLOBAL] +LOAD_CONST = bytes([dis.opmap['LOAD_CONST']]) +IMPORT_NAME = bytes([dis.opmap['IMPORT_NAME']]) +STORE_NAME = bytes([dis.opmap['STORE_NAME']]) +STORE_GLOBAL = bytes([dis.opmap['STORE_GLOBAL']]) +STORE_OPS = STORE_NAME, STORE_GLOBAL HAVE_ARGUMENT = bytes([dis.HAVE_ARGUMENT]) # Modulefinder does a good job at simulating Python's, but it can not -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 12:44:47 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 12 Apr 2016 16:44:47 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326647=3A_Cleanup_?= =?utf-8?q?opcode?= Message-ID: <20160412164414.110241.8870.8ED236E9@psf.io> https://hg.python.org/cpython/rev/7bf08a11d4c9 changeset: 100940:7bf08a11d4c9 parent: 100938:a5acd7ca8727 user: Victor Stinner date: Tue Apr 12 18:15:26 2016 +0200 summary: Issue #26647: Cleanup opcode Simplify code to build opcode.opname. Patch written by Demur Rumed. files: Lib/opcode.py | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/Lib/opcode.py b/Lib/opcode.py --- a/Lib/opcode.py +++ b/Lib/opcode.py @@ -34,9 +34,7 @@ hasnargs = [] opmap = {} -opname = [''] * 256 -for op in range(256): opname[op] = '<%r>' % (op,) -del op +opname = ['<%r>' % (op,) for op in range(256)] def def_op(name, op): opname[op] = name -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 12:46:17 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 12 Apr 2016 16:46:17 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Update_pygettext=2Epy_to_g?= =?utf-8?q?et_ride_of_imp?= Message-ID: <20160412164616.15614.26113.C45BF35C@psf.io> https://hg.python.org/cpython/rev/cd03ff74eaea changeset: 100944:cd03ff74eaea user: Victor Stinner date: Tue Apr 12 18:46:10 2016 +0200 summary: Update pygettext.py to get ride of imp Issue #26639: Replace imp with importlib in Tools/i18n/pygettext.py. Remove _get_modpkg_path(), replaced with importlib.util.find_spec(). files: Tools/i18n/pygettext.py | 51 ++++------------------------ 1 files changed, 8 insertions(+), 43 deletions(-) diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py --- a/Tools/i18n/pygettext.py +++ b/Tools/i18n/pygettext.py @@ -156,7 +156,8 @@ """) import os -import imp +import importlib.machinery +import importlib.util import sys import glob import time @@ -263,8 +264,7 @@ # get extension for python source files if '_py_ext' not in globals(): global _py_ext - _py_ext = [triple[0] for triple in imp.get_suffixes() - if triple[2] == imp.PY_SOURCE][0] + _py_ext = importlib.machinery.SOURCE_SUFFIXES[0] # don't recurse into CVS directories if 'CVS' in names: @@ -277,45 +277,6 @@ ) -def _get_modpkg_path(dotted_name, pathlist=None): - """Get the filesystem path for a module or a package. - - Return the file system path to a file for a module, and to a directory for - a package. Return None if the name is not found, or is a builtin or - extension module. - """ - # split off top-most name - parts = dotted_name.split('.', 1) - - if len(parts) > 1: - # we have a dotted path, import top-level package - try: - file, pathname, description = imp.find_module(parts[0], pathlist) - if file: file.close() - except ImportError: - return None - - # check if it's indeed a package - if description[2] == imp.PKG_DIRECTORY: - # recursively handle the remaining name parts - pathname = _get_modpkg_path(parts[1], [pathname]) - else: - pathname = None - else: - # plain name - try: - file, pathname, description = imp.find_module( - dotted_name, pathlist) - if file: - file.close() - if description[2] not in [imp.PY_SOURCE, imp.PKG_DIRECTORY]: - pathname = None - except ImportError: - pathname = None - - return pathname - - def getFilesForName(name): """Get a list of module files for a filename, a module or package name, or a directory. @@ -330,7 +291,11 @@ return list # try to find module or package - name = _get_modpkg_path(name) + try: + spec = importlib.util.find_spec(name) + name = spec.origin + except ImportError: + name = None if not name: return [] -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 16:39:54 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 12 Apr 2016 20:39:54 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogRml4IG9zLnVyYW5k?= =?utf-8?q?om=28=29_on_Solaris_11=2E3?= Message-ID: <20160412203954.32551.23384.5BF23A97@psf.io> https://hg.python.org/cpython/rev/fb7628e8dfef changeset: 100945:fb7628e8dfef branch: 3.5 parent: 100942:f8398dba48fb user: Victor Stinner date: Tue Apr 12 22:28:49 2016 +0200 summary: Fix os.urandom() on Solaris 11.3 Issue #26735: Fix os.urandom() on Solaris 11.3 and newer when reading more than 1,024 bytes: call getrandom() multiple times with a limit of 1024 bytes per call. files: Misc/NEWS | 4 ++++ Python/random.c | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -102,6 +102,10 @@ Library ------- +- Issue #26735: Fix :func:`os.urandom` on Solaris 11.3 and newer when reading + more than 1,024 bytes: call ``getrandom()`` multiple times with a limit of + 1024 bytes per call. + - Issue #16329: Add .webm to mimetypes.types_map. Patch by Giampaolo Rodola'. - Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson. diff --git a/Python/random.c b/Python/random.c --- a/Python/random.c +++ b/Python/random.c @@ -131,16 +131,23 @@ return 0; while (0 < size) { +#ifdef sun + /* Issue #26735: On Solaris, getrandom() is limited to returning up + to 1024 bytes */ + n = Py_MIN(size, 1024); +#else + n = size; +#endif + errno = 0; - #ifdef HAVE_GETRANDOM if (raise) { Py_BEGIN_ALLOW_THREADS - n = getrandom(buffer, size, flags); + n = getrandom(buffer, n, flags); Py_END_ALLOW_THREADS } else { - n = getrandom(buffer, size, flags); + n = getrandom(buffer, n, flags); } #else /* On Linux, use the syscall() function because the GNU libc doesn't @@ -148,11 +155,11 @@ * https://sourceware.org/bugzilla/show_bug.cgi?id=17252 */ if (raise) { Py_BEGIN_ALLOW_THREADS - n = syscall(SYS_getrandom, buffer, size, flags); + n = syscall(SYS_getrandom, buffer, n, flags); Py_END_ALLOW_THREADS } else { - n = syscall(SYS_getrandom, buffer, size, flags); + n = syscall(SYS_getrandom, buffer, n, flags); } #endif -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 16:39:57 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 12 Apr 2016 20:39:57 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogY29uZmlndXJlOiBm?= =?utf-8?q?ix_HAVE=5FGETRANDOM=5FSYSCALL_check?= Message-ID: <20160412203954.48904.32345.213B6500@psf.io> https://hg.python.org/cpython/rev/f6a5d26a157d changeset: 100946:f6a5d26a157d branch: 3.5 user: Victor Stinner date: Tue Apr 12 22:34:58 2016 +0200 summary: configure: fix HAVE_GETRANDOM_SYSCALL check syscall() function requires #include . files: configure | 1 + configure.ac | 167 +++++++++++++++++++------------------- 2 files changed, 85 insertions(+), 83 deletions(-) diff --git a/configure b/configure --- a/configure +++ b/configure @@ -16276,6 +16276,7 @@ /* end confdefs.h. */ + #include #include int main() { diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -86,7 +86,7 @@ dnl Last slash shouldn't be stripped if prefix=/ if test "$prefix" != "/"; then prefix=`echo "$prefix" | sed -e 's/\/$//g'` -fi +fi dnl This is for stuff that absolutely must end up in pyconfig.h. dnl Please use pyport.h instead, if possible. @@ -178,7 +178,7 @@ fi ;; esac - + ],[ UNIVERSALSDK= enable_universalsdk= @@ -240,7 +240,7 @@ AS_HELP_STRING([--enable-framework@<:@=INSTALLDIR@:>@], [Build (MacOSX|Darwin) framework]), [ case $enableval in - yes) + yes) enableval=/Library/Frameworks esac case $enableval in @@ -297,7 +297,7 @@ FRAMEWORKINSTALLAPPSPREFIX="${MDIR}/Applications" if test "${prefix}" = "NONE"; then - # User hasn't specified the + # User hasn't specified the # --prefix option, but wants to install # the framework in a non-default location, # ensure that the compatibility links get @@ -442,7 +442,7 @@ # Reconfirmed for OpenBSD 3.3 by Zachary Hamm, for 3.4 by Jason Ish. # In addition, Stefan Krah confirms that issue #1244610 exists through # OpenBSD 4.6, but is fixed in 4.7. - OpenBSD/2.* | OpenBSD/3.* | OpenBSD/4.@<:@0123456@:>@) + OpenBSD/2.* | OpenBSD/3.* | OpenBSD/4.@<:@0123456@:>@) define_xopen_source=no # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is # also defined. This can be overridden by defining _BSD_SOURCE @@ -480,12 +480,12 @@ # with _XOPEN_SOURCE and __BSD_VISIBLE does not re-enable them. FreeBSD/4.*) define_xopen_source=no;; - # On MacOS X 10.2, a bug in ncurses.h means that it craps out if + # On MacOS X 10.2, a bug in ncurses.h means that it craps out if # _XOPEN_EXTENDED_SOURCE is defined. Apparently, this is fixed in 10.3, which # identifies itself as Darwin/7.* # On Mac OS X 10.4, defining _POSIX_C_SOURCE or _XOPEN_SOURCE # disables platform specific features beyond repair. - # On Mac OS X 10.3, defining _POSIX_C_SOURCE or _XOPEN_SOURCE + # On Mac OS X 10.3, defining _POSIX_C_SOURCE or _XOPEN_SOURCE # has no effect, don't bother defining them Darwin/@<:@6789@:>@.*) define_xopen_source=no;; @@ -690,7 +690,7 @@ AS_HELP_STRING([--with-cxx-main=], [compile main() and link python executable with C++ compiler]), [ - + case $withval in no) with_cxx_main=no MAINCC='$(CC)';; @@ -870,7 +870,7 @@ if test x$PLATFORM_TRIPLET != x$MULTIARCH; then AC_MSG_ERROR([internal configure error for the platform triplet, please file a bug report]) fi -fi +fi PLATDIR=plat-$MACHDEP AC_SUBST(PLATDIR) AC_SUBST(PLATFORM_TRIPLET) @@ -959,7 +959,7 @@ # systems without shared libraries, LDLIBRARY is the same as LIBRARY # (defined in the Makefiles). On Cygwin LDLIBRARY is the import library, # DLLLIBRARY is the shared (i.e., DLL) library. -# +# # RUNSHARED is used to run shared python without installed libraries # # INSTSONAME is the name of the shared library that will be use to install @@ -987,7 +987,7 @@ # If CXX is set, and if it is needed to link a main function that was # compiled with CXX, LINKCC is CXX instead. Always using CXX is undesirable: # python might then depend on the C++ runtime -# This is altered for AIX in order to build the export list before +# This is altered for AIX in order to build the export list before # linking. AC_SUBST(LINKCC) AC_MSG_CHECKING(LINKCC) @@ -1041,7 +1041,7 @@ AS_HELP_STRING([--enable-shared], [disable/enable building shared python library])) if test -z "$enable_shared" -then +then case $ac_sys_system in CYGWIN*) enable_shared="yes";; @@ -1086,7 +1086,7 @@ BLDLIBRARY='' else BLDLIBRARY='$(LDLIBRARY)' -fi +fi # Other platforms follow if test $enable_shared = "yes"; then @@ -1221,14 +1221,14 @@ # Check for --with-pydebug AC_MSG_CHECKING(for --with-pydebug) -AC_ARG_WITH(pydebug, +AC_ARG_WITH(pydebug, AS_HELP_STRING([--with-pydebug], [build with Py_DEBUG defined]), [ if test "$withval" != no -then - AC_DEFINE(Py_DEBUG, 1, - [Define if you want to build an interpreter with many run-time checks.]) - AC_MSG_RESULT(yes); +then + AC_DEFINE(Py_DEBUG, 1, + [Define if you want to build an interpreter with many run-time checks.]) + AC_MSG_RESULT(yes); Py_DEBUG='true' ABIFLAGS="${ABIFLAGS}d" else AC_MSG_RESULT(no); Py_DEBUG='false' @@ -1696,7 +1696,7 @@ AC_MSG_RESULT($ac_cv_pthread_is_default) -if test $ac_cv_pthread_is_default = yes +if test $ac_cv_pthread_is_default = yes then ac_cv_kpthread=no else @@ -1795,14 +1795,14 @@ if test "$ac_cv_kpthread" = "yes" then - CXX="$CXX -Kpthread" + CXX="$CXX -Kpthread" ac_cv_cxx_thread=yes elif test "$ac_cv_kthread" = "yes" then CXX="$CXX -Kthread" ac_cv_cxx_thread=yes elif test "$ac_cv_pthread" = "yes" -then +then CXX="$CXX -pthread" ac_cv_cxx_thread=yes fi @@ -1950,11 +1950,11 @@ # These may affect some typedefs case $ac_sys_system/$ac_sys_release in AIX*) - AC_DEFINE(_LARGE_FILES, 1, + AC_DEFINE(_LARGE_FILES, 1, [This must be defined on AIX systems to enable large file support.]) ;; esac -AC_DEFINE(_LARGEFILE_SOURCE, 1, +AC_DEFINE(_LARGEFILE_SOURCE, 1, [This must be defined on some systems to enable large file support.]) AC_DEFINE(_FILE_OFFSET_BITS, 64, [This must be set to 64 on some systems to enable large file support.]) @@ -2018,7 +2018,7 @@ AC_MSG_CHECKING(for long long support) have_long_long=no AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[long long x; x = (long long)0;]])],[ - AC_DEFINE(HAVE_LONG_LONG, 1, [Define this if you have the type long long.]) + AC_DEFINE(HAVE_LONG_LONG, 1, [Define this if you have the type long long.]) have_long_long=yes ],[]) AC_MSG_RESULT($have_long_long) @@ -2029,7 +2029,7 @@ AC_MSG_CHECKING(for long double support) have_long_double=no AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[long double x; x = (long double)0;]])],[ - AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define this if you have the type long double.]) + AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define this if you have the type long double.]) have_long_double=yes ],[]) AC_MSG_RESULT($have_long_double) @@ -2041,7 +2041,7 @@ AC_MSG_CHECKING(for _Bool support) have_c99_bool=no AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[_Bool x; x = (_Bool)0;]])],[ - AC_DEFINE(HAVE_C99_BOOL, 1, [Define this if you have the type _Bool.]) + AC_DEFINE(HAVE_C99_BOOL, 1, [Define this if you have the type _Bool.]) have_c99_bool=yes ],[]) AC_MSG_RESULT($have_c99_bool) @@ -2049,8 +2049,8 @@ AC_CHECK_SIZEOF(_Bool, 1) fi -AC_CHECK_TYPES(uintptr_t, - [AC_CHECK_SIZEOF(uintptr_t, 4)], +AC_CHECK_TYPES(uintptr_t, + [AC_CHECK_SIZEOF(uintptr_t, 4)], [], [#ifdef HAVE_STDINT_H #include #endif @@ -2069,7 +2069,7 @@ then if test "$ac_cv_sizeof_off_t" -gt "$ac_cv_sizeof_long" -a \ "$ac_cv_sizeof_long_long" -ge "$ac_cv_sizeof_off_t"; then - AC_DEFINE(HAVE_LARGEFILE_SUPPORT, 1, + AC_DEFINE(HAVE_LARGEFILE_SUPPORT, 1, [Defined to enable large file support when an off_t is bigger than a long and long long is available and at least as big as an off_t. You may need to add some flags for configuration and compilation to enable this mode. @@ -2118,7 +2118,7 @@ AC_SUBST(OTHER_LIBTOOL_OPT) case $ac_sys_system/$ac_sys_release in - Darwin/@<:@01567@:>@\..*) + Darwin/@<:@01567@:>@\..*) OTHER_LIBTOOL_OPT="-prebind -seg1addr 0x10000000" ;; Darwin/*) @@ -2129,7 +2129,7 @@ AC_SUBST(LIBTOOL_CRUFT) case $ac_sys_system/$ac_sys_release in - Darwin/@<:@01567@:>@\..*) + Darwin/@<:@01567@:>@\..*) LIBTOOL_CRUFT="-framework System -lcc_dynamic" if test "${enable_universalsdk}"; then : @@ -2143,7 +2143,7 @@ if test ${gcc_version} '<' 4.0 then LIBTOOL_CRUFT="-lcc_dynamic" - else + else LIBTOOL_CRUFT="" fi AC_RUN_IFELSE([AC_LANG_SOURCE([[ @@ -2157,14 +2157,14 @@ } } ]])],[ac_osx_32bit=yes],[ac_osx_32bit=no],[ac_osx_32bit=yes]) - + if test "${ac_osx_32bit}" = "yes"; then case `/usr/bin/arch` in - i386) - MACOSX_DEFAULT_ARCH="i386" + i386) + MACOSX_DEFAULT_ARCH="i386" ;; - ppc) - MACOSX_DEFAULT_ARCH="ppc" + ppc) + MACOSX_DEFAULT_ARCH="ppc" ;; *) AC_MSG_ERROR([Unexpected output of 'arch' on OSX]) @@ -2172,11 +2172,11 @@ esac else case `/usr/bin/arch` in - i386) - MACOSX_DEFAULT_ARCH="x86_64" + i386) + MACOSX_DEFAULT_ARCH="x86_64" ;; - ppc) - MACOSX_DEFAULT_ARCH="ppc64" + ppc) + MACOSX_DEFAULT_ARCH="ppc64" ;; *) AC_MSG_ERROR([Unexpected output of 'arch' on OSX]) @@ -2193,9 +2193,9 @@ if test "$enable_framework" then BASECFLAGS="$BASECFLAGS -fno-common -dynamic" - # -F. is needed to allow linking to the framework while + # -F. is needed to allow linking to the framework while # in the build location. - AC_DEFINE(WITH_NEXT_FRAMEWORK, 1, + AC_DEFINE(WITH_NEXT_FRAMEWORK, 1, [Define if you want to produce an OpenStep/Rhapsody framework (shared library plus accessory files).]) AC_MSG_RESULT(yes) @@ -2210,7 +2210,7 @@ AC_MSG_CHECKING(for dyld) case $ac_sys_system/$ac_sys_release in Darwin/*) - AC_DEFINE(WITH_DYLD, 1, + AC_DEFINE(WITH_DYLD, 1, [Define if you want to use the new-style (Openstep, Rhapsody, MacOS) dynamic linker (dyld) instead of the old-style (NextStep) dynamic linker (rld). Dyld is necessary to support frameworks.]) @@ -2260,7 +2260,7 @@ ;; IRIX/5*) LDSHARED="ld -shared";; IRIX*/6*) LDSHARED="ld ${SGI_ABI} -shared -all";; - SunOS/5*) + SunOS/5*) if test "$GCC" = "yes" ; then LDSHARED='$(CC) -shared' LDCXXSHARED='$(CXX) -shared' @@ -2436,7 +2436,7 @@ BSD/OS/4*) LINKFORSHARED="-Xlinker -export-dynamic";; Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic";; # -u libsys_s pulls in all symbols in libsys - Darwin/*) + Darwin/*) LINKFORSHARED="$extra_undefs -framework CoreFoundation" # Issue #18075: the default maximum stack size (8MBytes) is too @@ -2452,7 +2452,7 @@ OpenUNIX*|UnixWare*) LINKFORSHARED="-Wl,-Bexport";; SCO_SV*) LINKFORSHARED="-Wl,-Bexport";; ReliantUNIX*) LINKFORSHARED="-W1 -Blargedynsym";; - FreeBSD*|NetBSD*|OpenBSD*|DragonFly*) + FreeBSD*|NetBSD*|OpenBSD*|DragonFly*) if [[ "`$CC -dM -E - ]], [[getpgrp(0);]])], [AC_DEFINE(GETPGRP_HAVE_ARG, 1, [Define if getpgrp() must be called as getpgrp(0).])], []) @@ -3544,7 +3544,7 @@ [AC_DEFINE(SETPGRP_HAVE_ARG, 1, [Define if setpgrp() must be called as setpgrp(0, 0).])], []) ) -AC_CHECK_FUNCS(gettimeofday, +AC_CHECK_FUNCS(gettimeofday, AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[gettimeofday((struct timeval*)0,(struct timezone*)0);]])], [], @@ -3589,7 +3589,7 @@ ]) # On OSF/1 V5.1, getaddrinfo is available, but a define -# for [no]getaddrinfo in netdb.h. +# for [no]getaddrinfo in netdb.h. AC_MSG_CHECKING(for getaddrinfo) AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include @@ -3749,7 +3749,7 @@ ]], [[;]])],[ AC_DEFINE(SYS_SELECT_WITH_SYS_TIME, 1, [Define if you can safely include both and - (which you can't on SCO ODT 3.0).]) + (which you can't on SCO ODT 3.0).]) was_it_defined=yes ],[]) AC_MSG_RESULT($was_it_defined) @@ -3800,8 +3800,8 @@ have_prototypes=no AC_MSG_CHECKING(for prototypes) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int foo(int x) { return 0; }]], [[return foo(10);]])], - [AC_DEFINE(HAVE_PROTOTYPES, 1, - [Define if your compiler supports function prototype]) + [AC_DEFINE(HAVE_PROTOTYPES, 1, + [Define if your compiler supports function prototype]) have_prototypes=yes], [] ) @@ -3822,7 +3822,7 @@ ]], [[return foo(10, "", 3.14);]])],[ AC_DEFINE(HAVE_STDARG_PROTOTYPES, 1, [Define if your compiler supports variable length function prototypes - (e.g. void fprintf(FILE *, char *, ...);) *and* ]) + (e.g. void fprintf(FILE *, char *, ...);) *and* ]) works=yes ],[]) AC_MSG_RESULT($works) @@ -3857,7 +3857,7 @@ #include #endif ]], [[va_list list1, list2; list1 = list2;]])],[],[ - AC_DEFINE(VA_LIST_IS_ARRAY, 1, [Define if a va_list is an array of some kind]) + AC_DEFINE(VA_LIST_IS_ARRAY, 1, [Define if a va_list is an array of some kind]) va_list_is_array=yes ]) AC_MSG_RESULT($va_list_is_array) @@ -3952,9 +3952,9 @@ AS_HELP_STRING([--with-fpectl], [enable SIGFPE catching]), [ if test "$withval" != no -then +then AC_DEFINE(WANT_SIGFPE_HANDLER, 1, - [Define if you want SIGFPE handled (see Include/pyfpe.h).]) + [Define if you want SIGFPE handled (see Include/pyfpe.h).]) AC_MSG_RESULT(yes) else AC_MSG_RESULT(no) fi], @@ -4325,8 +4325,8 @@ # check for wchar.h AC_CHECK_HEADER(wchar.h, [ - AC_DEFINE(HAVE_WCHAR_H, 1, - [Define if the compiler provides a wchar.h header file.]) + AC_DEFINE(HAVE_WCHAR_H, 1, + [Define if the compiler provides a wchar.h header file.]) wchar_h="yes" ], wchar_h="no" @@ -4609,7 +4609,7 @@ [Define if poll() sets errno on invalid file descriptors.]) fi -# Before we can test tzset, we need to check if struct tm has a tm_zone +# Before we can test tzset, we need to check if struct tm has a tm_zone # (which is not required by ISO C or UNIX spec) and/or if we support # tzname[] AC_STRUCT_TIMEZONE @@ -4635,7 +4635,7 @@ tm->tm_zone does not exist since it is the alternative way of getting timezone info. - Red Hat 6.2 doesn't understand the southern hemisphere + Red Hat 6.2 doesn't understand the southern hemisphere after New Year's Day. */ @@ -4648,7 +4648,7 @@ exit(1); #if HAVE_TZNAME /* For UTC, tzname[1] is sometimes "", sometimes " " */ - if (strcmp(tzname[0], "UTC") || + if (strcmp(tzname[0], "UTC") || (tzname[1][0] != 0 && tzname[1][0] != ' ')) exit(1); #endif @@ -4766,7 +4766,7 @@ if test "$ac_cv_window_has_flags" = yes then - AC_DEFINE(WINDOW_HAS_FLAGS, 1, + AC_DEFINE(WINDOW_HAS_FLAGS, 1, [Define if WINDOW in curses.h offers a field _flags.]) fi @@ -4965,7 +4965,7 @@ if test "$ac_cv_broken_mbstowcs" = yes then AC_DEFINE(HAVE_BROKEN_MBSTOWCS, 1, - [Define if mbstowcs(NULL, "text", 0) does not return the number of + [Define if mbstowcs(NULL, "text", 0) does not return the number of wide chars that would be converted.]) fi @@ -4976,15 +4976,15 @@ [Use computed gotos in evaluation loop (enabled by default on supported compilers)]), [ if test "$withval" = yes -then +then AC_DEFINE(USE_COMPUTED_GOTOS, 1, - [Define if you want to use computed gotos in ceval.c.]) + [Define if you want to use computed gotos in ceval.c.]) AC_MSG_RESULT(yes) fi if test "$withval" = no -then +then AC_DEFINE(USE_COMPUTED_GOTOS, 0, - [Define if you want to use computed gotos in ceval.c.]) + [Define if you want to use computed gotos in ceval.c.]) AC_MSG_RESULT(no) fi ], @@ -5018,7 +5018,7 @@ esac case $ac_sys_system in -AIX*) +AIX*) AC_DEFINE(HAVE_BROKEN_PIPE_BUF, 1, [Define if the system reports an invalid PIPE_BUF value.]) ;; esac @@ -5204,6 +5204,7 @@ AC_LINK_IFELSE( [ AC_LANG_SOURCE([[ + #include #include int main() { -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 16:40:04 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 12 Apr 2016 20:40:04 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy41IChvcy51cmFuZG9tKQ==?= Message-ID: <20160412203955.62835.10055.599AC122@psf.io> https://hg.python.org/cpython/rev/7b0fd592cd08 changeset: 100947:7b0fd592cd08 parent: 100944:cd03ff74eaea parent: 100946:f6a5d26a157d user: Victor Stinner date: Tue Apr 12 22:38:22 2016 +0200 summary: Merge 3.5 (os.urandom) files: Misc/NEWS | 4 + Python/random.c | 17 ++- configure | 1 + configure.ac | 167 ++++++++++++++++++----------------- 4 files changed, 101 insertions(+), 88 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -240,6 +240,10 @@ Library ------- +- Issue #26735: Fix :func:`os.urandom` on Solaris 11.3 and newer when reading + more than 1,024 bytes: call ``getrandom()`` multiple times with a limit of + 1024 bytes per call. + - Issue #26585: Eliminate http.server._quote_html() and use html.escape(quote=False). Patch by Xiang Zhang. diff --git a/Python/random.c b/Python/random.c --- a/Python/random.c +++ b/Python/random.c @@ -131,16 +131,23 @@ return 0; while (0 < size) { +#ifdef sun + /* Issue #26735: On Solaris, getrandom() is limited to returning up + to 1024 bytes */ + n = Py_MIN(size, 1024); +#else + n = size; +#endif + errno = 0; - #ifdef HAVE_GETRANDOM if (raise) { Py_BEGIN_ALLOW_THREADS - n = getrandom(buffer, size, flags); + n = getrandom(buffer, n, flags); Py_END_ALLOW_THREADS } else { - n = getrandom(buffer, size, flags); + n = getrandom(buffer, n, flags); } #else /* On Linux, use the syscall() function because the GNU libc doesn't @@ -148,11 +155,11 @@ * https://sourceware.org/bugzilla/show_bug.cgi?id=17252 */ if (raise) { Py_BEGIN_ALLOW_THREADS - n = syscall(SYS_getrandom, buffer, size, flags); + n = syscall(SYS_getrandom, buffer, n, flags); Py_END_ALLOW_THREADS } else { - n = syscall(SYS_getrandom, buffer, size, flags); + n = syscall(SYS_getrandom, buffer, n, flags); } #endif diff --git a/configure b/configure --- a/configure +++ b/configure @@ -16276,6 +16276,7 @@ /* end confdefs.h. */ + #include #include int main() { diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -86,7 +86,7 @@ dnl Last slash shouldn't be stripped if prefix=/ if test "$prefix" != "/"; then prefix=`echo "$prefix" | sed -e 's/\/$//g'` -fi +fi dnl This is for stuff that absolutely must end up in pyconfig.h. dnl Please use pyport.h instead, if possible. @@ -178,7 +178,7 @@ fi ;; esac - + ],[ UNIVERSALSDK= enable_universalsdk= @@ -240,7 +240,7 @@ AS_HELP_STRING([--enable-framework@<:@=INSTALLDIR@:>@], [Build (MacOSX|Darwin) framework]), [ case $enableval in - yes) + yes) enableval=/Library/Frameworks esac case $enableval in @@ -297,7 +297,7 @@ FRAMEWORKINSTALLAPPSPREFIX="${MDIR}/Applications" if test "${prefix}" = "NONE"; then - # User hasn't specified the + # User hasn't specified the # --prefix option, but wants to install # the framework in a non-default location, # ensure that the compatibility links get @@ -442,7 +442,7 @@ # Reconfirmed for OpenBSD 3.3 by Zachary Hamm, for 3.4 by Jason Ish. # In addition, Stefan Krah confirms that issue #1244610 exists through # OpenBSD 4.6, but is fixed in 4.7. - OpenBSD/2.* | OpenBSD/3.* | OpenBSD/4.@<:@0123456@:>@) + OpenBSD/2.* | OpenBSD/3.* | OpenBSD/4.@<:@0123456@:>@) define_xopen_source=no # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is # also defined. This can be overridden by defining _BSD_SOURCE @@ -480,12 +480,12 @@ # with _XOPEN_SOURCE and __BSD_VISIBLE does not re-enable them. FreeBSD/4.*) define_xopen_source=no;; - # On MacOS X 10.2, a bug in ncurses.h means that it craps out if + # On MacOS X 10.2, a bug in ncurses.h means that it craps out if # _XOPEN_EXTENDED_SOURCE is defined. Apparently, this is fixed in 10.3, which # identifies itself as Darwin/7.* # On Mac OS X 10.4, defining _POSIX_C_SOURCE or _XOPEN_SOURCE # disables platform specific features beyond repair. - # On Mac OS X 10.3, defining _POSIX_C_SOURCE or _XOPEN_SOURCE + # On Mac OS X 10.3, defining _POSIX_C_SOURCE or _XOPEN_SOURCE # has no effect, don't bother defining them Darwin/@<:@6789@:>@.*) define_xopen_source=no;; @@ -690,7 +690,7 @@ AS_HELP_STRING([--with-cxx-main=], [compile main() and link python executable with C++ compiler]), [ - + case $withval in no) with_cxx_main=no MAINCC='$(CC)';; @@ -870,7 +870,7 @@ if test x$PLATFORM_TRIPLET != x$MULTIARCH; then AC_MSG_ERROR([internal configure error for the platform triplet, please file a bug report]) fi -fi +fi PLATDIR=plat-$MACHDEP AC_SUBST(PLATDIR) AC_SUBST(PLATFORM_TRIPLET) @@ -959,7 +959,7 @@ # systems without shared libraries, LDLIBRARY is the same as LIBRARY # (defined in the Makefiles). On Cygwin LDLIBRARY is the import library, # DLLLIBRARY is the shared (i.e., DLL) library. -# +# # RUNSHARED is used to run shared python without installed libraries # # INSTSONAME is the name of the shared library that will be use to install @@ -987,7 +987,7 @@ # If CXX is set, and if it is needed to link a main function that was # compiled with CXX, LINKCC is CXX instead. Always using CXX is undesirable: # python might then depend on the C++ runtime -# This is altered for AIX in order to build the export list before +# This is altered for AIX in order to build the export list before # linking. AC_SUBST(LINKCC) AC_MSG_CHECKING(LINKCC) @@ -1041,7 +1041,7 @@ AS_HELP_STRING([--enable-shared], [disable/enable building shared python library])) if test -z "$enable_shared" -then +then case $ac_sys_system in CYGWIN*) enable_shared="yes";; @@ -1086,7 +1086,7 @@ BLDLIBRARY='' else BLDLIBRARY='$(LDLIBRARY)' -fi +fi # Other platforms follow if test $enable_shared = "yes"; then @@ -1221,14 +1221,14 @@ # Check for --with-pydebug AC_MSG_CHECKING(for --with-pydebug) -AC_ARG_WITH(pydebug, +AC_ARG_WITH(pydebug, AS_HELP_STRING([--with-pydebug], [build with Py_DEBUG defined]), [ if test "$withval" != no -then - AC_DEFINE(Py_DEBUG, 1, - [Define if you want to build an interpreter with many run-time checks.]) - AC_MSG_RESULT(yes); +then + AC_DEFINE(Py_DEBUG, 1, + [Define if you want to build an interpreter with many run-time checks.]) + AC_MSG_RESULT(yes); Py_DEBUG='true' ABIFLAGS="${ABIFLAGS}d" else AC_MSG_RESULT(no); Py_DEBUG='false' @@ -1696,7 +1696,7 @@ AC_MSG_RESULT($ac_cv_pthread_is_default) -if test $ac_cv_pthread_is_default = yes +if test $ac_cv_pthread_is_default = yes then ac_cv_kpthread=no else @@ -1795,14 +1795,14 @@ if test "$ac_cv_kpthread" = "yes" then - CXX="$CXX -Kpthread" + CXX="$CXX -Kpthread" ac_cv_cxx_thread=yes elif test "$ac_cv_kthread" = "yes" then CXX="$CXX -Kthread" ac_cv_cxx_thread=yes elif test "$ac_cv_pthread" = "yes" -then +then CXX="$CXX -pthread" ac_cv_cxx_thread=yes fi @@ -1950,11 +1950,11 @@ # These may affect some typedefs case $ac_sys_system/$ac_sys_release in AIX*) - AC_DEFINE(_LARGE_FILES, 1, + AC_DEFINE(_LARGE_FILES, 1, [This must be defined on AIX systems to enable large file support.]) ;; esac -AC_DEFINE(_LARGEFILE_SOURCE, 1, +AC_DEFINE(_LARGEFILE_SOURCE, 1, [This must be defined on some systems to enable large file support.]) AC_DEFINE(_FILE_OFFSET_BITS, 64, [This must be set to 64 on some systems to enable large file support.]) @@ -2018,7 +2018,7 @@ AC_MSG_CHECKING(for long long support) have_long_long=no AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[long long x; x = (long long)0;]])],[ - AC_DEFINE(HAVE_LONG_LONG, 1, [Define this if you have the type long long.]) + AC_DEFINE(HAVE_LONG_LONG, 1, [Define this if you have the type long long.]) have_long_long=yes ],[]) AC_MSG_RESULT($have_long_long) @@ -2029,7 +2029,7 @@ AC_MSG_CHECKING(for long double support) have_long_double=no AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[long double x; x = (long double)0;]])],[ - AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define this if you have the type long double.]) + AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define this if you have the type long double.]) have_long_double=yes ],[]) AC_MSG_RESULT($have_long_double) @@ -2041,7 +2041,7 @@ AC_MSG_CHECKING(for _Bool support) have_c99_bool=no AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[_Bool x; x = (_Bool)0;]])],[ - AC_DEFINE(HAVE_C99_BOOL, 1, [Define this if you have the type _Bool.]) + AC_DEFINE(HAVE_C99_BOOL, 1, [Define this if you have the type _Bool.]) have_c99_bool=yes ],[]) AC_MSG_RESULT($have_c99_bool) @@ -2049,8 +2049,8 @@ AC_CHECK_SIZEOF(_Bool, 1) fi -AC_CHECK_TYPES(uintptr_t, - [AC_CHECK_SIZEOF(uintptr_t, 4)], +AC_CHECK_TYPES(uintptr_t, + [AC_CHECK_SIZEOF(uintptr_t, 4)], [], [#ifdef HAVE_STDINT_H #include #endif @@ -2069,7 +2069,7 @@ then if test "$ac_cv_sizeof_off_t" -gt "$ac_cv_sizeof_long" -a \ "$ac_cv_sizeof_long_long" -ge "$ac_cv_sizeof_off_t"; then - AC_DEFINE(HAVE_LARGEFILE_SUPPORT, 1, + AC_DEFINE(HAVE_LARGEFILE_SUPPORT, 1, [Defined to enable large file support when an off_t is bigger than a long and long long is available and at least as big as an off_t. You may need to add some flags for configuration and compilation to enable this mode. @@ -2118,7 +2118,7 @@ AC_SUBST(OTHER_LIBTOOL_OPT) case $ac_sys_system/$ac_sys_release in - Darwin/@<:@01567@:>@\..*) + Darwin/@<:@01567@:>@\..*) OTHER_LIBTOOL_OPT="-prebind -seg1addr 0x10000000" ;; Darwin/*) @@ -2129,7 +2129,7 @@ AC_SUBST(LIBTOOL_CRUFT) case $ac_sys_system/$ac_sys_release in - Darwin/@<:@01567@:>@\..*) + Darwin/@<:@01567@:>@\..*) LIBTOOL_CRUFT="-framework System -lcc_dynamic" if test "${enable_universalsdk}"; then : @@ -2143,7 +2143,7 @@ if test ${gcc_version} '<' 4.0 then LIBTOOL_CRUFT="-lcc_dynamic" - else + else LIBTOOL_CRUFT="" fi AC_RUN_IFELSE([AC_LANG_SOURCE([[ @@ -2157,14 +2157,14 @@ } } ]])],[ac_osx_32bit=yes],[ac_osx_32bit=no],[ac_osx_32bit=yes]) - + if test "${ac_osx_32bit}" = "yes"; then case `/usr/bin/arch` in - i386) - MACOSX_DEFAULT_ARCH="i386" + i386) + MACOSX_DEFAULT_ARCH="i386" ;; - ppc) - MACOSX_DEFAULT_ARCH="ppc" + ppc) + MACOSX_DEFAULT_ARCH="ppc" ;; *) AC_MSG_ERROR([Unexpected output of 'arch' on OSX]) @@ -2172,11 +2172,11 @@ esac else case `/usr/bin/arch` in - i386) - MACOSX_DEFAULT_ARCH="x86_64" + i386) + MACOSX_DEFAULT_ARCH="x86_64" ;; - ppc) - MACOSX_DEFAULT_ARCH="ppc64" + ppc) + MACOSX_DEFAULT_ARCH="ppc64" ;; *) AC_MSG_ERROR([Unexpected output of 'arch' on OSX]) @@ -2193,9 +2193,9 @@ if test "$enable_framework" then BASECFLAGS="$BASECFLAGS -fno-common -dynamic" - # -F. is needed to allow linking to the framework while + # -F. is needed to allow linking to the framework while # in the build location. - AC_DEFINE(WITH_NEXT_FRAMEWORK, 1, + AC_DEFINE(WITH_NEXT_FRAMEWORK, 1, [Define if you want to produce an OpenStep/Rhapsody framework (shared library plus accessory files).]) AC_MSG_RESULT(yes) @@ -2210,7 +2210,7 @@ AC_MSG_CHECKING(for dyld) case $ac_sys_system/$ac_sys_release in Darwin/*) - AC_DEFINE(WITH_DYLD, 1, + AC_DEFINE(WITH_DYLD, 1, [Define if you want to use the new-style (Openstep, Rhapsody, MacOS) dynamic linker (dyld) instead of the old-style (NextStep) dynamic linker (rld). Dyld is necessary to support frameworks.]) @@ -2260,7 +2260,7 @@ ;; IRIX/5*) LDSHARED="ld -shared";; IRIX*/6*) LDSHARED="ld ${SGI_ABI} -shared -all";; - SunOS/5*) + SunOS/5*) if test "$GCC" = "yes" ; then LDSHARED='$(CC) -shared' LDCXXSHARED='$(CXX) -shared' @@ -2436,7 +2436,7 @@ BSD/OS/4*) LINKFORSHARED="-Xlinker -export-dynamic";; Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic";; # -u libsys_s pulls in all symbols in libsys - Darwin/*) + Darwin/*) LINKFORSHARED="$extra_undefs -framework CoreFoundation" # Issue #18075: the default maximum stack size (8MBytes) is too @@ -2452,7 +2452,7 @@ OpenUNIX*|UnixWare*) LINKFORSHARED="-Wl,-Bexport";; SCO_SV*) LINKFORSHARED="-Wl,-Bexport";; ReliantUNIX*) LINKFORSHARED="-W1 -Blargedynsym";; - FreeBSD*|NetBSD*|OpenBSD*|DragonFly*) + FreeBSD*|NetBSD*|OpenBSD*|DragonFly*) if [[ "`$CC -dM -E - ]], [[getpgrp(0);]])], [AC_DEFINE(GETPGRP_HAVE_ARG, 1, [Define if getpgrp() must be called as getpgrp(0).])], []) @@ -3544,7 +3544,7 @@ [AC_DEFINE(SETPGRP_HAVE_ARG, 1, [Define if setpgrp() must be called as setpgrp(0, 0).])], []) ) -AC_CHECK_FUNCS(gettimeofday, +AC_CHECK_FUNCS(gettimeofday, AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[gettimeofday((struct timeval*)0,(struct timezone*)0);]])], [], @@ -3589,7 +3589,7 @@ ]) # On OSF/1 V5.1, getaddrinfo is available, but a define -# for [no]getaddrinfo in netdb.h. +# for [no]getaddrinfo in netdb.h. AC_MSG_CHECKING(for getaddrinfo) AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include @@ -3749,7 +3749,7 @@ ]], [[;]])],[ AC_DEFINE(SYS_SELECT_WITH_SYS_TIME, 1, [Define if you can safely include both and - (which you can't on SCO ODT 3.0).]) + (which you can't on SCO ODT 3.0).]) was_it_defined=yes ],[]) AC_MSG_RESULT($was_it_defined) @@ -3800,8 +3800,8 @@ have_prototypes=no AC_MSG_CHECKING(for prototypes) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int foo(int x) { return 0; }]], [[return foo(10);]])], - [AC_DEFINE(HAVE_PROTOTYPES, 1, - [Define if your compiler supports function prototype]) + [AC_DEFINE(HAVE_PROTOTYPES, 1, + [Define if your compiler supports function prototype]) have_prototypes=yes], [] ) @@ -3822,7 +3822,7 @@ ]], [[return foo(10, "", 3.14);]])],[ AC_DEFINE(HAVE_STDARG_PROTOTYPES, 1, [Define if your compiler supports variable length function prototypes - (e.g. void fprintf(FILE *, char *, ...);) *and* ]) + (e.g. void fprintf(FILE *, char *, ...);) *and* ]) works=yes ],[]) AC_MSG_RESULT($works) @@ -3857,7 +3857,7 @@ #include #endif ]], [[va_list list1, list2; list1 = list2;]])],[],[ - AC_DEFINE(VA_LIST_IS_ARRAY, 1, [Define if a va_list is an array of some kind]) + AC_DEFINE(VA_LIST_IS_ARRAY, 1, [Define if a va_list is an array of some kind]) va_list_is_array=yes ]) AC_MSG_RESULT($va_list_is_array) @@ -3952,9 +3952,9 @@ AS_HELP_STRING([--with-fpectl], [enable SIGFPE catching]), [ if test "$withval" != no -then +then AC_DEFINE(WANT_SIGFPE_HANDLER, 1, - [Define if you want SIGFPE handled (see Include/pyfpe.h).]) + [Define if you want SIGFPE handled (see Include/pyfpe.h).]) AC_MSG_RESULT(yes) else AC_MSG_RESULT(no) fi], @@ -4325,8 +4325,8 @@ # check for wchar.h AC_CHECK_HEADER(wchar.h, [ - AC_DEFINE(HAVE_WCHAR_H, 1, - [Define if the compiler provides a wchar.h header file.]) + AC_DEFINE(HAVE_WCHAR_H, 1, + [Define if the compiler provides a wchar.h header file.]) wchar_h="yes" ], wchar_h="no" @@ -4609,7 +4609,7 @@ [Define if poll() sets errno on invalid file descriptors.]) fi -# Before we can test tzset, we need to check if struct tm has a tm_zone +# Before we can test tzset, we need to check if struct tm has a tm_zone # (which is not required by ISO C or UNIX spec) and/or if we support # tzname[] AC_STRUCT_TIMEZONE @@ -4635,7 +4635,7 @@ tm->tm_zone does not exist since it is the alternative way of getting timezone info. - Red Hat 6.2 doesn't understand the southern hemisphere + Red Hat 6.2 doesn't understand the southern hemisphere after New Year's Day. */ @@ -4648,7 +4648,7 @@ exit(1); #if HAVE_TZNAME /* For UTC, tzname[1] is sometimes "", sometimes " " */ - if (strcmp(tzname[0], "UTC") || + if (strcmp(tzname[0], "UTC") || (tzname[1][0] != 0 && tzname[1][0] != ' ')) exit(1); #endif @@ -4766,7 +4766,7 @@ if test "$ac_cv_window_has_flags" = yes then - AC_DEFINE(WINDOW_HAS_FLAGS, 1, + AC_DEFINE(WINDOW_HAS_FLAGS, 1, [Define if WINDOW in curses.h offers a field _flags.]) fi @@ -4965,7 +4965,7 @@ if test "$ac_cv_broken_mbstowcs" = yes then AC_DEFINE(HAVE_BROKEN_MBSTOWCS, 1, - [Define if mbstowcs(NULL, "text", 0) does not return the number of + [Define if mbstowcs(NULL, "text", 0) does not return the number of wide chars that would be converted.]) fi @@ -4976,15 +4976,15 @@ [Use computed gotos in evaluation loop (enabled by default on supported compilers)]), [ if test "$withval" = yes -then +then AC_DEFINE(USE_COMPUTED_GOTOS, 1, - [Define if you want to use computed gotos in ceval.c.]) + [Define if you want to use computed gotos in ceval.c.]) AC_MSG_RESULT(yes) fi if test "$withval" = no -then +then AC_DEFINE(USE_COMPUTED_GOTOS, 0, - [Define if you want to use computed gotos in ceval.c.]) + [Define if you want to use computed gotos in ceval.c.]) AC_MSG_RESULT(no) fi ], @@ -5018,7 +5018,7 @@ esac case $ac_sys_system in -AIX*) +AIX*) AC_DEFINE(HAVE_BROKEN_PIPE_BUF, 1, [Define if the system reports an invalid PIPE_BUF value.]) ;; esac @@ -5204,6 +5204,7 @@ AC_LINK_IFELSE( [ AC_LANG_SOURCE([[ + #include #include int main() { -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 20:32:25 2016 From: python-checkins at python.org (steven.daprano) Date: Wed, 13 Apr 2016 00:32:25 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Mark_pep_as_accepted=2E?= Message-ID: <20160413003225.30780.32333.CB0E59B4@psf.io> https://hg.python.org/peps/rev/787050e99ccf changeset: 6279:787050e99ccf user: Steven D'Aprano date: Wed Apr 13 10:32:11 2016 +1000 summary: Mark pep as accepted. https://mail.python.org/pipermail/python-dev/2016-April/143921.html files: pep-0506.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pep-0506.txt b/pep-0506.txt --- a/pep-0506.txt +++ b/pep-0506.txt @@ -3,7 +3,7 @@ Version: $Revision$ Last-Modified: $Date$ Author: Steven D'Aprano -Status: Draft +Status: Accepted Type: Standards Track Content-Type: text/x-rst Created: 19-Sep-2015 -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Tue Apr 12 22:41:28 2016 From: python-checkins at python.org (martin.panter) Date: Wed, 13 Apr 2016 02:41:28 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326404=3A_Add_cont?= =?utf-8?q?ext_manager_to_socketserver=2C_by_Aviv_Palivoda?= Message-ID: <20160413024127.11965.10857.E6606F93@psf.io> https://hg.python.org/cpython/rev/5c4303c46a18 changeset: 100948:5c4303c46a18 user: Martin Panter date: Wed Apr 13 00:36:52 2016 +0000 summary: Issue #26404: Add context manager to socketserver, by Aviv Palivoda files: Doc/library/http.server.rst | 7 +- Doc/library/socketserver.rst | 49 ++++++++++-------- Doc/library/wsgiref.rst | 32 ++++++------ Doc/library/xmlrpc.server.rst | 59 +++++++++++----------- Doc/whatsnew/3.6.rst | 10 +++ Lib/http/server.py | 18 +++--- Lib/socketserver.py | 6 ++ Lib/test/test_socketserver.py | 7 ++- Lib/wsgiref/simple_server.py | 13 ++-- Lib/xmlrpc/server.py | 25 ++++----- Misc/NEWS | 2 + 11 files changed, 125 insertions(+), 103 deletions(-) diff --git a/Doc/library/http.server.rst b/Doc/library/http.server.rst --- a/Doc/library/http.server.rst +++ b/Doc/library/http.server.rst @@ -375,10 +375,9 @@ Handler = http.server.SimpleHTTPRequestHandler - httpd = socketserver.TCPServer(("", PORT), Handler) - - print("serving at port", PORT) - httpd.serve_forever() + with socketserver.TCPServer(("", PORT), Handler) as httpd: + print("serving at port", PORT) + httpd.serve_forever() .. _http-server-cli: diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst --- a/Doc/library/socketserver.rst +++ b/Doc/library/socketserver.rst @@ -52,11 +52,12 @@ overriding its :meth:`~BaseRequestHandler.handle` method; this method will process incoming requests. Second, you must instantiate one of the server classes, passing it -the server's address and the request handler class. Then call the +the server's address and the request handler class. It is recommended to use +the server in a :keyword:`with` statement. Then call the :meth:`~BaseServer.handle_request` or :meth:`~BaseServer.serve_forever` method of the server object to process one or many requests. Finally, call :meth:`~BaseServer.server_close` -to close the socket. +to close the socket (unless you used a :keyword:`with` statement). When inheriting from :class:`ThreadingMixIn` for threaded connection behavior, you should explicitly declare how you want your threads to behave on an abrupt @@ -353,6 +354,11 @@ default implementation always returns :const:`True`. + .. versionchanged:: 3.6 + Support for the :term:`context manager` protocol was added. Exiting the + context manager is equivalent to calling :meth:`server_close`. + + Request Handler Objects ----------------------- @@ -433,11 +439,10 @@ HOST, PORT = "localhost", 9999 # Create the server, binding to localhost on port 9999 - server = socketserver.TCPServer((HOST, PORT), MyTCPHandler) - - # Activate the server; this will keep running until you - # interrupt the program with Ctrl-C - server.serve_forever() + with socketserver.TCPServer((HOST, PORT), MyTCPHandler) as server: + # Activate the server; this will keep running until you + # interrupt the program with Ctrl-C + server.serve_forever() An alternative request handler class that makes use of streams (file-like objects that simplify communication by providing the standard file interface):: @@ -529,8 +534,8 @@ if __name__ == "__main__": HOST, PORT = "localhost", 9999 - server = socketserver.UDPServer((HOST, PORT), MyUDPHandler) - server.serve_forever() + with socketserver.UDPServer((HOST, PORT), MyUDPHandler) as server: + server.serve_forever() This is the client side:: @@ -592,22 +597,22 @@ HOST, PORT = "localhost", 0 server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler) - ip, port = server.server_address + with server: + ip, port = server.server_address - # Start a thread with the server -- that thread will then start one - # more thread for each request - server_thread = threading.Thread(target=server.serve_forever) - # Exit the server thread when the main thread terminates - server_thread.daemon = True - server_thread.start() - print("Server loop running in thread:", server_thread.name) + # Start a thread with the server -- that thread will then start one + # more thread for each request + server_thread = threading.Thread(target=server.serve_forever) + # Exit the server thread when the main thread terminates + server_thread.daemon = True + server_thread.start() + print("Server loop running in thread:", server_thread.name) - client(ip, port, "Hello World 1") - client(ip, port, "Hello World 2") - client(ip, port, "Hello World 3") + client(ip, port, "Hello World 1") + client(ip, port, "Hello World 2") + client(ip, port, "Hello World 3") - server.shutdown() - server.server_close() + server.shutdown() The output of the example should look something like this:: diff --git a/Doc/library/wsgiref.rst b/Doc/library/wsgiref.rst --- a/Doc/library/wsgiref.rst +++ b/Doc/library/wsgiref.rst @@ -131,9 +131,9 @@ for key, value in environ.items()] return ret - httpd = make_server('', 8000, simple_app) - print("Serving on port 8000...") - httpd.serve_forever() + with make_server('', 8000, simple_app) as httpd: + print("Serving on port 8000...") + httpd.serve_forever() In addition to the environment functions above, the :mod:`wsgiref.util` module @@ -283,14 +283,14 @@ from wsgiref.simple_server import make_server, demo_app - httpd = make_server('', 8000, demo_app) - print("Serving HTTP on port 8000...") + with make_server('', 8000, demo_app) as httpd: + print("Serving HTTP on port 8000...") - # Respond to requests until process is killed - httpd.serve_forever() + # Respond to requests until process is killed + httpd.serve_forever() - # Alternative: serve one request, then exit - httpd.handle_request() + # Alternative: serve one request, then exit + httpd.handle_request() .. function:: demo_app(environ, start_response) @@ -430,9 +430,9 @@ # This is the application wrapped in a validator validator_app = validator(simple_app) - httpd = make_server('', 8000, validator_app) - print("Listening on port 8000....") - httpd.serve_forever() + with make_server('', 8000, validator_app) as httpd: + print("Listening on port 8000....") + httpd.serve_forever() :mod:`wsgiref.handlers` -- server/gateway base classes @@ -769,8 +769,8 @@ # The returned object is going to be printed return [b"Hello World"] - httpd = make_server('', 8000, hello_world_app) - print("Serving on port 8000...") + with make_server('', 8000, hello_world_app) as httpd: + print("Serving on port 8000...") - # Serve until process is killed - httpd.serve_forever() + # Serve until process is killed + httpd.serve_forever() diff --git a/Doc/library/xmlrpc.server.rst b/Doc/library/xmlrpc.server.rst --- a/Doc/library/xmlrpc.server.rst +++ b/Doc/library/xmlrpc.server.rst @@ -147,29 +147,29 @@ rpc_paths = ('/RPC2',) # Create server - server = SimpleXMLRPCServer(("localhost", 8000), - requestHandler=RequestHandler) - server.register_introspection_functions() + with SimpleXMLRPCServer(("localhost", 8000), + requestHandler=RequestHandler) as server: + server.register_introspection_functions() - # Register pow() function; this will use the value of - # pow.__name__ as the name, which is just 'pow'. - server.register_function(pow) + # Register pow() function; this will use the value of + # pow.__name__ as the name, which is just 'pow'. + server.register_function(pow) - # Register a function under a different name - def adder_function(x,y): - return x + y - server.register_function(adder_function, 'add') + # Register a function under a different name + def adder_function(x,y): + return x + y + server.register_function(adder_function, 'add') - # Register an instance; all the methods of the instance are - # published as XML-RPC methods (in this case, just 'mul'). - class MyFuncs: - def mul(self, x, y): - return x * y + # Register an instance; all the methods of the instance are + # published as XML-RPC methods (in this case, just 'mul'). + class MyFuncs: + def mul(self, x, y): + return x * y - server.register_instance(MyFuncs()) + server.register_instance(MyFuncs()) - # Run the server's main loop - server.serve_forever() + # Run the server's main loop + server.serve_forever() The following client code will call the methods made available by the preceding server:: @@ -206,18 +206,17 @@ def getCurrentTime(): return datetime.datetime.now() - server = SimpleXMLRPCServer(("localhost", 8000)) - server.register_function(pow) - server.register_function(lambda x,y: x+y, 'add') - server.register_instance(ExampleService(), allow_dotted_names=True) - server.register_multicall_functions() - print('Serving XML-RPC on localhost port 8000') - try: - server.serve_forever() - except KeyboardInterrupt: - print("\nKeyboard interrupt received, exiting.") - server.server_close() - sys.exit(0) + with SimpleXMLRPCServer(("localhost", 8000)) as server: + server.register_function(pow) + server.register_function(lambda x,y: x+y, 'add') + server.register_instance(ExampleService(), allow_dotted_names=True) + server.register_multicall_functions() + print('Serving XML-RPC on localhost port 8000') + try: + server.serve_forever() + except KeyboardInterrupt: + print("\nKeyboard interrupt received, exiting.") + sys.exit(0) This ExampleService demo can be invoked from the command line:: diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -259,6 +259,16 @@ (Contributed by Wolfgang Langner in :issue:`26587`). +socketserver +------------ + +Servers based on the :mod:`socketserver` module, including those +defined in :mod:`http.server`, :mod:`xmlrpc.server` and +:mod:`wsgiref.simple_server`, now support the :term:`context manager` +protocol. +(Contributed by Aviv Palivoda in :issue:`26404`.) + + telnetlib --------- diff --git a/Lib/http/server.py b/Lib/http/server.py --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -1175,16 +1175,14 @@ server_address = (bind, port) HandlerClass.protocol_version = protocol - httpd = ServerClass(server_address, HandlerClass) - - sa = httpd.socket.getsockname() - print("Serving HTTP on", sa[0], "port", sa[1], "...") - try: - httpd.serve_forever() - except KeyboardInterrupt: - print("\nKeyboard interrupt received, exiting.") - httpd.server_close() - sys.exit(0) + with ServerClass(server_address, HandlerClass) as httpd: + sa = httpd.socket.getsockname() + print("Serving HTTP on", sa[0], "port", sa[1], "...") + try: + httpd.serve_forever() + except KeyboardInterrupt: + print("\nKeyboard interrupt received, exiting.") + sys.exit(0) if __name__ == '__main__': parser = argparse.ArgumentParser() diff --git a/Lib/socketserver.py b/Lib/socketserver.py --- a/Lib/socketserver.py +++ b/Lib/socketserver.py @@ -378,6 +378,12 @@ traceback.print_exc() print('-'*40, file=sys.stderr) + def __enter__(self): + return self + + def __exit__(self, *args): + self.server_close() + class TCPServer(BaseServer): diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -104,7 +104,6 @@ class MyServer(svrcls): def handle_error(self, request, client_address): self.close_request(request) - self.server_close() raise class MyHandler(hdlrbase): @@ -280,6 +279,12 @@ socketserver.TCPServer((HOST, -1), socketserver.StreamRequestHandler) + def test_context_manager(self): + with socketserver.TCPServer((HOST, 0), + socketserver.StreamRequestHandler) as server: + pass + self.assertEqual(-1, server.socket.fileno()) + class ErrorHandlerTest(unittest.TestCase): """Test that the servers pass normal exceptions from the handler to diff --git a/Lib/wsgiref/simple_server.py b/Lib/wsgiref/simple_server.py --- a/Lib/wsgiref/simple_server.py +++ b/Lib/wsgiref/simple_server.py @@ -156,10 +156,9 @@ if __name__ == '__main__': - httpd = make_server('', 8000, demo_app) - sa = httpd.socket.getsockname() - print("Serving HTTP on", sa[0], "port", sa[1], "...") - import webbrowser - webbrowser.open('http://localhost:8000/xyz?abc') - httpd.handle_request() # serve one request, then exit - httpd.server_close() + with make_server('', 8000, demo_app) as httpd: + sa = httpd.socket.getsockname() + print("Serving HTTP on", sa[0], "port", sa[1], "...") + import webbrowser + webbrowser.open('http://localhost:8000/xyz?abc') + httpd.handle_request() # serve one request, then exit diff --git a/Lib/xmlrpc/server.py b/Lib/xmlrpc/server.py --- a/Lib/xmlrpc/server.py +++ b/Lib/xmlrpc/server.py @@ -971,16 +971,15 @@ def getCurrentTime(): return datetime.datetime.now() - server = SimpleXMLRPCServer(("localhost", 8000)) - server.register_function(pow) - server.register_function(lambda x,y: x+y, 'add') - server.register_instance(ExampleService(), allow_dotted_names=True) - server.register_multicall_functions() - print('Serving XML-RPC on localhost port 8000') - print('It is advisable to run this example server within a secure, closed network.') - try: - server.serve_forever() - except KeyboardInterrupt: - print("\nKeyboard interrupt received, exiting.") - server.server_close() - sys.exit(0) + with SimpleXMLRPCServer(("localhost", 8000)) as server: + server.register_function(pow) + server.register_function(lambda x,y: x+y, 'add') + server.register_instance(ExampleService(), allow_dotted_names=True) + server.register_multicall_functions() + print('Serving XML-RPC on localhost port 8000') + print('It is advisable to run this example server within a secure, closed network.') + try: + server.serve_forever() + except KeyboardInterrupt: + print("\nKeyboard interrupt received, exiting.") + sys.exit(0) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -240,6 +240,8 @@ Library ------- +- Issue #26404: Add context manager to socketserver. Patch by Aviv Palivoda. + - Issue #26735: Fix :func:`os.urandom` on Solaris 11.3 and newer when reading more than 1,024 bytes: call ``getrandom()`` multiple times with a limit of 1024 bytes per call. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 23:12:45 2016 From: python-checkins at python.org (steve.dower) Date: Wed, 13 Apr 2016 03:12:45 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Closes_=2326624=3A_Adds_validation_of_ucrtbase=5Bd=5D=2E?= =?utf-8?q?dll_version_with_warning_for_old?= Message-ID: <20160413031245.32543.50116.AF0DF5E2@psf.io> https://hg.python.org/cpython/rev/6ff020df61b8 changeset: 100950:6ff020df61b8 parent: 100948:5c4303c46a18 parent: 100949:605fde022b15 user: Steve Dower date: Tue Apr 12 20:11:45 2016 -0700 summary: Closes #26624: Adds validation of ucrtbase[d].dll version with warning for old versions. files: Misc/NEWS | 3 + PC/python_ver_rc.h | 3 +- PC/validate_ucrtbase.py | 88 +++++++++++++++++++++++++++++ PCbuild/python.vcxproj | 7 ++ 4 files changed, 99 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -973,6 +973,9 @@ Build ----- +- Issue #26624: Adds validation of ucrtbase[d].dll version with warning + for old versions. + - Issue #17603: Avoid error about nonexistant fileblocks.o file by using a lower-level check for st_blocks in struct stat. diff --git a/PC/python_ver_rc.h b/PC/python_ver_rc.h --- a/PC/python_ver_rc.h +++ b/PC/python_ver_rc.h @@ -9,11 +9,10 @@ #define MS_WINDOWS #include "modsupport.h" #include "patchlevel.h" +#include #ifdef _DEBUG -# include # define PYTHON_DEBUG_EXT "_d" #else -# include # define PYTHON_DEBUG_EXT #endif diff --git a/PC/validate_ucrtbase.py b/PC/validate_ucrtbase.py new file mode 100644 --- /dev/null +++ b/PC/validate_ucrtbase.py @@ -0,0 +1,88 @@ +''' +This script gets the version number from ucrtbased.dll and checks +whether it is a version with a known issue. +''' + +import sys + +from ctypes import (c_buffer, POINTER, byref, create_unicode_buffer, + Structure, WinDLL) +from ctypes.wintypes import DWORD, HANDLE + +class VS_FIXEDFILEINFO(Structure): + _fields_ = [ + ("dwSignature", DWORD), + ("dwStrucVersion", DWORD), + ("dwFileVersionMS", DWORD), + ("dwFileVersionLS", DWORD), + ("dwProductVersionMS", DWORD), + ("dwProductVersionLS", DWORD), + ("dwFileFlagsMask", DWORD), + ("dwFileFlags", DWORD), + ("dwFileOS", DWORD), + ("dwFileType", DWORD), + ("dwFileSubtype", DWORD), + ("dwFileDateMS", DWORD), + ("dwFileDateLS", DWORD), + ] + +kernel32 = WinDLL('kernel32') +version = WinDLL('version') + +if len(sys.argv) < 2: + print('Usage: validate_ucrtbase.py ') + sys.exit(2) + +try: + ucrtbased = WinDLL(sys.argv[1]) +except OSError: + print('Cannot find ucrtbased.dll') + # This likely means that VS is not installed, but that is an + # obvious enough problem if you're trying to produce a debug + # build that we don't need to fail here. + sys.exit(0) + +# We will immediately double the length up to MAX_PATH, but the +# path may be longer, so we retry until the returned string is +# shorter than our buffer. +name_len = actual_len = 130 +while actual_len == name_len: + name_len *= 2 + name = create_unicode_buffer(name_len) + actual_len = kernel32.GetModuleFileNameW(HANDLE(ucrtbased._handle), + name, len(name)) + if not actual_len: + print('Failed to get full module name.') + sys.exit(2) + +size = version.GetFileVersionInfoSizeW(name, None) +if not size: + print('Failed to get size of version info.') + sys.exit(2) + +ver_block = c_buffer(size) +if (not version.GetFileVersionInfoW(name, None, size, ver_block) or + not ver_block): + print('Failed to get version info.') + sys.exit(2) + +pvi = POINTER(VS_FIXEDFILEINFO)() +if not version.VerQueryValueW(ver_block, "", byref(pvi), byref(DWORD())): + print('Failed to get version value from info.') + sys.exit(2) + +ver = ( + pvi.contents.dwProductVersionMS >> 16, + pvi.contents.dwProductVersionMS & 0xFFFF, + pvi.contents.dwProductVersionLS >> 16, + pvi.contents.dwProductVersionLS & 0xFFFF, +) + +print('{} is version {}.{}.{}.{}'.format(name.value, *ver)) + +if ver < (10, 0, 10586): + print('WARN: ucrtbased contains known issues. ' + 'Please update Visual Studio or the Windows SDK.') + print('See:') + print(' http://bugs.python.org/issue26624') + sys.exit(1) diff --git a/PCbuild/python.vcxproj b/PCbuild/python.vcxproj --- a/PCbuild/python.vcxproj +++ b/PCbuild/python.vcxproj @@ -83,6 +83,13 @@ + + + ucrtbase + ucrtbased + + + <_Content>@rem This script invokes the most recently built Python with all arguments -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 23:12:45 2016 From: python-checkins at python.org (steve.dower) Date: Wed, 13 Apr 2016 03:12:45 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogQ2xvc2VzICMyNjYy?= =?utf-8?q?4=3A_Adds_validation_of_ucrtbase=5Bd=5D=2Edll_version_with_warn?= =?utf-8?q?ing_for_old?= Message-ID: <20160413031245.30772.40687.6E71C976@psf.io> https://hg.python.org/cpython/rev/605fde022b15 changeset: 100949:605fde022b15 branch: 3.5 parent: 100946:f6a5d26a157d user: Steve Dower date: Tue Apr 12 20:11:25 2016 -0700 summary: Closes #26624: Adds validation of ucrtbase[d].dll version with warning for old versions. files: Misc/NEWS | 3 + PC/python_ver_rc.h | 3 +- PC/validate_ucrtbase.py | 88 +++++++++++++++++++++++++++++ PCbuild/python.vcxproj | 7 ++ 4 files changed, 99 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -385,6 +385,9 @@ Build ----- +- Issue #26624: Adds validation of ucrtbase[d].dll version with warning + for old versions. + - Issue #17603: Avoid error about nonexistant fileblocks.o file by using a lower-level check for st_blocks in struct stat. diff --git a/PC/python_ver_rc.h b/PC/python_ver_rc.h --- a/PC/python_ver_rc.h +++ b/PC/python_ver_rc.h @@ -9,11 +9,10 @@ #define MS_WINDOWS #include "modsupport.h" #include "patchlevel.h" +#include #ifdef _DEBUG -# include # define PYTHON_DEBUG_EXT "_d" #else -# include # define PYTHON_DEBUG_EXT #endif diff --git a/PC/validate_ucrtbase.py b/PC/validate_ucrtbase.py new file mode 100644 --- /dev/null +++ b/PC/validate_ucrtbase.py @@ -0,0 +1,88 @@ +''' +This script gets the version number from ucrtbased.dll and checks +whether it is a version with a known issue. +''' + +import sys + +from ctypes import (c_buffer, POINTER, byref, create_unicode_buffer, + Structure, WinDLL) +from ctypes.wintypes import DWORD, HANDLE + +class VS_FIXEDFILEINFO(Structure): + _fields_ = [ + ("dwSignature", DWORD), + ("dwStrucVersion", DWORD), + ("dwFileVersionMS", DWORD), + ("dwFileVersionLS", DWORD), + ("dwProductVersionMS", DWORD), + ("dwProductVersionLS", DWORD), + ("dwFileFlagsMask", DWORD), + ("dwFileFlags", DWORD), + ("dwFileOS", DWORD), + ("dwFileType", DWORD), + ("dwFileSubtype", DWORD), + ("dwFileDateMS", DWORD), + ("dwFileDateLS", DWORD), + ] + +kernel32 = WinDLL('kernel32') +version = WinDLL('version') + +if len(sys.argv) < 2: + print('Usage: validate_ucrtbase.py ') + sys.exit(2) + +try: + ucrtbased = WinDLL(sys.argv[1]) +except OSError: + print('Cannot find ucrtbased.dll') + # This likely means that VS is not installed, but that is an + # obvious enough problem if you're trying to produce a debug + # build that we don't need to fail here. + sys.exit(0) + +# We will immediately double the length up to MAX_PATH, but the +# path may be longer, so we retry until the returned string is +# shorter than our buffer. +name_len = actual_len = 130 +while actual_len == name_len: + name_len *= 2 + name = create_unicode_buffer(name_len) + actual_len = kernel32.GetModuleFileNameW(HANDLE(ucrtbased._handle), + name, len(name)) + if not actual_len: + print('Failed to get full module name.') + sys.exit(2) + +size = version.GetFileVersionInfoSizeW(name, None) +if not size: + print('Failed to get size of version info.') + sys.exit(2) + +ver_block = c_buffer(size) +if (not version.GetFileVersionInfoW(name, None, size, ver_block) or + not ver_block): + print('Failed to get version info.') + sys.exit(2) + +pvi = POINTER(VS_FIXEDFILEINFO)() +if not version.VerQueryValueW(ver_block, "", byref(pvi), byref(DWORD())): + print('Failed to get version value from info.') + sys.exit(2) + +ver = ( + pvi.contents.dwProductVersionMS >> 16, + pvi.contents.dwProductVersionMS & 0xFFFF, + pvi.contents.dwProductVersionLS >> 16, + pvi.contents.dwProductVersionLS & 0xFFFF, +) + +print('{} is version {}.{}.{}.{}'.format(name.value, *ver)) + +if ver < (10, 0, 10586): + print('WARN: ucrtbased contains known issues. ' + 'Please update Visual Studio or the Windows SDK.') + print('See:') + print(' http://bugs.python.org/issue26624') + sys.exit(1) diff --git a/PCbuild/python.vcxproj b/PCbuild/python.vcxproj --- a/PCbuild/python.vcxproj +++ b/PCbuild/python.vcxproj @@ -83,6 +83,13 @@ + + + ucrtbase + ucrtbased + + + <_Content>@rem This script invokes the most recently built Python with all arguments -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 12 23:15:31 2016 From: python-checkins at python.org (steve.dower) Date: Wed, 13 Apr 2016 03:15:31 +0000 Subject: [Python-checkins] =?utf-8?q?devguide=3A_Issue_=2326624=3A_Adds_re?= =?utf-8?q?commendation_to_install_updates_of_VS_2015=2E?= Message-ID: <20160413031530.11965.37116.B79DA96C@psf.io> https://hg.python.org/devguide/rev/a352f7e96f85 changeset: 794:a352f7e96f85 user: Steve Dower date: Tue Apr 12 20:15:19 2016 -0700 summary: Issue #26624: Adds recommendation to install updates of VS 2015. files: setup.rst | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/setup.rst b/setup.rst --- a/setup.rst +++ b/setup.rst @@ -233,7 +233,8 @@ **Python 3.5** and later use Microsoft Visual Studio 2015. You can download and use any of the free or paid versions of `Visual Studio 2015 -`_. +`_. Installing the latest updates is also +recommended. Python 3.3 and 3.4 use Microsoft Visual Studio 2010. You can download Microsoft Visual Studio 2010 Express with an `MSDN subscription -- Repository URL: https://hg.python.org/devguide From python-checkins at python.org Wed Apr 13 00:32:30 2016 From: python-checkins at python.org (martin.panter) Date: Wed, 13 Apr 2016 04:32:30 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2325496=3A_Merge_tarfile_doc_from_3=2E5?= Message-ID: <20160413043230.79931.32572.B513015C@psf.io> https://hg.python.org/cpython/rev/a04455866ec7 changeset: 100952:a04455866ec7 parent: 100950:6ff020df61b8 parent: 100951:b1f3fe320adf user: Martin Panter date: Wed Apr 13 03:31:33 2016 +0000 summary: Issue #25496: Merge tarfile doc from 3.5 files: Doc/library/tarfile.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst --- a/Doc/library/tarfile.rst +++ b/Doc/library/tarfile.rst @@ -101,7 +101,7 @@ For modes ``'w:gz'``, ``'r:gz'``, ``'w:bz2'``, ``'r:bz2'``, ``'x:gz'``, ``'x:bz2'``, :func:`tarfile.open` accepts the keyword argument - *compresslevel* to specify the compression level of the file. + *compresslevel* (default ``9``) to specify the compression level of the file. For special purposes, there is a second format for *mode*: ``'filemode|[compression]'``. :func:`tarfile.open` will return a :class:`TarFile` -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 13 00:32:30 2016 From: python-checkins at python.org (martin.panter) Date: Wed, 13 Apr 2016 04:32:30 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Update_susp-ig?= =?utf-8?q?nore_file_=28=2325910=29=2E?= Message-ID: <20160413043230.109927.7031.1709A1D8@psf.io> https://hg.python.org/cpython/rev/4b65bee79dab changeset: 100954:4b65bee79dab branch: 2.7 user: Georg Brandl date: Sun Feb 28 21:13:23 2016 +0100 summary: Update susp-ignore file (#25910). files: Doc/tools/susp-ignored.csv | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/tools/susp-ignored.csv b/Doc/tools/susp-ignored.csv --- a/Doc/tools/susp-ignored.csv +++ b/Doc/tools/susp-ignored.csv @@ -173,7 +173,7 @@ using/cmdline,,:message,action:message:category:module:line using/cmdline,,:module,action:message:category:module:line using/cmdline,,:errorhandler,:errorhandler -using/unix,,:Packaging,http://en.opensuse.org/Portal:Packaging +using/unix,,:Packaging,https://en.opensuse.org/Portal:Packaging whatsnew/2.0,418,:len, whatsnew/2.3,,::, whatsnew/2.3,,:config, -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 13 00:32:36 2016 From: python-checkins at python.org (martin.panter) Date: Wed, 13 Apr 2016 04:32:36 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI1NDk2?= =?utf-8?q?=3A_Document_compresslevel_defaults_to_9=2C_by_Hamza_T_Khan?= Message-ID: <20160413043230.7555.77411.40BA3C55@psf.io> https://hg.python.org/cpython/rev/4b9d70d3ba1b changeset: 100953:4b9d70d3ba1b branch: 2.7 parent: 100939:c2f57f959c05 user: Martin Panter date: Wed Apr 13 03:24:06 2016 +0000 summary: Issue #25496: Document compresslevel defaults to 9, by Hamza T Khan files: Doc/library/tarfile.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst --- a/Doc/library/tarfile.rst +++ b/Doc/library/tarfile.rst @@ -79,8 +79,8 @@ for *name*. It is supposed to be at position 0. For modes ``'w:gz'``, ``'r:gz'``, ``'w:bz2'``, ``'r:bz2'``, :func:`tarfile.open` - accepts the keyword argument *compresslevel* to specify the compression level of - the file. + accepts the keyword argument *compresslevel* (default ``9``) to + specify the compression level of the file. For special purposes, there is a second format for *mode*: ``'filemode|[compression]'``. :func:`tarfile.open` will return a :class:`TarFile` -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 13 00:32:36 2016 From: python-checkins at python.org (martin.panter) Date: Wed, 13 Apr 2016 04:32:36 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI1NDk2?= =?utf-8?q?=3A_Document_compresslevel_defaults_to_9=2C_by_Hamza_T_Khan?= Message-ID: <20160413043230.11645.4944.38153766@psf.io> https://hg.python.org/cpython/rev/b1f3fe320adf changeset: 100951:b1f3fe320adf branch: 3.5 parent: 100949:605fde022b15 user: Martin Panter date: Wed Apr 13 03:24:06 2016 +0000 summary: Issue #25496: Document compresslevel defaults to 9, by Hamza T Khan files: Doc/library/tarfile.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst --- a/Doc/library/tarfile.rst +++ b/Doc/library/tarfile.rst @@ -101,7 +101,7 @@ For modes ``'w:gz'``, ``'r:gz'``, ``'w:bz2'``, ``'r:bz2'``, ``'x:gz'``, ``'x:bz2'``, :func:`tarfile.open` accepts the keyword argument - *compresslevel* to specify the compression level of the file. + *compresslevel* (default ``9``) to specify the compression level of the file. For special purposes, there is a second format for *mode*: ``'filemode|[compression]'``. :func:`tarfile.open` will return a :class:`TarFile` -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 13 02:15:52 2016 From: python-checkins at python.org (senthil.kumaran) Date: Wed, 13 Apr 2016 06:15:52 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy41Lg==?= Message-ID: <20160413061552.7543.48667.F57B42D6@psf.io> https://hg.python.org/cpython/rev/ad5b079565ad changeset: 100956:ad5b079565ad parent: 100952:a04455866ec7 parent: 100955:2b35ef6a9853 user: Senthil Kumaran date: Tue Apr 12 23:15:44 2016 -0700 summary: merge 3.5. [minor] - Correct the docstring of locale.str. Patch by poleto. files: Lib/locale.py | 17 ++++++++--------- 1 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Lib/locale.py b/Lib/locale.py --- a/Lib/locale.py +++ b/Lib/locale.py @@ -1,13 +1,12 @@ -""" Locale support. +"""Locale support module. - The module provides low-level access to the C lib's locale APIs - and adds high level number formatting APIs as well as a locale - aliasing engine to complement these. +The module provides low-level access to the C lib's locale APIs and adds high +level number formatting APIs as well as a locale aliasing engine to complement +these. - The aliasing engine includes support for many commonly used locale - names and maps them to values suitable for passing to the C lib's - setlocale() function. It also includes default encodings for all - supported locale names. +The aliasing engine includes support for many commonly used locale names and +maps them to values suitable for passing to the C lib's setlocale() function. It +also includes default encodings for all supported locale names. """ @@ -298,7 +297,7 @@ return s.replace('<', '').replace('>', '') def str(val): - """Convert float to integer, taking the locale into account.""" + """Convert float to string, taking the locale into account.""" return format("%.12g", val) def delocalize(string): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 13 02:15:52 2016 From: python-checkins at python.org (senthil.kumaran) Date: Wed, 13 Apr 2016 06:15:52 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogW21pbm9yXSAtIENv?= =?utf-8?q?rrect_the_docstring_of_locale=2Estr=2E_Patch_by_poleto=2E?= Message-ID: <20160413061552.41613.89302.9BCA0603@psf.io> https://hg.python.org/cpython/rev/2b35ef6a9853 changeset: 100955:2b35ef6a9853 branch: 3.5 parent: 100951:b1f3fe320adf user: Senthil Kumaran date: Tue Apr 12 23:14:14 2016 -0700 summary: [minor] - Correct the docstring of locale.str. Patch by poleto. files: Lib/locale.py | 17 ++++++++--------- 1 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Lib/locale.py b/Lib/locale.py --- a/Lib/locale.py +++ b/Lib/locale.py @@ -1,13 +1,12 @@ -""" Locale support. +"""Locale support module. - The module provides low-level access to the C lib's locale APIs - and adds high level number formatting APIs as well as a locale - aliasing engine to complement these. +The module provides low-level access to the C lib's locale APIs and adds high +level number formatting APIs as well as a locale aliasing engine to complement +these. - The aliasing engine includes support for many commonly used locale - names and maps them to values suitable for passing to the C lib's - setlocale() function. It also includes default encodings for all - supported locale names. +The aliasing engine includes support for many commonly used locale names and +maps them to values suitable for passing to the C lib's setlocale() function. It +also includes default encodings for all supported locale names. """ @@ -298,7 +297,7 @@ return s.replace('<', '').replace('>', '') def str(val): - """Convert float to integer, taking the locale into account.""" + """Convert float to string, taking the locale into account.""" return format("%.12g", val) def delocalize(string): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 13 02:16:02 2016 From: python-checkins at python.org (senthil.kumaran) Date: Wed, 13 Apr 2016 06:16:02 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogW21pbm9yXSAtIENv?= =?utf-8?q?rrect_the_docstring_of_locale=2Estr=2E_Patch_by_poleto=2E?= Message-ID: <20160413061601.30770.69229.51C7B358@psf.io> https://hg.python.org/cpython/rev/125d27d9cf9b changeset: 100957:125d27d9cf9b branch: 2.7 parent: 100954:4b65bee79dab user: Senthil Kumaran date: Tue Apr 12 23:13:33 2016 -0700 summary: [minor] - Correct the docstring of locale.str. Patch by poleto. files: Lib/locale.py | 18 ++++++++---------- 1 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Lib/locale.py b/Lib/locale.py --- a/Lib/locale.py +++ b/Lib/locale.py @@ -1,14 +1,12 @@ -""" Locale support. +"""Locale support module. - The module provides low-level access to the C lib's locale APIs - and adds high level number formatting APIs as well as a locale - aliasing engine to complement these. +The module provides low-level access to the C lib's locale APIs and adds high +level number formatting APIs as well as a locale aliasing engine to complement +these. - The aliasing engine includes support for many commonly used locale - names and maps them to values suitable for passing to the C lib's - setlocale() function. It also includes default encodings for all - supported locale names. - +The aliasing engine includes support for many commonly used locale names and +maps them to values suitable for passing to the C lib's setlocale() function. It +also includes default encodings for all supported locale names. """ import sys @@ -303,7 +301,7 @@ return s.replace('<', '').replace('>', '') def str(val): - """Convert float to integer, taking the locale into account.""" + """Convert float to string, taking the locale into account.""" return format("%.12g", val) def atof(string, func=float): -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Wed Apr 13 05:45:43 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 13 Apr 2016 09:45:43 +0000 Subject: [Python-checkins] Daily reference leaks (a04455866ec7): sum=6 Message-ID: <20160413094541.3713.59493.26F12844@psf.io> results for a04455866ec7 on branch "default" -------------------------------------------- test_collections leaked [2, 0, 0] references, sum=2 test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflog92lfy_', '--timeout', '7200'] From python-checkins at python.org Wed Apr 13 08:29:59 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 13 Apr 2016 12:29:59 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogSXNzdWUgIzI2NzE4OiBzdXBlci5fX2luaXRfXyBubyBsb25nZXIgbGVh?= =?utf-8?q?ks_memory_if_called_multiple_times=2E?= Message-ID: <20160413122958.3966.56322.1DF6E396@psf.io> https://hg.python.org/cpython/rev/55f4c1f8ca6a changeset: 100960:55f4c1f8ca6a parent: 100956:ad5b079565ad parent: 100958:450f36750cb9 user: Serhiy Storchaka date: Wed Apr 13 15:28:53 2016 +0300 summary: Issue #26718: super.__init__ no longer leaks memory if called multiple times. NOTE: A direct call of super.__init__ is not endorsed! files: Lib/test/test_super.py | 9 +++++++++ Misc/NEWS | 3 +++ Objects/typeobject.c | 6 +++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_super.py b/Lib/test/test_super.py --- a/Lib/test/test_super.py +++ b/Lib/test/test_super.py @@ -171,6 +171,15 @@ c = f().__closure__[0] self.assertRaises(TypeError, X.meth, c) + def test_super_init_leaks(self): + # Issue #26718: super.__init__ leaked memory if called multiple times. + # This will be caught by regrtest.py -R if this leak. + # NOTE: Despite the use in the test a direct call of super.__init__ + # is not endorsed. + sp = super(float, 1.0) + for i in range(1000): + super.__init__(sp, int, i) + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #26718: super.__init__ no longer leaks memory if called multiple times. + NOTE: A direct call of super.__init__ is not endorsed! + - Issue #25339: PYTHONIOENCODING now has priority over locale in setting the error handler for stdin and stdout. diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -7350,9 +7350,9 @@ Py_INCREF(obj); } Py_INCREF(type); - su->type = type; - su->obj = obj; - su->obj_type = obj_type; + Py_XSETREF(su->type, type); + Py_XSETREF(su->obj, obj); + Py_XSETREF(su->obj_type, obj_type); return 0; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 13 08:29:59 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 13 Apr 2016 12:29:59 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2NzE4?= =?utf-8?q?=3A_super=2E=5F=5Finit=5F=5F_no_longer_leaks_memory_if_called_m?= =?utf-8?q?ultiple_times=2E?= Message-ID: <20160413122957.42612.88644.88F21E71@psf.io> https://hg.python.org/cpython/rev/4680438f486f changeset: 100959:4680438f486f branch: 2.7 parent: 100957:125d27d9cf9b user: Serhiy Storchaka date: Wed Apr 13 15:27:33 2016 +0300 summary: Issue #26718: super.__init__ no longer leaks memory if called multiple times. NOTE: A direct call of super.__init__ is not endorsed! files: Misc/NEWS | 3 +++ Objects/typeobject.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #26718: super.__init__ no longer leaks memory if called multiple times. + NOTE: A direct call of super.__init__ is not endorsed! + - Issue #13410: Fixed a bug in PyUnicode_Format where it failed to properly ignore errors from a __int__() method. diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -6741,9 +6741,9 @@ Py_INCREF(obj); } Py_INCREF(type); - su->type = type; - su->obj = obj; - su->obj_type = obj_type; + Py_XSETREF(su->type, type); + Py_XSETREF(su->obj, obj); + Py_XSETREF(su->obj_type, obj_type); return 0; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 13 08:31:08 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 13 Apr 2016 12:31:08 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NzE4?= =?utf-8?q?=3A_super=2E=5F=5Finit=5F=5F_no_longer_leaks_memory_if_called_m?= =?utf-8?q?ultiple_times=2E?= Message-ID: <20160413122933.123362.962.D8C9AF2E@psf.io> https://hg.python.org/cpython/rev/450f36750cb9 changeset: 100958:450f36750cb9 branch: 3.5 parent: 100955:2b35ef6a9853 user: Serhiy Storchaka date: Wed Apr 13 15:27:33 2016 +0300 summary: Issue #26718: super.__init__ no longer leaks memory if called multiple times. NOTE: A direct call of super.__init__ is not endorsed! files: Lib/test/test_super.py | 9 +++++++++ Misc/NEWS | 3 +++ Objects/typeobject.c | 6 +++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_super.py b/Lib/test/test_super.py --- a/Lib/test/test_super.py +++ b/Lib/test/test_super.py @@ -171,6 +171,15 @@ c = f().__closure__[0] self.assertRaises(TypeError, X.meth, c) + def test_super_init_leaks(self): + # Issue #26718: super.__init__ leaked memory if called multiple times. + # This will be caught by regrtest.py -R if this leak. + # NOTE: Despite the use in the test a direct call of super.__init__ + # is not endorsed. + sp = super(float, 1.0) + for i in range(1000): + super.__init__(sp, int, i) + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #26718: super.__init__ no longer leaks memory if called multiple times. + NOTE: A direct call of super.__init__ is not endorsed! + - Issue #25339: PYTHONIOENCODING now has priority over locale in setting the error handler for stdin and stdout. diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -7336,9 +7336,9 @@ Py_INCREF(obj); } Py_INCREF(type); - su->type = type; - su->obj = obj; - su->obj_type = obj_type; + Py_XSETREF(su->type, type); + Py_XSETREF(su->obj, obj); + Py_XSETREF(su->obj_type, obj_type); return 0; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 13 08:44:36 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 13 Apr 2016 12:44:36 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326057=3A_Got_rid_?= =?utf-8?q?of_nonneeded_use_of_PyUnicode=5FFromObject=28=29=2E?= Message-ID: <20160413124435.3334.71086.8357AFB3@psf.io> https://hg.python.org/cpython/rev/3f3b3d4881f6 changeset: 100961:3f3b3d4881f6 user: Serhiy Storchaka date: Wed Apr 13 15:37:23 2016 +0300 summary: Issue #26057: Got rid of nonneeded use of PyUnicode_FromObject(). files: Modules/_codecsmodule.c | 231 +------- Modules/socketmodule.c | 44 +- Objects/stringlib/find.h | 13 +- Objects/unicodeobject.c | 658 ++++++++------------------ Python/bltinmodule.c | 5 +- Python/getargs.c | 26 +- 6 files changed, 288 insertions(+), 689 deletions(-) diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -20,10 +20,6 @@ _decode(char_buffer_obj[,errors='strict']) -> (Unicode object, bytes consumed) - _encode() interfaces also accept non-Unicode object as - input. The objects are then converted to Unicode using - PyUnicode_FromObject() prior to applying the conversion. - These s are available: utf_8, unicode_escape, raw_unicode_escape, unicode_internal, latin_1, ascii (7-bit), mbcs (on win32). @@ -718,7 +714,7 @@ /*[clinic input] _codecs.utf_7_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ @@ -728,22 +724,13 @@ const char *errors) /*[clinic end generated code: output=a7accc496a32b759 input=fd91a78f103b0421]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(_PyUnicode_EncodeUTF7(str, 0, 0, errors), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(_PyUnicode_EncodeUTF7(str, 0, 0, errors), + PyUnicode_GET_LENGTH(str)); } /*[clinic input] _codecs.utf_8_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ @@ -753,17 +740,8 @@ const char *errors) /*[clinic end generated code: output=ec831d80e7aedede input=2c22d40532f071f3]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(PyUnicode_AsEncodedString(str, "utf-8", errors), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(_PyUnicode_AsUTF8String(str, errors), + PyUnicode_GET_LENGTH(str)); } /* This version provides access to the byteorder parameter of the @@ -775,7 +753,7 @@ /*[clinic input] _codecs.utf_16_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL byteorder: int = 0 / @@ -786,22 +764,13 @@ const char *errors, int byteorder) /*[clinic end generated code: output=93ac58e960a9ee4d input=3935a489b2d5385e]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, byteorder), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(_PyUnicode_EncodeUTF16(str, errors, byteorder), + PyUnicode_GET_LENGTH(str)); } /*[clinic input] _codecs.utf_16_le_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ @@ -811,22 +780,13 @@ const char *errors) /*[clinic end generated code: output=422bedb8da34fb66 input=bc27df05d1d20dfe]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, -1), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(_PyUnicode_EncodeUTF16(str, errors, -1), + PyUnicode_GET_LENGTH(str)); } /*[clinic input] _codecs.utf_16_be_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ @@ -836,17 +796,8 @@ const char *errors) /*[clinic end generated code: output=3aa7ee9502acdd77 input=5a69d4112763462b]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, +1), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(_PyUnicode_EncodeUTF16(str, errors, +1), + PyUnicode_GET_LENGTH(str)); } /* This version provides access to the byteorder parameter of the @@ -858,7 +809,7 @@ /*[clinic input] _codecs.utf_32_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL byteorder: int = 0 / @@ -869,22 +820,13 @@ const char *errors, int byteorder) /*[clinic end generated code: output=3e7d5a003b02baed input=434a1efa492b8d58]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, byteorder), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(_PyUnicode_EncodeUTF32(str, errors, byteorder), + PyUnicode_GET_LENGTH(str)); } /*[clinic input] _codecs.utf_32_le_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ @@ -894,22 +836,13 @@ const char *errors) /*[clinic end generated code: output=5dda641cd33dbfc2 input=dfa2d7dc78b99422]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, -1), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(_PyUnicode_EncodeUTF32(str, errors, -1), + PyUnicode_GET_LENGTH(str)); } /*[clinic input] _codecs.utf_32_be_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ @@ -919,22 +852,13 @@ const char *errors) /*[clinic end generated code: output=ccca8b44d91a7c7a input=4595617b18169002]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, +1), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(_PyUnicode_EncodeUTF32(str, errors, +1), + PyUnicode_GET_LENGTH(str)); } /*[clinic input] _codecs.unicode_escape_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ @@ -944,22 +868,13 @@ const char *errors) /*[clinic end generated code: output=389f23d2b8f8d80b input=8273506f14076912]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(PyUnicode_AsUnicodeEscapeString(str), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(PyUnicode_AsUnicodeEscapeString(str), + PyUnicode_GET_LENGTH(str)); } /*[clinic input] _codecs.raw_unicode_escape_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ @@ -969,22 +884,13 @@ const char *errors) /*[clinic end generated code: output=fec4e39d6ec37a62 input=181755d5dfacef3c]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(PyUnicode_AsRawUnicodeEscapeString(str), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(PyUnicode_AsRawUnicodeEscapeString(str), + PyUnicode_GET_LENGTH(str)); } /*[clinic input] _codecs.latin_1_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ @@ -994,22 +900,13 @@ const char *errors) /*[clinic end generated code: output=ecf00eb8e48c889c input=f03f6dcf1d84bee4]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(_PyUnicode_AsLatin1String(str, errors), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(_PyUnicode_AsLatin1String(str, errors), + PyUnicode_GET_LENGTH(str)); } /*[clinic input] _codecs.ascii_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ @@ -1019,22 +916,13 @@ const char *errors) /*[clinic end generated code: output=a9d18fc6b6b91cfb input=d87e25a10a593fee]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(_PyUnicode_AsASCIIString(str, errors), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(_PyUnicode_AsASCIIString(str, errors), + PyUnicode_GET_LENGTH(str)); } /*[clinic input] _codecs.charmap_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL mapping: object = NULL / @@ -1045,20 +933,11 @@ const char *errors, PyObject *mapping) /*[clinic end generated code: output=14ca42b83853c643 input=85f4172661e8dad9]*/ { - PyObject *v; - if (mapping == Py_None) mapping = NULL; - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(_PyUnicode_EncodeCharmap(str, mapping, errors), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(_PyUnicode_EncodeCharmap(str, mapping, errors), + PyUnicode_GET_LENGTH(str)); } /*[clinic input] @@ -1078,7 +957,7 @@ /*[clinic input] _codecs.mbcs_encode - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ @@ -1088,23 +967,14 @@ const char *errors) /*[clinic end generated code: output=d1a013bc68798bd7 input=65c09ee1e4203263]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(PyUnicode_EncodeCodePage(CP_ACP, str, errors), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(PyUnicode_EncodeCodePage(CP_ACP, str, errors), + PyUnicode_GET_LENGTH(str)); } /*[clinic input] _codecs.code_page_encode code_page: int - str: object + str: unicode errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ @@ -1114,19 +984,8 @@ PyObject *str, const char *errors) /*[clinic end generated code: output=3b406618dbfbce25 input=c8562ec460c2e309]*/ { - PyObject *v; - - str = PyUnicode_FromObject(str); - if (str == NULL || PyUnicode_READY(str) < 0) { - Py_XDECREF(str); - return NULL; - } - v = codec_tuple(PyUnicode_EncodeCodePage(code_page, - str, - errors), - PyUnicode_GET_LENGTH(str)); - Py_DECREF(str); - return v; + return codec_tuple(PyUnicode_EncodeCodePage(code_page, str, errors), + PyUnicode_GET_LENGTH(str)); } #endif /* HAVE_MBCS */ diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1401,7 +1401,7 @@ idna_converter(PyObject *obj, struct maybe_idna *data) { size_t len; - PyObject *obj2, *obj3; + PyObject *obj2; if (obj == NULL) { idna_cleanup(data); return 1; @@ -1416,31 +1416,27 @@ data->buf = PyByteArray_AsString(obj); len = PyByteArray_Size(obj); } - else if (PyUnicode_Check(obj) && PyUnicode_READY(obj) == 0 && PyUnicode_IS_COMPACT_ASCII(obj)) { - data->buf = PyUnicode_DATA(obj); - len = PyUnicode_GET_LENGTH(obj); + else if (PyUnicode_Check(obj)) { + if (PyUnicode_READY(obj) == 0 && PyUnicode_IS_COMPACT_ASCII(obj)) { + data->buf = PyUnicode_DATA(obj); + len = PyUnicode_GET_LENGTH(obj); + } + else { + obj2 = PyUnicode_AsEncodedString(obj, "idna", NULL); + if (!obj2) { + PyErr_SetString(PyExc_TypeError, "encoding of hostname failed"); + return 0; + } + assert(PyBytes_Check(obj2)); + data->obj = obj2; + data->buf = PyBytes_AS_STRING(obj2); + len = PyBytes_GET_SIZE(obj2); + } } else { - obj2 = PyUnicode_FromObject(obj); - if (!obj2) { - PyErr_Format(PyExc_TypeError, "string or unicode text buffer expected, not %s", - obj->ob_type->tp_name); - return 0; - } - obj3 = PyUnicode_AsEncodedString(obj2, "idna", NULL); - Py_DECREF(obj2); - if (!obj3) { - PyErr_SetString(PyExc_TypeError, "encoding of hostname failed"); - return 0; - } - if (!PyBytes_Check(obj3)) { - Py_DECREF(obj3); - PyErr_SetString(PyExc_TypeError, "encoding of hostname failed to return bytes"); - return 0; - } - data->obj = obj3; - data->buf = PyBytes_AS_STRING(obj3); - len = PyBytes_GET_SIZE(obj3); + PyErr_Format(PyExc_TypeError, "str, bytes or bytearray expected, not %s", + obj->ob_type->tp_name); + return 0; } if (strlen(data->buf) != len) { Py_CLEAR(data->obj); diff --git a/Objects/stringlib/find.h b/Objects/stringlib/find.h --- a/Objects/stringlib/find.h +++ b/Objects/stringlib/find.h @@ -123,11 +123,6 @@ /* Wraps stringlib_parse_args_finds() and additionally ensures that the first argument is a unicode object. - -Note that we receive a pointer to the pointer of the substring object, -so when we create that object in this function we don't DECREF it, -because it continues living in the caller functions (those functions, -after finishing using the substring, must DECREF it). */ Py_LOCAL_INLINE(int) @@ -135,14 +130,10 @@ PyObject **substring, Py_ssize_t *start, Py_ssize_t *end) { - PyObject *tmp_substring; - - if(STRINGLIB(parse_args_finds)(function_name, args, &tmp_substring, + if(STRINGLIB(parse_args_finds)(function_name, args, substring, start, end)) { - tmp_substring = PyUnicode_FromObject(tmp_substring); - if (!tmp_substring) + if (ensure_unicode(*substring) < 0) return 0; - *substring = tmp_substring; return 1; } return 0; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -751,6 +751,18 @@ #undef BLOOM_UPDATE } +static int +ensure_unicode(PyObject *obj) +{ + if (!PyUnicode_Check(obj)) { + PyErr_Format(PyExc_TypeError, + "must be str, not %.100s", + Py_TYPE(obj)->tp_name); + return -1; + } + return PyUnicode_READY(obj); +} + /* Compilation of templated routines */ #include "stringlib/asciilib.h" @@ -3066,7 +3078,7 @@ /* Retrieve a bytes buffer view through the PEP 3118 buffer interface */ if (PyObject_GetBuffer(obj, &buffer, PyBUF_SIMPLE) < 0) { PyErr_Format(PyExc_TypeError, - "coercing to str: need a bytes-like object, %.80s found", + "decoding to str: need a bytes-like object, %.80s found", Py_TYPE(obj)->tp_name); return NULL; } @@ -3787,19 +3799,17 @@ output = arg; Py_INCREF(output); } - else { - arg = PyUnicode_FromObject(arg); - if (!arg) - return 0; + else if (PyUnicode_Check(arg)) { output = PyUnicode_EncodeFSDefault(arg); - Py_DECREF(arg); if (!output) return 0; - if (!PyBytes_Check(output)) { - Py_DECREF(output); - PyErr_SetString(PyExc_TypeError, "encoder failed to return bytes"); - return 0; - } + assert(PyBytes_Check(output)); + } + else { + PyErr_Format(PyExc_TypeError, + "must be str or bytes, not %.100s", + Py_TYPE(arg)->tp_name); + return 0; } size = PyBytes_GET_SIZE(output); data = PyBytes_AS_STRING(output); @@ -3871,7 +3881,7 @@ if (PyUnicode_UTF8(unicode) == NULL) { assert(!PyUnicode_IS_COMPACT_ASCII(unicode)); - bytes = _PyUnicode_AsUTF8String(unicode, "strict"); + bytes = _PyUnicode_AsUTF8String(unicode, NULL); if (bytes == NULL) return NULL; _PyUnicode_UTF8(unicode) = PyObject_MALLOC(PyBytes_GET_SIZE(bytes) + 1); @@ -8860,10 +8870,8 @@ kind = PyUnicode_KIND(input); size = PyUnicode_GET_LENGTH(input); - if (size == 0) { - Py_INCREF(input); - return input; - } + if (size == 0) + return PyUnicode_FromObject(input); /* allocate enough for a simple 1:1 translation without replacements, if we need more, we'll resize */ @@ -8974,14 +8982,9 @@ PyObject *mapping, const char *errors) { - PyObject *result; - - str = PyUnicode_FromObject(str); - if (str == NULL) - return NULL; - result = _PyUnicode_TranslateCharmap(str, mapping, errors); - Py_DECREF(str); - return result; + if (ensure_unicode(str) < 0) + return NULL; + return _PyUnicode_TranslateCharmap(str, mapping, errors); } static Py_UCS4 @@ -9163,9 +9166,10 @@ } static Py_ssize_t -any_find_slice(int direction, PyObject* s1, PyObject* s2, +any_find_slice(PyObject* s1, PyObject* s2, Py_ssize_t start, - Py_ssize_t end) + Py_ssize_t end, + int direction) { int kind1, kind2; void *buf1, *buf2; @@ -9334,54 +9338,35 @@ Py_ssize_t end) { Py_ssize_t result; - PyObject* str_obj; - PyObject* sub_obj; int kind1, kind2; void *buf1 = NULL, *buf2 = NULL; Py_ssize_t len1, len2; - str_obj = PyUnicode_FromObject(str); - if (!str_obj) - return -1; - sub_obj = PyUnicode_FromObject(substr); - if (!sub_obj) { - Py_DECREF(str_obj); - return -1; - } - if (PyUnicode_READY(sub_obj) == -1 || PyUnicode_READY(str_obj) == -1) { - Py_DECREF(sub_obj); - Py_DECREF(str_obj); - return -1; - } - - kind1 = PyUnicode_KIND(str_obj); - kind2 = PyUnicode_KIND(sub_obj); - if (kind1 < kind2) { - Py_DECREF(sub_obj); - Py_DECREF(str_obj); + if (ensure_unicode(str) < 0 || ensure_unicode(substr) < 0) + return -1; + + kind1 = PyUnicode_KIND(str); + kind2 = PyUnicode_KIND(substr); + if (kind1 < kind2) return 0; - } - - len1 = PyUnicode_GET_LENGTH(str_obj); - len2 = PyUnicode_GET_LENGTH(sub_obj); + + len1 = PyUnicode_GET_LENGTH(str); + len2 = PyUnicode_GET_LENGTH(substr); ADJUST_INDICES(start, end, len1); - if (end - start < len2) { - Py_DECREF(sub_obj); - Py_DECREF(str_obj); + if (end - start < len2) return 0; - } - - buf1 = PyUnicode_DATA(str_obj); - buf2 = PyUnicode_DATA(sub_obj); + + buf1 = PyUnicode_DATA(str); + buf2 = PyUnicode_DATA(substr); if (kind2 != kind1) { - buf2 = _PyUnicode_AsKind(sub_obj, kind1); + buf2 = _PyUnicode_AsKind(substr, kind1); if (!buf2) goto onError; } switch (kind1) { case PyUnicode_1BYTE_KIND: - if (PyUnicode_IS_ASCII(str_obj) && PyUnicode_IS_ASCII(sub_obj)) + if (PyUnicode_IS_ASCII(str) && PyUnicode_IS_ASCII(substr)) result = asciilib_count( ((Py_UCS1*)buf1) + start, end - start, buf2, len2, PY_SSIZE_T_MAX @@ -9408,16 +9393,11 @@ assert(0); result = 0; } - Py_DECREF(sub_obj); - Py_DECREF(str_obj); - if (kind2 != kind1) PyMem_Free(buf2); return result; onError: - Py_DECREF(sub_obj); - Py_DECREF(str_obj); if (kind2 != kind1 && buf2) PyMem_Free(buf2); return -1; @@ -9425,35 +9405,15 @@ Py_ssize_t PyUnicode_Find(PyObject *str, - PyObject *sub, + PyObject *substr, Py_ssize_t start, Py_ssize_t end, int direction) { - Py_ssize_t result; - - str = PyUnicode_FromObject(str); - if (!str) + if (ensure_unicode(str) < 0 || ensure_unicode(substr) < 0) return -2; - sub = PyUnicode_FromObject(sub); - if (!sub) { - Py_DECREF(str); - return -2; - } - if (PyUnicode_READY(sub) == -1 || PyUnicode_READY(str) == -1) { - Py_DECREF(sub); - Py_DECREF(str); - return -2; - } - - result = any_find_slice(direction, - str, sub, start, end - ); - - Py_DECREF(str); - Py_DECREF(sub); - - return result; + + return any_find_slice(str, substr, start, end, direction); } Py_ssize_t @@ -9556,22 +9516,10 @@ Py_ssize_t end, int direction) { - Py_ssize_t result; - - str = PyUnicode_FromObject(str); - if (str == NULL) - return -1; - substr = PyUnicode_FromObject(substr); - if (substr == NULL) { - Py_DECREF(str); - return -1; - } - - result = tailmatch(str, substr, - start, end, direction); - Py_DECREF(str); - Py_DECREF(substr); - return result; + if (ensure_unicode(str) < 0 || ensure_unicode(substr) < 0) + return -1; + + return tailmatch(str, substr, start, end, direction); } /* Apply fixfct filter to the Unicode object self and return a @@ -10177,13 +10125,8 @@ { PyObject *list; - string = PyUnicode_FromObject(string); - if (string == NULL) - return NULL; - if (PyUnicode_READY(string) == -1) { - Py_DECREF(string); - return NULL; - } + if (ensure_unicode(string) < 0) + return NULL; switch (PyUnicode_KIND(string)) { case PyUnicode_1BYTE_KIND: @@ -10210,7 +10153,6 @@ assert(0); list = 0; } - Py_DECREF(string); return list; } @@ -10771,28 +10713,27 @@ } -/* Argument converter. Coerces to a single unicode character */ +/* Argument converter. Accepts a single Unicode character. */ static int convert_uc(PyObject *obj, void *addr) { Py_UCS4 *fillcharloc = (Py_UCS4 *)addr; - PyObject *uniobj; - - uniobj = PyUnicode_FromObject(obj); - if (uniobj == NULL) { - PyErr_SetString(PyExc_TypeError, - "The fill character cannot be converted to Unicode"); + + if (!PyUnicode_Check(obj)) { + PyErr_Format(PyExc_TypeError, + "The fill character must be a unicode character, " + "not %.100s", Py_TYPE(obj)->tp_name); return 0; } - if (PyUnicode_GET_LENGTH(uniobj) != 1) { + if (PyUnicode_READY(obj) < 0) + return 0; + if (PyUnicode_GET_LENGTH(obj) != 1) { PyErr_SetString(PyExc_TypeError, "The fill character must be exactly one character long"); - Py_DECREF(uniobj); return 0; } - *fillcharloc = PyUnicode_READ_CHAR(uniobj, 0); - Py_DECREF(uniobj); + *fillcharloc = PyUnicode_READ_CHAR(obj, 0); return 1; } @@ -11114,59 +11055,43 @@ } int -PyUnicode_Contains(PyObject *container, PyObject *element) -{ - PyObject *str, *sub; +PyUnicode_Contains(PyObject *str, PyObject *substr) +{ int kind1, kind2; void *buf1, *buf2; Py_ssize_t len1, len2; int result; - /* Coerce the two arguments */ - sub = PyUnicode_FromObject(element); - if (!sub) { + if (!PyUnicode_Check(substr)) { PyErr_Format(PyExc_TypeError, - "'in ' requires string as left operand, not %s", - element->ob_type->tp_name); - return -1; - } - - str = PyUnicode_FromObject(container); - if (!str) { - Py_DECREF(sub); - return -1; - } + "'in ' requires string as left operand, not %.100s", + Py_TYPE(substr)->tp_name); + return -1; + } + if (PyUnicode_READY(substr) == -1) + return -1; + if (ensure_unicode(str) < 0) + return -1; kind1 = PyUnicode_KIND(str); - kind2 = PyUnicode_KIND(sub); - if (kind1 < kind2) { - Py_DECREF(sub); - Py_DECREF(str); + kind2 = PyUnicode_KIND(substr); + if (kind1 < kind2) return 0; - } len1 = PyUnicode_GET_LENGTH(str); - len2 = PyUnicode_GET_LENGTH(sub); - if (len1 < len2) { - Py_DECREF(sub); - Py_DECREF(str); + len2 = PyUnicode_GET_LENGTH(substr); + if (len1 < len2) return 0; - } buf1 = PyUnicode_DATA(str); - buf2 = PyUnicode_DATA(sub); + buf2 = PyUnicode_DATA(substr); if (len2 == 1) { Py_UCS4 ch = PyUnicode_READ(kind2, buf2, 0); result = findchar((const char *)buf1, kind1, len1, ch, 1) != -1; - Py_DECREF(sub); - Py_DECREF(str); return result; } if (kind2 != kind1) { - buf2 = _PyUnicode_AsKind(sub, kind1); - if (!buf2) { - Py_DECREF(sub); - Py_DECREF(str); + buf2 = _PyUnicode_AsKind(substr, kind1); + if (!buf2) return -1; - } } switch (kind1) { @@ -11184,9 +11109,6 @@ assert(0); } - Py_DECREF(str); - Py_DECREF(sub); - if (kind2 != kind1) PyMem_Free(buf2); @@ -11198,56 +11120,40 @@ PyObject * PyUnicode_Concat(PyObject *left, PyObject *right) { - PyObject *u = NULL, *v = NULL, *w; + PyObject *result; Py_UCS4 maxchar, maxchar2; - Py_ssize_t u_len, v_len, new_len; - - /* Coerce the two arguments */ - u = PyUnicode_FromObject(left); - if (u == NULL) - goto onError; - v = PyUnicode_FromObject(right); - if (v == NULL) - goto onError; + Py_ssize_t left_len, right_len, new_len; + + if (ensure_unicode(left) < 0 || ensure_unicode(right) < 0) + return NULL; /* Shortcuts */ - if (v == unicode_empty) { - Py_DECREF(v); - return u; - } - if (u == unicode_empty) { - Py_DECREF(u); - return v; - } - - u_len = PyUnicode_GET_LENGTH(u); - v_len = PyUnicode_GET_LENGTH(v); - if (u_len > PY_SSIZE_T_MAX - v_len) { + if (left == unicode_empty) + return PyUnicode_FromObject(right); + if (right == unicode_empty) + return PyUnicode_FromObject(left); + + left_len = PyUnicode_GET_LENGTH(left); + right_len = PyUnicode_GET_LENGTH(right); + if (left_len > PY_SSIZE_T_MAX - right_len) { PyErr_SetString(PyExc_OverflowError, "strings are too large to concat"); - goto onError; - } - new_len = u_len + v_len; - - maxchar = PyUnicode_MAX_CHAR_VALUE(u); - maxchar2 = PyUnicode_MAX_CHAR_VALUE(v); + return NULL; + } + new_len = left_len + right_len; + + maxchar = PyUnicode_MAX_CHAR_VALUE(left); + maxchar2 = PyUnicode_MAX_CHAR_VALUE(right); maxchar = Py_MAX(maxchar, maxchar2); /* Concat the two Unicode strings */ - w = PyUnicode_New(new_len, maxchar); - if (w == NULL) - goto onError; - _PyUnicode_FastCopyCharacters(w, 0, u, 0, u_len); - _PyUnicode_FastCopyCharacters(w, u_len, v, 0, v_len); - Py_DECREF(u); - Py_DECREF(v); - assert(_PyUnicode_CheckConsistency(w, 1)); - return w; - - onError: - Py_XDECREF(u); - Py_XDECREF(v); - return NULL; + result = PyUnicode_New(new_len, maxchar); + if (result == NULL) + return NULL; + _PyUnicode_FastCopyCharacters(result, 0, left, 0, left_len); + _PyUnicode_FastCopyCharacters(result, left_len, right, 0, right_len); + assert(_PyUnicode_CheckConsistency(result, 1)); + return result; } void @@ -11362,25 +11268,21 @@ kind1 = PyUnicode_KIND(self); kind2 = PyUnicode_KIND(substring); - if (kind1 < kind2) { - Py_DECREF(substring); + if (kind1 < kind2) return PyLong_FromLong(0); - } + len1 = PyUnicode_GET_LENGTH(self); len2 = PyUnicode_GET_LENGTH(substring); ADJUST_INDICES(start, end, len1); - if (end - start < len2) { - Py_DECREF(substring); + if (end - start < len2) return PyLong_FromLong(0); - } + buf1 = PyUnicode_DATA(self); buf2 = PyUnicode_DATA(substring); if (kind2 != kind1) { buf2 = _PyUnicode_AsKind(substring, kind1); - if (!buf2) { - Py_DECREF(substring); + if (!buf2) return NULL; - } } switch (kind1) { case PyUnicode_1BYTE_KIND: @@ -11410,8 +11312,6 @@ if (kind2 != kind1) PyMem_Free(buf2); - Py_DECREF(substring); - return result; } @@ -11549,18 +11449,10 @@ &start, &end)) return NULL; - if (PyUnicode_READY(self) == -1) { - Py_DECREF(substring); - return NULL; - } - if (PyUnicode_READY(substring) == -1) { - Py_DECREF(substring); - return NULL; - } - - result = any_find_slice(1, self, substring, start, end); - - Py_DECREF(substring); + if (PyUnicode_READY(self) == -1) + return NULL; + + result = any_find_slice(self, substring, start, end, 1); if (result == -2) return NULL; @@ -11637,18 +11529,10 @@ &start, &end)) return NULL; - if (PyUnicode_READY(self) == -1) { - Py_DECREF(substring); - return NULL; - } - if (PyUnicode_READY(substring) == -1) { - Py_DECREF(substring); - return NULL; - } - - result = any_find_slice(1, self, substring, start, end); - - Py_DECREF(substring); + if (PyUnicode_READY(self) == -1) + return NULL; + + result = any_find_slice(self, substring, start, end, 1); if (result == -2) return NULL; @@ -12457,40 +12341,15 @@ } PyObject * -PyUnicode_Replace(PyObject *obj, - PyObject *subobj, - PyObject *replobj, +PyUnicode_Replace(PyObject *str, + PyObject *substr, + PyObject *replstr, Py_ssize_t maxcount) { - PyObject *self; - PyObject *str1; - PyObject *str2; - PyObject *result; - - self = PyUnicode_FromObject(obj); - if (self == NULL) - return NULL; - str1 = PyUnicode_FromObject(subobj); - if (str1 == NULL) { - Py_DECREF(self); - return NULL; - } - str2 = PyUnicode_FromObject(replobj); - if (str2 == NULL) { - Py_DECREF(self); - Py_DECREF(str1); - return NULL; - } - if (PyUnicode_READY(self) == -1 || - PyUnicode_READY(str1) == -1 || - PyUnicode_READY(str2) == -1) - result = NULL; - else - result = replace(self, str1, str2, maxcount); - Py_DECREF(self); - Py_DECREF(str1); - Py_DECREF(str2); - return result; + if (ensure_unicode(str) < 0 || ensure_unicode(substr) < 0 || + ensure_unicode(replstr) < 0) + return NULL; + return replace(str, substr, replstr, maxcount); } PyDoc_STRVAR(replace__doc__, @@ -12506,28 +12365,12 @@ PyObject *str1; PyObject *str2; Py_ssize_t maxcount = -1; - PyObject *result; - - if (!PyArg_ParseTuple(args, "OO|n:replace", &str1, &str2, &maxcount)) + + if (!PyArg_ParseTuple(args, "UU|n:replace", &str1, &str2, &maxcount)) return NULL; if (PyUnicode_READY(self) == -1) return NULL; - str1 = PyUnicode_FromObject(str1); - if (str1 == NULL) - return NULL; - str2 = PyUnicode_FromObject(str2); - if (str2 == NULL) { - Py_DECREF(str1); - return NULL; - } - if (PyUnicode_READY(str1) == -1 || PyUnicode_READY(str2) == -1) - result = NULL; - else - result = replace(self, str1, str2, maxcount); - - Py_DECREF(str1); - Py_DECREF(str2); - return result; + return replace(self, str1, str2, maxcount); } static PyObject * @@ -12716,18 +12559,10 @@ &start, &end)) return NULL; - if (PyUnicode_READY(self) == -1) { - Py_DECREF(substring); - return NULL; - } - if (PyUnicode_READY(substring) == -1) { - Py_DECREF(substring); - return NULL; - } - - result = any_find_slice(-1, self, substring, start, end); - - Py_DECREF(substring); + if (PyUnicode_READY(self) == -1) + return NULL; + + result = any_find_slice(self, substring, start, end, -1); if (result == -2) return NULL; @@ -12753,18 +12588,10 @@ &start, &end)) return NULL; - if (PyUnicode_READY(self) == -1) { - Py_DECREF(substring); - return NULL; - } - if (PyUnicode_READY(substring) == -1) { - Py_DECREF(substring); - return NULL; - } - - result = any_find_slice(-1, self, substring, start, end); - - Py_DECREF(substring); + if (PyUnicode_READY(self) == -1) + return NULL; + + result = any_find_slice(self, substring, start, end, -1); if (result == -2) return NULL; @@ -12804,24 +12631,10 @@ PyObject * PyUnicode_Split(PyObject *s, PyObject *sep, Py_ssize_t maxsplit) { - PyObject *result; - - s = PyUnicode_FromObject(s); - if (s == NULL) - return NULL; - if (sep != NULL) { - sep = PyUnicode_FromObject(sep); - if (sep == NULL) { - Py_DECREF(s); - return NULL; - } - } - - result = split(s, sep, maxsplit); - - Py_DECREF(s); - Py_XDECREF(sep); - return result; + if (ensure_unicode(s) < 0 || (sep != NULL && ensure_unicode(sep) < 0)) + return NULL; + + return split(s, sep, maxsplit); } PyDoc_STRVAR(split__doc__, @@ -12846,35 +12659,26 @@ if (substring == Py_None) return split(self, NULL, maxcount); - else if (PyUnicode_Check(substring)) + + if (PyUnicode_Check(substring)) return split(self, substring, maxcount); - else - return PyUnicode_Split(self, substring, maxcount); -} - -PyObject * -PyUnicode_Partition(PyObject *str_in, PyObject *sep_in) -{ - PyObject* str_obj; - PyObject* sep_obj; + + PyErr_Format(PyExc_TypeError, + "must be str or None, not %.100s", + Py_TYPE(substring)->tp_name); + return NULL; +} + +PyObject * +PyUnicode_Partition(PyObject *str_obj, PyObject *sep_obj) +{ PyObject* out; int kind1, kind2; void *buf1, *buf2; Py_ssize_t len1, len2; - str_obj = PyUnicode_FromObject(str_in); - if (!str_obj) - return NULL; - sep_obj = PyUnicode_FromObject(sep_in); - if (!sep_obj) { - Py_DECREF(str_obj); - return NULL; - } - if (PyUnicode_READY(sep_obj) == -1 || PyUnicode_READY(str_obj) == -1) { - Py_DECREF(sep_obj); - Py_DECREF(str_obj); - return NULL; - } + if (ensure_unicode(str_obj) < 0 || ensure_unicode(sep_obj) < 0) + return NULL; kind1 = PyUnicode_KIND(str_obj); kind2 = PyUnicode_KIND(sep_obj); @@ -12888,8 +12692,6 @@ out = PyTuple_Pack(3, str_obj, unicode_empty, unicode_empty); Py_DECREF(unicode_empty); } - Py_DECREF(sep_obj); - Py_DECREF(str_obj); return out; } buf1 = PyUnicode_DATA(str_obj); @@ -12897,7 +12699,7 @@ if (kind2 != kind1) { buf2 = _PyUnicode_AsKind(sep_obj, kind1); if (!buf2) - goto onError; + return NULL; } switch (kind1) { @@ -12918,39 +12720,23 @@ out = 0; } - Py_DECREF(sep_obj); - Py_DECREF(str_obj); if (kind2 != kind1) PyMem_Free(buf2); return out; - onError: - Py_DECREF(sep_obj); - Py_DECREF(str_obj); - if (kind2 != kind1 && buf2) - PyMem_Free(buf2); - return NULL; -} - - -PyObject * -PyUnicode_RPartition(PyObject *str_in, PyObject *sep_in) -{ - PyObject* str_obj; - PyObject* sep_obj; +} + + +PyObject * +PyUnicode_RPartition(PyObject *str_obj, PyObject *sep_obj) +{ PyObject* out; int kind1, kind2; void *buf1, *buf2; Py_ssize_t len1, len2; - str_obj = PyUnicode_FromObject(str_in); - if (!str_obj) - return NULL; - sep_obj = PyUnicode_FromObject(sep_in); - if (!sep_obj) { - Py_DECREF(str_obj); - return NULL; - } + if (ensure_unicode(str_obj) < 0 || ensure_unicode(sep_obj) < 0) + return NULL; kind1 = PyUnicode_KIND(str_obj); kind2 = PyUnicode_KIND(sep_obj); @@ -12964,8 +12750,6 @@ out = PyTuple_Pack(3, unicode_empty, unicode_empty, str_obj); Py_DECREF(unicode_empty); } - Py_DECREF(sep_obj); - Py_DECREF(str_obj); return out; } buf1 = PyUnicode_DATA(str_obj); @@ -12973,7 +12757,7 @@ if (kind2 != kind1) { buf2 = _PyUnicode_AsKind(sep_obj, kind1); if (!buf2) - goto onError; + return NULL; } switch (kind1) { @@ -12994,18 +12778,10 @@ out = 0; } - Py_DECREF(sep_obj); - Py_DECREF(str_obj); if (kind2 != kind1) PyMem_Free(buf2); return out; - onError: - Py_DECREF(sep_obj); - Py_DECREF(str_obj); - if (kind2 != kind1 && buf2) - PyMem_Free(buf2); - return NULL; } PyDoc_STRVAR(partition__doc__, @@ -13037,24 +12813,10 @@ PyObject * PyUnicode_RSplit(PyObject *s, PyObject *sep, Py_ssize_t maxsplit) { - PyObject *result; - - s = PyUnicode_FromObject(s); - if (s == NULL) - return NULL; - if (sep != NULL) { - sep = PyUnicode_FromObject(sep); - if (sep == NULL) { - Py_DECREF(s); - return NULL; - } - } - - result = rsplit(s, sep, maxsplit); - - Py_DECREF(s); - Py_XDECREF(sep); - return result; + if (ensure_unicode(s) < 0 || (sep != NULL && ensure_unicode(sep) < 0)) + return NULL; + + return rsplit(s, sep, maxsplit); } PyDoc_STRVAR(rsplit__doc__, @@ -13079,10 +12841,14 @@ if (substring == Py_None) return rsplit(self, NULL, maxcount); - else if (PyUnicode_Check(substring)) + + if (PyUnicode_Check(substring)) return rsplit(self, substring, maxcount); - else - return PyUnicode_RSplit(self, substring, maxcount); + + PyErr_Format(PyExc_TypeError, + "must be str or None, not %.100s", + Py_TYPE(substring)->tp_name); + return NULL; } PyDoc_STRVAR(splitlines__doc__, @@ -13363,11 +13129,15 @@ if (PyTuple_Check(subobj)) { Py_ssize_t i; for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { - substring = PyUnicode_FromObject(PyTuple_GET_ITEM(subobj, i)); - if (substring == NULL) + substring = PyTuple_GET_ITEM(subobj, i); + if (!PyUnicode_Check(substring)) { + PyErr_Format(PyExc_TypeError, + "tuple for startswith must only contain str, " + "not %.100s", + Py_TYPE(substring)->tp_name); return NULL; + } result = tailmatch(self, substring, start, end, -1); - Py_DECREF(substring); if (result == -1) return NULL; if (result) { @@ -13377,15 +13147,13 @@ /* nothing matched */ Py_RETURN_FALSE; } - substring = PyUnicode_FromObject(subobj); - if (substring == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) - PyErr_Format(PyExc_TypeError, "startswith first arg must be str or " - "a tuple of str, not %s", Py_TYPE(subobj)->tp_name); - return NULL; - } - result = tailmatch(self, substring, start, end, -1); - Py_DECREF(substring); + if (!PyUnicode_Check(subobj)) { + PyErr_Format(PyExc_TypeError, + "startswith first arg must be str or " + "a tuple of str, not %.100s", Py_TYPE(subobj)->tp_name); + return NULL; + } + result = tailmatch(self, subobj, start, end, -1); if (result == -1) return NULL; return PyBool_FromLong(result); @@ -13415,12 +13183,15 @@ if (PyTuple_Check(subobj)) { Py_ssize_t i; for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { - substring = PyUnicode_FromObject( - PyTuple_GET_ITEM(subobj, i)); - if (substring == NULL) + substring = PyTuple_GET_ITEM(subobj, i); + if (!PyUnicode_Check(substring)) { + PyErr_Format(PyExc_TypeError, + "tuple for endswith must only contain str, " + "not %.100s", + Py_TYPE(substring)->tp_name); return NULL; + } result = tailmatch(self, substring, start, end, +1); - Py_DECREF(substring); if (result == -1) return NULL; if (result) { @@ -13429,15 +13200,13 @@ } Py_RETURN_FALSE; } - substring = PyUnicode_FromObject(subobj); - if (substring == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) - PyErr_Format(PyExc_TypeError, "endswith first arg must be str or " - "a tuple of str, not %s", Py_TYPE(subobj)->tp_name); - return NULL; - } - result = tailmatch(self, substring, start, end, +1); - Py_DECREF(substring); + if (!PyUnicode_Check(subobj)) { + PyErr_Format(PyExc_TypeError, + "endswith first arg must be str or " + "a tuple of str, not %.100s", Py_TYPE(subobj)->tp_name); + return NULL; + } + result = tailmatch(self, subobj, start, end, +1); if (result == -1) return NULL; return PyBool_FromLong(result); @@ -14907,13 +14676,10 @@ return NULL; } - ctx.fmtstr = PyUnicode_FromObject(format); - if (ctx.fmtstr == NULL) - return NULL; - if (PyUnicode_READY(ctx.fmtstr) == -1) { - Py_DECREF(ctx.fmtstr); - return NULL; - } + if (ensure_unicode(format) < 0) + return NULL; + + ctx.fmtstr = format; ctx.fmtdata = PyUnicode_DATA(ctx.fmtstr); ctx.fmtkind = PyUnicode_KIND(ctx.fmtstr); ctx.fmtcnt = PyUnicode_GET_LENGTH(ctx.fmtstr); @@ -14973,11 +14739,9 @@ if (ctx.args_owned) { Py_DECREF(ctx.args); } - Py_DECREF(ctx.fmtstr); return _PyUnicodeWriter_Finish(&ctx.writer); onError: - Py_DECREF(ctx.fmtstr); _PyUnicodeWriter_Dealloc(&ctx.writer); if (ctx.args_owned) { Py_DECREF(ctx.args); diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1931,9 +1931,8 @@ Py_CLEAR(stringpo); if (po == NULL) goto _readline_errors; - promptstr = PyBytes_AsString(po); - if (promptstr == NULL) - goto _readline_errors; + assert(PyBytes_Check(po)); + promptstr = PyBytes_AS_STRING(po); } else { po = NULL; diff --git a/Python/getargs.c b/Python/getargs.c --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1056,35 +1056,25 @@ return converterr("(AsCharBuffer failed)", arg, msgbuf, bufsize); } - else { - PyObject *u; - - /* Convert object to Unicode */ - u = PyUnicode_FromObject(arg); - if (u == NULL) - return converterr( - "string or unicode or text buffer", - arg, msgbuf, bufsize); - + else if (PyUnicode_Check(arg)) { /* Encode object; use default error handling */ - s = PyUnicode_AsEncodedString(u, + s = PyUnicode_AsEncodedString(arg, encoding, NULL); - Py_DECREF(u); if (s == NULL) return converterr("(encoding failed)", arg, msgbuf, bufsize); - if (!PyBytes_Check(s)) { - Py_DECREF(s); - return converterr( - "(encoder failed to return bytes)", - arg, msgbuf, bufsize); - } + assert(PyBytes_Check(s)); size = PyBytes_GET_SIZE(s); ptr = PyBytes_AS_STRING(s); if (ptr == NULL) ptr = ""; } + else { + return converterr( + recode_strings ? "str" : "str, bytes or bytearray", + arg, msgbuf, bufsize); + } /* Write output; output is guaranteed to be 0-terminated */ if (*format == '#') { -- Repository URL: https://hg.python.org/cpython From lp_benchmark_robot at intel.com Wed Apr 13 10:20:22 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Wed, 13 Apr 2016 15:20:22 +0100 Subject: [Python-checkins] GOOD Benchmark Results for Python 2.7 2016-04-13 Message-ID: <5304338e-10d5-4ee4-8eeb-a571c39ac8b7@irsmsx103.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-13 03:00:48 +0000 commit: c2f57f959c05 previous commit: 61c7deea9e6a revision date: 2016-04-12 05:51:41 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.22% 0.90% 5.11% 6.54% :-) pybench 0.12% -0.03% 6.37% 4.56% :-( regex_v8 0.80% -0.02% -2.95% 10.99% :-) nbody 0.08% 1.05% 9.40% 2.50% :-) json_dump_v2 0.14% -0.08% 3.62% 13.38% :-( normal_startup 1.87% 0.21% -5.48% 2.18% :-) ssbench 0.18% -0.08% 2.73% 0.75% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/good-benchmark-results-for-python-2-7-2016-04-13/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Wed Apr 13 10:15:22 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Wed, 13 Apr 2016 15:15:22 +0100 Subject: [Python-checkins] GOOD Benchmark Results for Python Default 2016-04-13 Message-ID: Results for project Python default, build date 2016-04-13 02:09:07 +0000 commit: 7b0fd592cd08 previous commit: e3c9a47a83fb revision date: 2016-04-12 20:38:22 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.22% 1.76% 9.84% 17.02% :-| pybench 0.14% -0.15% 0.66% 5.00% :-( regex_v8 2.64% 0.04% -4.11% 5.77% :-| nbody 0.09% 0.02% -1.71% 8.90% :-( json_dump_v2 0.21% -0.38% -2.67% 11.21% :-| normal_startup 0.90% 0.09% 0.19% 5.33% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/good-benchmark-results-for-python-default-2016-04-13/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Thu Apr 14 03:04:12 2016 From: python-checkins at python.org (ethan.furman) Date: Thu, 14 Apr 2016 07:04:12 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue26748=3A_Enum_classes_should_evaluate_as_True?= Message-ID: <20160414070411.8338.96241.39E19855@psf.io> https://hg.python.org/cpython/rev/2fc61f8ee2d2 changeset: 100964:2fc61f8ee2d2 parent: 100961:3f3b3d4881f6 parent: 100963:f840608f79da user: Ethan Furman date: Wed Apr 13 23:55:40 2016 -0700 summary: Issue26748: Enum classes should evaluate as True files: Lib/enum.py | 6 ++++++ Lib/test/test_enum.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-) diff --git a/Lib/enum.py b/Lib/enum.py --- a/Lib/enum.py +++ b/Lib/enum.py @@ -212,6 +212,12 @@ enum_class.__new__ = Enum.__new__ return enum_class + def __bool__(self): + """ + classes/types should always be True. + """ + return True + def __call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1): """Either returns an existing member, or creates a new enum class. diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -254,6 +254,19 @@ with self.assertRaises(AttributeError): del Season.SPRING.name + def test_bool_of_class(self): + class Empty(Enum): + pass + self.assertTrue(bool(Empty)) + + def test_bool_of_member(self): + class Count(Enum): + zero = 0 + one = 1 + two = 2 + for member in Count: + self.assertTrue(bool(member)) + def test_invalid_names(self): with self.assertRaises(ValueError): class Wrong(Enum): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 03:04:12 2016 From: python-checkins at python.org (ethan.furman) Date: Thu, 14 Apr 2016 07:04:12 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy40IC0+IDMuNSk6?= =?utf-8?q?_Issue26748=3A_Enum_classes_should_evaluate_as_True?= Message-ID: <20160414070411.395.12236.484CD4F0@psf.io> https://hg.python.org/cpython/rev/f840608f79da changeset: 100963:f840608f79da branch: 3.5 parent: 100958:450f36750cb9 parent: 100962:772805538caf user: Ethan Furman date: Wed Apr 13 23:53:45 2016 -0700 summary: Issue26748: Enum classes should evaluate as True files: Lib/enum.py | 6 ++++++ Lib/test/test_enum.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-) diff --git a/Lib/enum.py b/Lib/enum.py --- a/Lib/enum.py +++ b/Lib/enum.py @@ -206,6 +206,12 @@ enum_class.__new__ = Enum.__new__ return enum_class + def __bool__(self): + """ + classes/types should always be True. + """ + return True + def __call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1): """Either returns an existing member, or creates a new enum class. diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -253,6 +253,19 @@ with self.assertRaises(AttributeError): del Season.SPRING.name + def test_bool_of_class(self): + class Empty(Enum): + pass + self.assertTrue(bool(Empty)) + + def test_bool_of_member(self): + class Count(Enum): + zero = 0 + one = 1 + two = 2 + for member in Count: + self.assertTrue(bool(member)) + def test_invalid_names(self): with self.assertRaises(ValueError): class Wrong(Enum): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 03:04:12 2016 From: python-checkins at python.org (ethan.furman) Date: Thu, 14 Apr 2016 07:04:12 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy40KTogSXNzdWUyNjc0ODog?= =?utf-8?q?Enum_classes_should_evaluate_as_True?= Message-ID: <20160414070411.89047.4941.2F424DCA@psf.io> https://hg.python.org/cpython/rev/772805538caf changeset: 100962:772805538caf branch: 3.4 parent: 100644:ed85850499bd user: Ethan Furman date: Wed Apr 13 23:52:09 2016 -0700 summary: Issue26748: Enum classes should evaluate as True files: Lib/enum.py | 6 ++++++ Lib/test/test_enum.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-) diff --git a/Lib/enum.py b/Lib/enum.py --- a/Lib/enum.py +++ b/Lib/enum.py @@ -193,6 +193,12 @@ enum_class.__new__ = Enum.__new__ return enum_class + def __bool__(self): + """ + classes/types should always be True. + """ + return True + def __call__(cls, value, names=None, *, module=None, qualname=None, type=None): """Either returns an existing member, or creates a new enum class. diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -257,6 +257,19 @@ with self.assertRaises(AttributeError): del Season.SPRING.name + def test_bool_of_class(self): + class Empty(Enum): + pass + self.assertTrue(bool(Empty)) + + def test_bool_of_member(self): + class Count(Enum): + zero = 0 + one = 1 + two = 2 + for member in Count: + self.assertTrue(bool(member)) + def test_invalid_names(self): with self.assertRaises(ValueError): class Wrong(Enum): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 05:15:28 2016 From: python-checkins at python.org (berker.peksag) Date: Thu, 14 Apr 2016 09:15:28 +0000 Subject: [Python-checkins] =?utf-8?q?devguide=3A_Issue_=2326749=3A_Update_?= =?utf-8?q?devguide_to_include_DNF_package_manager?= Message-ID: <20160414091457.26075.55197.48499D88@psf.io> https://hg.python.org/devguide/rev/0ed2497e5aa4 changeset: 795:0ed2497e5aa4 user: Berker Peksag date: Thu Apr 14 12:15:56 2016 +0300 summary: Issue #26749: Update devguide to include DNF package manager Patch by Luiz Poleto. files: setup.rst | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/setup.rst b/setup.rst --- a/setup.rst +++ b/setup.rst @@ -113,6 +113,11 @@ $ sudo yum install yum-utils $ sudo yum-builddep python3 +Fedora and other ``DNF`` based systems:: + + $ sudo dnf install dnf-plugins-core # install this to use 'dnf builddep' + $ sudo dnf builddep python3 + Debian, Ubuntu and other ``apt`` based systems, try to get the dependencies for the Python version that you're working on e.g.:: -- Repository URL: https://hg.python.org/devguide From python-checkins at python.org Thu Apr 14 05:36:39 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 14 Apr 2016 09:36:39 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_fs=5Funicode=5Fconverter_i?= =?utf-8?q?s_no_longer_used=2E?= Message-ID: <20160414093631.12725.51628.6627D7EF@psf.io> https://hg.python.org/cpython/rev/49371affeb99 changeset: 100967:49371affeb99 user: Serhiy Storchaka date: Thu Apr 14 12:36:11 2016 +0300 summary: fs_unicode_converter is no longer used. files: Python/import.c | 8 -------- 1 files changed, 0 insertions(+), 8 deletions(-) diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -38,14 +38,6 @@ #include "clinic/import.c.h" -/*[python input] -class fs_unicode_converter(CConverter): - type = 'PyObject *' - converter = 'PyUnicode_FSDecoder' - -[python start generated code]*/ -/*[python end generated code: output=da39a3ee5e6b4b0d input=9d6786230166006e]*/ - /* Initialize things */ void -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 05:40:38 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 14 Apr 2016 09:40:38 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NzE2?= =?utf-8?q?=3A_Regenerate_Argument_Clinic_code=2E?= Message-ID: <20160414093119.8354.34158.23BB1E0A@psf.io> https://hg.python.org/cpython/rev/9ffe055f2b0e changeset: 100965:9ffe055f2b0e branch: 3.5 parent: 100963:f840608f79da user: Serhiy Storchaka date: Thu Apr 14 12:28:01 2016 +0300 summary: Issue #26716: Regenerate Argument Clinic code. files: Modules/clinic/fcntlmodule.c.h | 4 ++-- Modules/fcntlmodule.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/clinic/fcntlmodule.c.h b/Modules/clinic/fcntlmodule.c.h --- a/Modules/clinic/fcntlmodule.c.h +++ b/Modules/clinic/fcntlmodule.c.h @@ -145,7 +145,7 @@ "\n" "When operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with\n" "LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and the\n" -"lock cannot be acquired, an IOError will be raised and the exception will\n" +"lock cannot be acquired, an OSError will be raised and the exception will\n" "have an errno attribute set to EACCES or EAGAIN (depending on the operating\n" "system -- for portability, check for either value).\n" "\n" @@ -182,4 +182,4 @@ exit: return return_value; } -/*[clinic end generated code: output=92963b631d00f0fe input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b7d6e8fc2ad09c48 input=a9049054013a1b77]*/ diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -360,7 +360,7 @@ static PyObject * fcntl_lockf_impl(PyModuleDef *module, int fd, int code, PyObject *lenobj, PyObject *startobj, int whence) -/*[clinic end generated code: output=31af35eba08b9af7 input=9c594391de821f24]*/ +/*[clinic end generated code: output=31af35eba08b9af7 input=3a5dc01b04371f1a]*/ { int ret; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 05:40:38 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 14 Apr 2016 09:40:38 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issues_=2326716=2C_=2326057=3A_Regenerate_Argument_Clini?= =?utf-8?q?c_code=2E?= Message-ID: <20160414093119.12751.38705.54B0BD99@psf.io> https://hg.python.org/cpython/rev/19dec08e54a8 changeset: 100966:19dec08e54a8 parent: 100964:2fc61f8ee2d2 parent: 100965:9ffe055f2b0e user: Serhiy Storchaka date: Thu Apr 14 12:30:54 2016 +0300 summary: Issues #26716, #26057: Regenerate Argument Clinic code. files: Modules/_codecsmodule.c | 30 +++++++++--------- Modules/clinic/_codecsmodule.c.h | 32 ++++++++++---------- Modules/clinic/fcntlmodule.c.h | 4 +- Modules/fcntlmodule.c | 2 +- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -722,7 +722,7 @@ static PyObject * _codecs_utf_7_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) -/*[clinic end generated code: output=a7accc496a32b759 input=fd91a78f103b0421]*/ +/*[clinic end generated code: output=a7accc496a32b759 input=d1a47579e79cbe15]*/ { return codec_tuple(_PyUnicode_EncodeUTF7(str, 0, 0, errors), PyUnicode_GET_LENGTH(str)); @@ -738,7 +738,7 @@ static PyObject * _codecs_utf_8_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) -/*[clinic end generated code: output=ec831d80e7aedede input=2c22d40532f071f3]*/ +/*[clinic end generated code: output=ec831d80e7aedede input=42e3ba73c4392eef]*/ { return codec_tuple(_PyUnicode_AsUTF8String(str, errors), PyUnicode_GET_LENGTH(str)); @@ -762,7 +762,7 @@ static PyObject * _codecs_utf_16_encode_impl(PyModuleDef *module, PyObject *str, const char *errors, int byteorder) -/*[clinic end generated code: output=93ac58e960a9ee4d input=3935a489b2d5385e]*/ +/*[clinic end generated code: output=93ac58e960a9ee4d input=ff46416b04edb944]*/ { return codec_tuple(_PyUnicode_EncodeUTF16(str, errors, byteorder), PyUnicode_GET_LENGTH(str)); @@ -778,7 +778,7 @@ static PyObject * _codecs_utf_16_le_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) -/*[clinic end generated code: output=422bedb8da34fb66 input=bc27df05d1d20dfe]*/ +/*[clinic end generated code: output=422bedb8da34fb66 input=cb385455ea8f2fe0]*/ { return codec_tuple(_PyUnicode_EncodeUTF16(str, errors, -1), PyUnicode_GET_LENGTH(str)); @@ -794,7 +794,7 @@ static PyObject * _codecs_utf_16_be_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) -/*[clinic end generated code: output=3aa7ee9502acdd77 input=5a69d4112763462b]*/ +/*[clinic end generated code: output=3aa7ee9502acdd77 input=9119997066bdaefd]*/ { return codec_tuple(_PyUnicode_EncodeUTF16(str, errors, +1), PyUnicode_GET_LENGTH(str)); @@ -818,7 +818,7 @@ static PyObject * _codecs_utf_32_encode_impl(PyModuleDef *module, PyObject *str, const char *errors, int byteorder) -/*[clinic end generated code: output=3e7d5a003b02baed input=434a1efa492b8d58]*/ +/*[clinic end generated code: output=3e7d5a003b02baed input=c5e77da82fbe5c2a]*/ { return codec_tuple(_PyUnicode_EncodeUTF32(str, errors, byteorder), PyUnicode_GET_LENGTH(str)); @@ -834,7 +834,7 @@ static PyObject * _codecs_utf_32_le_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) -/*[clinic end generated code: output=5dda641cd33dbfc2 input=dfa2d7dc78b99422]*/ +/*[clinic end generated code: output=5dda641cd33dbfc2 input=9993b25fe0877848]*/ { return codec_tuple(_PyUnicode_EncodeUTF32(str, errors, -1), PyUnicode_GET_LENGTH(str)); @@ -850,7 +850,7 @@ static PyObject * _codecs_utf_32_be_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) -/*[clinic end generated code: output=ccca8b44d91a7c7a input=4595617b18169002]*/ +/*[clinic end generated code: output=ccca8b44d91a7c7a input=d3e0ccaa02920431]*/ { return codec_tuple(_PyUnicode_EncodeUTF32(str, errors, +1), PyUnicode_GET_LENGTH(str)); @@ -866,7 +866,7 @@ static PyObject * _codecs_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) -/*[clinic end generated code: output=389f23d2b8f8d80b input=8273506f14076912]*/ +/*[clinic end generated code: output=389f23d2b8f8d80b input=65d9eefca65b455a]*/ { return codec_tuple(PyUnicode_AsUnicodeEscapeString(str), PyUnicode_GET_LENGTH(str)); @@ -882,7 +882,7 @@ static PyObject * _codecs_raw_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) -/*[clinic end generated code: output=fec4e39d6ec37a62 input=181755d5dfacef3c]*/ +/*[clinic end generated code: output=fec4e39d6ec37a62 input=5aa33e4a133391ab]*/ { return codec_tuple(PyUnicode_AsRawUnicodeEscapeString(str), PyUnicode_GET_LENGTH(str)); @@ -898,7 +898,7 @@ static PyObject * _codecs_latin_1_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) -/*[clinic end generated code: output=ecf00eb8e48c889c input=f03f6dcf1d84bee4]*/ +/*[clinic end generated code: output=ecf00eb8e48c889c input=30b11c9e49a65150]*/ { return codec_tuple(_PyUnicode_AsLatin1String(str, errors), PyUnicode_GET_LENGTH(str)); @@ -914,7 +914,7 @@ static PyObject * _codecs_ascii_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) -/*[clinic end generated code: output=a9d18fc6b6b91cfb input=d87e25a10a593fee]*/ +/*[clinic end generated code: output=a9d18fc6b6b91cfb input=843a1d268e6dfa8e]*/ { return codec_tuple(_PyUnicode_AsASCIIString(str, errors), PyUnicode_GET_LENGTH(str)); @@ -931,7 +931,7 @@ static PyObject * _codecs_charmap_encode_impl(PyModuleDef *module, PyObject *str, const char *errors, PyObject *mapping) -/*[clinic end generated code: output=14ca42b83853c643 input=85f4172661e8dad9]*/ +/*[clinic end generated code: output=14ca42b83853c643 input=0752cde07a6d6d00]*/ { if (mapping == Py_None) mapping = NULL; @@ -965,7 +965,7 @@ static PyObject * _codecs_mbcs_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) -/*[clinic end generated code: output=d1a013bc68798bd7 input=65c09ee1e4203263]*/ +/*[clinic end generated code: output=d1a013bc68798bd7 input=de471e0815947553]*/ { return codec_tuple(PyUnicode_EncodeCodePage(CP_ACP, str, errors), PyUnicode_GET_LENGTH(str)); @@ -982,7 +982,7 @@ static PyObject * _codecs_code_page_encode_impl(PyModuleDef *module, int code_page, PyObject *str, const char *errors) -/*[clinic end generated code: output=3b406618dbfbce25 input=c8562ec460c2e309]*/ +/*[clinic end generated code: output=3b406618dbfbce25 input=786421ae617d680b]*/ { return codec_tuple(PyUnicode_EncodeCodePage(code_page, str, errors), PyUnicode_GET_LENGTH(str)); diff --git a/Modules/clinic/_codecsmodule.c.h b/Modules/clinic/_codecsmodule.c.h --- a/Modules/clinic/_codecsmodule.c.h +++ b/Modules/clinic/_codecsmodule.c.h @@ -878,7 +878,7 @@ PyObject *str; const char *errors = NULL; - if (!PyArg_ParseTuple(args, "O|z:utf_7_encode", + if (!PyArg_ParseTuple(args, "U|z:utf_7_encode", &str, &errors)) goto exit; return_value = _codecs_utf_7_encode_impl(module, str, errors); @@ -906,7 +906,7 @@ PyObject *str; const char *errors = NULL; - if (!PyArg_ParseTuple(args, "O|z:utf_8_encode", + if (!PyArg_ParseTuple(args, "U|z:utf_8_encode", &str, &errors)) goto exit; return_value = _codecs_utf_8_encode_impl(module, str, errors); @@ -935,7 +935,7 @@ const char *errors = NULL; int byteorder = 0; - if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode", + if (!PyArg_ParseTuple(args, "U|zi:utf_16_encode", &str, &errors, &byteorder)) goto exit; return_value = _codecs_utf_16_encode_impl(module, str, errors, byteorder); @@ -963,7 +963,7 @@ PyObject *str; const char *errors = NULL; - if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode", + if (!PyArg_ParseTuple(args, "U|z:utf_16_le_encode", &str, &errors)) goto exit; return_value = _codecs_utf_16_le_encode_impl(module, str, errors); @@ -991,7 +991,7 @@ PyObject *str; const char *errors = NULL; - if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode", + if (!PyArg_ParseTuple(args, "U|z:utf_16_be_encode", &str, &errors)) goto exit; return_value = _codecs_utf_16_be_encode_impl(module, str, errors); @@ -1020,7 +1020,7 @@ const char *errors = NULL; int byteorder = 0; - if (!PyArg_ParseTuple(args, "O|zi:utf_32_encode", + if (!PyArg_ParseTuple(args, "U|zi:utf_32_encode", &str, &errors, &byteorder)) goto exit; return_value = _codecs_utf_32_encode_impl(module, str, errors, byteorder); @@ -1048,7 +1048,7 @@ PyObject *str; const char *errors = NULL; - if (!PyArg_ParseTuple(args, "O|z:utf_32_le_encode", + if (!PyArg_ParseTuple(args, "U|z:utf_32_le_encode", &str, &errors)) goto exit; return_value = _codecs_utf_32_le_encode_impl(module, str, errors); @@ -1076,7 +1076,7 @@ PyObject *str; const char *errors = NULL; - if (!PyArg_ParseTuple(args, "O|z:utf_32_be_encode", + if (!PyArg_ParseTuple(args, "U|z:utf_32_be_encode", &str, &errors)) goto exit; return_value = _codecs_utf_32_be_encode_impl(module, str, errors); @@ -1104,7 +1104,7 @@ PyObject *str; const char *errors = NULL; - if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode", + if (!PyArg_ParseTuple(args, "U|z:unicode_escape_encode", &str, &errors)) goto exit; return_value = _codecs_unicode_escape_encode_impl(module, str, errors); @@ -1132,7 +1132,7 @@ PyObject *str; const char *errors = NULL; - if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode", + if (!PyArg_ParseTuple(args, "U|z:raw_unicode_escape_encode", &str, &errors)) goto exit; return_value = _codecs_raw_unicode_escape_encode_impl(module, str, errors); @@ -1160,7 +1160,7 @@ PyObject *str; const char *errors = NULL; - if (!PyArg_ParseTuple(args, "O|z:latin_1_encode", + if (!PyArg_ParseTuple(args, "U|z:latin_1_encode", &str, &errors)) goto exit; return_value = _codecs_latin_1_encode_impl(module, str, errors); @@ -1188,7 +1188,7 @@ PyObject *str; const char *errors = NULL; - if (!PyArg_ParseTuple(args, "O|z:ascii_encode", + if (!PyArg_ParseTuple(args, "U|z:ascii_encode", &str, &errors)) goto exit; return_value = _codecs_ascii_encode_impl(module, str, errors); @@ -1217,7 +1217,7 @@ const char *errors = NULL; PyObject *mapping = NULL; - if (!PyArg_ParseTuple(args, "O|zO:charmap_encode", + if (!PyArg_ParseTuple(args, "U|zO:charmap_encode", &str, &errors, &mapping)) goto exit; return_value = _codecs_charmap_encode_impl(module, str, errors, mapping); @@ -1272,7 +1272,7 @@ PyObject *str; const char *errors = NULL; - if (!PyArg_ParseTuple(args, "O|z:mbcs_encode", + if (!PyArg_ParseTuple(args, "U|z:mbcs_encode", &str, &errors)) goto exit; return_value = _codecs_mbcs_encode_impl(module, str, errors); @@ -1305,7 +1305,7 @@ PyObject *str; const char *errors = NULL; - if (!PyArg_ParseTuple(args, "iO|z:code_page_encode", + if (!PyArg_ParseTuple(args, "iU|z:code_page_encode", &code_page, &str, &errors)) goto exit; return_value = _codecs_code_page_encode_impl(module, code_page, str, errors); @@ -1393,4 +1393,4 @@ #ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF #define _CODECS_CODE_PAGE_ENCODE_METHODDEF #endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */ -/*[clinic end generated code: output=9c9967048027c1c7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=04007a13c8387689 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/fcntlmodule.c.h b/Modules/clinic/fcntlmodule.c.h --- a/Modules/clinic/fcntlmodule.c.h +++ b/Modules/clinic/fcntlmodule.c.h @@ -145,7 +145,7 @@ "\n" "When operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with\n" "LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and the\n" -"lock cannot be acquired, an IOError will be raised and the exception will\n" +"lock cannot be acquired, an OSError will be raised and the exception will\n" "have an errno attribute set to EACCES or EAGAIN (depending on the operating\n" "system -- for portability, check for either value).\n" "\n" @@ -182,4 +182,4 @@ exit: return return_value; } -/*[clinic end generated code: output=92963b631d00f0fe input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b7d6e8fc2ad09c48 input=a9049054013a1b77]*/ diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -360,7 +360,7 @@ static PyObject * fcntl_lockf_impl(PyModuleDef *module, int fd, int code, PyObject *lenobj, PyObject *startobj, int whence) -/*[clinic end generated code: output=31af35eba08b9af7 input=9c594391de821f24]*/ +/*[clinic end generated code: output=31af35eba08b9af7 input=3a5dc01b04371f1a]*/ { int ret; -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Thu Apr 14 05:47:49 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 14 Apr 2016 09:47:49 +0000 Subject: [Python-checkins] Daily reference leaks (3f3b3d4881f6): sum=4 Message-ID: <20160414094602.19519.24448.E5C07138@psf.io> results for 3f3b3d4881f6 on branch "default" -------------------------------------------- test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogWNHgNy', '--timeout', '7200'] From lp_benchmark_robot at intel.com Thu Apr 14 07:09:01 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Thu, 14 Apr 2016 12:09:01 +0100 Subject: [Python-checkins] UGLY Benchmark Results for Python Default 2016-04-14 Message-ID: Results for project Python default, build date 2016-04-14 02:09:24 +0000 commit: 3f3b3d4881f6 previous commit: 7b0fd592cd08 revision date: 2016-04-13 12:37:23 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.19% 1.64% 11.32% 13.23% :-| pybench 0.21% -0.34% 0.32% 6.01% :-( regex_v8 2.72% 1.12% -2.94% 5.23% :-| nbody 0.11% -0.02% -1.73% 7.33% :-( json_dump_v2 0.21% -1.04% -3.74% 11.56% :-| normal_startup 0.79% 0.13% 0.17% 5.48% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/ugly-benchmark-results-for-python-default-2016-04-14/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Thu Apr 14 07:09:37 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Thu, 14 Apr 2016 12:09:37 +0100 Subject: [Python-checkins] BAD Benchmark Results for Python 2.7 2016-04-14 Message-ID: Results for project Python 2.7, build date 2016-04-14 03:01:31 +0000 commit: 4680438f486f previous commit: c2f57f959c05 revision date: 2016-04-13 12:27:33 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.19% 0.94% 6.01% 3.90% :-) pybench 0.11% -0.18% 6.19% 3.64% :-( regex_v8 0.85% 0.33% -2.61% 10.81% :-) nbody 0.30% -2.99% 6.69% 5.83% :-) json_dump_v2 0.24% -0.32% 3.31% 11.48% :-( normal_startup 1.85% -0.37% -5.88% 2.57% :-) ssbench 0.22% -0.10% 2.63% 0.73% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/bad-benchmark-results-for-python-2-7-2016-04-14/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Thu Apr 14 08:50:55 2016 From: python-checkins at python.org (berker.peksag) Date: Thu, 14 Apr 2016 12:50:55 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2NzQ3?= =?utf-8?q?=3A_Document_that_InstanceTypes_only_works_for_old-style_classe?= =?utf-8?q?s?= Message-ID: <20160414125052.8352.30178.EF93A5A6@psf.io> https://hg.python.org/cpython/rev/b684298671f9 changeset: 100968:b684298671f9 branch: 2.7 parent: 100959:4680438f486f user: Berker Peksag date: Thu Apr 14 15:51:22 2016 +0300 summary: Issue #26747: Document that InstanceTypes only works for old-style classes Patch by Nan Wu. files: Doc/library/types.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/types.rst b/Doc/library/types.rst --- a/Doc/library/types.rst +++ b/Doc/library/types.rst @@ -147,7 +147,7 @@ .. data:: InstanceType - The type of instances of user-defined classes. + The type of instances of user-defined old-style classes. .. data:: MethodType -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 09:49:54 2016 From: python-checkins at python.org (berker.peksag) Date: Thu, 14 Apr 2016 13:49:54 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Fix_unused_var?= =?utf-8?q?iable_=27libver=27_warning_in_Modules/=5Fssl=2Ec?= Message-ID: <20160414134821.403.80916.58EB7F65@psf.io> https://hg.python.org/cpython/rev/b1f466e344c6 changeset: 100969:b1f466e344c6 branch: 3.5 parent: 100965:9ffe055f2b0e user: Berker Peksag date: Thu Apr 14 16:48:48 2016 +0300 summary: Fix unused variable 'libver' warning in Modules/_ssl.c It can be seen on various buildbots like 3.x.cea-indiana-amd64 and 3.x.murray-snowleopard: /export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_ssl.c:2227: warning: unused variable 'libver' /Users/buildbot/buildarea/3.x.murray-snowleopard/build/Modules/_ssl.c:2227: warning: unused variable ?libver? files: Modules/_ssl.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Modules/_ssl.c b/Modules/_ssl.c --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -2224,7 +2224,9 @@ PySSLContext *self; long options; SSL_CTX *ctx = NULL; +#if defined(SSL_MODE_RELEASE_BUFFERS) unsigned long libver; +#endif PySSL_BEGIN_ALLOW_THREADS if (proto_version == PY_SSL_VERSION_TLS1) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 09:49:54 2016 From: python-checkins at python.org (berker.peksag) Date: Thu, 14 Apr 2016 13:49:54 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Fix_unused_variable_=27libver=27_warning_in_Modules/=5Fs?= =?utf-8?q?sl=2Ec?= Message-ID: <20160414134824.411.64012.64D43AB6@psf.io> https://hg.python.org/cpython/rev/66b0eeb4d116 changeset: 100970:66b0eeb4d116 parent: 100967:49371affeb99 parent: 100969:b1f466e344c6 user: Berker Peksag date: Thu Apr 14 16:49:21 2016 +0300 summary: Fix unused variable 'libver' warning in Modules/_ssl.c It can be seen on various buildbots like 3.x.cea-indiana-amd64 and 3.x.murray-snowleopard: /export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_ssl.c:2227: warning: unused variable 'libver' /Users/buildbot/buildarea/3.x.murray-snowleopard/build/Modules/_ssl.c:2227: warning: unused variable ?libver? files: Modules/_ssl.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Modules/_ssl.c b/Modules/_ssl.c --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -2224,7 +2224,9 @@ PySSLContext *self; long options; SSL_CTX *ctx = NULL; +#if defined(SSL_MODE_RELEASE_BUFFERS) unsigned long libver; +#endif PySSL_BEGIN_ALLOW_THREADS if (proto_version == PY_SSL_VERSION_TLS1) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 11:13:47 2016 From: python-checkins at python.org (victor.stinner) Date: Thu, 14 Apr 2016 15:13:47 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP_509=3A_dict_version_is_no?= =?utf-8?q?w_global?= Message-ID: <20160414151328.26087.7823.535CE745@psf.io> https://hg.python.org/peps/rev/4335314e45ef changeset: 6280:4335314e45ef user: Victor Stinner date: Thu Apr 14 17:13:07 2016 +0200 summary: PEP 509: dict version is now global * Rename ma_version to ma_version_tag * Add links to fatoptimizer and fat projects files: pep-0509.txt | 130 ++++++++++++++++++++++++-------------- 1 files changed, 81 insertions(+), 49 deletions(-) diff --git a/pep-0509.txt b/pep-0509.txt --- a/pep-0509.txt +++ b/pep-0509.txt @@ -13,8 +13,9 @@ Abstract ======== -Add a new private version to builtin ``dict`` type, incremented at each -change, to implement fast guards on namespaces. +Add a new private version to the builtin ``dict`` type, incremented at +each dictionary creation and at each dictionary change, to implement +fast guards on namespaces. Rationale @@ -38,7 +39,9 @@ on namespaces. Dictionary lookups can be skipped if the version does not change which -is the common case for most namespaces. The performance of a guard does +is the common case for most namespaces. Since the version is globally +unique, the version is also enough to check if the namespace dictionary +was not replaced with a new dictionary. The performance of a guard does not depend on the number of watched dictionary entries, complexity of O(1), if the dictionary version does not change. @@ -71,9 +74,10 @@ self.version = dict_get_version(dict) def check(self): - """Return True if the dictionary entry did not changed.""" + """Return True if the dictionary entry did not changed + and the dictionary was not replaced.""" - # read the version field of the dict structure + # read the version of the dict structure version = dict_get_version(self.dict) if version == self.version: # Fast-path: dictionary lookup avoided @@ -94,6 +98,22 @@ Usage of the dict version ========================= +Speedup method calls 1.2x +------------------------- + +Yury Selivanov wrote a patch to optimize method calls. The patch depends +on the `implement per-opcode cache in ceval +`_ patch which requires dictionary +versions to invalidate the cache if the globals dictionary or the +builtins dictionary has been modified. + +The cache also requires that the dictionary version is globally unique. +It is possible to define a function in a namespace and call it +in a different namespace: using ``exec()`` with the *globals* parameter +for example. In this case, the globals dictionary was changed and the +cache must be invalidated. + + Specialized functions using guards ---------------------------------- @@ -102,8 +122,9 @@ specialized functions with guards. It allows to implement static optimizers for Python without breaking the Python semantics. -Example of a static Python optimizer: the astoptimizer of the `FAT -Python `_ project +Example of a static Python optimizer: the `fatoptimizer +`_ of the `FAT Python +`_ project implements many optimizations which require guards on namespaces. Examples: @@ -128,7 +149,7 @@ Unladen Swallow --------------- -Even if dictionary version was not explicitly mentioned, optimization +Even if dictionary version was not explicitly mentioned, optimizing globals and builtins lookup was part of the Unladen Swallow plan: "Implement one of the several proposed schemes for speeding lookups of globals and builtins." Source: `Unladen Swallow ProjectPlan @@ -143,9 +164,12 @@ Changes ======= -Add a ``ma_version`` field to the ``PyDictObject`` structure with the C -type ``PY_INT64_T``, 64-bit unsigned integer. New empty dictionaries are -initilized to version ``0``. The version is incremented at each change: +Add a ``ma_version_tag`` field to the ``PyDictObject`` structure with +the C type ``PY_INT64_T``, 64-bit unsigned integer. Add also a global +dictionary version. Each time a dictionary is created, the global +version is incremented and the dictionary version is initialized to the +global version. The global version is also incremented and copied to the +dictionary version at each dictionary change: * ``clear()`` if the dict was non-empty * ``pop(key)`` if the key exists @@ -158,30 +182,27 @@ values are compared by identity, not by their content; the version can be incremented multiple times -.. note:: - The ``PyDictObject`` structure is not part of the stable ABI. +The ``PyDictObject`` structure is not part of the stable ABI. + +The field is called ``ma_version_tag`` rather than ``ma_version`` to +suggest to compare it using ``version_tag == old_version_tag`` rather +than ``version <= old_version`` which makes the integer overflow much +likely. Example using an hypothetical ``dict_get_version(dict)`` function:: >>> d = {} >>> dict_get_version(d) - 0 + 100 >>> d['key'] = 'value' >>> dict_get_version(d) - 1 + 101 >>> d['key'] = 'new value' >>> dict_get_version(d) - 2 + 102 >>> del d['key'] >>> dict_get_version(d) - 3 - -If a dictionary is created with items, the version is also incremented -at each dictionary insertion. Example:: - - >>> d = dict(x=7, y=33) - >>> dict_get_version(d) - 2 + 103 The version is not incremented if an existing key is set to the same value. For efficiency, values are compared by their identity: @@ -192,10 +213,10 @@ >>> value = object() >>> d['key'] = value >>> dict_get_version(d) - 1 + 40 >>> d['key'] = value >>> dict_get_version(d) - 1 + 40 .. note:: CPython uses some singleton like integers in the range [-5; 257], @@ -204,10 +225,10 @@ singleton, the version is not modified. -Implementation -============== +Implementation and Performance +============================== -The `issue #26058: PEP 509: Add ma_version to PyDictObject +The `issue #26058: PEP 509: Add ma_version_tag to PyDictObject `_ contains a patch implementing this PEP. @@ -221,23 +242,26 @@ ns, whereas the guard still only costs 3.8 ns when the version does not change (39x as fast). +The `fat module +`_ implements +such guards: ``fat.GuardDict`` is based on the dictionary version. + Integer overflow ================ -The implementation uses the C unsigned integer type ``PY_UINT64_T`` to -store the version, a 64 bits unsigned integer. The C code uses -``version++``. On integer overflow, the version is wrapped to ``0`` (and -then continue to be incremented) according to the C standard. +The implementation uses the C type ``PY_UINT64_T`` to store the version: +a 64 bits unsigned integer. The C code uses ``version++``. On integer +overflow, the version is wrapped to ``0`` (and then continue to be +incremented) according to the C standard. After an integer overflow, a guard can succeed whereas the watched -dictionary key was modified. The bug occurs if the dictionary is -modified at least ``2 ** 64`` times between two checks of the guard and -if the new version (theoretical value with no integer overflow) is equal -to the old version modulo ``2 ** 64``. +dictionary key was modified. The bug only occurs at a guard check if +there are exaclty ``2 ** 64`` dictionary creations or modifications +since the previous guard check. -If a dictionary is modified each nanosecond, an overflow takes longer -than 584 years. Using a 32-bit version, the overflow occurs only after 4 +If a dictionary is modified every nanosecond, ``2 ** 64`` modifications +takes longer than 584 years. Using a 32-bit version, it only takes 4 seconds. That's why a 64-bit unsigned type is also used on 32-bit systems. A dictionary lookup at the C level takes 14.8 ns. @@ -264,11 +288,6 @@ * All Python implementations must implement this new property, it gives more work to other implementations, whereas they may not use the dictionary version at all. -* The ``__version__`` can be wrapped on integer overflow. It is error - prone: using ``dict.__version__ <= guard_version`` is wrong, - ``dict.__version__ == guard_version`` must be used instead to reduce - the risk of bug on integer overflow (even if the integer overflow is - unlikely in practice). * Exposing the dictionary version at Python level can lead the false assumption on performances. Checking ``dict.__version__`` at the Python level is not faster than a dictionary lookup. A dictionary @@ -281,7 +300,13 @@ $ ./python -m timeit -s 'd = {str(i):i for i in range(100)}' 'd.__version__ == 100' 10000000 loops, best of 3: 0.0475 usec per loop -Bikeshedding on the property name: +* The ``__version__`` can be wrapped on integer overflow. It is error + prone: using ``dict.__version__ <= guard_version`` is wrong, + ``dict.__version__ == guard_version`` must be used instead to reduce + the risk of bug on integer overflow (even if the integer overflow is + unlikely in practice). + +Mandatory bikeshedding on the property name: * ``__cache_token__``: name proposed by Nick Coghlan, name coming from `abc.get_cache_token() @@ -318,9 +343,10 @@ self.entry_version = dict_get_entry_version(dict, key) def check(self): - """Return True if the dictionary entry did not changed.""" + """Return True if the dictionary entry did not changed + and the dictionary was not replaced.""" - # read the version field of the dict structure + # read the version of the dict structure dict_version = dict_get_version(self.dict) if dict_version == self.version: # Fast-path: dictionary lookup avoided @@ -486,8 +512,14 @@ Discussion ========== -Thread on the python-ideas mailing list: `RFC: PEP: Add dict.__version__ -`_. +Thread on the mailing lists: + +* python-dev: `PEP 509: Add a private version to dict + `_ + (january 2016) +* python-ideas: `RFC: PEP: Add dict.__version__ + `_ + (january 2016) Copyright -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Thu Apr 14 11:19:22 2016 From: python-checkins at python.org (victor.stinner) Date: Thu, 14 Apr 2016 15:19:22 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP_509=3A_add_link_to_Yury?= =?utf-8?q?=27s_patch?= Message-ID: <20160414151916.19653.53109.5748AF8E@psf.io> https://hg.python.org/peps/rev/35965c13278d changeset: 6281:35965c13278d user: Victor Stinner date: Thu Apr 14 17:19:09 2016 +0200 summary: PEP 509: add link to Yury's patch files: pep-0509.txt | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pep-0509.txt b/pep-0509.txt --- a/pep-0509.txt +++ b/pep-0509.txt @@ -101,8 +101,9 @@ Speedup method calls 1.2x ------------------------- -Yury Selivanov wrote a patch to optimize method calls. The patch depends -on the `implement per-opcode cache in ceval +Yury Selivanov wrote a `patch to optimize method calls +`_. The patch depends on the +`implement per-opcode cache in ceval `_ patch which requires dictionary versions to invalidate the cache if the globals dictionary or the builtins dictionary has been modified. -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Thu Apr 14 11:23:47 2016 From: python-checkins at python.org (zach.ware) Date: Thu, 14 Apr 2016 15:23:47 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Closes_=2326706=3A_Merge_with_3=2E5?= Message-ID: <20160414152346.88646.57714.1CE9ABD8@psf.io> https://hg.python.org/cpython/rev/430f5a23a853 changeset: 100973:430f5a23a853 parent: 100970:66b0eeb4d116 parent: 100972:4936b2723471 user: Zachary Ware date: Thu Apr 14 10:22:58 2016 -0500 summary: Closes #26706: Merge with 3.5 files: PCbuild/readme.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/PCbuild/readme.txt b/PCbuild/readme.txt --- a/PCbuild/readme.txt +++ b/PCbuild/readme.txt @@ -169,7 +169,7 @@ Homepage: http://tukaani.org/xz/ _ssl - Python wrapper for version 1.0.2f of the OpenSSL secure sockets + Python wrapper for version 1.0.2g of the OpenSSL secure sockets library, which is built by ssl.vcxproj Homepage: http://www.openssl.org/ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 11:24:13 2016 From: python-checkins at python.org (zach.ware) Date: Thu, 14 Apr 2016 15:24:13 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NzA2?= =?utf-8?q?=3A_Update_OpenSSL_version_in_PCbuild/readme=2Etxt?= Message-ID: <20160414152346.26097.15765.80AAF74F@psf.io> https://hg.python.org/cpython/rev/4936b2723471 changeset: 100972:4936b2723471 branch: 3.5 parent: 100969:b1f466e344c6 user: Zachary Ware date: Thu Apr 14 10:22:12 2016 -0500 summary: Issue #26706: Update OpenSSL version in PCbuild/readme.txt Thanks to Shaun Walbridge for noticing. files: PCbuild/readme.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/PCbuild/readme.txt b/PCbuild/readme.txt --- a/PCbuild/readme.txt +++ b/PCbuild/readme.txt @@ -169,7 +169,7 @@ Homepage: http://tukaani.org/xz/ _ssl - Python wrapper for version 1.0.2f of the OpenSSL secure sockets + Python wrapper for version 1.0.2g of the OpenSSL secure sockets library, which is built by ssl.vcxproj Homepage: http://www.openssl.org/ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 11:24:13 2016 From: python-checkins at python.org (zach.ware) Date: Thu, 14 Apr 2016 15:24:13 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2NDY1?= =?utf-8?q?=3A_Update_VS9=2E0_build_files_for_OpenSSL_1=2E0=2E2g?= Message-ID: <20160414152344.26653.62496.ADB47849@psf.io> https://hg.python.org/cpython/rev/3a3b30c310e5 changeset: 100971:3a3b30c310e5 branch: 2.7 parent: 100968:b684298671f9 user: Zachary Ware date: Thu Apr 14 10:18:27 2016 -0500 summary: Issue #26465: Update VS9.0 build files for OpenSSL 1.0.2g files: PC/VS9.0/pyproject.vsprops | 2 +- PC/VS9.0/readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PC/VS9.0/pyproject.vsprops b/PC/VS9.0/pyproject.vsprops --- a/PC/VS9.0/pyproject.vsprops +++ b/PC/VS9.0/pyproject.vsprops @@ -82,7 +82,7 @@ /> https://hg.python.org/cpython/rev/2979be0abf89 changeset: 100974:2979be0abf89 user: Steven D'Aprano date: Fri Apr 15 01:51:31 2016 +1000 summary: Add secrets module and tests. files: Lib/secrets.py | 149 +++++++++++++++++++++++++++ Lib/test/test_secrets.py | 120 +++++++++++++++++++++ 2 files changed, 269 insertions(+), 0 deletions(-) diff --git a/Lib/secrets.py b/Lib/secrets.py new file mode 100644 --- /dev/null +++ b/Lib/secrets.py @@ -0,0 +1,149 @@ +"""Generate cryptographically strong pseudo-random numbers suitable for +managing secrets such as account authentication, tokens, and similar. +See PEP 506 for more information. + +https://www.python.org/dev/peps/pep-0506/ + + +Random numbers +============== + +The ``secrets`` module provides the following pseudo-random functions, based +on SystemRandom, which in turn uses the most secure source of randomness your +operating system provides. + + + choice(sequence) + Choose a random element from a non-empty sequence. + + randbelow(n) + Return a random int in the range [0, n). + + randbits(k) + Generates an int with k random bits. + + SystemRandom + Class for generating random numbers using sources provided by + the operating system. See the ``random`` module for documentation. + + +Token functions +=============== + +The ``secrets`` module provides a number of functions for generating secure +tokens, suitable for applications such as password resets, hard-to-guess +URLs, and similar. All the ``token_*`` functions take an optional single +argument specifying the number of bytes of randomness to use. If that is +not given, or is ``None``, a reasonable default is used. That default is +subject to change at any time, including during maintenance releases. + + + token_bytes(nbytes=None) + Return a random byte-string containing ``nbytes`` number of bytes. + + >>> secrets.token_bytes(16) #doctest:+SKIP + b'\\xebr\\x17D*t\\xae\\xd4\\xe3S\\xb6\\xe2\\xebP1\\x8b' + + + token_hex(nbytes=None) + Return a random text-string, in hexadecimal. The string has ``nbytes`` + random bytes, each byte converted to two hex digits. + + >>> secrets.token_hex(16) #doctest:+SKIP + 'f9bf78b9a18ce6d46a0cd2b0b86df9da' + + token_urlsafe(nbytes=None) + Return a random URL-safe text-string, containing ``nbytes`` random + bytes. On average, each byte results in approximately 1.3 characters + in the final result. + + >>> secrets.token_urlsafe(16) #doctest:+SKIP + 'Drmhze6EPcv0fN_81Bj-nA' + + +(The examples above assume Python 3. In Python 2, byte-strings will display +using regular quotes ``''`` with no prefix, and text-strings will have a +``u`` prefix.) + + +Other functions +=============== + + compare_digest(a, b) + Return True if strings a and b are equal, otherwise False. + Performs the equality comparison in such a way as to reduce the + risk of timing attacks. + + See http://codahale.com/a-lesson-in-timing-attacks/ for a + discussion on how timing attacks against ``==`` can reveal + secrets from your application. + + +""" + +__all__ = ['choice', 'randbelow', 'randbits', 'SystemRandom', + 'token_bytes', 'token_hex', 'token_urlsafe', + 'compare_digest', + ] + + +import base64 +import binascii +import os + +try: + from hmac import compare_digest +except ImportError: + # Python version is too old. Fall back to a pure-Python version. + + import operator + from functools import reduce + + def compare_digest(a, b): + """Return ``a == b`` using an approach resistant to timing analysis. + + a and b must both be of the same type: either both text strings, + or both byte strings. + + Note: If a and b are of different lengths, or if an error occurs, + a timing attack could theoretically reveal information about the + types and lengths of a and b, but not their values. + """ + # For a similar approach, see + # http://codahale.com/a-lesson-in-timing-attacks/ + for T in (bytes, str): + if isinstance(a, T) and isinstance(b, T): + break + else: # for...else + raise TypeError("arguments must be both strings or both bytes") + if len(a) != len(b): + return False + # Thanks to Raymond Hettinger for this one-liner. + return reduce(operator.and_, map(operator.eq, a, b), True) + + + +from random import SystemRandom + +_sysrand = SystemRandom() + +randbits = _sysrand.getrandbits +choice = _sysrand.choice + +def randbelow(exclusive_upper_bound): + return _sysrand._randbelow(exclusive_upper_bound) + +DEFAULT_ENTROPY = 32 # number of bytes to return by default + +def token_bytes(nbytes=None): + if nbytes is None: + nbytes = DEFAULT_ENTROPY + return os.urandom(nbytes) + +def token_hex(nbytes=None): + return binascii.hexlify(token_bytes(nbytes)).decode('ascii') + +def token_urlsafe(nbytes=None): + tok = token_bytes(nbytes) + return base64.urlsafe_b64encode(tok).rstrip(b'=').decode('ascii') + diff --git a/Lib/test/test_secrets.py b/Lib/test/test_secrets.py new file mode 100644 --- /dev/null +++ b/Lib/test/test_secrets.py @@ -0,0 +1,120 @@ +"""Test the secrets module. + +As most of the functions in secrets are thin wrappers around functions +defined elsewhere, we don't need to test them exhaustively. +""" + + +import secrets +import unittest +import string + + +# === Unit tests === + +class Compare_Digest_Tests(unittest.TestCase): + """Test secrets.compare_digest function.""" + + def test_equal(self): + # Test compare_digest functionality with equal (byte/text) strings. + for s in ("a", "bcd", "xyz123"): + a = s*100 + b = s*100 + self.assertTrue(secrets.compare_digest(a, b)) + self.assertTrue(secrets.compare_digest(a.encode('utf-8'), b.encode('utf-8'))) + + def test_unequal(self): + # Test compare_digest functionality with unequal (byte/text) strings. + self.assertFalse(secrets.compare_digest("abc", "abcd")) + self.assertFalse(secrets.compare_digest(b"abc", b"abcd")) + for s in ("x", "mn", "a1b2c3"): + a = s*100 + "q" + b = s*100 + "k" + self.assertFalse(secrets.compare_digest(a, b)) + self.assertFalse(secrets.compare_digest(a.encode('utf-8'), b.encode('utf-8'))) + + def test_bad_types(self): + # Test that compare_digest raises with mixed types. + a = 'abcde' + b = a.encode('utf-8') + assert isinstance(a, str) + assert isinstance(b, bytes) + self.assertRaises(TypeError, secrets.compare_digest, a, b) + self.assertRaises(TypeError, secrets.compare_digest, b, a) + + def test_bool(self): + # Test that compare_digest returns a bool. + self.assertTrue(isinstance(secrets.compare_digest("abc", "abc"), bool)) + self.assertTrue(isinstance(secrets.compare_digest("abc", "xyz"), bool)) + + +class Random_Tests(unittest.TestCase): + """Test wrappers around SystemRandom methods.""" + + def test_randbits(self): + # Test randbits. + errmsg = "randbits(%d) returned %d" + for numbits in (3, 12, 30): + for i in range(6): + n = secrets.randbits(numbits) + self.assertTrue(0 <= n < 2**numbits, errmsg % (numbits, n)) + + def test_choice(self): + # Test choice. + items = [1, 2, 4, 8, 16, 32, 64] + for i in range(10): + self.assertTrue(secrets.choice(items) in items) + + def test_randbelow(self): + # Test randbelow. + errmsg = "randbelow(%d) returned %d" + for i in range(2, 10): + n = secrets.randbelow(i) + self.assertTrue(n in range(i), errmsg % (i, n)) + self.assertRaises(ValueError, secrets.randbelow, 0) + + +class Token_Tests(unittest.TestCase): + """Test token functions.""" + + def test_token_defaults(self): + # Test that token_* functions handle default size correctly. + for func in (secrets.token_bytes, secrets.token_hex, + secrets.token_urlsafe): + name = func.__name__ + try: + func() + except TypeError: + self.fail("%s cannot be called with no argument" % name) + try: + func(None) + except TypeError: + self.fail("%s cannot be called with None" % name) + size = secrets.DEFAULT_ENTROPY + self.assertEqual(len(secrets.token_bytes(None)), size) + self.assertEqual(len(secrets.token_hex(None)), 2*size) + + def test_token_bytes(self): + # Test token_bytes. + self.assertTrue(isinstance(secrets.token_bytes(11), bytes)) + for n in (1, 8, 17, 100): + self.assertEqual(len(secrets.token_bytes(n)), n) + + def test_token_hex(self): + # Test token_hex. + self.assertTrue(isinstance(secrets.token_hex(7), str)) + for n in (1, 12, 25, 90): + s = secrets.token_hex(n) + self.assertEqual(len(s), 2*n) + self.assertTrue(all(c in string.hexdigits for c in s)) + + def test_token_urlsafe(self): + # Test token_urlsafe. + self.assertTrue(isinstance(secrets.token_urlsafe(9), str)) + legal = string.ascii_letters + string.digits + '-_' + for n in (1, 11, 28, 76): + self.assertTrue(all(c in legal for c in secrets.token_urlsafe(n))) + + +if __name__ == '__main__': + unittest.main() -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 11:56:05 2016 From: python-checkins at python.org (steven.daprano) Date: Thu, 14 Apr 2016 15:56:05 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_run_Tools/reindent=2Epy_on?= =?utf-8?q?_secrets=2Epy_to_satisfy_the_checkwhitespace_hook?= Message-ID: <20160414155532.15376.8053.4AF6B48D@psf.io> https://hg.python.org/cpython/rev/6872f94902ec changeset: 100975:6872f94902ec user: Steven D'Aprano date: Fri Apr 15 01:55:14 2016 +1000 summary: run Tools/reindent.py on secrets.py to satisfy the checkwhitespace hook files: Lib/secrets.py | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/Lib/secrets.py b/Lib/secrets.py --- a/Lib/secrets.py +++ b/Lib/secrets.py @@ -146,4 +146,3 @@ def token_urlsafe(nbytes=None): tok = token_bytes(nbytes) return base64.urlsafe_b64encode(tok).rstrip(b'=').decode('ascii') - -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 13:22:05 2016 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 14 Apr 2016 17:22:05 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Fix_style_inconsistency_with_?= =?utf-8?q?=22and=22_on_continuation_line=2E?= Message-ID: <20160414172201.19493.20971.DA079BA4@psf.io> https://hg.python.org/peps/rev/502239ce4889 changeset: 6282:502239ce4889 user: Guido van Rossum date: Thu Apr 14 10:21:55 2016 -0700 summary: Fix style inconsistency with "and" on continuation line. files: pep-0008.txt | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pep-0008.txt b/pep-0008.txt --- a/pep-0008.txt +++ b/pep-0008.txt @@ -147,8 +147,8 @@ do_something() # Add some extra indentation on the conditional continuation line. - if (this_is_one_thing - and that_is_another_thing): + if (this_is_one_thing and + that_is_another_thing): do_something() The closing brace/bracket/parenthesis on multi-line constructs may -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Thu Apr 14 20:06:46 2016 From: python-checkins at python.org (steven.daprano) Date: Fri, 15 Apr 2016 00:06:46 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Improve_tests_with_more_mo?= =?utf-8?q?dern_assert*_methods_and_subTests=2E?= Message-ID: <20160415000646.17779.91772.63A78468@psf.io> https://hg.python.org/cpython/rev/1539ddc847f1 changeset: 100976:1539ddc847f1 user: Steven D'Aprano date: Fri Apr 15 10:04:24 2016 +1000 summary: Improve tests with more modern assert* methods and subTests. files: Lib/test/test_secrets.py | 47 ++++++++++++++------------- 1 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Lib/test/test_secrets.py b/Lib/test/test_secrets.py --- a/Lib/test/test_secrets.py +++ b/Lib/test/test_secrets.py @@ -44,8 +44,8 @@ def test_bool(self): # Test that compare_digest returns a bool. - self.assertTrue(isinstance(secrets.compare_digest("abc", "abc"), bool)) - self.assertTrue(isinstance(secrets.compare_digest("abc", "xyz"), bool)) + self.assertIsInstance(secrets.compare_digest("abc", "abc"), bool) + self.assertIsInstance(secrets.compare_digest("abc", "xyz"), bool) class Random_Tests(unittest.TestCase): @@ -67,10 +67,8 @@ def test_randbelow(self): # Test randbelow. - errmsg = "randbelow(%d) returned %d" for i in range(2, 10): - n = secrets.randbelow(i) - self.assertTrue(n in range(i), errmsg % (i, n)) + self.assertIn(secrets.randbelow(i), range(i)) self.assertRaises(ValueError, secrets.randbelow, 0) @@ -81,39 +79,44 @@ # Test that token_* functions handle default size correctly. for func in (secrets.token_bytes, secrets.token_hex, secrets.token_urlsafe): - name = func.__name__ - try: - func() - except TypeError: - self.fail("%s cannot be called with no argument" % name) - try: - func(None) - except TypeError: - self.fail("%s cannot be called with None" % name) + with self.subTest(func=func): + name = func.__name__ + try: + func() + except TypeError: + self.fail("%s cannot be called with no argument" % name) + try: + func(None) + except TypeError: + self.fail("%s cannot be called with None" % name) size = secrets.DEFAULT_ENTROPY self.assertEqual(len(secrets.token_bytes(None)), size) self.assertEqual(len(secrets.token_hex(None)), 2*size) def test_token_bytes(self): # Test token_bytes. - self.assertTrue(isinstance(secrets.token_bytes(11), bytes)) for n in (1, 8, 17, 100): - self.assertEqual(len(secrets.token_bytes(n)), n) + with self.subTest(n=n): + self.assertIsInstance(secrets.token_bytes(n), bytes) + self.assertEqual(len(secrets.token_bytes(n)), n) def test_token_hex(self): # Test token_hex. - self.assertTrue(isinstance(secrets.token_hex(7), str)) for n in (1, 12, 25, 90): - s = secrets.token_hex(n) - self.assertEqual(len(s), 2*n) - self.assertTrue(all(c in string.hexdigits for c in s)) + with self.subTest(n=n): + s = secrets.token_hex(n) + self.assertIsInstance(s, str)) + self.assertEqual(len(s), 2*n) + self.assertTrue(all(c in string.hexdigits for c in s)) def test_token_urlsafe(self): # Test token_urlsafe. - self.assertTrue(isinstance(secrets.token_urlsafe(9), str)) legal = string.ascii_letters + string.digits + '-_' for n in (1, 11, 28, 76): - self.assertTrue(all(c in legal for c in secrets.token_urlsafe(n))) + with self.subTest(n=n): + s = secrets.token_urlsafe(n) + self.assertIsInstance(s, str)) + self.assertTrue(all(c in legal for c in s)) if __name__ == '__main__': -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 20:06:47 2016 From: python-checkins at python.org (steven.daprano) Date: Fri, 15 Apr 2016 00:06:47 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_missing_parens=2E?= Message-ID: <20160415000646.53493.7008.643418B9@psf.io> https://hg.python.org/cpython/rev/b128e019ec32 changeset: 100977:b128e019ec32 user: Steven D'Aprano date: Fri Apr 15 10:06:18 2016 +1000 summary: Fix missing parens. files: Lib/test/test_secrets.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_secrets.py b/Lib/test/test_secrets.py --- a/Lib/test/test_secrets.py +++ b/Lib/test/test_secrets.py @@ -105,7 +105,7 @@ for n in (1, 12, 25, 90): with self.subTest(n=n): s = secrets.token_hex(n) - self.assertIsInstance(s, str)) + self.assertIsInstance(s, str) self.assertEqual(len(s), 2*n) self.assertTrue(all(c in string.hexdigits for c in s)) @@ -115,7 +115,7 @@ for n in (1, 11, 28, 76): with self.subTest(n=n): s = secrets.token_urlsafe(n) - self.assertIsInstance(s, str)) + self.assertIsInstance(s, str) self.assertTrue(all(c in legal for c in s)) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 23:35:26 2016 From: python-checkins at python.org (martin.panter) Date: Fri, 15 Apr 2016 03:35:26 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzE1OTg0?= =?utf-8?q?=3A_Correct_PyUnicode=5FFromObject=28=29_and_=5FFromEncodedObje?= =?utf-8?b?Y3QoKSBkb2Nz?= Message-ID: <20160415033526.421.836.6D2035FC@psf.io> https://hg.python.org/cpython/rev/af655e73f7bd changeset: 100979:af655e73f7bd branch: 3.5 user: Martin Panter date: Fri Apr 15 00:56:21 2016 +0000 summary: Issue #15984: Correct PyUnicode_FromObject() and _FromEncodedObject() docs files: Doc/c-api/unicode.rst | 12 +++++++----- Include/unicodeobject.h | 28 ++++++++++------------------ 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -556,14 +556,13 @@ .. c:function:: PyObject* PyUnicode_FromEncodedObject(PyObject *obj, \ const char *encoding, const char *errors) - Coerce an encoded object *obj* to a Unicode object and return a reference with - incremented refcount. + Decode an encoded object *obj* to a Unicode object. :class:`bytes`, :class:`bytearray` and other :term:`bytes-like objects ` are decoded according to the given *encoding* and using the error handling defined by *errors*. Both can be *NULL* to have the interface use the default - values (see the next section for details). + values (see :ref:`builtincodecs` for details). All other objects, including Unicode objects, cause a :exc:`TypeError` to be set. @@ -745,8 +744,11 @@ .. c:function:: PyObject* PyUnicode_FromObject(PyObject *obj) - Shortcut for ``PyUnicode_FromEncodedObject(obj, NULL, "strict")`` which is used - throughout the interpreter whenever coercion to Unicode is needed. + Copy an instance of a Unicode subtype to a new true Unicode object if + necessary. If *obj* is already a true Unicode object (not a subtype), + return the reference with incremented refcount. + + Objects other than Unicode or its subtypes will cause a :exc:`TypeError`. Locale Encoding diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -844,17 +844,13 @@ Py_ssize_t length /* New length */ ); -/* Coerce obj to a Unicode object and return a reference with - *incremented* refcount. - - Coercion is done in the following way: - - 1. bytes, bytearray and other bytes-like objects are decoded - under the assumptions that they contain data using the UTF-8 - encoding. Decoding is done in "strict" mode. - - 2. All other objects (including Unicode objects) raise an - exception. +/* Decode obj to an Unicode object. + + bytes, bytearray and other bytes-like objects are decoded according to the + given encoding and error handler. The encoding and error handler can be + NULL to have the interface use UTF-8 and "strict". + + All other objects (including Unicode objects) raise an exception. The API returns NULL in case of an error. The caller is responsible for decref'ing the returned objects. @@ -867,13 +863,9 @@ const char *errors /* error handling */ ); -/* Coerce obj to a Unicode object and return a reference with - *incremented* refcount. - - Unicode objects are passed back as-is (subclasses are converted to - true Unicode objects), all other objects are delegated to - PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in - using UTF-8 encoding as basis for decoding the object. +/* Copy an instance of a Unicode subtype to a new true Unicode object if + necessary. If obj is already a true Unicode object (not a subtype), return + the reference with *incremented* refcount. The API returns NULL in case of an error. The caller is responsible for decref'ing the returned objects. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 23:35:27 2016 From: python-checkins at python.org (martin.panter) Date: Fri, 15 Apr 2016 03:35:27 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogQ29ycmVjdCDigJxh?= =?utf-8?b?buKAnSDihpIg4oCcYeKAnSB3aXRoIOKAnFVuaWNvZGXigJ0sIOKAnHVzZXI=?= =?utf-8?b?4oCdLCDigJxVVEbigJ0sIGV0Yw==?= Message-ID: <20160415033527.8336.89372.657B33C7@psf.io> https://hg.python.org/cpython/rev/0f5eb87afd23 changeset: 100981:0f5eb87afd23 branch: 2.7 parent: 100971:3a3b30c310e5 user: Martin Panter date: Fri Apr 15 02:14:19 2016 +0000 summary: Correct ?an? ? ?a? with ?Unicode?, ?user?, ?UTF?, etc This affects documentation and code comments. files: Doc/c-api/unicode.rst | 6 +++--- Doc/howto/urllib2.rst | 2 +- Doc/library/ctypes.rst | 2 +- Doc/library/heapq.rst | 2 +- Doc/library/ic.rst | 2 +- Doc/library/io.rst | 2 +- Doc/library/logging.handlers.rst | 2 +- Doc/library/ttk.rst | 2 +- Doc/library/webbrowser.rst | 2 +- Doc/library/xml.etree.elementtree.rst | 2 +- Doc/library/xml.sax.reader.rst | 2 +- Doc/library/xmlrpclib.rst | 4 ++-- Include/stringobject.h | 6 +++--- Include/unicodeobject.h | 4 ++-- Lib/heapq.py | 2 +- Lib/ntpath.py | 4 ++-- Lib/os2emxpath.py | 4 ++-- Lib/test/test_print.py | 2 +- Lib/test/test_zlib.py | 2 +- Lib/xml/etree/ElementTree.py | 2 +- Mac/Modules/icgluemodule.c | 4 ++-- Misc/HISTORY | 2 +- Misc/NEWS | 8 ++++---- Modules/_elementtree.c | 2 +- Modules/_heapqmodule.c | 2 +- Objects/codeobject.c | 2 +- Python/codecs.c | 4 ++-- 27 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -234,7 +234,7 @@ .. c:function:: PyObject *PyUnicode_FromString(const char *u) - Create a Unicode object from an UTF-8 encoded null-terminated char buffer + Create a Unicode object from a UTF-8 encoded null-terminated char buffer *u*. .. versionadded:: 2.6 @@ -347,7 +347,7 @@ .. c:function:: PyObject* PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, const char *errors) - Coerce an encoded object *obj* to an Unicode object and return a reference with + Coerce an encoded object *obj* to a Unicode object and return a reference with incremented refcount. String and other char buffer compatible objects are decoded according to the @@ -663,7 +663,7 @@ If *Py_UNICODE_WIDE* is defined, a single :c:type:`Py_UNICODE` value may get represented as a surrogate pair. If it is not defined, each :c:type:`Py_UNICODE` - values is interpreted as an UCS-2 character. + values is interpreted as a UCS-2 character. Return *NULL* if an exception was raised by the codec. diff --git a/Doc/howto/urllib2.rst b/Doc/howto/urllib2.rst --- a/Doc/howto/urllib2.rst +++ b/Doc/howto/urllib2.rst @@ -55,7 +55,7 @@ html = response.read() Many uses of urllib2 will be that simple (note that instead of an 'http:' URL we -could have used an URL starting with 'ftp:', 'file:', etc.). However, it's the +could have used a URL starting with 'ftp:', 'file:', etc.). However, it's the purpose of this tutorial to explain the more complicated cases, concentrating on HTTP. diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -1873,7 +1873,7 @@ allows specifying the size of the array if the length of the string should not be used. - If the first parameter is a 8-bit string, it is converted into an unicode string + If the first parameter is a 8-bit string, it is converted into a unicode string according to ctypes conversion rules. diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst --- a/Doc/library/heapq.rst +++ b/Doc/library/heapq.rst @@ -244,7 +244,7 @@ 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -In the tree above, each cell *k* is topping ``2*k+1`` and ``2*k+2``. In an usual +In the tree above, each cell *k* is topping ``2*k+1`` and ``2*k+2``. In a usual binary tournament we see in sports, each cell is the winner over the two cells it tops, and we can trace the winner down the tree to see all opponents s/he had. However, in many computer applications of such tournaments, we do not need diff --git a/Doc/library/ic.rst b/Doc/library/ic.rst --- a/Doc/library/ic.rst +++ b/Doc/library/ic.rst @@ -83,7 +83,7 @@ .. method:: IC.parseurl(data[, start[, end[, hint]]]) - Find an URL somewhere in *data* and return start position, end position and the + Find a URL somewhere in *data* and return start position, end position and the URL. The optional *start* and *end* can be used to limit the search, so for instance if a user clicks in a long text field you can pass the whole text field and the click-position in *start* and this routine will return the whole URL in diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -661,7 +661,7 @@ .. class:: TextIOBase - Base class for text streams. This class provides an unicode character + Base class for text streams. This class provides a unicode character and line based interface to stream I/O. There is no :meth:`readinto` method because Python's :class:`unicode` strings are immutable. It inherits :class:`IOBase`. There is no public constructor. diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst --- a/Doc/library/logging.handlers.rst +++ b/Doc/library/logging.handlers.rst @@ -743,7 +743,7 @@ .. method:: emit(record) - Sends the record to the Web server as an URL-encoded dictionary. The + Sends the record to the Web server as a URL-encoded dictionary. The :meth:`mapLogRecord` method is used to convert the record to the dictionary to be sent. diff --git a/Doc/library/ttk.rst b/Doc/library/ttk.rst --- a/Doc/library/ttk.rst +++ b/Doc/library/ttk.rst @@ -686,7 +686,7 @@ headings. Columns may be accessed by number or symbolic names listed in the widget option columns. See `Column Identifiers`_. -Each item is identified by an unique name. The widget will generate item IDs +Each item is identified by a unique name. The widget will generate item IDs if they are not supplied by the caller. There is a distinguished root item, named ``{}``. The root item itself is not displayed; its children appear at the top level of the hierarchy. diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst --- a/Doc/library/webbrowser.rst +++ b/Doc/library/webbrowser.rst @@ -33,7 +33,7 @@ browser and wait. The script :program:`webbrowser` can be used as a command-line interface for the -module. It accepts an URL as the argument. It accepts the following optional +module. It accepts a URL as the argument. It accepts the following optional parameters: ``-n`` opens the URL in a new browser window, if possible; ``-t`` opens the URL in a new browser page ("tab"). The options are, naturally, mutually exclusive. Usage example:: diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -901,7 +901,7 @@ to get proper namespace handling on output. *text_or_uri* is a string containing the QName value, in the form {uri}local, or, if the tag argument is given, the URI part of a QName. If *tag* is given, the first argument is - interpreted as an URI, and this argument is interpreted as a local name. + interpreted as a URI, and this argument is interpreted as a local name. :class:`QName` instances are opaque. diff --git a/Doc/library/xml.sax.reader.rst b/Doc/library/xml.sax.reader.rst --- a/Doc/library/xml.sax.reader.rst +++ b/Doc/library/xml.sax.reader.rst @@ -101,7 +101,7 @@ Process an input source, producing SAX events. The *source* object can be a system identifier (a string identifying the input source -- typically a file - name or an URL), a file-like object, or an :class:`InputSource` object. When + name or a URL), a file-like object, or an :class:`InputSource` object. When :meth:`parse` returns, the input is completely processed, and the parser object can be discarded or reset. As a limitation, the current implementation only accepts byte streams; processing of character streams is for further study. diff --git a/Doc/library/xmlrpclib.rst b/Doc/library/xmlrpclib.rst --- a/Doc/library/xmlrpclib.rst +++ b/Doc/library/xmlrpclib.rst @@ -434,11 +434,11 @@ error. In the following example we're going to intentionally cause a :exc:`ProtocolError` -by providing an URI that doesn't point to an XMLRPC server:: +by providing a URI that doesn't point to an XMLRPC server:: import xmlrpclib - # create a ServerProxy with an URI that doesn't respond to XMLRPC requests + # create a ServerProxy with a URI that doesn't respond to XMLRPC requests proxy = xmlrpclib.ServerProxy("http://www.google.com/") try: diff --git a/Include/stringobject.h b/Include/stringobject.h --- a/Include/stringobject.h +++ b/Include/stringobject.h @@ -129,7 +129,7 @@ /* Encodes a string object and returns the result as Python string object. - If the codec returns an Unicode object, the object is converted + If the codec returns a Unicode object, the object is converted back to a string using the default encoding. DEPRECATED - use PyString_AsEncodedObject() instead. */ @@ -152,7 +152,7 @@ /* Decodes a string object and returns the result as Python string object. - If the codec returns an Unicode object, the object is converted + If the codec returns a Unicode object, the object is converted back to a string using the default encoding. DEPRECATED - use PyString_AsDecodedObject() instead. */ @@ -164,7 +164,7 @@ ); /* Provides access to the internal data buffer and size of a string - object or the default encoded version of an Unicode object. Passing + object or the default encoded version of a Unicode object. Passing NULL as *len parameter will force the string buffer to be 0-terminated (passing a string with embedded NULL characters will cause an exception). */ diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -513,7 +513,7 @@ Py_ssize_t length /* New length */ ); -/* Coerce obj to an Unicode object and return a reference with +/* Coerce obj to a Unicode object and return a reference with *incremented* refcount. Coercion is done in the following way: @@ -536,7 +536,7 @@ const char *errors /* error handling */ ); -/* Coerce obj to an Unicode object and return a reference with +/* Coerce obj to a Unicode object and return a reference with *incremented* refcount. Unicode objects are passed back as-is (subclasses are converted to diff --git a/Lib/heapq.py b/Lib/heapq.py --- a/Lib/heapq.py +++ b/Lib/heapq.py @@ -56,7 +56,7 @@ In the tree above, each cell `k' is topping `2*k+1' and `2*k+2'. In -an usual binary tournament we see in sports, each cell is the winner +a usual binary tournament we see in sports, each cell is the winner over the two cells it tops, and we can trace the winner down the tree to see all opponents s/he had. However, in many computer applications of such tournaments, we do not need to trace the history of a winner. diff --git a/Lib/ntpath.py b/Lib/ntpath.py --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -141,7 +141,7 @@ Return a 2-tuple (unc, rest); either part may be empty. If unc is not empty, it has the form '//host/mount' (or similar using backslashes). unc+rest is always the input path. - Paths containing drive letters never have an UNC part. + Paths containing drive letters never have a UNC part. """ if p[1:2] == ':': return '', p # Drive letter present @@ -227,7 +227,7 @@ lexists = exists # Is a path a mount point? Either a root (with or without drive letter) -# or an UNC path with at most a / or \ after the mount point. +# or a UNC path with at most a / or \ after the mount point. def ismount(path): """Test whether a path is a mount point (defined as root of drive)""" diff --git a/Lib/os2emxpath.py b/Lib/os2emxpath.py --- a/Lib/os2emxpath.py +++ b/Lib/os2emxpath.py @@ -62,7 +62,7 @@ Return a 2-tuple (unc, rest); either part may be empty. If unc is not empty, it has the form '//host/mount' (or similar using backslashes). unc+rest is always the input path. - Paths containing drive letters never have an UNC part. + Paths containing drive letters never have a UNC part. """ if p[1:2] == ':': return '', p # Drive letter present @@ -105,7 +105,7 @@ # Is a path a directory? # Is a path a mount point? Either a root (with or without drive letter) -# or an UNC path with at most a / or \ after the mount point. +# or a UNC path with at most a / or \ after the mount point. def ismount(path): """Test whether a path is a mount point (defined as root of drive)""" diff --git a/Lib/test/test_print.py b/Lib/test/test_print.py --- a/Lib/test/test_print.py +++ b/Lib/test/test_print.py @@ -107,7 +107,7 @@ self.assertRaises(AttributeError, print, '', file='') def test_mixed_args(self): - # If an unicode arg is passed, sep and end should be unicode, too. + # If a unicode arg is passed, sep and end should be unicode, too. class Recorder(object): def __init__(self, must_be_unicode): diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -150,7 +150,7 @@ self.assertEqual(zlib.decompress(x), data) def test_incomplete_stream(self): - # An useful error message is given + # A useful error message is given x = zlib.compress(HAMLET_SCENE) self.assertRaisesRegexp(zlib.error, "Error -5 while decompressing data: incomplete or truncated stream", diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -574,7 +574,7 @@ # @param text A string containing the QName value, in the form {uri}local, # or, if the tag argument is given, the URI part of a QName. # @param tag Optional tag. If given, the first argument is interpreted as -# an URI, and this argument is interpreted as a local name. +# a URI, and this argument is interpreted as a local name. # @return An opaque object, representing the QName. class QName(object): diff --git a/Mac/Modules/icgluemodule.c b/Mac/Modules/icgluemodule.c --- a/Mac/Modules/icgluemodule.c +++ b/Mac/Modules/icgluemodule.c @@ -229,7 +229,7 @@ static char ici_ICParseURL__doc__[] = -"(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle" +"(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find a URL, return in handle" ; static PyObject * @@ -253,7 +253,7 @@ static char ici_ICLaunchURL__doc__[] = -"(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app" +"(hint, data, selStart, selEnd)->None; Find a URL and launch the correct app" ; static PyObject * diff --git a/Misc/HISTORY b/Misc/HISTORY --- a/Misc/HISTORY +++ b/Misc/HISTORY @@ -8024,7 +8024,7 @@ - There is a new Unicode companion to the PyObject_Str() API called PyObject_Unicode(). It behaves in the same way as the - former, but assures that the returned value is an Unicode object + former, but assures that the returned value is a Unicode object (applying the usual coercion if necessary). - The comparison operators support "rich comparison overloading" (PEP diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -5992,7 +5992,7 @@ - Issue #8211: Save/restore CFLAGS around AC_PROG_CC in configure.in, in case it is set. -- Issue #1583863: An unicode subclass can now override the __unicode__ method +- Issue #1583863: A unicode subclass can now override the __unicode__ method - Issue #6474: Make error message from passing an inadequate number of keyword arguments to a function correct. @@ -6497,7 +6497,7 @@ when the release file is empty. - Issue #7748: Since unicode values are supported for some metadata options in - Distutils, the DistributionMetadata get_* methods will now return an utf-8 + Distutils, the DistributionMetadata get_* methods will now return a utf-8 encoded string for them. This ensures that the upload and register commands send the correct values to PyPI without any error. @@ -8873,7 +8873,7 @@ - Silence the DeprecationWarning raised when importing mimetools in BaseHTTPServer, cgi (and rfc822), httplib. -- Issue #2776: fixed small issue when handling an URL with double slash +- Issue #2776: fixed small issue when handling a URL with double slash after a 302 response in the case of not going through a proxy. - Issue #2676: in the email package, content-type parsing was hanging on @@ -10205,7 +10205,7 @@ ``object.__reduce_ex__()`` is called with an object that is faking its type. -- Patch #1680015: Don't modify __slots__ tuple if it contains an +- Patch #1680015: Don't modify __slots__ tuple if it contains a unicode name. - Patch #1444529: the builtin compile() now accepts keyword arguments. diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -2104,7 +2104,7 @@ /* decode universal name */ #if defined(Py_USING_UNICODE) /* inline makestring, to avoid duplicating the source string if - it's not an utf-8 string */ + it's not a utf-8 string */ p = PyString_AS_STRING(tag); if (checkstring(p, size)) { value = PyUnicode_DecodeUTF8(p, size, "strict"); diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c --- a/Modules/_heapqmodule.c +++ b/Modules/_heapqmodule.c @@ -619,7 +619,7 @@ \n\ \n\ In the tree above, each cell `k' is topping `2*k+1' and `2*k+2'. In\n\ -an usual binary tournament we see in sports, each cell is the winner\n\ +a usual binary tournament we see in sports, each cell is the winner\n\ over the two cells it tops, and we can trace the winner down the tree\n\ to see all opponents s/he had. However, in many computer applications\n\ of such tournaments, we do not need to trace the history of a winner.\n\ diff --git a/Objects/codeobject.c b/Objects/codeobject.c --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -492,7 +492,7 @@ return key; } else { - /* for other types, use the object identifier as an unique identifier + /* for other types, use the object identifier as a unique identifier * to ensure that they are seen as unequal. */ PyObject *obj_id = PyLong_FromVoidPtr(op); if (obj_id == NULL) diff --git a/Python/codecs.c b/Python/codecs.c --- a/Python/codecs.c +++ b/Python/codecs.c @@ -334,7 +334,7 @@ return codec_getstreamcodec(encoding, stream, errors, 3); } -/* Encode an object (e.g. an Unicode object) using the given encoding +/* Encode an object (e.g. a Unicode object) using the given encoding and return the resulting encoded object (usually a Python string). errors is passed to the encoder factory as argument if non-NULL. */ @@ -379,7 +379,7 @@ } /* Decode an object (usually a Python string) using the given encoding - and return an equivalent object (e.g. an Unicode object). + and return an equivalent object (e.g. a Unicode object). errors is passed to the decoder factory as argument if non-NULL. */ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 23:35:27 2016 From: python-checkins at python.org (martin.panter) Date: Fri, 15 Apr 2016 03:35:27 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogQ29ycmVjdCDigJxh?= =?utf-8?b?buKAnSDihpIg4oCcYeKAnSB3aXRoIOKAnFVuaWNvZGXigJ0sIOKAnHVzZXI=?= =?utf-8?b?4oCdLCDigJxVVEbigJ0sIGV0Yw==?= Message-ID: <20160415033526.70517.15173.2D3CAA1D@psf.io> https://hg.python.org/cpython/rev/d4ea5b9802f8 changeset: 100978:d4ea5b9802f8 branch: 3.5 parent: 100972:4936b2723471 user: Martin Panter date: Fri Apr 15 02:14:19 2016 +0000 summary: Correct ?an? ? ?a? with ?Unicode?, ?user?, ?UTF?, etc This affects documentation, code comments, and a debugging messages. files: Doc/c-api/exceptions.rst | 4 ++-- Doc/c-api/import.rst | 2 +- Doc/c-api/method.rst | 2 +- Doc/c-api/module.rst | 2 +- Doc/c-api/unicode.rst | 6 +++--- Doc/howto/urllib2.rst | 2 +- Doc/library/heapq.rst | 2 +- Doc/library/logging.handlers.rst | 2 +- Doc/library/os.rst | 2 +- Doc/library/re.rst | 2 +- Doc/library/tkinter.ttk.rst | 2 +- Doc/library/webbrowser.rst | 2 +- Doc/library/xml.etree.elementtree.rst | 2 +- Doc/library/xml.sax.reader.rst | 2 +- Doc/library/xmlrpc.client.rst | 2 +- Include/bytesobject.h | 2 +- Include/unicodeobject.h | 8 ++++---- Lib/asyncio/windows_events.py | 2 +- Lib/email/utils.py | 2 +- Lib/heapq.py | 2 +- Lib/nntplib.py | 8 ++++---- Lib/ntpath.py | 2 +- Lib/test/test_codecs.py | 2 +- Lib/test/test_multibytecodec.py | 4 ++-- Lib/test/test_nntplib.py | 2 +- Lib/test/test_unicode.py | 2 +- Lib/test/test_zlib.py | 2 +- Misc/HISTORY | 10 +++++----- Misc/NEWS | 6 +++--- Modules/_heapqmodule.c | 2 +- Modules/_pickle.c | 2 +- Modules/_tracemalloc.c | 2 +- Objects/codeobject.c | 2 +- Objects/unicodeobject.c | 2 +- Python/codecs.c | 4 ++-- 35 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -285,7 +285,7 @@ .. c:function:: int PyErr_WarnEx(PyObject *category, const char *message, Py_ssize_t stack_level) Issue a warning message. The *category* argument is a warning category (see - below) or *NULL*; the *message* argument is an UTF-8 encoded string. *stack_level* is a + below) or *NULL*; the *message* argument is a UTF-8 encoded string. *stack_level* is a positive number giving a number of stack frames; the warning will be issued from the currently executing line of code in that stack frame. A *stack_level* of 1 is the function calling :c:func:`PyErr_WarnEx`, 2 is the function above that, @@ -609,7 +609,7 @@ .. c:function:: PyObject* PyUnicodeTranslateError_Create(const Py_UNICODE *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason) Create a :class:`UnicodeTranslateError` object with the attributes *object*, - *length*, *start*, *end* and *reason*. *reason* is an UTF-8 encoded string. + *length*, *start*, *end* and *reason*. *reason* is a UTF-8 encoded string. .. c:function:: PyObject* PyUnicodeDecodeError_GetEncoding(PyObject *exc) PyObject* PyUnicodeEncodeError_GetEncoding(PyObject *exc) diff --git a/Doc/c-api/import.rst b/Doc/c-api/import.rst --- a/Doc/c-api/import.rst +++ b/Doc/c-api/import.rst @@ -72,7 +72,7 @@ .. c:function:: PyObject* PyImport_ImportModuleLevel(const char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level) - Similar to :c:func:`PyImport_ImportModuleLevelObject`, but the name is an + Similar to :c:func:`PyImport_ImportModuleLevelObject`, but the name is a UTF-8 encoded string instead of a Unicode object. .. versionchanged:: 3.3 diff --git a/Doc/c-api/method.rst b/Doc/c-api/method.rst --- a/Doc/c-api/method.rst +++ b/Doc/c-api/method.rst @@ -49,7 +49,7 @@ .. index:: object: method Methods are bound function objects. Methods are always bound to an instance of -an user-defined class. Unbound methods (methods bound to a class object) are +a user-defined class. Unbound methods (methods bound to a class object) are no longer available. diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -50,7 +50,7 @@ .. c:function:: PyObject* PyModule_New(const char *name) - Similar to :c:func:`PyImport_NewObject`, but the name is an UTF-8 encoded + Similar to :c:func:`PyImport_NewObject`, but the name is a UTF-8 encoded string instead of a Unicode object. diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -423,7 +423,7 @@ .. c:function:: PyObject *PyUnicode_FromString(const char *u) - Create a Unicode object from an UTF-8 encoded null-terminated char buffer + Create a Unicode object from a UTF-8 encoded null-terminated char buffer *u*. @@ -556,7 +556,7 @@ .. c:function:: PyObject* PyUnicode_FromEncodedObject(PyObject *obj, \ const char *encoding, const char *errors) - Coerce an encoded object *obj* to an Unicode object and return a reference with + Coerce an encoded object *obj* to a Unicode object and return a reference with incremented refcount. :class:`bytes`, :class:`bytearray` and other @@ -1224,7 +1224,7 @@ If *Py_UNICODE_WIDE* is defined, a single :c:type:`Py_UNICODE` value may get represented as a surrogate pair. If it is not defined, each :c:type:`Py_UNICODE` - values is interpreted as an UCS-2 character. + values is interpreted as a UCS-2 character. Return *NULL* if an exception was raised by the codec. diff --git a/Doc/howto/urllib2.rst b/Doc/howto/urllib2.rst --- a/Doc/howto/urllib2.rst +++ b/Doc/howto/urllib2.rst @@ -64,7 +64,7 @@ html = open(local_filename) Many uses of urllib will be that simple (note that instead of an 'http:' URL we -could have used an URL starting with 'ftp:', 'file:', etc.). However, it's the +could have used a URL starting with 'ftp:', 'file:', etc.). However, it's the purpose of this tutorial to explain the more complicated cases, concentrating on HTTP. diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst --- a/Doc/library/heapq.rst +++ b/Doc/library/heapq.rst @@ -242,7 +242,7 @@ 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -In the tree above, each cell *k* is topping ``2*k+1`` and ``2*k+2``. In an usual +In the tree above, each cell *k* is topping ``2*k+1`` and ``2*k+2``. In a usual binary tournament we see in sports, each cell is the winner over the two cells it tops, and we can trace the winner down the tree to see all opponents s/he had. However, in many computer applications of such tournaments, we do not need diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst --- a/Doc/library/logging.handlers.rst +++ b/Doc/library/logging.handlers.rst @@ -866,7 +866,7 @@ .. method:: emit(record) - Sends the record to the Web server as an URL-encoded dictionary. The + Sends the record to the Web server as a URL-encoded dictionary. The :meth:`mapLogRecord` method is used to convert the record to the dictionary to be sent. diff --git a/Doc/library/os.rst b/Doc/library/os.rst --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1762,7 +1762,7 @@ ``os.path.join(os.path.dirname(path), result)``. If the *path* is a string object, the result will also be a string object, - and the call may raise an UnicodeDecodeError. If the *path* is a bytes + and the call may raise a UnicodeDecodeError. If the *path* is a bytes object, the result will be a bytes object. This function can also support :ref:`paths relative to directory descriptors diff --git a/Doc/library/re.rst b/Doc/library/re.rst --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -12,7 +12,7 @@ Both patterns and strings to be searched can be Unicode strings as well as 8-bit strings. However, Unicode strings and 8-bit strings cannot be mixed: -that is, you cannot match an Unicode string with a byte pattern or +that is, you cannot match a Unicode string with a byte pattern or vice-versa; similarly, when asking for a substitution, the replacement string must be of the same type as both the pattern and the search string. diff --git a/Doc/library/tkinter.ttk.rst b/Doc/library/tkinter.ttk.rst --- a/Doc/library/tkinter.ttk.rst +++ b/Doc/library/tkinter.ttk.rst @@ -701,7 +701,7 @@ headings. Columns may be accessed by number or symbolic names listed in the widget option columns. See `Column Identifiers`_. -Each item is identified by an unique name. The widget will generate item IDs +Each item is identified by a unique name. The widget will generate item IDs if they are not supplied by the caller. There is a distinguished root item, named ``{}``. The root item itself is not displayed; its children appear at the top level of the hierarchy. diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst --- a/Doc/library/webbrowser.rst +++ b/Doc/library/webbrowser.rst @@ -33,7 +33,7 @@ browser and wait. The script :program:`webbrowser` can be used as a command-line interface for the -module. It accepts an URL as the argument. It accepts the following optional +module. It accepts a URL as the argument. It accepts the following optional parameters: ``-n`` opens the URL in a new browser window, if possible; ``-t`` opens the URL in a new browser page ("tab"). The options are, naturally, mutually exclusive. Usage example:: diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -978,7 +978,7 @@ to get proper namespace handling on output. *text_or_uri* is a string containing the QName value, in the form {uri}local, or, if the tag argument is given, the URI part of a QName. If *tag* is given, the first argument is - interpreted as an URI, and this argument is interpreted as a local name. + interpreted as a URI, and this argument is interpreted as a local name. :class:`QName` instances are opaque. diff --git a/Doc/library/xml.sax.reader.rst b/Doc/library/xml.sax.reader.rst --- a/Doc/library/xml.sax.reader.rst +++ b/Doc/library/xml.sax.reader.rst @@ -98,7 +98,7 @@ Process an input source, producing SAX events. The *source* object can be a system identifier (a string identifying the input source -- typically a file - name or an URL), a file-like object, or an :class:`InputSource` object. When + name or a URL), a file-like object, or an :class:`InputSource` object. When :meth:`parse` returns, the input is completely processed, and the parser object can be discarded or reset. diff --git a/Doc/library/xmlrpc.client.rst b/Doc/library/xmlrpc.client.rst --- a/Doc/library/xmlrpc.client.rst +++ b/Doc/library/xmlrpc.client.rst @@ -420,7 +420,7 @@ import xmlrpc.client - # create a ServerProxy with an URI that doesn't respond to XMLRPC requests + # create a ServerProxy with a URI that doesn't respond to XMLRPC requests proxy = xmlrpc.client.ServerProxy("http://google.com/") try: diff --git a/Include/bytesobject.h b/Include/bytesobject.h --- a/Include/bytesobject.h +++ b/Include/bytesobject.h @@ -82,7 +82,7 @@ #endif /* Provides access to the internal data buffer and size of a string - object or the default encoded version of an Unicode object. Passing + object or the default encoded version of a Unicode object. Passing NULL as *len parameter will force the string buffer to be 0-terminated (passing a string with embedded NULL characters will cause an exception). */ diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -823,7 +823,7 @@ PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void); #endif -/* Resize an Unicode object. The length is the number of characters, except +/* Resize a Unicode object. The length is the number of characters, except if the kind of the string is PyUnicode_WCHAR_KIND: in this case, the length is the number of Py_UNICODE characters. @@ -844,7 +844,7 @@ Py_ssize_t length /* New length */ ); -/* Coerce obj to an Unicode object and return a reference with +/* Coerce obj to a Unicode object and return a reference with *incremented* refcount. Coercion is done in the following way: @@ -867,7 +867,7 @@ const char *errors /* error handling */ ); -/* Coerce obj to an Unicode object and return a reference with +/* Coerce obj to a Unicode object and return a reference with *incremented* refcount. Unicode objects are passed back as-is (subclasses are converted to @@ -981,7 +981,7 @@ Py_ssize_t len /* length in bytes */ ); -/* Get the value of the writer as an Unicode string. Clear the +/* Get the value of the writer as a Unicode string. Clear the buffer of the writer. Raise an exception and return NULL on error. */ PyAPI_FUNC(PyObject *) diff --git a/Lib/asyncio/windows_events.py b/Lib/asyncio/windows_events.py --- a/Lib/asyncio/windows_events.py +++ b/Lib/asyncio/windows_events.py @@ -197,7 +197,7 @@ # # If the IocpProactor already received the event, it's safe to call # _unregister() because we kept a reference to the Overlapped object - # which is used as an unique key. + # which is used as a unique key. self._proactor._unregister(self._ov) self._proactor = None diff --git a/Lib/email/utils.py b/Lib/email/utils.py --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -87,7 +87,7 @@ 'utf-8'. """ name, address = pair - # The address MUST (per RFC) be ascii, so raise an UnicodeError if it isn't. + # The address MUST (per RFC) be ascii, so raise a UnicodeError if it isn't. address.encode('ascii') if name: try: diff --git a/Lib/heapq.py b/Lib/heapq.py --- a/Lib/heapq.py +++ b/Lib/heapq.py @@ -54,7 +54,7 @@ In the tree above, each cell `k' is topping `2*k+1' and `2*k+2'. In -an usual binary tournament we see in sports, each cell is the winner +a usual binary tournament we see in sports, each cell is the winner over the two cells it tops, and we can trace the winner down the tree to see all opponents s/he had. However, in many computer applications of such tournaments, we do not need to trace the history of a winner. diff --git a/Lib/nntplib.py b/Lib/nntplib.py --- a/Lib/nntplib.py +++ b/Lib/nntplib.py @@ -165,7 +165,7 @@ # Helper function(s) def decode_header(header_str): - """Takes an unicode string representing a munged header value + """Takes a unicode string representing a munged header value and decodes it as a (possibly non-ASCII) readable value.""" parts = [] for v, enc in _email_decode_header(header_str): @@ -420,7 +420,7 @@ def _putcmd(self, line): """Internal: send one command to the server (through _putline()). - The `line` must be an unicode string.""" + The `line` must be a unicode string.""" if self.debugging: print('*cmd*', repr(line)) line = line.encode(self.encoding, self.errors) self._putline(line) @@ -445,7 +445,7 @@ def _getresp(self): """Internal: get a response from the server. Raise various errors if the response indicates an error. - Returns an unicode string.""" + Returns a unicode string.""" resp = self._getline() if self.debugging: print('*resp*', repr(resp)) resp = resp.decode(self.encoding, self.errors) @@ -462,7 +462,7 @@ """Internal: get a response plus following text from the server. Raise various errors if the response indicates an error. - Returns a (response, lines) tuple where `response` is an unicode + Returns a (response, lines) tuple where `response` is a unicode string and `lines` is a list of bytes objects. If `file` is a file-like object, it must be open in binary mode. """ diff --git a/Lib/ntpath.py b/Lib/ntpath.py --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -177,7 +177,7 @@ Return a 2-tuple (unc, rest); either part may be empty. If unc is not empty, it has the form '//host/mount' (or similar using backslashes). unc+rest is always the input path. - Paths containing drive letters never have an UNC part. + Paths containing drive letters never have a UNC part. """ import warnings warnings.warn("ntpath.splitunc is deprecated, use ntpath.splitdrive instead", diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -2355,7 +2355,7 @@ self.assertRaises(TypeError, decoder, "xxx") def test_unicode_escape(self): - # Escape-decoding an unicode string is supported ang gives the same + # Escape-decoding a unicode string is supported ang gives the same # result as decoding the equivalent ASCII bytes string. self.assertEqual(codecs.unicode_escape_decode(r"\u1234"), ("\u1234", 6)) self.assertEqual(codecs.unicode_escape_decode(br"\u1234"), ("\u1234", 6)) diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -67,7 +67,7 @@ _multibytecodec.MultibyteStreamWriter, None) def test_decode_unicode(self): - # Trying to decode an unicode string should raise a TypeError + # Trying to decode a unicode string should raise a TypeError for enc in ALL_CJKENCODINGS: self.assertRaises(TypeError, codecs.getdecoder(enc), "") @@ -160,7 +160,7 @@ self.assertEqual(decoder.decode(b'B@$'), '\u4e16') def test_decode_unicode(self): - # Trying to decode an unicode string should raise a TypeError + # Trying to decode a unicode string should raise a TypeError for enc in ALL_CJKENCODINGS: decoder = codecs.getincrementaldecoder(enc)() self.assertRaises(TypeError, decoder.decode, "") diff --git a/Lib/test/test_nntplib.py b/Lib/test/test_nntplib.py --- a/Lib/test/test_nntplib.py +++ b/Lib/test/test_nntplib.py @@ -609,7 +609,7 @@ "\t\t6683\t16" "\t" "\n" - # An UTF-8 overview line from fr.comp.lang.python + # A UTF-8 overview line from fr.comp.lang.python "59\tRe: Message d'erreur incompr?hensible (par moi)" "\tEric Brunel " "\tWed, 15 Sep 2010 18:09:15 +0200" diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1774,7 +1774,7 @@ def assertCorrectUTF8Decoding(self, seq, res, err): """ - Check that an invalid UTF-8 sequence raises an UnicodeDecodeError when + Check that an invalid UTF-8 sequence raises a UnicodeDecodeError when 'strict' is used, returns res when 'replace' is used, and that doesn't return anything when 'ignore' is used. """ diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -171,7 +171,7 @@ self.assertEqual(zlib.decompress(ob), data) def test_incomplete_stream(self): - # An useful error message is given + # A useful error message is given x = zlib.compress(HAMLET_SCENE) self.assertRaisesRegex(zlib.error, "Error -5 while decompressing data: incomplete or truncated stream", diff --git a/Misc/HISTORY b/Misc/HISTORY --- a/Misc/HISTORY +++ b/Misc/HISTORY @@ -2237,7 +2237,7 @@ attribute which allows setting custom per-pickler reduction functions. Patch by sbt. -- Issue #14177: marshal.loads() now raises TypeError when given an unicode +- Issue #14177: marshal.loads() now raises TypeError when given a unicode string. Patch by Guilherme Gon?alves. - Issue #13550: Remove the debug machinery from the threading module: remove @@ -8304,7 +8304,7 @@ - Issue #1664: Make nntplib IPv6-capable. Patch by Derek Morr. - Issue #5006: Better handling of unicode byte-order marks (BOM) in the io - library. This means, for example, that opening an UTF-16 text file in + library. This means, for example, that opening a UTF-16 text file in append mode doesn't add a BOM at the end of the file if the file isn't empty. @@ -9328,7 +9328,7 @@ - Issue #4756: zipfile.is_zipfile() now supports file-like objects. Patch by Gabriel Genellina. -- Issue #4574: reading an UTF16-encoded text file crashes if \r on 64-char +- Issue #4574: reading a UTF16-encoded text file crashes if \r on 64-char boundary. - Issue #4223: inspect.getsource() will now correctly display source code @@ -9929,7 +9929,7 @@ exploitation of poor argument checking. - bsddb code updated to version 4.7.3pre2. This code is the same than - Python 2.6 one, since the intention is to keep an unified 2.x/3.x codebase. + Python 2.6 one, since the intention is to keep a unified 2.x/3.x codebase. The Python code is automatically translated using "2to3". Please, do not update this code in Python 3.0 by hand. Update the 2.6 one and then do "2to3". @@ -18936,7 +18936,7 @@ - There is a new Unicode companion to the PyObject_Str() API called PyObject_Unicode(). It behaves in the same way as the - former, but assures that the returned value is an Unicode object + former, but assures that the returned value is a Unicode object (applying the usual coercion if necessary). - The comparison operators support "rich comparison overloading" (PEP diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2227,7 +2227,7 @@ static type in some cases. - Issue #15859: PyUnicode_EncodeFSDefault(), PyUnicode_EncodeMBCS() and - PyUnicode_EncodeCodePage() now raise an exception if the object is not an + PyUnicode_EncodeCodePage() now raise an exception if the object is not a Unicode object. For PyUnicode_EncodeFSDefault(), it was already the case on platforms other than Windows. Patch written by Campbell Barton. @@ -3318,7 +3318,7 @@ - Issue #21226: Set up modules properly in PyImport_ExecCodeModuleObject (and friends). -- Issue #21398: Fix an unicode error in the pydoc pager when the documentation +- Issue #21398: Fix a unicode error in the pydoc pager when the documentation contains characters not encodable to the stdout encoding. - Issue #16531: ipaddress.IPv4Network and ipaddress.IPv6Network now accept @@ -6322,7 +6322,7 @@ - Issue #17173: Remove uses of locale-dependent C functions (isalpha() etc.) in the interpreter. -- Issue #17137: When an Unicode string is resized, the internal wide character +- Issue #17137: When a Unicode string is resized, the internal wide character string (wstr) format is now cleared. - Issue #17043: The unicode-internal decoder no longer read past the end of diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c --- a/Modules/_heapqmodule.c +++ b/Modules/_heapqmodule.c @@ -550,7 +550,7 @@ \n\ \n\ In the tree above, each cell `k' is topping `2*k+1' and `2*k+2'. In\n\ -an usual binary tournament we see in sports, each cell is the winner\n\ +a usual binary tournament we see in sports, each cell is the winner\n\ over the two cells it tops, and we can trace the winner down the tree\n\ to see all opponents s/he had. However, in many computer applications\n\ of such tournaments, we do not need to trace the history of a winner.\n\ diff --git a/Modules/_pickle.c b/Modules/_pickle.c --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -1096,7 +1096,7 @@ return 0; assert(self->peek); /* otherwise we did something wrong */ - /* This makes an useless copy... */ + /* This makes a useless copy... */ r = PyObject_CallFunction(self->read, "n", consumed); if (r == NULL) return -1; diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -296,7 +296,7 @@ if (!PyUnicode_Check(filename)) { #ifdef TRACE_DEBUG - tracemalloc_error("filename is not an unicode string"); + tracemalloc_error("filename is not a unicode string"); #endif return; } diff --git a/Objects/codeobject.c b/Objects/codeobject.c --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -520,7 +520,7 @@ return key; } else { - /* for other types, use the object identifier as an unique identifier + /* for other types, use the object identifier as a unique identifier * to ensure that they are seen as unequal. */ PyObject *obj_id = PyLong_FromVoidPtr(op); if (obj_id == NULL) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -675,7 +675,7 @@ } #ifdef Py_DEBUG -/* Fill the data of an Unicode string with invalid characters to detect bugs +/* Fill the data of a Unicode string with invalid characters to detect bugs earlier. _PyUnicode_CheckConsistency(str, 1) detects invalid characters, at least for diff --git a/Python/codecs.c b/Python/codecs.c --- a/Python/codecs.c +++ b/Python/codecs.c @@ -403,7 +403,7 @@ operation, encoding); } -/* Encode an object (e.g. an Unicode object) using the given encoding +/* Encode an object (e.g. a Unicode object) using the given encoding and return the resulting encoded object (usually a Python string). errors is passed to the encoder factory as argument if non-NULL. */ @@ -450,7 +450,7 @@ } /* Decode an object (usually a Python string) using the given encoding - and return an equivalent object (e.g. an Unicode object). + and return an equivalent object (e.g. a Unicode object). errors is passed to the decoder factory as argument if non-NULL. */ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 14 23:35:27 2016 From: python-checkins at python.org (martin.panter) Date: Fri, 15 Apr 2016 03:35:27 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315984=3A_Merge_PyUnicode_doc_from_3=2E5?= Message-ID: <20160415033527.19515.14043.22037689@psf.io> https://hg.python.org/cpython/rev/570ada02d0f0 changeset: 100980:570ada02d0f0 parent: 100977:b128e019ec32 parent: 100979:af655e73f7bd user: Martin Panter date: Fri Apr 15 02:27:11 2016 +0000 summary: Issue #15984: Merge PyUnicode doc from 3.5 files: Doc/c-api/exceptions.rst | 4 +- Doc/c-api/import.rst | 2 +- Doc/c-api/method.rst | 2 +- Doc/c-api/module.rst | 2 +- Doc/c-api/unicode.rst | 16 ++++--- Doc/howto/urllib2.rst | 2 +- Doc/library/heapq.rst | 2 +- Doc/library/logging.handlers.rst | 2 +- Doc/library/os.rst | 2 +- Doc/library/re.rst | 2 +- Doc/library/tkinter.ttk.rst | 2 +- Doc/library/webbrowser.rst | 2 +- Doc/library/xml.etree.elementtree.rst | 2 +- Doc/library/xml.sax.reader.rst | 2 +- Doc/library/xmlrpc.client.rst | 2 +- Include/bytesobject.h | 2 +- Include/unicodeobject.h | 32 +++++--------- Lib/asyncio/windows_events.py | 2 +- Lib/email/utils.py | 2 +- Lib/heapq.py | 2 +- Lib/nntplib.py | 8 +- Lib/ntpath.py | 2 +- Lib/test/test_codecs.py | 2 +- Lib/test/test_multibytecodec.py | 4 +- Lib/test/test_nntplib.py | 2 +- Lib/test/test_unicode.py | 2 +- Lib/test/test_zlib.py | 2 +- Misc/HISTORY | 10 ++-- Misc/NEWS | 6 +- Modules/_heapqmodule.c | 2 +- Modules/_pickle.c | 2 +- Modules/_tracemalloc.c | 2 +- Objects/codeobject.c | 2 +- Objects/unicodeobject.c | 2 +- Python/codecs.c | 4 +- 35 files changed, 66 insertions(+), 72 deletions(-) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -285,7 +285,7 @@ .. c:function:: int PyErr_WarnEx(PyObject *category, const char *message, Py_ssize_t stack_level) Issue a warning message. The *category* argument is a warning category (see - below) or *NULL*; the *message* argument is an UTF-8 encoded string. *stack_level* is a + below) or *NULL*; the *message* argument is a UTF-8 encoded string. *stack_level* is a positive number giving a number of stack frames; the warning will be issued from the currently executing line of code in that stack frame. A *stack_level* of 1 is the function calling :c:func:`PyErr_WarnEx`, 2 is the function above that, @@ -617,7 +617,7 @@ .. c:function:: PyObject* PyUnicodeTranslateError_Create(const Py_UNICODE *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason) Create a :class:`UnicodeTranslateError` object with the attributes *object*, - *length*, *start*, *end* and *reason*. *reason* is an UTF-8 encoded string. + *length*, *start*, *end* and *reason*. *reason* is a UTF-8 encoded string. .. c:function:: PyObject* PyUnicodeDecodeError_GetEncoding(PyObject *exc) PyObject* PyUnicodeEncodeError_GetEncoding(PyObject *exc) diff --git a/Doc/c-api/import.rst b/Doc/c-api/import.rst --- a/Doc/c-api/import.rst +++ b/Doc/c-api/import.rst @@ -72,7 +72,7 @@ .. c:function:: PyObject* PyImport_ImportModuleLevel(const char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level) - Similar to :c:func:`PyImport_ImportModuleLevelObject`, but the name is an + Similar to :c:func:`PyImport_ImportModuleLevelObject`, but the name is a UTF-8 encoded string instead of a Unicode object. .. versionchanged:: 3.3 diff --git a/Doc/c-api/method.rst b/Doc/c-api/method.rst --- a/Doc/c-api/method.rst +++ b/Doc/c-api/method.rst @@ -49,7 +49,7 @@ .. index:: object: method Methods are bound function objects. Methods are always bound to an instance of -an user-defined class. Unbound methods (methods bound to a class object) are +a user-defined class. Unbound methods (methods bound to a class object) are no longer available. diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -50,7 +50,7 @@ .. c:function:: PyObject* PyModule_New(const char *name) - Similar to :c:func:`PyImport_NewObject`, but the name is an UTF-8 encoded + Similar to :c:func:`PyImport_NewObject`, but the name is a UTF-8 encoded string instead of a Unicode object. diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -423,7 +423,7 @@ .. c:function:: PyObject *PyUnicode_FromString(const char *u) - Create a Unicode object from an UTF-8 encoded null-terminated char buffer + Create a Unicode object from a UTF-8 encoded null-terminated char buffer *u*. @@ -556,14 +556,13 @@ .. c:function:: PyObject* PyUnicode_FromEncodedObject(PyObject *obj, \ const char *encoding, const char *errors) - Coerce an encoded object *obj* to an Unicode object and return a reference with - incremented refcount. + Decode an encoded object *obj* to a Unicode object. :class:`bytes`, :class:`bytearray` and other :term:`bytes-like objects ` are decoded according to the given *encoding* and using the error handling defined by *errors*. Both can be *NULL* to have the interface use the default - values (see the next section for details). + values (see :ref:`builtincodecs` for details). All other objects, including Unicode objects, cause a :exc:`TypeError` to be set. @@ -745,8 +744,11 @@ .. c:function:: PyObject* PyUnicode_FromObject(PyObject *obj) - Shortcut for ``PyUnicode_FromEncodedObject(obj, NULL, "strict")`` which is used - throughout the interpreter whenever coercion to Unicode is needed. + Copy an instance of a Unicode subtype to a new true Unicode object if + necessary. If *obj* is already a true Unicode object (not a subtype), + return the reference with incremented refcount. + + Objects other than Unicode or its subtypes will cause a :exc:`TypeError`. Locale Encoding @@ -1224,7 +1226,7 @@ If *Py_UNICODE_WIDE* is defined, a single :c:type:`Py_UNICODE` value may get represented as a surrogate pair. If it is not defined, each :c:type:`Py_UNICODE` - values is interpreted as an UCS-2 character. + values is interpreted as a UCS-2 character. Return *NULL* if an exception was raised by the codec. diff --git a/Doc/howto/urllib2.rst b/Doc/howto/urllib2.rst --- a/Doc/howto/urllib2.rst +++ b/Doc/howto/urllib2.rst @@ -64,7 +64,7 @@ html = open(local_filename) Many uses of urllib will be that simple (note that instead of an 'http:' URL we -could have used an URL starting with 'ftp:', 'file:', etc.). However, it's the +could have used a URL starting with 'ftp:', 'file:', etc.). However, it's the purpose of this tutorial to explain the more complicated cases, concentrating on HTTP. diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst --- a/Doc/library/heapq.rst +++ b/Doc/library/heapq.rst @@ -242,7 +242,7 @@ 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -In the tree above, each cell *k* is topping ``2*k+1`` and ``2*k+2``. In an usual +In the tree above, each cell *k* is topping ``2*k+1`` and ``2*k+2``. In a usual binary tournament we see in sports, each cell is the winner over the two cells it tops, and we can trace the winner down the tree to see all opponents s/he had. However, in many computer applications of such tournaments, we do not need diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst --- a/Doc/library/logging.handlers.rst +++ b/Doc/library/logging.handlers.rst @@ -874,7 +874,7 @@ .. method:: emit(record) - Sends the record to the Web server as an URL-encoded dictionary. The + Sends the record to the Web server as a URL-encoded dictionary. The :meth:`mapLogRecord` method is used to convert the record to the dictionary to be sent. diff --git a/Doc/library/os.rst b/Doc/library/os.rst --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1762,7 +1762,7 @@ ``os.path.join(os.path.dirname(path), result)``. If the *path* is a string object, the result will also be a string object, - and the call may raise an UnicodeDecodeError. If the *path* is a bytes + and the call may raise a UnicodeDecodeError. If the *path* is a bytes object, the result will be a bytes object. This function can also support :ref:`paths relative to directory descriptors diff --git a/Doc/library/re.rst b/Doc/library/re.rst --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -12,7 +12,7 @@ Both patterns and strings to be searched can be Unicode strings as well as 8-bit strings. However, Unicode strings and 8-bit strings cannot be mixed: -that is, you cannot match an Unicode string with a byte pattern or +that is, you cannot match a Unicode string with a byte pattern or vice-versa; similarly, when asking for a substitution, the replacement string must be of the same type as both the pattern and the search string. diff --git a/Doc/library/tkinter.ttk.rst b/Doc/library/tkinter.ttk.rst --- a/Doc/library/tkinter.ttk.rst +++ b/Doc/library/tkinter.ttk.rst @@ -701,7 +701,7 @@ headings. Columns may be accessed by number or symbolic names listed in the widget option columns. See `Column Identifiers`_. -Each item is identified by an unique name. The widget will generate item IDs +Each item is identified by a unique name. The widget will generate item IDs if they are not supplied by the caller. There is a distinguished root item, named ``{}``. The root item itself is not displayed; its children appear at the top level of the hierarchy. diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst --- a/Doc/library/webbrowser.rst +++ b/Doc/library/webbrowser.rst @@ -33,7 +33,7 @@ browser and wait. The script :program:`webbrowser` can be used as a command-line interface for the -module. It accepts an URL as the argument. It accepts the following optional +module. It accepts a URL as the argument. It accepts the following optional parameters: ``-n`` opens the URL in a new browser window, if possible; ``-t`` opens the URL in a new browser page ("tab"). The options are, naturally, mutually exclusive. Usage example:: diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -978,7 +978,7 @@ to get proper namespace handling on output. *text_or_uri* is a string containing the QName value, in the form {uri}local, or, if the tag argument is given, the URI part of a QName. If *tag* is given, the first argument is - interpreted as an URI, and this argument is interpreted as a local name. + interpreted as a URI, and this argument is interpreted as a local name. :class:`QName` instances are opaque. diff --git a/Doc/library/xml.sax.reader.rst b/Doc/library/xml.sax.reader.rst --- a/Doc/library/xml.sax.reader.rst +++ b/Doc/library/xml.sax.reader.rst @@ -98,7 +98,7 @@ Process an input source, producing SAX events. The *source* object can be a system identifier (a string identifying the input source -- typically a file - name or an URL), a file-like object, or an :class:`InputSource` object. When + name or a URL), a file-like object, or an :class:`InputSource` object. When :meth:`parse` returns, the input is completely processed, and the parser object can be discarded or reset. diff --git a/Doc/library/xmlrpc.client.rst b/Doc/library/xmlrpc.client.rst --- a/Doc/library/xmlrpc.client.rst +++ b/Doc/library/xmlrpc.client.rst @@ -420,7 +420,7 @@ import xmlrpc.client - # create a ServerProxy with an URI that doesn't respond to XMLRPC requests + # create a ServerProxy with a URI that doesn't respond to XMLRPC requests proxy = xmlrpc.client.ServerProxy("http://google.com/") try: diff --git a/Include/bytesobject.h b/Include/bytesobject.h --- a/Include/bytesobject.h +++ b/Include/bytesobject.h @@ -89,7 +89,7 @@ #endif /* Provides access to the internal data buffer and size of a string - object or the default encoded version of an Unicode object. Passing + object or the default encoded version of a Unicode object. Passing NULL as *len parameter will force the string buffer to be 0-terminated (passing a string with embedded NULL characters will cause an exception). */ diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -823,7 +823,7 @@ PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void); #endif -/* Resize an Unicode object. The length is the number of characters, except +/* Resize a Unicode object. The length is the number of characters, except if the kind of the string is PyUnicode_WCHAR_KIND: in this case, the length is the number of Py_UNICODE characters. @@ -844,17 +844,13 @@ Py_ssize_t length /* New length */ ); -/* Coerce obj to an Unicode object and return a reference with - *incremented* refcount. - - Coercion is done in the following way: - - 1. bytes, bytearray and other bytes-like objects are decoded - under the assumptions that they contain data using the UTF-8 - encoding. Decoding is done in "strict" mode. - - 2. All other objects (including Unicode objects) raise an - exception. +/* Decode obj to an Unicode object. + + bytes, bytearray and other bytes-like objects are decoded according to the + given encoding and error handler. The encoding and error handler can be + NULL to have the interface use UTF-8 and "strict". + + All other objects (including Unicode objects) raise an exception. The API returns NULL in case of an error. The caller is responsible for decref'ing the returned objects. @@ -867,13 +863,9 @@ const char *errors /* error handling */ ); -/* Coerce obj to an Unicode object and return a reference with - *incremented* refcount. - - Unicode objects are passed back as-is (subclasses are converted to - true Unicode objects), all other objects are delegated to - PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in - using UTF-8 encoding as basis for decoding the object. +/* Copy an instance of a Unicode subtype to a new true Unicode object if + necessary. If obj is already a true Unicode object (not a subtype), return + the reference with *incremented* refcount. The API returns NULL in case of an error. The caller is responsible for decref'ing the returned objects. @@ -998,7 +990,7 @@ Py_ssize_t len /* length in bytes */ ); -/* Get the value of the writer as an Unicode string. Clear the +/* Get the value of the writer as a Unicode string. Clear the buffer of the writer. Raise an exception and return NULL on error. */ PyAPI_FUNC(PyObject *) diff --git a/Lib/asyncio/windows_events.py b/Lib/asyncio/windows_events.py --- a/Lib/asyncio/windows_events.py +++ b/Lib/asyncio/windows_events.py @@ -197,7 +197,7 @@ # # If the IocpProactor already received the event, it's safe to call # _unregister() because we kept a reference to the Overlapped object - # which is used as an unique key. + # which is used as a unique key. self._proactor._unregister(self._ov) self._proactor = None diff --git a/Lib/email/utils.py b/Lib/email/utils.py --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -87,7 +87,7 @@ 'utf-8'. """ name, address = pair - # The address MUST (per RFC) be ascii, so raise an UnicodeError if it isn't. + # The address MUST (per RFC) be ascii, so raise a UnicodeError if it isn't. address.encode('ascii') if name: try: diff --git a/Lib/heapq.py b/Lib/heapq.py --- a/Lib/heapq.py +++ b/Lib/heapq.py @@ -54,7 +54,7 @@ In the tree above, each cell `k' is topping `2*k+1' and `2*k+2'. In -an usual binary tournament we see in sports, each cell is the winner +a usual binary tournament we see in sports, each cell is the winner over the two cells it tops, and we can trace the winner down the tree to see all opponents s/he had. However, in many computer applications of such tournaments, we do not need to trace the history of a winner. diff --git a/Lib/nntplib.py b/Lib/nntplib.py --- a/Lib/nntplib.py +++ b/Lib/nntplib.py @@ -165,7 +165,7 @@ # Helper function(s) def decode_header(header_str): - """Takes an unicode string representing a munged header value + """Takes a unicode string representing a munged header value and decodes it as a (possibly non-ASCII) readable value.""" parts = [] for v, enc in _email_decode_header(header_str): @@ -420,7 +420,7 @@ def _putcmd(self, line): """Internal: send one command to the server (through _putline()). - The `line` must be an unicode string.""" + The `line` must be a unicode string.""" if self.debugging: print('*cmd*', repr(line)) line = line.encode(self.encoding, self.errors) self._putline(line) @@ -445,7 +445,7 @@ def _getresp(self): """Internal: get a response from the server. Raise various errors if the response indicates an error. - Returns an unicode string.""" + Returns a unicode string.""" resp = self._getline() if self.debugging: print('*resp*', repr(resp)) resp = resp.decode(self.encoding, self.errors) @@ -462,7 +462,7 @@ """Internal: get a response plus following text from the server. Raise various errors if the response indicates an error. - Returns a (response, lines) tuple where `response` is an unicode + Returns a (response, lines) tuple where `response` is a unicode string and `lines` is a list of bytes objects. If `file` is a file-like object, it must be open in binary mode. """ diff --git a/Lib/ntpath.py b/Lib/ntpath.py --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -177,7 +177,7 @@ Return a 2-tuple (unc, rest); either part may be empty. If unc is not empty, it has the form '//host/mount' (or similar using backslashes). unc+rest is always the input path. - Paths containing drive letters never have an UNC part. + Paths containing drive letters never have a UNC part. """ import warnings warnings.warn("ntpath.splitunc is deprecated, use ntpath.splitdrive instead", diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -2401,7 +2401,7 @@ self.assertRaises(TypeError, decoder, "xxx") def test_unicode_escape(self): - # Escape-decoding an unicode string is supported ang gives the same + # Escape-decoding a unicode string is supported ang gives the same # result as decoding the equivalent ASCII bytes string. self.assertEqual(codecs.unicode_escape_decode(r"\u1234"), ("\u1234", 6)) self.assertEqual(codecs.unicode_escape_decode(br"\u1234"), ("\u1234", 6)) diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -67,7 +67,7 @@ _multibytecodec.MultibyteStreamWriter, None) def test_decode_unicode(self): - # Trying to decode an unicode string should raise a TypeError + # Trying to decode a unicode string should raise a TypeError for enc in ALL_CJKENCODINGS: self.assertRaises(TypeError, codecs.getdecoder(enc), "") @@ -160,7 +160,7 @@ self.assertEqual(decoder.decode(b'B@$'), '\u4e16') def test_decode_unicode(self): - # Trying to decode an unicode string should raise a TypeError + # Trying to decode a unicode string should raise a TypeError for enc in ALL_CJKENCODINGS: decoder = codecs.getincrementaldecoder(enc)() self.assertRaises(TypeError, decoder.decode, "") diff --git a/Lib/test/test_nntplib.py b/Lib/test/test_nntplib.py --- a/Lib/test/test_nntplib.py +++ b/Lib/test/test_nntplib.py @@ -609,7 +609,7 @@ "\t\t6683\t16" "\t" "\n" - # An UTF-8 overview line from fr.comp.lang.python + # A UTF-8 overview line from fr.comp.lang.python "59\tRe: Message d'erreur incompr?hensible (par moi)" "\tEric Brunel " "\tWed, 15 Sep 2010 18:09:15 +0200" diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1774,7 +1774,7 @@ def assertCorrectUTF8Decoding(self, seq, res, err): """ - Check that an invalid UTF-8 sequence raises an UnicodeDecodeError when + Check that an invalid UTF-8 sequence raises a UnicodeDecodeError when 'strict' is used, returns res when 'replace' is used, and that doesn't return anything when 'ignore' is used. """ diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -175,7 +175,7 @@ self.assertEqual(zlib.decompress(ob), data) def test_incomplete_stream(self): - # An useful error message is given + # A useful error message is given x = zlib.compress(HAMLET_SCENE) self.assertRaisesRegex(zlib.error, "Error -5 while decompressing data: incomplete or truncated stream", diff --git a/Misc/HISTORY b/Misc/HISTORY --- a/Misc/HISTORY +++ b/Misc/HISTORY @@ -2237,7 +2237,7 @@ attribute which allows setting custom per-pickler reduction functions. Patch by sbt. -- Issue #14177: marshal.loads() now raises TypeError when given an unicode +- Issue #14177: marshal.loads() now raises TypeError when given a unicode string. Patch by Guilherme Gon?alves. - Issue #13550: Remove the debug machinery from the threading module: remove @@ -8304,7 +8304,7 @@ - Issue #1664: Make nntplib IPv6-capable. Patch by Derek Morr. - Issue #5006: Better handling of unicode byte-order marks (BOM) in the io - library. This means, for example, that opening an UTF-16 text file in + library. This means, for example, that opening a UTF-16 text file in append mode doesn't add a BOM at the end of the file if the file isn't empty. @@ -9328,7 +9328,7 @@ - Issue #4756: zipfile.is_zipfile() now supports file-like objects. Patch by Gabriel Genellina. -- Issue #4574: reading an UTF16-encoded text file crashes if \r on 64-char +- Issue #4574: reading a UTF16-encoded text file crashes if \r on 64-char boundary. - Issue #4223: inspect.getsource() will now correctly display source code @@ -9929,7 +9929,7 @@ exploitation of poor argument checking. - bsddb code updated to version 4.7.3pre2. This code is the same than - Python 2.6 one, since the intention is to keep an unified 2.x/3.x codebase. + Python 2.6 one, since the intention is to keep a unified 2.x/3.x codebase. The Python code is automatically translated using "2to3". Please, do not update this code in Python 3.0 by hand. Update the 2.6 one and then do "2to3". @@ -18936,7 +18936,7 @@ - There is a new Unicode companion to the PyObject_Str() API called PyObject_Unicode(). It behaves in the same way as the - former, but assures that the returned value is an Unicode object + former, but assures that the returned value is a Unicode object (applying the usual coercion if necessary). - The comparison operators support "rich comparison overloading" (PEP diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2834,7 +2834,7 @@ static type in some cases. - Issue #15859: PyUnicode_EncodeFSDefault(), PyUnicode_EncodeMBCS() and - PyUnicode_EncodeCodePage() now raise an exception if the object is not an + PyUnicode_EncodeCodePage() now raise an exception if the object is not a Unicode object. For PyUnicode_EncodeFSDefault(), it was already the case on platforms other than Windows. Patch written by Campbell Barton. @@ -3925,7 +3925,7 @@ - Issue #21226: Set up modules properly in PyImport_ExecCodeModuleObject (and friends). -- Issue #21398: Fix an unicode error in the pydoc pager when the documentation +- Issue #21398: Fix a unicode error in the pydoc pager when the documentation contains characters not encodable to the stdout encoding. - Issue #16531: ipaddress.IPv4Network and ipaddress.IPv6Network now accept @@ -6929,7 +6929,7 @@ - Issue #17173: Remove uses of locale-dependent C functions (isalpha() etc.) in the interpreter. -- Issue #17137: When an Unicode string is resized, the internal wide character +- Issue #17137: When a Unicode string is resized, the internal wide character string (wstr) format is now cleared. - Issue #17043: The unicode-internal decoder no longer read past the end of diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c --- a/Modules/_heapqmodule.c +++ b/Modules/_heapqmodule.c @@ -550,7 +550,7 @@ \n\ \n\ In the tree above, each cell `k' is topping `2*k+1' and `2*k+2'. In\n\ -an usual binary tournament we see in sports, each cell is the winner\n\ +a usual binary tournament we see in sports, each cell is the winner\n\ over the two cells it tops, and we can trace the winner down the tree\n\ to see all opponents s/he had. However, in many computer applications\n\ of such tournaments, we do not need to trace the history of a winner.\n\ diff --git a/Modules/_pickle.c b/Modules/_pickle.c --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -1119,7 +1119,7 @@ return 0; assert(self->peek); /* otherwise we did something wrong */ - /* This makes an useless copy... */ + /* This makes a useless copy... */ r = PyObject_CallFunction(self->read, "n", consumed); if (r == NULL) return -1; diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -379,7 +379,7 @@ if (!PyUnicode_Check(filename)) { #ifdef TRACE_DEBUG - tracemalloc_error("filename is not an unicode string"); + tracemalloc_error("filename is not a unicode string"); #endif return; } diff --git a/Objects/codeobject.c b/Objects/codeobject.c --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -520,7 +520,7 @@ return key; } else { - /* for other types, use the object identifier as an unique identifier + /* for other types, use the object identifier as a unique identifier * to ensure that they are seen as unequal. */ PyObject *obj_id = PyLong_FromVoidPtr(op); if (obj_id == NULL) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -850,7 +850,7 @@ } #ifdef Py_DEBUG -/* Fill the data of an Unicode string with invalid characters to detect bugs +/* Fill the data of a Unicode string with invalid characters to detect bugs earlier. _PyUnicode_CheckConsistency(str, 1) detects invalid characters, at least for diff --git a/Python/codecs.c b/Python/codecs.c --- a/Python/codecs.c +++ b/Python/codecs.c @@ -403,7 +403,7 @@ operation, encoding); } -/* Encode an object (e.g. an Unicode object) using the given encoding +/* Encode an object (e.g. a Unicode object) using the given encoding and return the resulting encoded object (usually a Python string). errors is passed to the encoder factory as argument if non-NULL. */ @@ -450,7 +450,7 @@ } /* Decode an object (usually a Python string) using the given encoding - and return an equivalent object (e.g. an Unicode object). + and return an equivalent object (e.g. a Unicode object). errors is passed to the decoder factory as argument if non-NULL. */ -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Fri Apr 15 05:47:03 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 15 Apr 2016 09:47:03 +0000 Subject: [Python-checkins] Daily reference leaks (570ada02d0f0): sum=4 Message-ID: <20160415094703.70537.58096.D422736A@psf.io> results for 570ada02d0f0 on branch "default" -------------------------------------------- test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogdG9y6l', '--timeout', '7200'] From lp_benchmark_robot at intel.com Fri Apr 15 06:07:51 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Fri, 15 Apr 2016 11:07:51 +0100 Subject: [Python-checkins] BAD Benchmark Results for Python Default 2016-04-15 Message-ID: <4db011fa-316f-4fe4-83a3-fafaaaa1a278@irsmsx102.ger.corp.intel.com> Results for project Python default, build date 2016-04-15 02:09:30 +0000 commit: b128e019ec32 previous commit: 3f3b3d4881f6 revision date: 2016-04-15 00:06:18 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.25% -1.20% 10.26% 15.65% :-| pybench 0.20% 0.10% 0.41% 6.47% :-( regex_v8 2.69% 0.10% -2.84% 3.00% :-| nbody 0.11% -0.04% -1.77% 8.20% :-( json_dump_v2 0.28% 0.80% -2.91% 10.87% :-| normal_startup 0.65% 0.31% 0.64% 4.99% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/bad-benchmark-results-for-python-default-2016-04-15/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Fri Apr 15 06:08:53 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Fri, 15 Apr 2016 11:08:53 +0100 Subject: [Python-checkins] NEUTRAL Benchmark Results for Python 2.7 2016-04-15 Message-ID: <8777bba6-eb45-4b27-be6b-4bf669046a55@irsmsx102.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-15 03:01:11 +0000 commit: 3a3b30c310e5 previous commit: 4680438f486f revision date: 2016-04-14 15:18:27 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.16% 0.71% 6.68% 3.81% :-) pybench 0.10% 0.02% 6.21% 4.52% :-( regex_v8 0.83% -0.03% -2.65% 11.08% :-) nbody 0.10% 0.57% 7.22% 3.79% :-) json_dump_v2 0.36% 0.20% 3.50% 11.74% :-( normal_startup 1.99% -0.37% -6.27% 2.98% :-) ssbench 0.15% -0.06% 2.57% 1.12% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/neutral-benchmark-results-for-python-2-7-2016-04-15/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Fri Apr 15 07:14:41 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 15 Apr 2016 11:14:41 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326764=3A_Fixed_Sy?= =?utf-8?q?stemError_in_bytes=2E=5F=5Frmod=5F=5F=2E?= Message-ID: <20160415111441.15356.16544.F38C59BB@psf.io> https://hg.python.org/cpython/rev/ebece99c0bb6 changeset: 100982:ebece99c0bb6 parent: 100980:570ada02d0f0 user: Serhiy Storchaka date: Fri Apr 15 14:11:10 2016 +0300 summary: Issue #26764: Fixed SystemError in bytes.__rmod__. files: Lib/test/test_bytes.py | 37 ++++++++--------------------- Objects/bytesobject.c | 10 +++---- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -483,26 +483,33 @@ self.assertRaises(ValueError, b.rindex, w, 1, 3) def test_mod(self): - b = b'hello, %b!' + b = self.type2test(b'hello, %b!') orig = b b = b % b'world' self.assertEqual(b, b'hello, world!') self.assertEqual(orig, b'hello, %b!') self.assertFalse(b is orig) - b = b'%s / 100 = %d%%' + b = self.type2test(b'%s / 100 = %d%%') a = b % (b'seventy-nine', 79) self.assertEqual(a, b'seventy-nine / 100 = 79%') + self.assertIs(type(a), bytes) def test_imod(self): - b = b'hello, %b!' + b = self.type2test(b'hello, %b!') orig = b b %= b'world' self.assertEqual(b, b'hello, world!') self.assertEqual(orig, b'hello, %b!') self.assertFalse(b is orig) - b = b'%s / 100 = %d%%' + b = self.type2test(b'%s / 100 = %d%%') b %= (b'seventy-nine', 79) self.assertEqual(b, b'seventy-nine / 100 = 79%') + self.assertIs(type(b), bytes) + + def test_rmod(self): + with self.assertRaises(TypeError): + object() % self.type2test(b'abc') + self.assertIs(self.type2test(b'abc').__rmod__('%r'), NotImplemented) def test_replace(self): b = self.type2test(b'mississippi') @@ -1064,28 +1071,6 @@ b[8:] = b self.assertEqual(b, bytearray(list(range(8)) + list(range(256)))) - def test_mod(self): - b = bytearray(b'hello, %b!') - orig = b - b = b % b'world' - self.assertEqual(b, b'hello, world!') - self.assertEqual(orig, bytearray(b'hello, %b!')) - self.assertFalse(b is orig) - b = bytearray(b'%s / 100 = %d%%') - a = b % (b'seventy-nine', 79) - self.assertEqual(a, bytearray(b'seventy-nine / 100 = 79%')) - - def test_imod(self): - b = bytearray(b'hello, %b!') - orig = b - b %= b'world' - self.assertEqual(b, b'hello, world!') - self.assertEqual(orig, bytearray(b'hello, %b!')) - self.assertFalse(b is orig) - b = bytearray(b'%s / 100 = %d%%') - b %= (b'seventy-nine', 79) - self.assertEqual(b, bytearray(b'seventy-nine / 100 = 79%')) - def test_iconcat(self): b = bytearray(b"abc") b1 = b diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3282,15 +3282,13 @@ }; static PyObject * -bytes_mod(PyObject *self, PyObject *args) +bytes_mod(PyObject *self, PyObject *arg) { - if (self == NULL || !PyBytes_Check(self)) { - PyErr_BadInternalCall(); - return NULL; + if (!PyBytes_Check(self)) { + Py_RETURN_NOTIMPLEMENTED; } - return _PyBytes_FormatEx(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), - args, 0); + arg, 0); } static PyNumberMethods bytes_as_number = { -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 07:14:42 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 15 Apr 2016 11:14:42 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NzY0?= =?utf-8?q?=3A_Bacported_tests_for_bytes_formatting=2E?= Message-ID: <20160415111442.107520.98845.3CEEC84B@psf.io> https://hg.python.org/cpython/rev/8dee0c09b46e changeset: 100983:8dee0c09b46e branch: 3.5 parent: 100979:af655e73f7bd user: Serhiy Storchaka date: Fri Apr 15 14:13:37 2016 +0300 summary: Issue #26764: Bacported tests for bytes formatting. files: Lib/test/test_bytes.py | 37 ++++++++--------------------- 1 files changed, 11 insertions(+), 26 deletions(-) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -469,26 +469,33 @@ self.assertRaises(ValueError, b.rindex, w, 1, 3) def test_mod(self): - b = b'hello, %b!' + b = self.type2test(b'hello, %b!') orig = b b = b % b'world' self.assertEqual(b, b'hello, world!') self.assertEqual(orig, b'hello, %b!') self.assertFalse(b is orig) - b = b'%s / 100 = %d%%' + b = self.type2test(b'%s / 100 = %d%%') a = b % (b'seventy-nine', 79) self.assertEqual(a, b'seventy-nine / 100 = 79%') + self.assertIs(type(a), self.type2test) def test_imod(self): - b = b'hello, %b!' + b = self.type2test(b'hello, %b!') orig = b b %= b'world' self.assertEqual(b, b'hello, world!') self.assertEqual(orig, b'hello, %b!') self.assertFalse(b is orig) - b = b'%s / 100 = %d%%' + b = self.type2test(b'%s / 100 = %d%%') b %= (b'seventy-nine', 79) self.assertEqual(b, b'seventy-nine / 100 = 79%') + self.assertIs(type(b), self.type2test) + + def test_rmod(self): + with self.assertRaises(TypeError): + object() % self.type2test(b'abc') + self.assertIs(self.type2test(b'abc').__rmod__('%r'), NotImplemented) def test_replace(self): b = self.type2test(b'mississippi') @@ -969,28 +976,6 @@ b[8:] = b self.assertEqual(b, bytearray(list(range(8)) + list(range(256)))) - def test_mod(self): - b = bytearray(b'hello, %b!') - orig = b - b = b % b'world' - self.assertEqual(b, b'hello, world!') - self.assertEqual(orig, bytearray(b'hello, %b!')) - self.assertFalse(b is orig) - b = bytearray(b'%s / 100 = %d%%') - a = b % (b'seventy-nine', 79) - self.assertEqual(a, bytearray(b'seventy-nine / 100 = 79%')) - - def test_imod(self): - b = bytearray(b'hello, %b!') - orig = b - b %= b'world' - self.assertEqual(b, b'hello, world!') - self.assertEqual(orig, bytearray(b'hello, %b!')) - self.assertFalse(b is orig) - b = bytearray(b'%s / 100 = %d%%') - b %= (b'seventy-nine', 79) - self.assertEqual(b, bytearray(b'seventy-nine / 100 = 79%')) - def test_iconcat(self): b = bytearray(b"abc") b1 = b -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 07:14:42 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 15 Apr 2016 11:14:42 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Null_merge?= Message-ID: <20160415111442.8517.91239.1E7491D5@psf.io> https://hg.python.org/cpython/rev/3d1e7792f5a0 changeset: 100984:3d1e7792f5a0 parent: 100982:ebece99c0bb6 parent: 100983:8dee0c09b46e user: Serhiy Storchaka date: Fri Apr 15 14:14:05 2016 +0300 summary: Null merge files: -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 11:52:46 2016 From: python-checkins at python.org (victor.stinner) Date: Fri, 15 Apr 2016 15:52:46 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326766=3A_Fix_=5FP?= =?utf-8?q?yBytesWriter=5FFinish=28=29?= Message-ID: <20160415155245.19511.15732.F46C82C0@psf.io> https://hg.python.org/cpython/rev/1eb586d5b321 changeset: 100985:1eb586d5b321 user: Victor Stinner date: Fri Apr 15 17:52:27 2016 +0200 summary: Issue #26766: Fix _PyBytesWriter_Finish() Return a bytearray object when bytearray is requested and when the small buffer is used. Fix also test_bytes: bytearray%args must return a bytearray type. files: Lib/test/test_bytes.py | 4 ++-- Objects/bytesobject.c | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -492,7 +492,7 @@ b = self.type2test(b'%s / 100 = %d%%') a = b % (b'seventy-nine', 79) self.assertEqual(a, b'seventy-nine / 100 = 79%') - self.assertIs(type(a), bytes) + self.assertIs(type(a), self.type2test) def test_imod(self): b = self.type2test(b'hello, %b!') @@ -504,7 +504,7 @@ b = self.type2test(b'%s / 100 = %d%%') b %= (b'seventy-nine', 79) self.assertEqual(b, b'seventy-nine / 100 = 79%') - self.assertIs(type(b), bytes) + self.assertIs(type(b), self.type2test) def test_rmod(self): with self.assertRaises(TypeError): diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -4150,7 +4150,12 @@ result = PyBytes_FromStringAndSize(NULL, 0); } else if (writer->use_small_buffer) { - result = PyBytes_FromStringAndSize(writer->small_buffer, size); + if (writer->use_bytearray) { + result = PyByteArray_FromStringAndSize(writer->small_buffer, size); + } + else { + result = PyBytes_FromStringAndSize(writer->small_buffer, size); + } } else { result = writer->buffer; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 12:45:31 2016 From: python-checkins at python.org (guido.van.rossum) Date: Fri, 15 Apr 2016 16:45:31 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_According_to_Knuth=2C_it_is_b?= =?utf-8?q?etter_to_break_*before*_a_binary_operator=2E?= Message-ID: <20160415164530.26103.38962.56895880@psf.io> https://hg.python.org/peps/rev/3857909d7956 changeset: 6283:3857909d7956 user: Guido van Rossum date: Fri Apr 15 09:43:52 2016 -0700 summary: According to Knuth, it is better to break *before* a binary operator. files: pep-0008.txt | 46 +++++++++++++++++++++++++++------------ 1 files changed, 32 insertions(+), 14 deletions(-) diff --git a/pep-0008.txt b/pep-0008.txt --- a/pep-0008.txt +++ b/pep-0008.txt @@ -151,6 +151,9 @@ that_is_another_thing): do_something() +(Also see the discussion of whether to break before or after binary +operators below.) + The closing brace/bracket/parenthesis on multi-line constructs may either line up under the first non-whitespace character of the last line of list, as in:: @@ -244,20 +247,33 @@ Another such case is with ``assert`` statements. -Make sure to indent the continued line appropriately. The preferred -place to break around a binary operator is *after* the operator, not -before it. Some examples:: +Make sure to indent the continued line appropriately. + + +Should a line break before or after a binary operator? +------------------------------------------------------ + +For decades the recommended style has been to break after binary +operators. However, recent reseach unearthed recommendations by +Donald Knuth to break *before* binary operators, in his writings about +typesetting [3]_. Therefore it is permissible to break before or +after a binary operator, as long as the convention is consistent +locally. For new code Knuth's style is suggested. + +Some examples of code beaking before binary Boolean operators:: class Rectangle(Blob): def __init__(self, width, height, color='black', emphasis=None, highlight=0): - if (width == 0 and height == 0 and - color == 'red' and emphasis == 'strong' or - highlight > 100): + if (width == 0 + and height == 0 + and color == 'red' + and emphasis == 'strong' + or highlight > 100): raise ValueError("sorry, you lose") - if width == 0 and height == 0 and (color == 'red' or - emphasis is None): + if (width == 0 and height == 0 + and (color == 'red' or emphasis is None)): raise ValueError("I don't think so -- values are %s, %s" % (width, height)) Blob.__init__(self, width, height, @@ -709,7 +725,7 @@ - ``UPPERCASE`` - ``UPPER_CASE_WITH_UNDERSCORES`` - ``CapitalizedWords`` (or CapWords, or CamelCase -- so named because - of the bumpy look of its letters [3]_). This is also sometimes known + of the bumpy look of its letters [4]_). This is also sometimes known as StudlyCaps. Note: When using abbreviations in CapWords, capitalize all the @@ -1286,11 +1302,11 @@ PEP 484 recommends the use of stub files: .pyi files that are read by the type checker in preference of the corresponding .py files. Stub files can be distributed with a library, or separately (with - the library author's permission) through the typeshed repo [4]_. + the library author's permission) through the typeshed repo [5]_. - For code that needs to be backwards compatible, function annotations can be added in the form of comments. See the relevant section of - PEP 484 [5]_. + PEP 484 [6]_. .. rubric:: Footnotes @@ -1311,12 +1327,14 @@ .. [2] Barry's GNU Mailman style guide http://barry.warsaw.us/software/STYLEGUIDE.txt -.. [3] http://www.wikipedia.com/wiki/CamelCase +.. [3] http://rhodesmill.org/brandon/slides/2012-11-pyconca/#laying-down-the-law -.. [4] Typeshed repo +.. [4] http://www.wikipedia.com/wiki/CamelCase + +.. [5] Typeshed repo https://github.com/python/typeshed -.. [5] Suggested syntax for Python 2.7 and straddling code +.. [6] Suggested syntax for Python 2.7 and straddling code https://www.python.org/dev/peps/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-code -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Fri Apr 15 12:54:49 2016 From: python-checkins at python.org (guido.van.rossum) Date: Fri, 15 Apr 2016 16:54:49 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Fix_typo=2E_Revert_my_previou?= =?utf-8?q?s_diff_that_removed_another_example_breaking_before?= Message-ID: <20160415165449.421.80927.316E992B@psf.io> https://hg.python.org/peps/rev/c8554dfd4f22 changeset: 6284:c8554dfd4f22 user: Guido van Rossum date: Fri Apr 15 09:54:42 2016 -0700 summary: Fix typo. Revert my previous diff that removed another example breaking before "and". files: pep-0008.txt | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pep-0008.txt b/pep-0008.txt --- a/pep-0008.txt +++ b/pep-0008.txt @@ -147,8 +147,8 @@ do_something() # Add some extra indentation on the conditional continuation line. - if (this_is_one_thing and - that_is_another_thing): + if (this_is_one_thing + and that_is_another_thing): do_something() (Also see the discussion of whether to break before or after binary @@ -260,7 +260,7 @@ after a binary operator, as long as the convention is consistent locally. For new code Knuth's style is suggested. -Some examples of code beaking before binary Boolean operators:: +Some examples of code breaking before binary Boolean operators:: class Rectangle(Blob): -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Fri Apr 15 13:51:49 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 15 Apr 2016 17:51:49 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_for_issue_=2325609?= Message-ID: <20160415175149.26075.43028.8BFF2AC5@psf.io> https://hg.python.org/cpython/rev/14cf0011c5e9 changeset: 100987:14cf0011c5e9 parent: 100985:1eb586d5b321 parent: 100986:257dd57dd732 user: Brett Cannon date: Fri Apr 15 10:51:46 2016 -0700 summary: Merge for issue #25609 files: -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 13:51:50 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 15 Apr 2016 17:51:50 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI1NjA5?= =?utf-8?q?=3A_Backport_typing=2EContextManager=2E?= Message-ID: <20160415175149.70537.14689.EF5D2B15@psf.io> https://hg.python.org/cpython/rev/257dd57dd732 changeset: 100986:257dd57dd732 branch: 3.5 parent: 100983:8dee0c09b46e user: Brett Cannon date: Fri Apr 15 10:51:30 2016 -0700 summary: Issue #25609: Backport typing.ContextManager. This has no semantic impact as the class is guarded with a hasattr() check; this is being done to keep typing.py in sync between Python 3.5 and 3.6 as requested by Guido. files: Lib/typing.py | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/Lib/typing.py b/Lib/typing.py --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1,6 +1,7 @@ import abc from abc import abstractmethod, abstractproperty import collections +import contextlib import functools import re as stdlib_re # Avoid confusion with the re we export. import sys @@ -1530,6 +1531,12 @@ pass +if hasattr(contextlib, 'AbstractContextManager'): + class ContextManager(Generic[T_co], extra=contextlib.AbstractContextManager): + __slots__ = () + __all__.append('ContextManager') + + class Dict(dict, MutableMapping[KT, VT]): def __new__(cls, *args, **kwds): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 14:34:22 2016 From: python-checkins at python.org (steven.daprano) Date: Fri, 15 Apr 2016 18:34:22 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Remove_python_fallback_for?= =?utf-8?q?_compare=5Fdigest=2E?= Message-ID: <20160415183422.26085.32095.593FCE23@psf.io> https://hg.python.org/cpython/rev/92388bdba01c changeset: 100988:92388bdba01c user: Steven D'Aprano date: Sat Apr 16 04:33:55 2016 +1000 summary: Remove python fallback for compare_digest. See https://mail.python.org/pipermail/python-dev/2016-April/144198.html https://mail.python.org/pipermail/python-dev/2016-April/144203.html files: Lib/secrets.py | 33 +-------------------------------- 1 files changed, 1 insertions(+), 32 deletions(-) diff --git a/Lib/secrets.py b/Lib/secrets.py --- a/Lib/secrets.py +++ b/Lib/secrets.py @@ -91,38 +91,7 @@ import binascii import os -try: - from hmac import compare_digest -except ImportError: - # Python version is too old. Fall back to a pure-Python version. - - import operator - from functools import reduce - - def compare_digest(a, b): - """Return ``a == b`` using an approach resistant to timing analysis. - - a and b must both be of the same type: either both text strings, - or both byte strings. - - Note: If a and b are of different lengths, or if an error occurs, - a timing attack could theoretically reveal information about the - types and lengths of a and b, but not their values. - """ - # For a similar approach, see - # http://codahale.com/a-lesson-in-timing-attacks/ - for T in (bytes, str): - if isinstance(a, T) and isinstance(b, T): - break - else: # for...else - raise TypeError("arguments must be both strings or both bytes") - if len(a) != len(b): - return False - # Thanks to Raymond Hettinger for this one-liner. - return reduce(operator.and_, map(operator.eq, a, b), True) - - - +from hmac import compare_digest from random import SystemRandom _sysrand = SystemRandom() -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 15:23:43 2016 From: python-checkins at python.org (chris.angelico) Date: Fri, 15 Apr 2016 19:23:43 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Fix_typo=2C_resea=5Br=5Dch?= Message-ID: <20160415192342.8334.64304.3A56A2BB@psf.io> https://hg.python.org/peps/rev/d05f70bfbd58 changeset: 6285:d05f70bfbd58 user: Chris Angelico date: Sat Apr 16 05:23:30 2016 +1000 summary: Fix typo, resea[r]ch files: pep-0008.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pep-0008.txt b/pep-0008.txt --- a/pep-0008.txt +++ b/pep-0008.txt @@ -254,7 +254,7 @@ ------------------------------------------------------ For decades the recommended style has been to break after binary -operators. However, recent reseach unearthed recommendations by +operators. However, recent research unearthed recommendations by Donald Knuth to break *before* binary operators, in his writings about typesetting [3]_. Therefore it is permissible to break before or after a binary operator, as long as the convention is consistent -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Fri Apr 15 15:44:12 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 15 Apr 2016 19:44:12 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NzYw?= =?utf-8?q?=3A_Minimally_document_PyFrameObject?= Message-ID: <20160415194411.26083.32915.C6FDE702@psf.io> https://hg.python.org/cpython/rev/ba6f4f0fe9ea changeset: 100989:ba6f4f0fe9ea branch: 3.5 parent: 100986:257dd57dd732 user: Brett Cannon date: Fri Apr 15 12:43:50 2016 -0700 summary: Issue #26760: Minimally document PyFrameObject files: Doc/c-api/veryhigh.rst | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/Doc/c-api/veryhigh.rst b/Doc/c-api/veryhigh.rst --- a/Doc/c-api/veryhigh.rst +++ b/Doc/c-api/veryhigh.rst @@ -307,10 +307,16 @@ cells. +.. c:type:: PyFrameObject + + The C structure of the objects used to describe frame objects. The + fields of this type are subject to change at any time. + + .. c:function:: PyObject* PyEval_EvalFrame(PyFrameObject *f) Evaluate an execution frame. This is a simplified interface to - PyEval_EvalFrameEx, for backward compatibility. + :c:func:`PyEval_EvalFrameEx`, for backward compatibility. .. c:function:: PyObject* PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 15:44:17 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 15 Apr 2016 19:44:17 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_for_issue_=2326760?= Message-ID: <20160415194412.70517.50791.24564B25@psf.io> https://hg.python.org/cpython/rev/5c18598382e9 changeset: 100990:5c18598382e9 parent: 100988:92388bdba01c parent: 100989:ba6f4f0fe9ea user: Brett Cannon date: Fri Apr 15 12:44:09 2016 -0700 summary: Merge for issue #26760 files: Doc/c-api/veryhigh.rst | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/Doc/c-api/veryhigh.rst b/Doc/c-api/veryhigh.rst --- a/Doc/c-api/veryhigh.rst +++ b/Doc/c-api/veryhigh.rst @@ -307,10 +307,16 @@ cells. +.. c:type:: PyFrameObject + + The C structure of the objects used to describe frame objects. The + fields of this type are subject to change at any time. + + .. c:function:: PyObject* PyEval_EvalFrame(PyFrameObject *f) Evaluate an execution frame. This is a simplified interface to - PyEval_EvalFrameEx, for backward compatibility. + :c:func:`PyEval_EvalFrameEx`, for backward compatibility. .. c:function:: PyObject* PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 18:19:48 2016 From: python-checkins at python.org (berker.peksag) Date: Fri, 15 Apr 2016 22:19:48 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326766=3A_Remove_r?= =?utf-8?q?edundant_bytearray=5Fformat=28=29_from_bytearrayobject=2Ec?= Message-ID: <20160415221940.88662.6680.8BDF2CA8@psf.io> https://hg.python.org/cpython/rev/b3e3efc5afa4 changeset: 100991:b3e3efc5afa4 user: Berker Peksag date: Sat Apr 16 01:20:47 2016 +0300 summary: Issue #26766: Remove redundant bytearray_format() from bytearrayobject.c files: Objects/bytearrayobject.c | 15 +-------------- 1 files changed, 1 insertions(+), 14 deletions(-) diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -279,19 +279,6 @@ return (PyObject *)result; } -static PyObject * -bytearray_format(PyByteArrayObject *self, PyObject *args) -{ - if (self == NULL || !PyByteArray_Check(self)) { - PyErr_BadInternalCall(); - return NULL; - } - - return _PyBytes_FormatEx(PyByteArray_AS_STRING(self), - PyByteArray_GET_SIZE(self), - args, 1); -} - /* Functions stuffed into the type object */ static Py_ssize_t @@ -3014,7 +3001,7 @@ { if (!PyByteArray_Check(v)) Py_RETURN_NOTIMPLEMENTED; - return bytearray_format((PyByteArrayObject *)v, w); + return _PyBytes_FormatEx(PyByteArray_AS_STRING(v), PyByteArray_GET_SIZE(v), w, 1); } static PyNumberMethods bytearray_as_number = { -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 19:45:29 2016 From: python-checkins at python.org (martin.panter) Date: Fri, 15 Apr 2016 23:45:29 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NTM1?= =?utf-8?q?=3A_Correct_docs_regarding_the_struct_buffer_size?= Message-ID: <20160415234528.26279.35799.B0BA25DD@psf.io> https://hg.python.org/cpython/rev/7889fcb0697b changeset: 100992:7889fcb0697b branch: 3.5 parent: 100989:ba6f4f0fe9ea user: Martin Panter date: Fri Apr 15 23:03:54 2016 +0000 summary: Issue #26535: Correct docs regarding the struct buffer size files: Doc/library/struct.rst | 21 +++++++++++---------- Modules/_struct.c | 16 ++++++++-------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst --- a/Doc/library/struct.rst +++ b/Doc/library/struct.rst @@ -62,16 +62,16 @@ Unpack from the buffer *buffer* (presumably packed by ``pack(fmt, ...)``) according to the format string *fmt*. The result is a tuple even if it - contains exactly one item. The buffer must contain exactly the amount of - data required by the format (``len(bytes)`` must equal ``calcsize(fmt)``). + contains exactly one item. The buffer's size in bytes must match the + size required by the format, as reflected by :func:`calcsize`. .. function:: unpack_from(fmt, buffer, offset=0) Unpack from *buffer* starting at position *offset*, according to the format string *fmt*. The result is a tuple even if it contains exactly one - item. *buffer* must contain at least the amount of data required by the - format (``len(buffer[offset:])`` must be at least ``calcsize(fmt)``). + item. The buffer's size in bytes, minus *offset*, must be at least + the size required by the format, as reflected by :func:`calcsize`. .. function:: iter_unpack(fmt, buffer) @@ -79,8 +79,8 @@ Iteratively unpack from the buffer *buffer* according to the format string *fmt*. This function returns an iterator which will read equally-sized chunks from the buffer until all its contents have been - consumed. The buffer's size in bytes must be a multiple of the amount - of data required by the format, as reflected by :func:`calcsize`. + consumed. The buffer's size in bytes must be a multiple of the size + required by the format, as reflected by :func:`calcsize`. Each iteration yields a tuple as specified by the format string. @@ -389,7 +389,7 @@ .. method:: pack(v1, v2, ...) Identical to the :func:`pack` function, using the compiled format. - (``len(result)`` will equal :attr:`self.size`.) + (``len(result)`` will equal :attr:`size`.) .. method:: pack_into(buffer, offset, v1, v2, ...) @@ -400,19 +400,20 @@ .. method:: unpack(buffer) Identical to the :func:`unpack` function, using the compiled format. - (``len(buffer)`` must equal :attr:`self.size`). + The buffer's size in bytes must equal :attr:`size`. .. method:: unpack_from(buffer, offset=0) Identical to the :func:`unpack_from` function, using the compiled format. - (``len(buffer[offset:])`` must be at least :attr:`self.size`). + The buffer's size in bytes, minus *offset*, must be at least + :attr:`size`. .. method:: iter_unpack(buffer) Identical to the :func:`iter_unpack` function, using the compiled format. - (``len(buffer)`` must be a multiple of :attr:`self.size`). + The buffer's size in bytes must be a multiple of :attr:`size`. .. versionadded:: 3.4 diff --git a/Modules/_struct.c b/Modules/_struct.c --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1497,8 +1497,8 @@ "S.unpack(buffer) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format\n\ -string S.format. Requires len(buffer) == S.size. See help(struct)\n\ -for more on format strings."); +string S.format. The buffer's size in bytes must be S.size. See\n\ +help(struct) for more on format strings."); static PyObject * s_unpack(PyObject *self, PyObject *input) @@ -1527,8 +1527,8 @@ "S.unpack_from(buffer, offset=0) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format\n\ -string S.format. Requires len(buffer[offset:]) >= S.size. See\n\ -help(struct) for more on format strings."); +string S.format. The buffer's size in bytes, minus offset, must be at\n\ +least S.size. See help(struct) for more on format strings."); static PyObject * s_unpack_from(PyObject *self, PyObject *args, PyObject *kwds) @@ -2130,8 +2130,8 @@ "unpack(fmt, buffer) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format string\n\ -fmt. Requires len(buffer) == calcsize(fmt). See help(struct) for more\n\ -on format strings."); +fmt. The buffer's size in bytes must be calcsize(fmt). See help(struct)\n\ +for more on format strings."); static PyObject * unpack(PyObject *self, PyObject *args) @@ -2153,8 +2153,8 @@ "unpack_from(fmt, buffer, offset=0) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format string\n\ -fmt. Requires len(buffer[offset:]) >= calcsize(fmt). See help(struct)\n\ -for more on format strings."); +fmt. The buffer's size, minus offset, must be at least calcsize(fmt).\n\ +See help(struct) for more on format strings."); static PyObject * unpack_from(PyObject *self, PyObject *args, PyObject *kwds) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 19:45:29 2016 From: python-checkins at python.org (martin.panter) Date: Fri, 15 Apr 2016 23:45:29 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326535=3A_Merge_struct_doc_from_3=2E5?= Message-ID: <20160415234528.15356.9228.021E1362@psf.io> https://hg.python.org/cpython/rev/39dc2f39373d changeset: 100993:39dc2f39373d parent: 100991:b3e3efc5afa4 parent: 100992:7889fcb0697b user: Martin Panter date: Fri Apr 15 23:16:51 2016 +0000 summary: Issue #26535: Merge struct doc from 3.5 files: Doc/library/struct.rst | 21 +++++++++++---------- Modules/_struct.c | 16 ++++++++-------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst --- a/Doc/library/struct.rst +++ b/Doc/library/struct.rst @@ -62,16 +62,16 @@ Unpack from the buffer *buffer* (presumably packed by ``pack(fmt, ...)``) according to the format string *fmt*. The result is a tuple even if it - contains exactly one item. The buffer must contain exactly the amount of - data required by the format (``len(bytes)`` must equal ``calcsize(fmt)``). + contains exactly one item. The buffer's size in bytes must match the + size required by the format, as reflected by :func:`calcsize`. .. function:: unpack_from(fmt, buffer, offset=0) Unpack from *buffer* starting at position *offset*, according to the format string *fmt*. The result is a tuple even if it contains exactly one - item. *buffer* must contain at least the amount of data required by the - format (``len(buffer[offset:])`` must be at least ``calcsize(fmt)``). + item. The buffer's size in bytes, minus *offset*, must be at least + the size required by the format, as reflected by :func:`calcsize`. .. function:: iter_unpack(fmt, buffer) @@ -79,8 +79,8 @@ Iteratively unpack from the buffer *buffer* according to the format string *fmt*. This function returns an iterator which will read equally-sized chunks from the buffer until all its contents have been - consumed. The buffer's size in bytes must be a multiple of the amount - of data required by the format, as reflected by :func:`calcsize`. + consumed. The buffer's size in bytes must be a multiple of the size + required by the format, as reflected by :func:`calcsize`. Each iteration yields a tuple as specified by the format string. @@ -389,7 +389,7 @@ .. method:: pack(v1, v2, ...) Identical to the :func:`pack` function, using the compiled format. - (``len(result)`` will equal :attr:`self.size`.) + (``len(result)`` will equal :attr:`size`.) .. method:: pack_into(buffer, offset, v1, v2, ...) @@ -400,19 +400,20 @@ .. method:: unpack(buffer) Identical to the :func:`unpack` function, using the compiled format. - (``len(buffer)`` must equal :attr:`self.size`). + The buffer's size in bytes must equal :attr:`size`. .. method:: unpack_from(buffer, offset=0) Identical to the :func:`unpack_from` function, using the compiled format. - (``len(buffer[offset:])`` must be at least :attr:`self.size`). + The buffer's size in bytes, minus *offset*, must be at least + :attr:`size`. .. method:: iter_unpack(buffer) Identical to the :func:`iter_unpack` function, using the compiled format. - (``len(buffer)`` must be a multiple of :attr:`self.size`). + The buffer's size in bytes must be a multiple of :attr:`size`. .. versionadded:: 3.4 diff --git a/Modules/_struct.c b/Modules/_struct.c --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1497,8 +1497,8 @@ "S.unpack(buffer) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format\n\ -string S.format. Requires len(buffer) == S.size. See help(struct)\n\ -for more on format strings."); +string S.format. The buffer's size in bytes must be S.size. See\n\ +help(struct) for more on format strings."); static PyObject * s_unpack(PyObject *self, PyObject *input) @@ -1527,8 +1527,8 @@ "S.unpack_from(buffer, offset=0) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format\n\ -string S.format. Requires len(buffer[offset:]) >= S.size. See\n\ -help(struct) for more on format strings."); +string S.format. The buffer's size in bytes, minus offset, must be at\n\ +least S.size. See help(struct) for more on format strings."); static PyObject * s_unpack_from(PyObject *self, PyObject *args, PyObject *kwds) @@ -2130,8 +2130,8 @@ "unpack(fmt, buffer) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format string\n\ -fmt. Requires len(buffer) == calcsize(fmt). See help(struct) for more\n\ -on format strings."); +fmt. The buffer's size in bytes must be calcsize(fmt). See help(struct)\n\ +for more on format strings."); static PyObject * unpack(PyObject *self, PyObject *args) @@ -2153,8 +2153,8 @@ "unpack_from(fmt, buffer, offset=0) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format string\n\ -fmt. Requires len(buffer[offset:]) >= calcsize(fmt). See help(struct)\n\ -for more on format strings."); +fmt. The buffer's size, minus offset, must be at least calcsize(fmt).\n\ +See help(struct) for more on format strings."); static PyObject * unpack_from(PyObject *self, PyObject *args, PyObject *kwds) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 19:51:12 2016 From: python-checkins at python.org (gregory.p.smith) Date: Fri, 15 Apr 2016 23:51:12 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Exclude_super_long_running_tests_from_the_PROFILE=5FTASK?= =?utf-8?q?_for_PGO?= Message-ID: <20160415235112.8352.55634.035A0B82@psf.io> https://hg.python.org/cpython/rev/dd071094591a changeset: 100995:dd071094591a parent: 100991:b3e3efc5afa4 parent: 100994:51e6894936f5 user: Gregory P. Smith date: Fri Apr 15 16:46:14 2016 -0700 summary: Exclude super long running tests from the PROFILE_TASK for PGO builds. multiprocessing and subprocess tests in particular along with test_asyncore and test_gdb. Running them does not meaningfully add to the profile guidance. files: Makefile.pre.in | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -230,8 +230,10 @@ TCLTK_INCLUDES= @TCLTK_INCLUDES@ TCLTK_LIBS= @TCLTK_LIBS@ -# The task to run while instrument when building the profile-opt target -PROFILE_TASK=-m test.regrtest --pgo +# The task to run while instrumented when building the profile-opt target. +# We exclude unittests with -x that take a rediculious amount of time to +# run in the instrumented training build or do not provide much value. +PROFILE_TASK=-m test.regrtest --pgo -x test_asyncore test_gdb test_multiprocessing_fork test_multiprocessing_forkserver test_multiprocessing_main_handling test_multiprocessing_spawn test_subprocess # report files for gcov / lcov coverage report COVERAGE_INFO= $(abs_builddir)/coverage.info -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 19:51:13 2016 From: python-checkins at python.org (gregory.p.smith) Date: Fri, 15 Apr 2016 23:51:13 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <20160415235112.417.25040.07F0D0F2@psf.io> https://hg.python.org/cpython/rev/218e9d18d07b changeset: 100997:218e9d18d07b parent: 100995:dd071094591a parent: 100996:bd00b025bd73 user: Gregory P. Smith date: Fri Apr 15 16:47:32 2016 -0700 summary: merge heads files: Doc/library/struct.rst | 21 +++++++++++---------- Modules/_struct.c | 16 ++++++++-------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst --- a/Doc/library/struct.rst +++ b/Doc/library/struct.rst @@ -62,16 +62,16 @@ Unpack from the buffer *buffer* (presumably packed by ``pack(fmt, ...)``) according to the format string *fmt*. The result is a tuple even if it - contains exactly one item. The buffer must contain exactly the amount of - data required by the format (``len(bytes)`` must equal ``calcsize(fmt)``). + contains exactly one item. The buffer's size in bytes must match the + size required by the format, as reflected by :func:`calcsize`. .. function:: unpack_from(fmt, buffer, offset=0) Unpack from *buffer* starting at position *offset*, according to the format string *fmt*. The result is a tuple even if it contains exactly one - item. *buffer* must contain at least the amount of data required by the - format (``len(buffer[offset:])`` must be at least ``calcsize(fmt)``). + item. The buffer's size in bytes, minus *offset*, must be at least + the size required by the format, as reflected by :func:`calcsize`. .. function:: iter_unpack(fmt, buffer) @@ -79,8 +79,8 @@ Iteratively unpack from the buffer *buffer* according to the format string *fmt*. This function returns an iterator which will read equally-sized chunks from the buffer until all its contents have been - consumed. The buffer's size in bytes must be a multiple of the amount - of data required by the format, as reflected by :func:`calcsize`. + consumed. The buffer's size in bytes must be a multiple of the size + required by the format, as reflected by :func:`calcsize`. Each iteration yields a tuple as specified by the format string. @@ -389,7 +389,7 @@ .. method:: pack(v1, v2, ...) Identical to the :func:`pack` function, using the compiled format. - (``len(result)`` will equal :attr:`self.size`.) + (``len(result)`` will equal :attr:`size`.) .. method:: pack_into(buffer, offset, v1, v2, ...) @@ -400,19 +400,20 @@ .. method:: unpack(buffer) Identical to the :func:`unpack` function, using the compiled format. - (``len(buffer)`` must equal :attr:`self.size`). + The buffer's size in bytes must equal :attr:`size`. .. method:: unpack_from(buffer, offset=0) Identical to the :func:`unpack_from` function, using the compiled format. - (``len(buffer[offset:])`` must be at least :attr:`self.size`). + The buffer's size in bytes, minus *offset*, must be at least + :attr:`size`. .. method:: iter_unpack(buffer) Identical to the :func:`iter_unpack` function, using the compiled format. - (``len(buffer)`` must be a multiple of :attr:`self.size`). + The buffer's size in bytes must be a multiple of :attr:`size`. .. versionadded:: 3.4 diff --git a/Modules/_struct.c b/Modules/_struct.c --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1497,8 +1497,8 @@ "S.unpack(buffer) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format\n\ -string S.format. Requires len(buffer) == S.size. See help(struct)\n\ -for more on format strings."); +string S.format. The buffer's size in bytes must be S.size. See\n\ +help(struct) for more on format strings."); static PyObject * s_unpack(PyObject *self, PyObject *input) @@ -1527,8 +1527,8 @@ "S.unpack_from(buffer, offset=0) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format\n\ -string S.format. Requires len(buffer[offset:]) >= S.size. See\n\ -help(struct) for more on format strings."); +string S.format. The buffer's size in bytes, minus offset, must be at\n\ +least S.size. See help(struct) for more on format strings."); static PyObject * s_unpack_from(PyObject *self, PyObject *args, PyObject *kwds) @@ -2130,8 +2130,8 @@ "unpack(fmt, buffer) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format string\n\ -fmt. Requires len(buffer) == calcsize(fmt). See help(struct) for more\n\ -on format strings."); +fmt. The buffer's size in bytes must be calcsize(fmt). See help(struct)\n\ +for more on format strings."); static PyObject * unpack(PyObject *self, PyObject *args) @@ -2153,8 +2153,8 @@ "unpack_from(fmt, buffer, offset=0) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format string\n\ -fmt. Requires len(buffer[offset:]) >= calcsize(fmt). See help(struct)\n\ -for more on format strings."); +fmt. The buffer's size, minus offset, must be at least calcsize(fmt).\n\ +See help(struct) for more on format strings."); static PyObject * unpack_from(PyObject *self, PyObject *args, PyObject *kwds) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 19:51:14 2016 From: python-checkins at python.org (gregory.p.smith) Date: Fri, 15 Apr 2016 23:51:14 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy41IC0+IDMuNSk6?= =?utf-8?q?_merge_heads?= Message-ID: <20160415235112.15348.85700.DDDD37E6@psf.io> https://hg.python.org/cpython/rev/bd00b025bd73 changeset: 100996:bd00b025bd73 branch: 3.5 parent: 100994:51e6894936f5 parent: 100992:7889fcb0697b user: Gregory P. Smith date: Fri Apr 15 16:47:15 2016 -0700 summary: merge heads files: Doc/library/struct.rst | 21 +++++++++++---------- Modules/_struct.c | 16 ++++++++-------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst --- a/Doc/library/struct.rst +++ b/Doc/library/struct.rst @@ -62,16 +62,16 @@ Unpack from the buffer *buffer* (presumably packed by ``pack(fmt, ...)``) according to the format string *fmt*. The result is a tuple even if it - contains exactly one item. The buffer must contain exactly the amount of - data required by the format (``len(bytes)`` must equal ``calcsize(fmt)``). + contains exactly one item. The buffer's size in bytes must match the + size required by the format, as reflected by :func:`calcsize`. .. function:: unpack_from(fmt, buffer, offset=0) Unpack from *buffer* starting at position *offset*, according to the format string *fmt*. The result is a tuple even if it contains exactly one - item. *buffer* must contain at least the amount of data required by the - format (``len(buffer[offset:])`` must be at least ``calcsize(fmt)``). + item. The buffer's size in bytes, minus *offset*, must be at least + the size required by the format, as reflected by :func:`calcsize`. .. function:: iter_unpack(fmt, buffer) @@ -79,8 +79,8 @@ Iteratively unpack from the buffer *buffer* according to the format string *fmt*. This function returns an iterator which will read equally-sized chunks from the buffer until all its contents have been - consumed. The buffer's size in bytes must be a multiple of the amount - of data required by the format, as reflected by :func:`calcsize`. + consumed. The buffer's size in bytes must be a multiple of the size + required by the format, as reflected by :func:`calcsize`. Each iteration yields a tuple as specified by the format string. @@ -389,7 +389,7 @@ .. method:: pack(v1, v2, ...) Identical to the :func:`pack` function, using the compiled format. - (``len(result)`` will equal :attr:`self.size`.) + (``len(result)`` will equal :attr:`size`.) .. method:: pack_into(buffer, offset, v1, v2, ...) @@ -400,19 +400,20 @@ .. method:: unpack(buffer) Identical to the :func:`unpack` function, using the compiled format. - (``len(buffer)`` must equal :attr:`self.size`). + The buffer's size in bytes must equal :attr:`size`. .. method:: unpack_from(buffer, offset=0) Identical to the :func:`unpack_from` function, using the compiled format. - (``len(buffer[offset:])`` must be at least :attr:`self.size`). + The buffer's size in bytes, minus *offset*, must be at least + :attr:`size`. .. method:: iter_unpack(buffer) Identical to the :func:`iter_unpack` function, using the compiled format. - (``len(buffer)`` must be a multiple of :attr:`self.size`). + The buffer's size in bytes must be a multiple of :attr:`size`. .. versionadded:: 3.4 diff --git a/Modules/_struct.c b/Modules/_struct.c --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1497,8 +1497,8 @@ "S.unpack(buffer) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format\n\ -string S.format. Requires len(buffer) == S.size. See help(struct)\n\ -for more on format strings."); +string S.format. The buffer's size in bytes must be S.size. See\n\ +help(struct) for more on format strings."); static PyObject * s_unpack(PyObject *self, PyObject *input) @@ -1527,8 +1527,8 @@ "S.unpack_from(buffer, offset=0) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format\n\ -string S.format. Requires len(buffer[offset:]) >= S.size. See\n\ -help(struct) for more on format strings."); +string S.format. The buffer's size in bytes, minus offset, must be at\n\ +least S.size. See help(struct) for more on format strings."); static PyObject * s_unpack_from(PyObject *self, PyObject *args, PyObject *kwds) @@ -2130,8 +2130,8 @@ "unpack(fmt, buffer) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format string\n\ -fmt. Requires len(buffer) == calcsize(fmt). See help(struct) for more\n\ -on format strings."); +fmt. The buffer's size in bytes must be calcsize(fmt). See help(struct)\n\ +for more on format strings."); static PyObject * unpack(PyObject *self, PyObject *args) @@ -2153,8 +2153,8 @@ "unpack_from(fmt, buffer, offset=0) -> (v1, v2, ...)\n\ \n\ Return a tuple containing values unpacked according to the format string\n\ -fmt. Requires len(buffer[offset:]) >= calcsize(fmt). See help(struct)\n\ -for more on format strings."); +fmt. The buffer's size, minus offset, must be at least calcsize(fmt).\n\ +See help(struct) for more on format strings."); static PyObject * unpack_from(PyObject *self, PyObject *args, PyObject *kwds) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 19:51:16 2016 From: python-checkins at python.org (gregory.p.smith) Date: Fri, 15 Apr 2016 23:51:16 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <20160415235113.88658.76128.AB9DCFF4@psf.io> https://hg.python.org/cpython/rev/e3c6362cc139 changeset: 100998:e3c6362cc139 parent: 100997:218e9d18d07b parent: 100993:39dc2f39373d user: Gregory P. Smith date: Fri Apr 15 16:51:02 2016 -0700 summary: merge heads files: -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 19:51:16 2016 From: python-checkins at python.org (gregory.p.smith) Date: Fri, 15 Apr 2016 23:51:16 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Exclude_super_?= =?utf-8?q?long_running_tests_from_the_PROFILE=5FTASK_for_PGO?= Message-ID: <20160415235112.15366.82643.FC735495@psf.io> https://hg.python.org/cpython/rev/51e6894936f5 changeset: 100994:51e6894936f5 branch: 3.5 parent: 100989:ba6f4f0fe9ea user: Gregory P. Smith date: Fri Apr 15 16:45:43 2016 -0700 summary: Exclude super long running tests from the PROFILE_TASK for PGO builds. multiprocessing and subprocess tests in particular along with test_asyncore and test_gdb. Running them does not meaningfully add to the profile guidance. files: Makefile.pre.in | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -230,8 +230,10 @@ TCLTK_INCLUDES= @TCLTK_INCLUDES@ TCLTK_LIBS= @TCLTK_LIBS@ -# The task to run while instrument when building the profile-opt target -PROFILE_TASK=-m test.regrtest --pgo +# The task to run while instrumented when building the profile-opt target. +# We exclude unittests with -x that take a rediculious amount of time to +# run in the instrumented training build or do not provide much value. +PROFILE_TASK=-m test.regrtest --pgo -x test_asyncore test_gdb test_multiprocessing_fork test_multiprocessing_forkserver test_multiprocessing_main_handling test_multiprocessing_spawn test_subprocess # report files for gcov / lcov coverage report COVERAGE_INFO= $(abs_builddir)/coverage.info -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 19:59:12 2016 From: python-checkins at python.org (gregory.p.smith) Date: Fri, 15 Apr 2016 23:59:12 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI1NzAy?= =?utf-8?q?=3A_A_--with-lto_configure_option_has_been_added_that_will?= Message-ID: <20160415235912.12755.64350.5191CE04@psf.io> https://hg.python.org/cpython/rev/f16ec63055ad changeset: 100999:f16ec63055ad branch: 3.5 parent: 100996:bd00b025bd73 user: Gregory P. Smith date: Fri Apr 15 16:57:04 2016 -0700 summary: Issue #25702: A --with-lto configure option has been added that will enable link time optimizations at build time during a make profile-opt. files: Makefile.pre.in | 4 +- Misc/NEWS | 6 ++++ configure | 46 +++++++++++++++++++++++++++++++++++++ configure.ac | 33 ++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -504,7 +504,7 @@ $(MAKE) profile-removal build_all_generate_profile: - $(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG)" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG)" LIBS="$(LIBS)" + $(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LIBS="$(LIBS)" run_profile_task: : # FIXME: can't run for a cross build @@ -514,7 +514,7 @@ $(LLVM_PROF_MERGER) build_all_use_profile: - $(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG)" + $(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) @LTOFLAGS@" # Compile and run with gcov .PHONY=coverage coverage-lcov coverage-report diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -388,6 +388,12 @@ Build ----- +- Issue #25702: A --with-lto configure option has been added that will + enable link time optimizations at build time during a make profile-opt. + Some compilers and toolchains are known to not produce stable code when + using LTO, be sure to test things thoroughly before relying on it. + It can provide a few % speed up over profile-opt alone. + - Issue #26624: Adds validation of ucrtbase[d].dll version with warning for old versions. diff --git a/configure b/configure --- a/configure +++ b/configure @@ -673,6 +673,7 @@ LLVM_PROF_MERGER PGO_PROF_USE_FLAG PGO_PROF_GEN_FLAG +LTOFLAGS ABIFLAGS LN MKDIR_P @@ -807,6 +808,7 @@ enable_shared enable_profiling with_pydebug +with_lto with_hash_algorithm with_address_sanitizer with_libs @@ -1487,6 +1489,8 @@ compiler --with-suffix=.exe set executable suffix --with-pydebug build with Py_DEBUG defined + --with-lto Enable Link Time Optimization in PGO builds. + Disabled by default. --with-hash-algorithm=[fnv|siphash24] select hash algorithm --with-address-sanitizer @@ -6560,6 +6564,48 @@ fi +# Enable LTO flags + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-lto" >&5 +$as_echo_n "checking for --with-lto... " >&6; } + +# Check whether --with-lto was given. +if test "${with_lto+set}" = set; then : + withval=$with_lto; +if test "$withval" != no +then + Py_LTO='true' + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; }; +else + Py_LTO='false' + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; }; +fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + +if test "$Py_LTO" = 'true' ; then + case $CC in + *clang*) + # Any changes made here should be reflected in the GCC+Darwin case below + LTOFLAGS="-flto" + ;; + *gcc*) + case $ac_sys_system in + Darwin*) + LTOFLAGS="-flto" + ;; + *) + LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none" + ;; + esac + ;; + esac +fi + # Enable PGO flags. diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1235,6 +1235,39 @@ fi], [AC_MSG_RESULT(no)]) +# Enable LTO flags +AC_SUBST(LTOFLAGS) +AC_MSG_CHECKING(for --with-lto) +AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto], [Enable Link Time Optimization in PGO builds. Disabled by default.]), +[ +if test "$withval" != no +then + Py_LTO='true' + AC_MSG_RESULT(yes); +else + Py_LTO='false' + AC_MSG_RESULT(no); +fi], +[AC_MSG_RESULT(no)]) +if test "$Py_LTO" = 'true' ; then + case $CC in + *clang*) + # Any changes made here should be reflected in the GCC+Darwin case below + LTOFLAGS="-flto" + ;; + *gcc*) + case $ac_sys_system in + Darwin*) + LTOFLAGS="-flto" + ;; + *) + LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none" + ;; + esac + ;; + esac +fi + # Enable PGO flags. AC_SUBST(PGO_PROF_GEN_FLAG) AC_SUBST(PGO_PROF_USE_FLAG) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 19:59:17 2016 From: python-checkins at python.org (gregory.p.smith) Date: Fri, 15 Apr 2016 23:59:17 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2325702=3A_A_--with-lto_configure_option_has_been?= =?utf-8?q?_added_that_will?= Message-ID: <20160415235913.89039.68968.E9375869@psf.io> https://hg.python.org/cpython/rev/3103af76f4c4 changeset: 101000:3103af76f4c4 parent: 100998:e3c6362cc139 parent: 100999:f16ec63055ad user: Gregory P. Smith date: Fri Apr 15 16:58:51 2016 -0700 summary: Issue #25702: A --with-lto configure option has been added that will enable link time optimizations at build time during a make profile-opt. files: Makefile.pre.in | 4 +- Misc/NEWS | 6 ++++ configure | 46 +++++++++++++++++++++++++++++++++++++ configure.ac | 33 ++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -504,7 +504,7 @@ $(MAKE) profile-removal build_all_generate_profile: - $(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG)" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG)" LIBS="$(LIBS)" + $(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LIBS="$(LIBS)" run_profile_task: : # FIXME: can't run for a cross build @@ -514,7 +514,7 @@ $(LLVM_PROF_MERGER) build_all_use_profile: - $(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG)" + $(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) @LTOFLAGS@" # Compile and run with gcov .PHONY=coverage coverage-lcov coverage-report diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -976,6 +976,12 @@ Build ----- +- Issue #25702: A --with-lto configure option has been added that will + enable link time optimizations at build time during a make profile-opt. + Some compilers and toolchains are known to not produce stable code when + using LTO, be sure to test things thoroughly before relying on it. + It can provide a few % speed up over profile-opt alone. + - Issue #26624: Adds validation of ucrtbase[d].dll version with warning for old versions. diff --git a/configure b/configure --- a/configure +++ b/configure @@ -673,6 +673,7 @@ LLVM_PROF_MERGER PGO_PROF_USE_FLAG PGO_PROF_GEN_FLAG +LTOFLAGS ABIFLAGS LN MKDIR_P @@ -807,6 +808,7 @@ enable_shared enable_profiling with_pydebug +with_lto with_hash_algorithm with_address_sanitizer with_libs @@ -1487,6 +1489,8 @@ compiler --with-suffix=.exe set executable suffix --with-pydebug build with Py_DEBUG defined + --with-lto Enable Link Time Optimization in PGO builds. + Disabled by default. --with-hash-algorithm=[fnv|siphash24] select hash algorithm --with-address-sanitizer @@ -6560,6 +6564,48 @@ fi +# Enable LTO flags + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-lto" >&5 +$as_echo_n "checking for --with-lto... " >&6; } + +# Check whether --with-lto was given. +if test "${with_lto+set}" = set; then : + withval=$with_lto; +if test "$withval" != no +then + Py_LTO='true' + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; }; +else + Py_LTO='false' + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; }; +fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + +if test "$Py_LTO" = 'true' ; then + case $CC in + *clang*) + # Any changes made here should be reflected in the GCC+Darwin case below + LTOFLAGS="-flto" + ;; + *gcc*) + case $ac_sys_system in + Darwin*) + LTOFLAGS="-flto" + ;; + *) + LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none" + ;; + esac + ;; + esac +fi + # Enable PGO flags. diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1235,6 +1235,39 @@ fi], [AC_MSG_RESULT(no)]) +# Enable LTO flags +AC_SUBST(LTOFLAGS) +AC_MSG_CHECKING(for --with-lto) +AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto], [Enable Link Time Optimization in PGO builds. Disabled by default.]), +[ +if test "$withval" != no +then + Py_LTO='true' + AC_MSG_RESULT(yes); +else + Py_LTO='false' + AC_MSG_RESULT(no); +fi], +[AC_MSG_RESULT(no)]) +if test "$Py_LTO" = 'true' ; then + case $CC in + *clang*) + # Any changes made here should be reflected in the GCC+Darwin case below + LTOFLAGS="-flto" + ;; + *gcc*) + case $ac_sys_system in + Darwin*) + LTOFLAGS="-flto" + ;; + *) + LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none" + ;; + esac + ;; + esac +fi + # Enable PGO flags. AC_SUBST(PGO_PROF_GEN_FLAG) AC_SUBST(PGO_PROF_USE_FLAG) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 20:21:57 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 00:21:57 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI1MzE0?= =?utf-8?q?=3A_Remove_confused_statement_about_const_argument?= Message-ID: <20160416002157.12737.88161.E4E4FDCC@psf.io> https://hg.python.org/cpython/rev/c42a9233af04 changeset: 101001:c42a9233af04 branch: 2.7 parent: 100981:0f5eb87afd23 user: Martin Panter date: Sat Apr 09 03:49:48 2016 +0000 summary: Issue #25314: Remove confused statement about const argument files: Doc/library/argparse.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -675,8 +675,7 @@ Namespace(foo='1') * ``'store_const'`` - This stores the value specified by the const_ keyword - argument. (Note that the const_ keyword argument defaults to the rather - unhelpful ``None``.) The ``'store_const'`` action is most commonly used with + argument. The ``'store_const'`` action is most commonly used with optional arguments that specify some sort of flag. For example:: >>> parser = argparse.ArgumentParser() @@ -878,7 +877,8 @@ command-line argument following it, the value of ``const`` will be assumed instead. See the nargs_ description for examples. -The ``const`` keyword argument defaults to ``None``. +With the ``'store_const'`` and ``'append_const'`` actions, the ``const`` +keyword argument must be given. For other actions, is defaults to ``None``. default -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 20:22:08 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 00:22:08 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2325314=3A_Merge_argparse_doc_from_3=2E5?= Message-ID: <20160416002157.15621.18334.ECB61F95@psf.io> https://hg.python.org/cpython/rev/7d61a991f405 changeset: 101003:7d61a991f405 parent: 101000:3103af76f4c4 parent: 101002:59b8db278e3c user: Martin Panter date: Sat Apr 16 00:20:21 2016 +0000 summary: Issue #25314: Merge argparse doc from 3.5 files: Doc/library/argparse.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -720,8 +720,7 @@ Namespace(foo='1') * ``'store_const'`` - This stores the value specified by the const_ keyword - argument. (Note that the const_ keyword argument defaults to the rather - unhelpful ``None``.) The ``'store_const'`` action is most commonly used with + argument. The ``'store_const'`` action is most commonly used with optional arguments that specify some sort of flag. For example:: >>> parser = argparse.ArgumentParser() @@ -923,7 +922,8 @@ command-line argument following it, the value of ``const`` will be assumed instead. See the nargs_ description for examples. -The ``const`` keyword argument defaults to ``None``. +With the ``'store_const'`` and ``'append_const'`` actions, the ``const`` +keyword argument must be given. For other actions, is defaults to ``None``. default -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 15 20:22:08 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 00:22:08 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI1MzE0?= =?utf-8?q?=3A_Remove_confused_statement_about_const_argument?= Message-ID: <20160416002157.107514.66269.52EF1633@psf.io> https://hg.python.org/cpython/rev/59b8db278e3c changeset: 101002:59b8db278e3c branch: 3.5 parent: 100999:f16ec63055ad user: Martin Panter date: Sat Apr 09 03:49:48 2016 +0000 summary: Issue #25314: Remove confused statement about const argument files: Doc/library/argparse.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -720,8 +720,7 @@ Namespace(foo='1') * ``'store_const'`` - This stores the value specified by the const_ keyword - argument. (Note that the const_ keyword argument defaults to the rather - unhelpful ``None``.) The ``'store_const'`` action is most commonly used with + argument. The ``'store_const'`` action is most commonly used with optional arguments that specify some sort of flag. For example:: >>> parser = argparse.ArgumentParser() @@ -923,7 +922,8 @@ command-line argument following it, the value of ``const`` will be assumed instead. See the nargs_ description for examples. -The ``const`` keyword argument defaults to ``None``. +With the ``'store_const'`` and ``'append_const'`` actions, the ``const`` +keyword argument must be given. For other actions, is defaults to ``None``. default -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 03:47:26 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 07:47:26 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2NjM4?= =?utf-8?q?=3A_Fix_links_to_some_CLI_options?= Message-ID: <20160416074726.12751.29453.A0149A29@psf.io> https://hg.python.org/cpython/rev/3e0321584f23 changeset: 101006:3e0321584f23 branch: 2.7 parent: 101001:c42a9233af04 user: Martin Panter date: Sat Apr 16 04:59:38 2016 +0000 summary: Issue #26638: Fix links to some CLI options Disable inappropriate links to Python interpreter options. Also make CLI section label in timeit less ambiguous. files: Doc/distutils/apiref.rst | 8 ++++---- Doc/distutils/configfile.rst | 2 +- Doc/install/index.rst | 6 +++--- Doc/library/2to3.rst | 10 +++++----- Doc/library/timeit.rst | 6 +++--- Doc/library/warnings.rst | 2 +- Doc/whatsnew/2.2.rst | 2 +- Doc/whatsnew/2.3.rst | 6 +++--- Doc/whatsnew/2.4.rst | 4 ++-- Doc/whatsnew/2.5.rst | 6 +++--- Doc/whatsnew/2.7.rst | 8 ++++---- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -314,12 +314,12 @@ .. function:: gen_preprocess_options(macros, include_dirs) - Generate C pre-processor options (:option:`-D`, :option:`-U`, :option:`-I`) as + Generate C pre-processor options (:option:`-D`, :option:`!-U`, :option:`!-I`) as used by at least two types of compilers: the typical Unix compiler and Visual C++. *macros* is the usual thing, a list of 1- or 2-tuples, where ``(name,)`` - means undefine (:option:`-U`) macro *name*, and ``(name, value)`` means define + means undefine (:option:`!-U`) macro *name*, and ``(name, value)`` means define (:option:`-D`) macro *name* to *value*. *include_dirs* is just a list of - directory names to be added to the header file search path (:option:`-I`). + directory names to be added to the header file search path (:option:`!-I`). Returns a list of command-line options suitable for either Unix compilers or Visual C++. @@ -794,7 +794,7 @@ * library search directories specified with :option:`-Ldir` -* compile handled by :program:`cc` (or similar) executable with :option:`-c` +* compile handled by :program:`cc` (or similar) executable with :option:`!-c` option: compiles :file:`.c` to :file:`.o` * link static library handled by :program:`ar` command (possibly with diff --git a/Doc/distutils/configfile.rst b/Doc/distutils/configfile.rst --- a/Doc/distutils/configfile.rst +++ b/Doc/distutils/configfile.rst @@ -51,7 +51,7 @@ continuation lines. You can find out the list of options supported by a particular command with the -universal :option:`--help` option, e.g. :: +universal :option:`!--help` option, e.g. :: > python setup.py --help build_ext [...] diff --git a/Doc/install/index.rst b/Doc/install/index.rst --- a/Doc/install/index.rst +++ b/Doc/install/index.rst @@ -862,12 +862,12 @@ run, they will use the values in the config file.) You can find out the complete list of options for any command using the -:option:`--help` option, e.g.:: +:option:`!--help` option, e.g.:: python setup.py build --help and you can find out the complete list of global options by using -:option:`--help` without a command:: +:option:`!--help` without a command:: python setup.py --help @@ -924,7 +924,7 @@ to be in Objective C. * *cpparg* is an argument for the C preprocessor, and is anything starting with - :option:`-I`, :option:`-D`, :option:`-U` or :option:`-C`. + :option:`!-I`, :option:`-D`, :option:`!-U` or :option:`-C`. * *library* is anything ending in :file:`.a` or beginning with :option:`-l` or :option:`-L`. diff --git a/Doc/library/2to3.rst b/Doc/library/2to3.rst --- a/Doc/library/2to3.rst +++ b/Doc/library/2to3.rst @@ -56,7 +56,7 @@ By default, 2to3 runs a set of :ref:`predefined fixers <2to3-fixers>`. The :option:`-l` flag lists all available fixers. An explicit set of fixers to run -can be given with :option:`-f`. Likewise the :option:`-x` explicitly disables a +can be given with :option:`-f`. Likewise the :option:`!-x` explicitly disables a fixer. The following example runs only the ``imports`` and ``has_key`` fixers:: $ 2to3 -f imports -f has_key example.py @@ -78,12 +78,12 @@ beneath the diff for a file. You should address the warning in order to have compliant 3.x code. -2to3 can also refactor doctests. To enable this mode, use the :option:`-d` +2to3 can also refactor doctests. To enable this mode, use the :option:`!-d` flag. Note that *only* doctests will be refactored. This also doesn't require the module to be valid Python. For example, doctest like examples in a reST document could also be refactored with this option. -The :option:`-v` option enables output of more information on the translation +The :option:`!-v` option enables output of more information on the translation process. Since some print statements can be parsed as function calls or statements, 2to3 @@ -102,14 +102,14 @@ .. versionadded:: 2.7.3 The :option:`-o` option was added. -The :option:`-W` or :option:`--write-unchanged-files` flag tells 2to3 to always +The :option:`!-W` or :option:`--write-unchanged-files` flag tells 2to3 to always write output files even if no changes were required to the file. This is most useful with :option:`-o` so that an entire Python source tree is copied with translation from one directory to another. This option implies the :option:`-w` flag as it would not make sense otherwise. .. versionadded:: 2.7.3 - The :option:`-W` flag was added. + The :option:`!-W` flag was added. The :option:`--add-suffix` option specifies a string to append to all output filenames. The :option:`-n` flag is required when specifying this as backups diff --git a/Doc/library/timeit.rst b/Doc/library/timeit.rst --- a/Doc/library/timeit.rst +++ b/Doc/library/timeit.rst @@ -16,7 +16,7 @@ -------------- This module provides a simple way to time small bits of Python code. It has both -a :ref:`command-line-interface` as well as a :ref:`callable ` +a :ref:`timeit-command-line-interface` as well as a :ref:`callable ` one. It avoids a number of common traps for measuring execution times. See also Tim Peters' introduction to the "Algorithms" chapter in the *Python Cookbook*, published by O'Reilly. @@ -25,7 +25,7 @@ Basic Examples -------------- -The following example shows how the :ref:`command-line-interface` +The following example shows how the :ref:`timeit-command-line-interface` can be used to compare three different expressions: .. code-block:: sh @@ -170,7 +170,7 @@ where the traceback is sent; it defaults to :data:`sys.stderr`. -.. _command-line-interface: +.. _timeit-command-line-interface: Command-Line Interface ---------------------- diff --git a/Doc/library/warnings.rst b/Doc/library/warnings.rst --- a/Doc/library/warnings.rst +++ b/Doc/library/warnings.rst @@ -256,7 +256,7 @@ Warnings that are only of interest to the developer are ignored by default. As such you should make sure to test your code with typically ignored warnings -made visible. You can do this from the command-line by passing :option:`-Wd` +made visible. You can do this from the command-line by passing :option:`-Wd <-W>` to the interpreter (this is shorthand for :option:`-W default`). This enables default handling for all warnings, including those that are ignored by default. To change what action is taken for encountered warnings you simply change what diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst --- a/Doc/whatsnew/2.2.rst +++ b/Doc/whatsnew/2.2.rst @@ -759,7 +759,7 @@ * Python 2.2 supports some command-line arguments for testing whether code will works with the changed division semantics. Running python with :option:`-Q - warn` will cause a warning to be issued whenever division is applied to two + warn <-Q>` will cause a warning to be issued whenever division is applied to two integers. You can use this to find code that's affected by the change and fix it. By default, Python 2.2 will simply perform classic division without a warning; the warning will be turned on by default in Python 2.3. diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -1057,7 +1057,7 @@ * A new warning, :exc:`PendingDeprecationWarning` was added to indicate features which are in the process of being deprecated. The warning will *not* be printed by default. To check for use of features that will be deprecated in the future, - supply :option:`-Walways::PendingDeprecationWarning::` on the command line or + supply :option:`-Walways::PendingDeprecationWarning:: <-W>` on the command line or use :func:`warnings.filterwarnings`. * The process of deprecating string-based exceptions, as in ``raise "Error @@ -1734,7 +1734,7 @@ The :mod:`getopt` module provides simple parsing of command-line arguments. The new :mod:`optparse` module (originally named Optik) provides more elaborate command-line parsing that follows the Unix conventions, automatically creates -the output for :option:`--help`, and can perform different actions for different +the output for :option:`!--help`, and can perform different actions for different options. You start by creating an instance of :class:`OptionParser` and telling it what @@ -1973,7 +1973,7 @@ the Python program as part of its execution. * The :file:`regrtest.py` script now provides a way to allow "all resources - except *foo*." A resource name passed to the :option:`-u` option can now be + except *foo*." A resource name passed to the :option:`!-u` option can now be prefixed with a hyphen (``'-'``) to mean "remove this resource." For example, the option '``-uall,-bsddb``' could be used to enable the use of all resources except ``bsddb``. diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -1483,8 +1483,8 @@ intended as an aid to people developing the Python core. Providing :option:`----enable-profiling` to the :program:`configure` script will let you profile the interpreter with :program:`gprof`, and providing the - :option:`----with-tsc` switch enables profiling using the Pentium's Time-Stamp- - Counter register. Note that the :option:`----with-tsc` switch is slightly + :option:`--with-tsc` switch enables profiling using the Pentium's Time-Stamp- + Counter register. Note that the :option:`--with-tsc` switch is slightly misnamed, because the profiling feature also works on the PowerPC platform, though that processor architecture doesn't call that register "the TSC register". (Contributed by Jeremy Hylton.) diff --git a/Doc/whatsnew/2.5.rst b/Doc/whatsnew/2.5.rst --- a/Doc/whatsnew/2.5.rst +++ b/Doc/whatsnew/2.5.rst @@ -1095,7 +1095,7 @@ log all the paths searched. In Python 2.5, a new :exc:`ImportWarning` warning is triggered when an import would have picked up a directory as a package but no :file:`__init__.py` was found. This warning is silently ignored by default; - provide the :option:`-Wd` option when running the Python executable to display + provide the :option:`-Wd <-W>` option when running the Python executable to display the warning message. (Implemented by Thomas Wouters.) * The list of base classes in a class definition can now be empty. As an @@ -1126,7 +1126,7 @@ Georg Brandl.) The Python executable now accepts the standard long options :option:`--help` -and :option:`--version`; on Windows, it also accepts the :option:`/?` option +and :option:`--version`; on Windows, it also accepts the :option:`/? <-?>` option for displaying a help message. (Implemented by Georg Brandl.) .. ====================================================================== @@ -1640,7 +1640,7 @@ * The :mod:`webbrowser` module received a number of enhancements. It's now usable as a script with ``python -m webbrowser``, taking a URL as the argument; there are a number of switches to control the behaviour (:option:`-n` for a new - browser window, :option:`-t` for a new tab). New module-level functions, + browser window, :option:`!-t` for a new tab). New module-level functions, :func:`open_new` and :func:`open_new_tab`, were added to support this. The module's :func:`open` function supports an additional feature, an *autoraise* parameter that signals whether to raise the open window when possible. A number diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -1820,12 +1820,12 @@ The :func:`~unittest.main` function supports some other new options: -* :option:`-b` or :option:`--buffer` will buffer the standard output +* :option:`-b ` or :option:`--buffer` will buffer the standard output and standard error streams during each test. If the test passes, any resulting output will be discarded; on failure, the buffered output will be displayed. -* :option:`-c` or :option:`--catch` will cause the control-C interrupt +* :option:`-c ` or :option:`--catch` will cause the control-C interrupt to be handled more gracefully. Instead of interrupting the test process immediately, the currently running test will be completed and then the partial results up to the interruption will be reported. @@ -1839,7 +1839,7 @@ :func:`~unittest.removeHandler` decorator that can be used to mark tests that should have the control-C handling disabled. -* :option:`-f` or :option:`--failfast` makes +* :option:`-f ` or :option:`--failfast` makes test execution stop immediately when a test fails instead of continuing to execute further tests. (Suggested by Cliff Dyer and implemented by Michael Foord; :issue:`8074`.) @@ -2381,7 +2381,7 @@ takes an integer specifying how many tests run in parallel. This allows reducing the total runtime on multi-core machines. This option is compatible with several other options, including the - :option:`-R` switch which is known to produce long runtimes. + :option:`!-R` switch which is known to produce long runtimes. (Added by Antoine Pitrou, :issue:`6152`.) This can also be used with a new :option:`-F` switch that runs selected tests in a loop until they fail. (Added by Antoine Pitrou; :issue:`7312`.) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 03:47:26 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 07:47:26 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326638=3A_Merge_link_fixes_from_3=2E5?= Message-ID: <20160416074725.19501.66470.CC6CE509@psf.io> https://hg.python.org/cpython/rev/68b84643dffd changeset: 101005:68b84643dffd parent: 101003:7d61a991f405 parent: 101004:23a884c32a39 user: Martin Panter date: Sat Apr 16 07:36:08 2016 +0000 summary: Issue #26638: Merge link fixes from 3.5 files: Doc/distutils/apiref.rst | 8 ++++---- Doc/distutils/configfile.rst | 2 +- Doc/install/index.rst | 6 +++--- Doc/library/2to3.rst | 10 +++++----- Doc/library/timeit.rst | 6 +++--- Doc/library/warnings.rst | 2 +- Doc/library/zipapp.rst | 2 +- Doc/whatsnew/2.3.rst | 6 +++--- Doc/whatsnew/2.4.rst | 4 ++-- Doc/whatsnew/2.5.rst | 6 +++--- Doc/whatsnew/2.7.rst | 8 ++++---- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -319,12 +319,12 @@ .. function:: gen_preprocess_options(macros, include_dirs) - Generate C pre-processor options (:option:`-D`, :option:`-U`, :option:`-I`) as + Generate C pre-processor options (:option:`-D`, :option:`!-U`, :option:`!-I`) as used by at least two types of compilers: the typical Unix compiler and Visual C++. *macros* is the usual thing, a list of 1- or 2-tuples, where ``(name,)`` - means undefine (:option:`-U`) macro *name*, and ``(name, value)`` means define + means undefine (:option:`!-U`) macro *name*, and ``(name, value)`` means define (:option:`-D`) macro *name* to *value*. *include_dirs* is just a list of - directory names to be added to the header file search path (:option:`-I`). + directory names to be added to the header file search path (:option:`!-I`). Returns a list of command-line options suitable for either Unix compilers or Visual C++. @@ -799,7 +799,7 @@ * library search directories specified with :option:`-Ldir` -* compile handled by :program:`cc` (or similar) executable with :option:`-c` +* compile handled by :program:`cc` (or similar) executable with :option:`!-c` option: compiles :file:`.c` to :file:`.o` * link static library handled by :program:`ar` command (possibly with diff --git a/Doc/distutils/configfile.rst b/Doc/distutils/configfile.rst --- a/Doc/distutils/configfile.rst +++ b/Doc/distutils/configfile.rst @@ -51,7 +51,7 @@ continuation lines. You can find out the list of options supported by a particular command with the -universal :option:`--help` option, e.g. :: +universal :option:`!--help` option, e.g. :: > python setup.py --help build_ext [...] diff --git a/Doc/install/index.rst b/Doc/install/index.rst --- a/Doc/install/index.rst +++ b/Doc/install/index.rst @@ -865,12 +865,12 @@ run, they will use the values in the config file.) You can find out the complete list of options for any command using the -:option:`--help` option, e.g.:: +:option:`!--help` option, e.g.:: python setup.py build --help and you can find out the complete list of global options by using -:option:`--help` without a command:: +:option:`!--help` without a command:: python setup.py --help @@ -927,7 +927,7 @@ to be in Objective C. * *cpparg* is an argument for the C preprocessor, and is anything starting with - :option:`-I`, :option:`-D`, :option:`-U` or :option:`-C`. + :option:`!-I`, :option:`-D`, :option:`!-U` or :option:`-C`. * *library* is anything ending in :file:`.a` or beginning with :option:`-l` or :option:`-L`. diff --git a/Doc/library/2to3.rst b/Doc/library/2to3.rst --- a/Doc/library/2to3.rst +++ b/Doc/library/2to3.rst @@ -56,7 +56,7 @@ By default, 2to3 runs a set of :ref:`predefined fixers <2to3-fixers>`. The :option:`-l` flag lists all available fixers. An explicit set of fixers to run -can be given with :option:`-f`. Likewise the :option:`-x` explicitly disables a +can be given with :option:`-f`. Likewise the :option:`!-x` explicitly disables a fixer. The following example runs only the ``imports`` and ``has_key`` fixers:: $ 2to3 -f imports -f has_key example.py @@ -78,12 +78,12 @@ beneath the diff for a file. You should address the warning in order to have compliant 3.x code. -2to3 can also refactor doctests. To enable this mode, use the :option:`-d` +2to3 can also refactor doctests. To enable this mode, use the :option:`!-d` flag. Note that *only* doctests will be refactored. This also doesn't require the module to be valid Python. For example, doctest like examples in a reST document could also be refactored with this option. -The :option:`-v` option enables output of more information on the translation +The :option:`!-v` option enables output of more information on the translation process. Since some print statements can be parsed as function calls or statements, 2to3 @@ -102,14 +102,14 @@ .. versionadded:: 3.2.3 The :option:`-o` option was added. -The :option:`-W` or :option:`--write-unchanged-files` flag tells 2to3 to always +The :option:`!-W` or :option:`--write-unchanged-files` flag tells 2to3 to always write output files even if no changes were required to the file. This is most useful with :option:`-o` so that an entire Python source tree is copied with translation from one directory to another. This option implies the :option:`-w` flag as it would not make sense otherwise. .. versionadded:: 3.2.3 - The :option:`-W` flag was added. + The :option:`!-W` flag was added. The :option:`--add-suffix` option specifies a string to append to all output filenames. The :option:`-n` flag is required when specifying this as backups diff --git a/Doc/library/timeit.rst b/Doc/library/timeit.rst --- a/Doc/library/timeit.rst +++ b/Doc/library/timeit.rst @@ -14,7 +14,7 @@ -------------- This module provides a simple way to time small bits of Python code. It has both -a :ref:`command-line-interface` as well as a :ref:`callable ` +a :ref:`timeit-command-line-interface` as well as a :ref:`callable ` one. It avoids a number of common traps for measuring execution times. See also Tim Peters' introduction to the "Algorithms" chapter in the *Python Cookbook*, published by O'Reilly. @@ -23,7 +23,7 @@ Basic Examples -------------- -The following example shows how the :ref:`command-line-interface` +The following example shows how the :ref:`timeit-command-line-interface` can be used to compare three different expressions: .. code-block:: sh @@ -174,7 +174,7 @@ where the traceback is sent; it defaults to :data:`sys.stderr`. -.. _command-line-interface: +.. _timeit-command-line-interface: Command-Line Interface ---------------------- diff --git a/Doc/library/warnings.rst b/Doc/library/warnings.rst --- a/Doc/library/warnings.rst +++ b/Doc/library/warnings.rst @@ -265,7 +265,7 @@ Warnings that are only of interest to the developer are ignored by default. As such you should make sure to test your code with typically ignored warnings -made visible. You can do this from the command-line by passing :option:`-Wd` +made visible. You can do this from the command-line by passing :option:`-Wd <-W>` to the interpreter (this is shorthand for :option:`-W default`). This enables default handling for all warnings, including those that are ignored by default. To change what action is taken for encountered warnings you simply change what diff --git a/Doc/library/zipapp.rst b/Doc/library/zipapp.rst --- a/Doc/library/zipapp.rst +++ b/Doc/library/zipapp.rst @@ -23,7 +23,7 @@ Basic Example ------------- -The following example shows how the :ref:`command-line-interface` +The following example shows how the :ref:`zipapp-command-line-interface` can be used to create an executable archive from a directory containing Python code. When run, the archive will execute the ``main`` function from the module ``myapp`` in the archive. diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -1057,7 +1057,7 @@ * A new warning, :exc:`PendingDeprecationWarning` was added to indicate features which are in the process of being deprecated. The warning will *not* be printed by default. To check for use of features that will be deprecated in the future, - supply :option:`-Walways::PendingDeprecationWarning::` on the command line or + supply :option:`-Walways::PendingDeprecationWarning:: <-W>` on the command line or use :func:`warnings.filterwarnings`. * The process of deprecating string-based exceptions, as in ``raise "Error @@ -1734,7 +1734,7 @@ The :mod:`getopt` module provides simple parsing of command-line arguments. The new :mod:`optparse` module (originally named Optik) provides more elaborate command-line parsing that follows the Unix conventions, automatically creates -the output for :option:`--help`, and can perform different actions for different +the output for :option:`!--help`, and can perform different actions for different options. You start by creating an instance of :class:`OptionParser` and telling it what @@ -1973,7 +1973,7 @@ the Python program as part of its execution. * The :file:`regrtest.py` script now provides a way to allow "all resources - except *foo*." A resource name passed to the :option:`-u` option can now be + except *foo*." A resource name passed to the :option:`!-u` option can now be prefixed with a hyphen (``'-'``) to mean "remove this resource." For example, the option '``-uall,-bsddb``' could be used to enable the use of all resources except ``bsddb``. diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -1483,8 +1483,8 @@ intended as an aid to people developing the Python core. Providing :option:`----enable-profiling` to the :program:`configure` script will let you profile the interpreter with :program:`gprof`, and providing the - :option:`----with-tsc` switch enables profiling using the Pentium's Time-Stamp- - Counter register. Note that the :option:`----with-tsc` switch is slightly + :option:`--with-tsc` switch enables profiling using the Pentium's Time-Stamp- + Counter register. Note that the :option:`--with-tsc` switch is slightly misnamed, because the profiling feature also works on the PowerPC platform, though that processor architecture doesn't call that register "the TSC register". (Contributed by Jeremy Hylton.) diff --git a/Doc/whatsnew/2.5.rst b/Doc/whatsnew/2.5.rst --- a/Doc/whatsnew/2.5.rst +++ b/Doc/whatsnew/2.5.rst @@ -1095,7 +1095,7 @@ log all the paths searched. In Python 2.5, a new :exc:`ImportWarning` warning is triggered when an import would have picked up a directory as a package but no :file:`__init__.py` was found. This warning is silently ignored by default; - provide the :option:`-Wd` option when running the Python executable to display + provide the :option:`-Wd <-W>` option when running the Python executable to display the warning message. (Implemented by Thomas Wouters.) * The list of base classes in a class definition can now be empty. As an @@ -1126,7 +1126,7 @@ Georg Brandl.) The Python executable now accepts the standard long options :option:`--help` -and :option:`--version`; on Windows, it also accepts the :option:`/?` option +and :option:`--version`; on Windows, it also accepts the :option:`/? <-?>` option for displaying a help message. (Implemented by Georg Brandl.) .. ====================================================================== @@ -1640,7 +1640,7 @@ * The :mod:`webbrowser` module received a number of enhancements. It's now usable as a script with ``python -m webbrowser``, taking a URL as the argument; there are a number of switches to control the behaviour (:option:`-n` for a new - browser window, :option:`-t` for a new tab). New module-level functions, + browser window, :option:`!-t` for a new tab). New module-level functions, :func:`open_new` and :func:`open_new_tab`, were added to support this. The module's :func:`open` function supports an additional feature, an *autoraise* parameter that signals whether to raise the open window when possible. A number diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -1820,12 +1820,12 @@ The :func:`~unittest.main` function supports some other new options: -* :option:`-b` or :option:`--buffer` will buffer the standard output +* :option:`-b ` or :option:`--buffer` will buffer the standard output and standard error streams during each test. If the test passes, any resulting output will be discarded; on failure, the buffered output will be displayed. -* :option:`-c` or :option:`--catch` will cause the control-C interrupt +* :option:`-c ` or :option:`--catch` will cause the control-C interrupt to be handled more gracefully. Instead of interrupting the test process immediately, the currently running test will be completed and then the partial results up to the interruption will be reported. @@ -1839,7 +1839,7 @@ :func:`~unittest.removeHandler` decorator that can be used to mark tests that should have the control-C handling disabled. -* :option:`-f` or :option:`--failfast` makes +* :option:`-f ` or :option:`--failfast` makes test execution stop immediately when a test fails instead of continuing to execute further tests. (Suggested by Cliff Dyer and implemented by Michael Foord; :issue:`8074`.) @@ -2381,7 +2381,7 @@ takes an integer specifying how many tests run in parallel. This allows reducing the total runtime on multi-core machines. This option is compatible with several other options, including the - :option:`-R` switch which is known to produce long runtimes. + :option:`!-R` switch which is known to produce long runtimes. (Added by Antoine Pitrou, :issue:`6152`.) This can also be used with a new :option:`-F` switch that runs selected tests in a loop until they fail. (Added by Antoine Pitrou; :issue:`7312`.) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 03:47:26 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 07:47:26 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NjM4?= =?utf-8?q?=3A_Fix_links_to_some_CLI_options_and_section_headings?= Message-ID: <20160416074725.107504.60845.377AEA1A@psf.io> https://hg.python.org/cpython/rev/23a884c32a39 changeset: 101004:23a884c32a39 branch: 3.5 parent: 101002:59b8db278e3c user: Martin Panter date: Sat Apr 16 04:59:38 2016 +0000 summary: Issue #26638: Fix links to some CLI options and section headings * Disable inappropriate links to Python interpreter options * Correct link to CLI section in zipapp * Make CLI section label in timeit less ambiguous files: Doc/distutils/apiref.rst | 8 ++++---- Doc/distutils/configfile.rst | 2 +- Doc/install/index.rst | 6 +++--- Doc/library/2to3.rst | 10 +++++----- Doc/library/timeit.rst | 6 +++--- Doc/library/warnings.rst | 2 +- Doc/library/zipapp.rst | 2 +- Doc/whatsnew/2.3.rst | 6 +++--- Doc/whatsnew/2.4.rst | 4 ++-- Doc/whatsnew/2.5.rst | 6 +++--- Doc/whatsnew/2.7.rst | 8 ++++---- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -319,12 +319,12 @@ .. function:: gen_preprocess_options(macros, include_dirs) - Generate C pre-processor options (:option:`-D`, :option:`-U`, :option:`-I`) as + Generate C pre-processor options (:option:`-D`, :option:`!-U`, :option:`!-I`) as used by at least two types of compilers: the typical Unix compiler and Visual C++. *macros* is the usual thing, a list of 1- or 2-tuples, where ``(name,)`` - means undefine (:option:`-U`) macro *name*, and ``(name, value)`` means define + means undefine (:option:`!-U`) macro *name*, and ``(name, value)`` means define (:option:`-D`) macro *name* to *value*. *include_dirs* is just a list of - directory names to be added to the header file search path (:option:`-I`). + directory names to be added to the header file search path (:option:`!-I`). Returns a list of command-line options suitable for either Unix compilers or Visual C++. @@ -799,7 +799,7 @@ * library search directories specified with :option:`-Ldir` -* compile handled by :program:`cc` (or similar) executable with :option:`-c` +* compile handled by :program:`cc` (or similar) executable with :option:`!-c` option: compiles :file:`.c` to :file:`.o` * link static library handled by :program:`ar` command (possibly with diff --git a/Doc/distutils/configfile.rst b/Doc/distutils/configfile.rst --- a/Doc/distutils/configfile.rst +++ b/Doc/distutils/configfile.rst @@ -51,7 +51,7 @@ continuation lines. You can find out the list of options supported by a particular command with the -universal :option:`--help` option, e.g. :: +universal :option:`!--help` option, e.g. :: > python setup.py --help build_ext [...] diff --git a/Doc/install/index.rst b/Doc/install/index.rst --- a/Doc/install/index.rst +++ b/Doc/install/index.rst @@ -865,12 +865,12 @@ run, they will use the values in the config file.) You can find out the complete list of options for any command using the -:option:`--help` option, e.g.:: +:option:`!--help` option, e.g.:: python setup.py build --help and you can find out the complete list of global options by using -:option:`--help` without a command:: +:option:`!--help` without a command:: python setup.py --help @@ -927,7 +927,7 @@ to be in Objective C. * *cpparg* is an argument for the C preprocessor, and is anything starting with - :option:`-I`, :option:`-D`, :option:`-U` or :option:`-C`. + :option:`!-I`, :option:`-D`, :option:`!-U` or :option:`-C`. * *library* is anything ending in :file:`.a` or beginning with :option:`-l` or :option:`-L`. diff --git a/Doc/library/2to3.rst b/Doc/library/2to3.rst --- a/Doc/library/2to3.rst +++ b/Doc/library/2to3.rst @@ -56,7 +56,7 @@ By default, 2to3 runs a set of :ref:`predefined fixers <2to3-fixers>`. The :option:`-l` flag lists all available fixers. An explicit set of fixers to run -can be given with :option:`-f`. Likewise the :option:`-x` explicitly disables a +can be given with :option:`-f`. Likewise the :option:`!-x` explicitly disables a fixer. The following example runs only the ``imports`` and ``has_key`` fixers:: $ 2to3 -f imports -f has_key example.py @@ -78,12 +78,12 @@ beneath the diff for a file. You should address the warning in order to have compliant 3.x code. -2to3 can also refactor doctests. To enable this mode, use the :option:`-d` +2to3 can also refactor doctests. To enable this mode, use the :option:`!-d` flag. Note that *only* doctests will be refactored. This also doesn't require the module to be valid Python. For example, doctest like examples in a reST document could also be refactored with this option. -The :option:`-v` option enables output of more information on the translation +The :option:`!-v` option enables output of more information on the translation process. Since some print statements can be parsed as function calls or statements, 2to3 @@ -102,14 +102,14 @@ .. versionadded:: 3.2.3 The :option:`-o` option was added. -The :option:`-W` or :option:`--write-unchanged-files` flag tells 2to3 to always +The :option:`!-W` or :option:`--write-unchanged-files` flag tells 2to3 to always write output files even if no changes were required to the file. This is most useful with :option:`-o` so that an entire Python source tree is copied with translation from one directory to another. This option implies the :option:`-w` flag as it would not make sense otherwise. .. versionadded:: 3.2.3 - The :option:`-W` flag was added. + The :option:`!-W` flag was added. The :option:`--add-suffix` option specifies a string to append to all output filenames. The :option:`-n` flag is required when specifying this as backups diff --git a/Doc/library/timeit.rst b/Doc/library/timeit.rst --- a/Doc/library/timeit.rst +++ b/Doc/library/timeit.rst @@ -14,7 +14,7 @@ -------------- This module provides a simple way to time small bits of Python code. It has both -a :ref:`command-line-interface` as well as a :ref:`callable ` +a :ref:`timeit-command-line-interface` as well as a :ref:`callable ` one. It avoids a number of common traps for measuring execution times. See also Tim Peters' introduction to the "Algorithms" chapter in the *Python Cookbook*, published by O'Reilly. @@ -23,7 +23,7 @@ Basic Examples -------------- -The following example shows how the :ref:`command-line-interface` +The following example shows how the :ref:`timeit-command-line-interface` can be used to compare three different expressions: .. code-block:: sh @@ -174,7 +174,7 @@ where the traceback is sent; it defaults to :data:`sys.stderr`. -.. _command-line-interface: +.. _timeit-command-line-interface: Command-Line Interface ---------------------- diff --git a/Doc/library/warnings.rst b/Doc/library/warnings.rst --- a/Doc/library/warnings.rst +++ b/Doc/library/warnings.rst @@ -265,7 +265,7 @@ Warnings that are only of interest to the developer are ignored by default. As such you should make sure to test your code with typically ignored warnings -made visible. You can do this from the command-line by passing :option:`-Wd` +made visible. You can do this from the command-line by passing :option:`-Wd <-W>` to the interpreter (this is shorthand for :option:`-W default`). This enables default handling for all warnings, including those that are ignored by default. To change what action is taken for encountered warnings you simply change what diff --git a/Doc/library/zipapp.rst b/Doc/library/zipapp.rst --- a/Doc/library/zipapp.rst +++ b/Doc/library/zipapp.rst @@ -23,7 +23,7 @@ Basic Example ------------- -The following example shows how the :ref:`command-line-interface` +The following example shows how the :ref:`zipapp-command-line-interface` can be used to create an executable archive from a directory containing Python code. When run, the archive will execute the ``main`` function from the module ``myapp`` in the archive. diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -1057,7 +1057,7 @@ * A new warning, :exc:`PendingDeprecationWarning` was added to indicate features which are in the process of being deprecated. The warning will *not* be printed by default. To check for use of features that will be deprecated in the future, - supply :option:`-Walways::PendingDeprecationWarning::` on the command line or + supply :option:`-Walways::PendingDeprecationWarning:: <-W>` on the command line or use :func:`warnings.filterwarnings`. * The process of deprecating string-based exceptions, as in ``raise "Error @@ -1734,7 +1734,7 @@ The :mod:`getopt` module provides simple parsing of command-line arguments. The new :mod:`optparse` module (originally named Optik) provides more elaborate command-line parsing that follows the Unix conventions, automatically creates -the output for :option:`--help`, and can perform different actions for different +the output for :option:`!--help`, and can perform different actions for different options. You start by creating an instance of :class:`OptionParser` and telling it what @@ -1973,7 +1973,7 @@ the Python program as part of its execution. * The :file:`regrtest.py` script now provides a way to allow "all resources - except *foo*." A resource name passed to the :option:`-u` option can now be + except *foo*." A resource name passed to the :option:`!-u` option can now be prefixed with a hyphen (``'-'``) to mean "remove this resource." For example, the option '``-uall,-bsddb``' could be used to enable the use of all resources except ``bsddb``. diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -1483,8 +1483,8 @@ intended as an aid to people developing the Python core. Providing :option:`----enable-profiling` to the :program:`configure` script will let you profile the interpreter with :program:`gprof`, and providing the - :option:`----with-tsc` switch enables profiling using the Pentium's Time-Stamp- - Counter register. Note that the :option:`----with-tsc` switch is slightly + :option:`--with-tsc` switch enables profiling using the Pentium's Time-Stamp- + Counter register. Note that the :option:`--with-tsc` switch is slightly misnamed, because the profiling feature also works on the PowerPC platform, though that processor architecture doesn't call that register "the TSC register". (Contributed by Jeremy Hylton.) diff --git a/Doc/whatsnew/2.5.rst b/Doc/whatsnew/2.5.rst --- a/Doc/whatsnew/2.5.rst +++ b/Doc/whatsnew/2.5.rst @@ -1095,7 +1095,7 @@ log all the paths searched. In Python 2.5, a new :exc:`ImportWarning` warning is triggered when an import would have picked up a directory as a package but no :file:`__init__.py` was found. This warning is silently ignored by default; - provide the :option:`-Wd` option when running the Python executable to display + provide the :option:`-Wd <-W>` option when running the Python executable to display the warning message. (Implemented by Thomas Wouters.) * The list of base classes in a class definition can now be empty. As an @@ -1126,7 +1126,7 @@ Georg Brandl.) The Python executable now accepts the standard long options :option:`--help` -and :option:`--version`; on Windows, it also accepts the :option:`/?` option +and :option:`--version`; on Windows, it also accepts the :option:`/? <-?>` option for displaying a help message. (Implemented by Georg Brandl.) .. ====================================================================== @@ -1640,7 +1640,7 @@ * The :mod:`webbrowser` module received a number of enhancements. It's now usable as a script with ``python -m webbrowser``, taking a URL as the argument; there are a number of switches to control the behaviour (:option:`-n` for a new - browser window, :option:`-t` for a new tab). New module-level functions, + browser window, :option:`!-t` for a new tab). New module-level functions, :func:`open_new` and :func:`open_new_tab`, were added to support this. The module's :func:`open` function supports an additional feature, an *autoraise* parameter that signals whether to raise the open window when possible. A number diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -1820,12 +1820,12 @@ The :func:`~unittest.main` function supports some other new options: -* :option:`-b` or :option:`--buffer` will buffer the standard output +* :option:`-b ` or :option:`--buffer` will buffer the standard output and standard error streams during each test. If the test passes, any resulting output will be discarded; on failure, the buffered output will be displayed. -* :option:`-c` or :option:`--catch` will cause the control-C interrupt +* :option:`-c ` or :option:`--catch` will cause the control-C interrupt to be handled more gracefully. Instead of interrupting the test process immediately, the currently running test will be completed and then the partial results up to the interruption will be reported. @@ -1839,7 +1839,7 @@ :func:`~unittest.removeHandler` decorator that can be used to mark tests that should have the control-C handling disabled. -* :option:`-f` or :option:`--failfast` makes +* :option:`-f ` or :option:`--failfast` makes test execution stop immediately when a test fails instead of continuing to execute further tests. (Suggested by Cliff Dyer and implemented by Michael Foord; :issue:`8074`.) @@ -2381,7 +2381,7 @@ takes an integer specifying how many tests run in parallel. This allows reducing the total runtime on multi-core machines. This option is compatible with several other options, including the - :option:`-R` switch which is known to produce long runtimes. + :option:`!-R` switch which is known to produce long runtimes. (Added by Antoine Pitrou, :issue:`6152`.) This can also be used with a new :option:`-F` switch that runs selected tests in a loop until they fail. (Added by Antoine Pitrou; :issue:`7312`.) -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Sat Apr 16 05:46:04 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 16 Apr 2016 09:46:04 +0000 Subject: [Python-checkins] Daily reference leaks (7d61a991f405): sum=4 Message-ID: <20160416094601.107676.980.B78D4BFD@psf.io> results for 7d61a991f405 on branch "default" -------------------------------------------- test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogZkhPw1', '--timeout', '7200'] From python-checkins at python.org Sat Apr 16 05:49:25 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 09:49:25 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Fix_typos_in_c?= =?utf-8?q?ode_comments_and_documentation?= Message-ID: <20160416094925.12735.18115.D308E16C@psf.io> https://hg.python.org/cpython/rev/7e74001ec567 changeset: 101007:7e74001ec567 branch: 3.5 parent: 101004:23a884c32a39 user: Martin Panter date: Sat Apr 16 09:28:57 2016 +0000 summary: Fix typos in code comments and documentation files: Doc/library/argparse.rst | 2 +- Doc/whatsnew/2.4.rst | 2 +- Lib/posixpath.py | 2 +- Lib/test/test_codecs.py | 4 ++-- Modules/_io/bytesio.c | 4 ++-- Modules/_io/clinic/bytesio.c.h | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -923,7 +923,7 @@ See the nargs_ description for examples. With the ``'store_const'`` and ``'append_const'`` actions, the ``const`` -keyword argument must be given. For other actions, is defaults to ``None``. +keyword argument must be given. For other actions, it defaults to ``None``. default diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -1481,7 +1481,7 @@ * Python can now be built with additional profiling for the interpreter itself, intended as an aid to people developing the Python core. Providing - :option:`----enable-profiling` to the :program:`configure` script will let you + :option:`--enable-profiling` to the :program:`configure` script will let you profile the interpreter with :program:`gprof`, and providing the :option:`--with-tsc` switch enables profiling using the Pentium's Time-Stamp- Counter register. Note that the :option:`--with-tsc` switch is slightly diff --git a/Lib/posixpath.py b/Lib/posixpath.py --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -372,7 +372,7 @@ path, ok = _joinrealpath(filename[:0], filename, {}) return abspath(path) -# Join two paths, normalizing ang eliminating any symbolic links +# Join two paths, normalizing and eliminating any symbolic links # encountered in the second path. def _joinrealpath(path, rest, seen): if isinstance(path, bytes): diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -2355,7 +2355,7 @@ self.assertRaises(TypeError, decoder, "xxx") def test_unicode_escape(self): - # Escape-decoding a unicode string is supported ang gives the same + # Escape-decoding a unicode string is supported and gives the same # result as decoding the equivalent ASCII bytes string. self.assertEqual(codecs.unicode_escape_decode(r"\u1234"), ("\u1234", 6)) self.assertEqual(codecs.unicode_escape_decode(br"\u1234"), ("\u1234", 6)) @@ -2762,7 +2762,7 @@ # type and a single str argument. # Use a local codec registry to avoid appearing to leak objects when -# registering multiple seach functions +# registering multiple search functions _TEST_CODECS = {} def _get_test_codec(codec_name): diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -551,12 +551,12 @@ Read up to len(buffer) bytes into buffer. Returns number of bytes read (0 for EOF), or None if the object -is set not to block as has no data to read. +is set not to block and has no data to read. [clinic start generated code]*/ static PyObject * _io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer) -/*[clinic end generated code: output=a5d407217dcf0639 input=71581f32635c3a31]*/ +/*[clinic end generated code: output=a5d407217dcf0639 input=b52a8782706f0037]*/ { Py_ssize_t len, n; diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h --- a/Modules/_io/clinic/bytesio.c.h +++ b/Modules/_io/clinic/bytesio.c.h @@ -262,7 +262,7 @@ "Read up to len(buffer) bytes into buffer.\n" "\n" "Returns number of bytes read (0 for EOF), or None if the object\n" -"is set not to block as has no data to read."); +"is set not to block and has no data to read."); #define _IO_BYTESIO_READINTO_METHODDEF \ {"readinto", (PyCFunction)_io_BytesIO_readinto, METH_O, _io_BytesIO_readinto__doc__}, @@ -419,4 +419,4 @@ exit: return return_value; } -/*[clinic end generated code: output=500ccc149587fac4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=164cf0e4117dadbe input=a9049054013a1b77]*/ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 05:49:25 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 09:49:25 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_typos_in_c?= =?utf-8?q?ode_comment_and_documentation?= Message-ID: <20160416094925.26099.21316.4E19B0D7@psf.io> https://hg.python.org/cpython/rev/5bbe514d0291 changeset: 101009:5bbe514d0291 branch: 2.7 parent: 101006:3e0321584f23 user: Martin Panter date: Sat Apr 16 09:28:57 2016 +0000 summary: Fix typos in code comment and documentation files: Doc/library/argparse.rst | 2 +- Doc/whatsnew/2.4.rst | 2 +- Lib/posixpath.py | 2 +- Modules/_io/bytesio.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -878,7 +878,7 @@ See the nargs_ description for examples. With the ``'store_const'`` and ``'append_const'`` actions, the ``const`` -keyword argument must be given. For other actions, is defaults to ``None``. +keyword argument must be given. For other actions, it defaults to ``None``. default diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -1481,7 +1481,7 @@ * Python can now be built with additional profiling for the interpreter itself, intended as an aid to people developing the Python core. Providing - :option:`----enable-profiling` to the :program:`configure` script will let you + :option:`--enable-profiling` to the :program:`configure` script will let you profile the interpreter with :program:`gprof`, and providing the :option:`--with-tsc` switch enables profiling using the Pentium's Time-Stamp- Counter register. Note that the :option:`--with-tsc` switch is slightly diff --git a/Lib/posixpath.py b/Lib/posixpath.py --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -375,7 +375,7 @@ path, ok = _joinrealpath('', filename, {}) return abspath(path) -# Join two paths, normalizing ang eliminating any symbolic links +# Join two paths, normalizing and eliminating any symbolic links # encountered in the second path. def _joinrealpath(path, rest, seen): if isabs(rest): diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -395,7 +395,7 @@ "readinto(bytearray) -> int. Read up to len(b) bytes into b.\n" "\n" "Returns number of bytes read (0 for EOF), or None if the object\n" -"is set not to block as has no data to read."); +"is set not to block and has no data to read."); static PyObject * bytesio_readinto(bytesio *self, PyObject *args) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 05:49:26 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 09:49:26 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_typo_fixes_from_3=2E5?= Message-ID: <20160416094925.88672.12939.5E210241@psf.io> https://hg.python.org/cpython/rev/ddc4d837a0b7 changeset: 101008:ddc4d837a0b7 parent: 101005:68b84643dffd parent: 101007:7e74001ec567 user: Martin Panter date: Sat Apr 16 09:29:17 2016 +0000 summary: Merge typo fixes from 3.5 files: Doc/library/argparse.rst | 2 +- Doc/whatsnew/2.4.rst | 2 +- Lib/posixpath.py | 2 +- Lib/test/test_codecs.py | 4 ++-- Modules/_io/bytesio.c | 4 ++-- Modules/_io/clinic/bytesio.c.h | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -923,7 +923,7 @@ See the nargs_ description for examples. With the ``'store_const'`` and ``'append_const'`` actions, the ``const`` -keyword argument must be given. For other actions, is defaults to ``None``. +keyword argument must be given. For other actions, it defaults to ``None``. default diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -1481,7 +1481,7 @@ * Python can now be built with additional profiling for the interpreter itself, intended as an aid to people developing the Python core. Providing - :option:`----enable-profiling` to the :program:`configure` script will let you + :option:`--enable-profiling` to the :program:`configure` script will let you profile the interpreter with :program:`gprof`, and providing the :option:`--with-tsc` switch enables profiling using the Pentium's Time-Stamp- Counter register. Note that the :option:`--with-tsc` switch is slightly diff --git a/Lib/posixpath.py b/Lib/posixpath.py --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -372,7 +372,7 @@ path, ok = _joinrealpath(filename[:0], filename, {}) return abspath(path) -# Join two paths, normalizing ang eliminating any symbolic links +# Join two paths, normalizing and eliminating any symbolic links # encountered in the second path. def _joinrealpath(path, rest, seen): if isinstance(path, bytes): diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -2401,7 +2401,7 @@ self.assertRaises(TypeError, decoder, "xxx") def test_unicode_escape(self): - # Escape-decoding a unicode string is supported ang gives the same + # Escape-decoding a unicode string is supported and gives the same # result as decoding the equivalent ASCII bytes string. self.assertEqual(codecs.unicode_escape_decode(r"\u1234"), ("\u1234", 6)) self.assertEqual(codecs.unicode_escape_decode(br"\u1234"), ("\u1234", 6)) @@ -2809,7 +2809,7 @@ # type and a single str argument. # Use a local codec registry to avoid appearing to leak objects when -# registering multiple seach functions +# registering multiple search functions _TEST_CODECS = {} def _get_test_codec(codec_name): diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -549,12 +549,12 @@ Read up to len(buffer) bytes into buffer. Returns number of bytes read (0 for EOF), or None if the object -is set not to block as has no data to read. +is set not to block and has no data to read. [clinic start generated code]*/ static PyObject * _io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer) -/*[clinic end generated code: output=a5d407217dcf0639 input=71581f32635c3a31]*/ +/*[clinic end generated code: output=a5d407217dcf0639 input=b52a8782706f0037]*/ { Py_ssize_t len, n; diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h --- a/Modules/_io/clinic/bytesio.c.h +++ b/Modules/_io/clinic/bytesio.c.h @@ -262,7 +262,7 @@ "Read up to len(buffer) bytes into buffer.\n" "\n" "Returns number of bytes read (0 for EOF), or None if the object\n" -"is set not to block as has no data to read."); +"is set not to block and has no data to read."); #define _IO_BYTESIO_READINTO_METHODDEF \ {"readinto", (PyCFunction)_io_BytesIO_readinto, METH_O, _io_BytesIO_readinto__doc__}, @@ -419,4 +419,4 @@ exit: return return_value; } -/*[clinic end generated code: output=500ccc149587fac4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=164cf0e4117dadbe input=a9049054013a1b77]*/ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 08:12:39 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 12:12:39 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzEwODM4?= =?utf-8?b?OiBSdW4gdGVzdF9fYWxsX18oKSBldmVyeXdoZXJlLCBldmVuIGlmIHBvbGwo?= =?utf-8?q?=29_is_not_available?= Message-ID: <20160416121239.19519.26728.E24ABEB3@psf.io> https://hg.python.org/cpython/rev/cb38866e4c13 changeset: 101010:cb38866e4c13 branch: 3.5 parent: 101007:7e74001ec567 user: Martin Panter date: Sat Apr 16 11:28:10 2016 +0000 summary: Issue #10838: Run test__all__() everywhere, even if poll() is not available files: Lib/test/test_subprocess.py | 29 ++++++++++++------------ 1 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -2518,7 +2518,7 @@ def test_terminate_dead(self): self._kill_dead_process('terminate') -class CommandTests(unittest.TestCase): +class MiscTests(unittest.TestCase): def test_getoutput(self): self.assertEqual(subprocess.getoutput('echo xyzzy'), 'xyzzy') self.assertEqual(subprocess.getstatusoutput('echo xyzzy'), @@ -2538,19 +2538,6 @@ if dir is not None: os.rmdir(dir) - - at unittest.skipUnless(hasattr(selectors, 'PollSelector'), - "Test needs selectors.PollSelector") -class ProcessTestCaseNoPoll(ProcessTestCase): - def setUp(self): - self.orig_selector = subprocess._PopenSelector - subprocess._PopenSelector = selectors.SelectSelector - ProcessTestCase.setUp(self) - - def tearDown(self): - subprocess._PopenSelector = self.orig_selector - ProcessTestCase.tearDown(self) - def test__all__(self): """Ensure that __all__ is populated properly.""" intentionally_excluded = set(("list2cmdline",)) @@ -2566,6 +2553,18 @@ self.assertEqual(exported, possible_exports - intentionally_excluded) + at unittest.skipUnless(hasattr(selectors, 'PollSelector'), + "Test needs selectors.PollSelector") +class ProcessTestCaseNoPoll(ProcessTestCase): + def setUp(self): + self.orig_selector = subprocess._PopenSelector + subprocess._PopenSelector = selectors.SelectSelector + ProcessTestCase.setUp(self) + + def tearDown(self): + subprocess._PopenSelector = self.orig_selector + ProcessTestCase.tearDown(self) + @unittest.skipUnless(mswindows, "Windows-specific tests") class CommandsWithSpaces (BaseTestCase): @@ -2669,7 +2668,7 @@ unit_tests = (ProcessTestCase, POSIXProcessTestCase, Win32ProcessTestCase, - CommandTests, + MiscTests, ProcessTestCaseNoPoll, CommandsWithSpaces, ContextManagerTests, -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 08:12:39 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 12:12:39 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_subprocess_test_from_3=2E5?= Message-ID: <20160416121239.8354.45708.39040797@psf.io> https://hg.python.org/cpython/rev/ebb1a16de89b changeset: 101011:ebb1a16de89b parent: 101008:ddc4d837a0b7 parent: 101010:cb38866e4c13 user: Martin Panter date: Sat Apr 16 11:51:31 2016 +0000 summary: Merge subprocess test from 3.5 files: Lib/test/test_subprocess.py | 29 ++++++++++++------------ 1 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -2518,7 +2518,7 @@ def test_terminate_dead(self): self._kill_dead_process('terminate') -class CommandTests(unittest.TestCase): +class MiscTests(unittest.TestCase): def test_getoutput(self): self.assertEqual(subprocess.getoutput('echo xyzzy'), 'xyzzy') self.assertEqual(subprocess.getstatusoutput('echo xyzzy'), @@ -2538,19 +2538,6 @@ if dir is not None: os.rmdir(dir) - - at unittest.skipUnless(hasattr(selectors, 'PollSelector'), - "Test needs selectors.PollSelector") -class ProcessTestCaseNoPoll(ProcessTestCase): - def setUp(self): - self.orig_selector = subprocess._PopenSelector - subprocess._PopenSelector = selectors.SelectSelector - ProcessTestCase.setUp(self) - - def tearDown(self): - subprocess._PopenSelector = self.orig_selector - ProcessTestCase.tearDown(self) - def test__all__(self): """Ensure that __all__ is populated properly.""" intentionally_excluded = set(("list2cmdline",)) @@ -2566,6 +2553,18 @@ self.assertEqual(exported, possible_exports - intentionally_excluded) + at unittest.skipUnless(hasattr(selectors, 'PollSelector'), + "Test needs selectors.PollSelector") +class ProcessTestCaseNoPoll(ProcessTestCase): + def setUp(self): + self.orig_selector = subprocess._PopenSelector + subprocess._PopenSelector = selectors.SelectSelector + ProcessTestCase.setUp(self) + + def tearDown(self): + subprocess._PopenSelector = self.orig_selector + ProcessTestCase.tearDown(self) + @unittest.skipUnless(mswindows, "Windows-specific tests") class CommandsWithSpaces (BaseTestCase): @@ -2669,7 +2668,7 @@ unit_tests = (ProcessTestCase, POSIXProcessTestCase, Win32ProcessTestCase, - CommandTests, + MiscTests, ProcessTestCaseNoPoll, CommandsWithSpaces, ContextManagerTests, -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 10:15:58 2016 From: python-checkins at python.org (senthil.kumaran) Date: Sat, 16 Apr 2016 14:15:58 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Improve_the_co?= =?utf-8?q?verage_of_urlparse_module=2E_Backport_to_2=2E7_branch=2E?= Message-ID: <20160416141543.107508.27603.B40696B6@psf.io> https://hg.python.org/cpython/rev/e3ed950ad728 changeset: 101012:e3ed950ad728 branch: 2.7 parent: 101009:5bbe514d0291 user: Senthil Kumaran date: Sat Apr 16 07:15:38 2016 -0700 summary: Improve the coverage of urlparse module. Backport to 2.7 branch. files: Lib/test/test_urlparse.py | 52 +++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -22,6 +22,49 @@ ("&a=b", [('a', 'b')]), ("a=a+b&b=b+c", [('a', 'a b'), ('b', 'b c')]), ("a=1&a=2", [('a', '1'), ('a', '2')]), + (";", []), + (";;", []), + (";a=b", [('a', 'b')]), + ("a=a+b;b=b+c", [('a', 'a b'), ('b', 'b c')]), + ("a=1;a=2", [('a', '1'), ('a', '2')]), + (b";", []), + (b";;", []), + (b";a=b", [(b'a', b'b')]), + (b"a=a+b;b=b+c", [(b'a', b'a b'), (b'b', b'b c')]), + (b"a=1;a=2", [(b'a', b'1'), (b'a', b'2')]), +] + +parse_qs_test_cases = [ + ("", {}), + ("&", {}), + ("&&", {}), + ("=", {'': ['']}), + ("=a", {'': ['a']}), + ("a", {'a': ['']}), + ("a=", {'a': ['']}), + ("&a=b", {'a': ['b']}), + ("a=a+b&b=b+c", {'a': ['a b'], 'b': ['b c']}), + ("a=1&a=2", {'a': ['1', '2']}), + (b"", {}), + (b"&", {}), + (b"&&", {}), + (b"=", {b'': [b'']}), + (b"=a", {b'': [b'a']}), + (b"a", {b'a': [b'']}), + (b"a=", {b'a': [b'']}), + (b"&a=b", {b'a': [b'b']}), + (b"a=a+b&b=b+c", {b'a': [b'a b'], b'b': [b'b c']}), + (b"a=1&a=2", {b'a': [b'1', b'2']}), + (";", {}), + (";;", {}), + (";a=b", {'a': ['b']}), + ("a=a+b;b=b+c", {'a': ['a b'], 'b': ['b c']}), + ("a=1;a=2", {'a': ['1', '2']}), + (b";", {}), + (b";;", {}), + (b";a=b", {b'a': [b'b']}), + (b"a=a+b;b=b+c", {b'a': [b'a b'], b'b': [b'b c']}), + (b"a=1;a=2", {b'a': [b'1', b'2']}), ] class UrlParseTestCase(unittest.TestCase): @@ -86,6 +129,15 @@ self.assertEqual(result, expect_without_blanks, "Error parsing %r" % orig) + def test_qs(self): + for orig, expect in parse_qs_test_cases: + result = urlparse.parse_qs(orig, keep_blank_values=True) + self.assertEqual(result, expect, "Error parsing %r" % orig) + expect_without_blanks = dict( + [(v, expect[v]) for v in expect if len(expect[v][0])]) + result = urlparse.parse_qs(orig, keep_blank_values=False) + self.assertEqual(result, expect_without_blanks, + "Error parsing %r" % orig) def test_roundtrips(self): testcases = [ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 10:34:31 2016 From: python-checkins at python.org (senthil.kumaran) Date: Sat, 16 Apr 2016 14:34:31 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy41?= Message-ID: <20160416143430.15368.94514.94CA994F@psf.io> https://hg.python.org/cpython/rev/401dca6ac084 changeset: 101014:401dca6ac084 parent: 101011:ebb1a16de89b parent: 101013:8f02747ff908 user: Senthil Kumaran date: Sat Apr 16 07:34:24 2016 -0700 summary: merge 3.5 issue26775 - Improve test coverage for urllib.parse Patch contributed by Luiz Poleto. files: Lib/test/test_urlparse.py | 55 ++++++++++++++++++++++++++- 1 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -17,7 +17,6 @@ ("=a", [('', 'a')]), ("a", [('a', '')]), ("a=", [('a', '')]), - ("a=", [('a', '')]), ("&a=b", [('a', 'b')]), ("a=a+b&b=b+c", [('a', 'a b'), ('b', 'b c')]), ("a=1&a=2", [('a', '1'), ('a', '2')]), @@ -28,10 +27,52 @@ (b"=a", [(b'', b'a')]), (b"a", [(b'a', b'')]), (b"a=", [(b'a', b'')]), - (b"a=", [(b'a', b'')]), (b"&a=b", [(b'a', b'b')]), (b"a=a+b&b=b+c", [(b'a', b'a b'), (b'b', b'b c')]), (b"a=1&a=2", [(b'a', b'1'), (b'a', b'2')]), + (";", []), + (";;", []), + (";a=b", [('a', 'b')]), + ("a=a+b;b=b+c", [('a', 'a b'), ('b', 'b c')]), + ("a=1;a=2", [('a', '1'), ('a', '2')]), + (b";", []), + (b";;", []), + (b";a=b", [(b'a', b'b')]), + (b"a=a+b;b=b+c", [(b'a', b'a b'), (b'b', b'b c')]), + (b"a=1;a=2", [(b'a', b'1'), (b'a', b'2')]), +] + +parse_qs_test_cases = [ + ("", {}), + ("&", {}), + ("&&", {}), + ("=", {'': ['']}), + ("=a", {'': ['a']}), + ("a", {'a': ['']}), + ("a=", {'a': ['']}), + ("&a=b", {'a': ['b']}), + ("a=a+b&b=b+c", {'a': ['a b'], 'b': ['b c']}), + ("a=1&a=2", {'a': ['1', '2']}), + (b"", {}), + (b"&", {}), + (b"&&", {}), + (b"=", {b'': [b'']}), + (b"=a", {b'': [b'a']}), + (b"a", {b'a': [b'']}), + (b"a=", {b'a': [b'']}), + (b"&a=b", {b'a': [b'b']}), + (b"a=a+b&b=b+c", {b'a': [b'a b'], b'b': [b'b c']}), + (b"a=1&a=2", {b'a': [b'1', b'2']}), + (";", {}), + (";;", {}), + (";a=b", {'a': ['b']}), + ("a=a+b;b=b+c", {'a': ['a b'], 'b': ['b c']}), + ("a=1;a=2", {'a': ['1', '2']}), + (b";", {}), + (b";;", {}), + (b";a=b", {b'a': [b'b']}), + (b"a=a+b;b=b+c", {b'a': [b'a b'], b'b': [b'b c']}), + (b"a=1;a=2", {b'a': [b'1', b'2']}), ] class UrlParseTestCase(unittest.TestCase): @@ -96,6 +137,16 @@ self.assertEqual(result, expect_without_blanks, "Error parsing %r" % orig) + def test_qs(self): + for orig, expect in parse_qs_test_cases: + result = urllib.parse.parse_qs(orig, keep_blank_values=True) + self.assertEqual(result, expect, "Error parsing %r" % orig) + expect_without_blanks = {v: expect[v] + for v in expect if len(expect[v][0])} + result = urllib.parse.parse_qs(orig, keep_blank_values=False) + self.assertEqual(result, expect_without_blanks, + "Error parsing %r" % orig) + def test_roundtrips(self): str_cases = [ ('file:///tmp/junk.txt', -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 10:34:31 2016 From: python-checkins at python.org (senthil.kumaran) Date: Sat, 16 Apr 2016 14:34:31 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_issue26775_-_I?= =?utf-8?q?mprove_test_coverage_for_urllib=2Eparse?= Message-ID: <20160416143430.88646.55892.18E560C6@psf.io> https://hg.python.org/cpython/rev/8f02747ff908 changeset: 101013:8f02747ff908 branch: 3.5 parent: 101010:cb38866e4c13 user: Senthil Kumaran date: Sat Apr 16 07:33:15 2016 -0700 summary: issue26775 - Improve test coverage for urllib.parse Patch contributed by Luiz Poleto. files: Lib/test/test_urlparse.py | 55 ++++++++++++++++++++++++++- 1 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -17,7 +17,6 @@ ("=a", [('', 'a')]), ("a", [('a', '')]), ("a=", [('a', '')]), - ("a=", [('a', '')]), ("&a=b", [('a', 'b')]), ("a=a+b&b=b+c", [('a', 'a b'), ('b', 'b c')]), ("a=1&a=2", [('a', '1'), ('a', '2')]), @@ -28,10 +27,52 @@ (b"=a", [(b'', b'a')]), (b"a", [(b'a', b'')]), (b"a=", [(b'a', b'')]), - (b"a=", [(b'a', b'')]), (b"&a=b", [(b'a', b'b')]), (b"a=a+b&b=b+c", [(b'a', b'a b'), (b'b', b'b c')]), (b"a=1&a=2", [(b'a', b'1'), (b'a', b'2')]), + (";", []), + (";;", []), + (";a=b", [('a', 'b')]), + ("a=a+b;b=b+c", [('a', 'a b'), ('b', 'b c')]), + ("a=1;a=2", [('a', '1'), ('a', '2')]), + (b";", []), + (b";;", []), + (b";a=b", [(b'a', b'b')]), + (b"a=a+b;b=b+c", [(b'a', b'a b'), (b'b', b'b c')]), + (b"a=1;a=2", [(b'a', b'1'), (b'a', b'2')]), +] + +parse_qs_test_cases = [ + ("", {}), + ("&", {}), + ("&&", {}), + ("=", {'': ['']}), + ("=a", {'': ['a']}), + ("a", {'a': ['']}), + ("a=", {'a': ['']}), + ("&a=b", {'a': ['b']}), + ("a=a+b&b=b+c", {'a': ['a b'], 'b': ['b c']}), + ("a=1&a=2", {'a': ['1', '2']}), + (b"", {}), + (b"&", {}), + (b"&&", {}), + (b"=", {b'': [b'']}), + (b"=a", {b'': [b'a']}), + (b"a", {b'a': [b'']}), + (b"a=", {b'a': [b'']}), + (b"&a=b", {b'a': [b'b']}), + (b"a=a+b&b=b+c", {b'a': [b'a b'], b'b': [b'b c']}), + (b"a=1&a=2", {b'a': [b'1', b'2']}), + (";", {}), + (";;", {}), + (";a=b", {'a': ['b']}), + ("a=a+b;b=b+c", {'a': ['a b'], 'b': ['b c']}), + ("a=1;a=2", {'a': ['1', '2']}), + (b";", {}), + (b";;", {}), + (b";a=b", {b'a': [b'b']}), + (b"a=a+b;b=b+c", {b'a': [b'a b'], b'b': [b'b c']}), + (b"a=1;a=2", {b'a': [b'1', b'2']}), ] class UrlParseTestCase(unittest.TestCase): @@ -96,6 +137,16 @@ self.assertEqual(result, expect_without_blanks, "Error parsing %r" % orig) + def test_qs(self): + for orig, expect in parse_qs_test_cases: + result = urllib.parse.parse_qs(orig, keep_blank_values=True) + self.assertEqual(result, expect, "Error parsing %r" % orig) + expect_without_blanks = {v: expect[v] + for v in expect if len(expect[v][0])} + result = urllib.parse.parse_qs(orig, keep_blank_values=False) + self.assertEqual(result, expect_without_blanks, + "Error parsing %r" % orig) + def test_roundtrips(self): str_cases = [ ('file:///tmp/junk.txt', -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 10:51:39 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 16 Apr 2016 14:51:39 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogSXNzdWUgIzI2NzgzOiB0ZXN0X29zLldhbGtUZXN0cy50ZXN0X3dhbGtf?= =?utf-8?q?topdown_did=27t_test_fwalk_and_bytes=2E?= Message-ID: <20160416145139.415.30330.36066BF6@psf.io> https://hg.python.org/cpython/rev/be96434b8777 changeset: 101016:be96434b8777 parent: 101014:401dca6ac084 parent: 101015:e44a2dc62c11 user: Serhiy Storchaka date: Sat Apr 16 17:51:17 2016 +0300 summary: Issue #26783: test_os.WalkTests.test_walk_topdown did't test fwalk and bytes. Patch by Aviv Palivoda. files: Lib/test/test_os.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -857,7 +857,7 @@ def test_walk_topdown(self): # Walk top-down. - all = list(os.walk(self.walk_path)) + all = list(self.walk(self.walk_path)) self.assertEqual(len(all), 4) # We can't know which order SUB1 and SUB2 will appear in. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 10:51:40 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 16 Apr 2016 14:51:40 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2Nzgz?= =?utf-8?q?=3A_test=5Fos=2EWalkTests=2Etest=5Fwalk=5Ftopdown_did=27t_test_?= =?utf-8?q?fwalk_and_bytes=2E?= Message-ID: <20160416145139.107516.90751.A8DA1DBD@psf.io> https://hg.python.org/cpython/rev/e44a2dc62c11 changeset: 101015:e44a2dc62c11 branch: 3.5 parent: 101013:8f02747ff908 user: Serhiy Storchaka date: Sat Apr 16 17:51:00 2016 +0300 summary: Issue #26783: test_os.WalkTests.test_walk_topdown did't test fwalk and bytes. Patch by Aviv Palivoda. files: Lib/test/test_os.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -843,7 +843,7 @@ def test_walk_topdown(self): # Walk top-down. - all = list(os.walk(self.walk_path)) + all = list(self.walk(self.walk_path)) self.assertEqual(len(all), 4) # We can't know which order SUB1 and SUB2 will appear in. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 11:44:07 2016 From: python-checkins at python.org (steven.daprano) Date: Sat, 16 Apr 2016 15:44:07 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Documentation_for_secrets?= =?utf-8?b?LnB5?= Message-ID: <20160416154407.8348.61352.D21EE8A4@psf.io> https://hg.python.org/cpython/rev/3bb3e6316098 changeset: 101017:3bb3e6316098 user: Steven D'Aprano date: Sun Apr 17 01:42:33 2016 +1000 summary: Documentation for secrets.py files: Doc/library/crypto.rst | 1 + Doc/library/random.rst | 3 +- Doc/library/secrets.rst | 199 ++++++++++++++++++++++++++++ 3 files changed, 202 insertions(+), 1 deletions(-) diff --git a/Doc/library/crypto.rst b/Doc/library/crypto.rst --- a/Doc/library/crypto.rst +++ b/Doc/library/crypto.rst @@ -16,3 +16,4 @@ hashlib.rst hmac.rst + secrets.rst diff --git a/Doc/library/random.rst b/Doc/library/random.rst --- a/Doc/library/random.rst +++ b/Doc/library/random.rst @@ -46,7 +46,8 @@ .. warning:: The pseudo-random generators of this module should not be used for - security purposes. + security purposes. For security or cryptographic uses, see the + :mod:`secrets` module. Bookkeeping functions: diff --git a/Doc/library/secrets.rst b/Doc/library/secrets.rst new file mode 100644 --- /dev/null +++ b/Doc/library/secrets.rst @@ -0,0 +1,199 @@ +:mod:`secrets` --- Generate secure random numbers for managing secrets +====================================================================== + +.. module:: secrets + :synopsis: Generate secure random numbers for managing secrets. + +.. moduleauthor:: Steven D'Aprano +.. sectionauthor:: Steven D'Aprano +.. versionadded:: 3.6 + +.. testsetup:: + + from secrets import * + __name__ = '' + +**Source code:** :source:`Lib/secrets.py` + +------------- + +The :mod:`secrets` module is used for generating cryptographically strong +random numbers suitable for managing data such as passwords, account +authentication, security tokens, and related secrets. + +In particularly, :mod:`secrets` should be used in preference to the +default pseudo-random number generator in the :mod:`random` module, which +is designed for modelling and simulation, not security or cryptography. + +.. seealso:: + + :pep:`506` + + +Random numbers +-------------- + +The :mod:`secrets` module provides access to the most secure source of +randomness that your operating system provides. + +.. class:: SystemRandom + + A class for generating random numbers using the highest-quality + sources provided by the operating system. See + :class:`random.SystemRandom` for additional details. + +.. function:: choice(sequence) + + Return a randomly-chosen element from a non-empty sequence. + +.. function:: randbelow(n) + + Return a random int in the range [0, *n*). + +.. function:: randbits(k) + + Return an int with *k* random bits. + + +Generating tokens +----------------- + +The :mod:`secrets` module provides functions for generating secure +tokens, suitable for applications such as password resets, +hard-to-guess URLs, and similar. + +.. function:: token_bytes([nbytes=None]) + + Return a random byte string containing *nbytes* number of bytes. + If *nbytes* is ``None`` or not supplied, a reasonable default is + used. + + .. doctest:: + + >>> token_bytes(16) #doctest:+SKIP + b'\xebr\x17D*t\xae\xd4\xe3S\xb6\xe2\xebP1\x8b' + + +.. function:: token_hex([nbytes=None]) + + Return a random text string, in hexadecimal. The string has *nbytes* + random bytes, each byte converted to two hex digits. If *nbytes* is + ``None`` or not supplied, a reasonable default is used. + + .. doctest:: + + >>> token_hex(16) #doctest:+SKIP + 'f9bf78b9a18ce6d46a0cd2b0b86df9da' + +.. function:: token_urlsafe([nbytes=None]) + + Return a random URL-safe text string, containing *nbytes* random + bytes. The text is Base64 encoded, so on average, each byte results + in approximately 1.3 characters. If *nbytes* is ``None`` or not + supplied, a reasonable default is used. + + .. doctest:: + + >>> token_urlsafe(16) #doctest:+SKIP + 'Drmhze6EPcv0fN_81Bj-nA' + + +How many bytes should tokens use? +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +To be secure against +`brute-force attacks `_, +tokens need to have sufficient randomness. Unfortunately, what is +considered sufficient will necessarily increase as computers get more +powerful and able to make more guesses in a shorter period. As of 2015, +it is believed that 64 bytes (512 bits) of randomness is sufficient for +the typical use-case expected for the :mod:`secrets` module. + +For those who want to manage their own token length, you can explicitly +specify how much randomness is used for tokens by giving an :class:`int` +argument to the various ``token_*`` functions. That argument is taken +as the number of bytes of randomness to use. + +Otherwise, if no argument is provided, or if the argument is ``None``, +the ``token_*`` functions will use a reasonable default instead. + +.. note:: + + That default is subject to change at any time, including during + maintenance releases. + + +Other functions +--------------- + +.. function:: compare_digest(a, b) + + Return ``True`` if strings *a* and *b* are equal, otherwise ``False``, + in such a way as to redice the risk of + `timing attacks `_ . + See :func:`hmac.compare_digest` for additional details. + + +Recipes and best practices +-------------------------- + +This section shows recipes and best practices for using :mod:`secrets` +to manage a basic level of security. + +Generate an eight-character alphanumeric password: + +.. testcode:: + + import string + alphabet = string.ascii_letters + string.digits + password = ''.join(choice(alphabet) for i in range(8)) + + +.. note:: + + Applications should + `not store passwords in a recoverable format `_ , + whether plain text or encrypted. They should always be salted and + hashed using a cryptographically-strong one-way (irreversible) hash + function. + + +Generate a ten-character alphanumeric password with at least one +lowercase character, at least one uppercase character, and at least +three digits: + +.. testcode:: + + import string + alphabet = string.ascii_letters + string.digits + while True: + password = ''.join(choice(alphabet) for i in range(10)) + if (any(c.islower() for c in password) + and any(c.isupper() for c in password) + and sum(c.isdigit() for c in password) >= 3): + break + + +Generate an `XKCD-style passphrase `_ : + +.. testcode:: + + # On standard Linux systems, use a convenient dictionary file. + # Other platforms may need to provide their own word-list. + with open('/usr/share/dict/words') as f: + words = [word.strip() for word in f] + password = ' '.join(choice(words) for i in range(4)) + + +Generate a hard-to-guess temporary URL containing a security token +suitable for password recovery applications: + +.. testcode:: + + url = 'https://mydomain.com/reset=' + token_urlsafe() + + + +.. + # This modeline must appear within the last ten lines of the file. + kate: indent-width 3; remove-trailing-space on; replace-tabs on; encoding utf-8; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 15:14:53 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 16 Apr 2016 19:14:53 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzIzMDI5?= =?utf-8?q?=3A_Fix_catch=5Fwarnings=28=29_in_test=5Ffilename=5Fnone?= Message-ID: <20160416191452.89025.86812.AABC5F97@psf.io> https://hg.python.org/cpython/rev/009e36e6d16d changeset: 101018:009e36e6d16d branch: 2.7 parent: 101012:e3ed950ad728 user: Berker Peksag date: Sat Apr 16 22:16:05 2016 +0300 summary: Issue #23029: Fix catch_warnings() in test_filename_none It was printed UserWarning output because catch_warnings() was missing record=True. files: Lib/test/test_warnings.py | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -553,10 +553,13 @@ globals_dict = globals() oldfile = globals_dict['__file__'] try: - with original_warnings.catch_warnings(module=self.module) as w: + with original_warnings.catch_warnings(module=self.module, record=True) as w: self.module.filterwarnings("always", category=UserWarning) globals_dict['__file__'] = None self.module.warn('test', UserWarning) + self.assertEqual(len(w), 1) + self.assertEqual(w[0].category, UserWarning) + self.assertEqual(str(w[0].message), 'test') finally: globals_dict['__file__'] = oldfile -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 16:14:26 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 16 Apr 2016 20:14:26 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI0MTcz?= =?utf-8?q?=3A_Fix_curses=2Ewrapper_link_in_curses_HOWTO?= Message-ID: <20160416201426.89225.45940.E80CBB72@psf.io> https://hg.python.org/cpython/rev/5c9cda2bdfd2 changeset: 101019:5c9cda2bdfd2 branch: 2.7 user: Berker Peksag date: Sat Apr 16 23:15:39 2016 +0300 summary: Issue #24173: Fix curses.wrapper link in curses HOWTO files: Doc/howto/curses.rst | 13 ++++++------- 1 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Doc/howto/curses.rst b/Doc/howto/curses.rst --- a/Doc/howto/curses.rst +++ b/Doc/howto/curses.rst @@ -122,13 +122,12 @@ you type them, for example, which makes using the shell difficult. In Python you can avoid these complications and make debugging much easier by -importing the module :mod:`curses.wrapper`. It supplies a :func:`wrapper` -function that takes a callable. It does the initializations described above, -and also initializes colors if color support is present. It then runs your -provided callable and finally deinitializes appropriately. The callable is -called inside a try-catch clause which catches exceptions, performs curses -deinitialization, and then passes the exception upwards. Thus, your terminal -won't be left in a funny state on exception. +importing the :func:`curses.wrapper` function. It takes a callable and does +the initializations described above, also initializing colors if color support +is present. It then runs your provided callable and finally deinitializes +appropriately. The callable is called inside a try-catch clause which catches +exceptions, performs curses deinitialization, and then passes the exception +upwards. Thus, your terminal won't be left in a funny state on exception. Windows and Pads -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 17:54:37 2016 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 16 Apr 2016 21:54:37 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_add_gc_support?= =?utf-8?q?_to_slice_=28closes_=2326659=29?= Message-ID: <20160416215437.19505.45403.DBC41387@psf.io> https://hg.python.org/cpython/rev/9e2176d18965 changeset: 101021:9e2176d18965 branch: 3.5 parent: 101015:e44a2dc62c11 user: Benjamin Peterson date: Sat Apr 16 14:47:12 2016 -0700 summary: add gc support to slice (closes #26659) files: Lib/test/test_slice.py | 17 ++++++++++++++--- Misc/NEWS | 2 ++ Objects/sliceobject.c | 19 +++++++++++++++---- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_slice.py b/Lib/test/test_slice.py --- a/Lib/test/test_slice.py +++ b/Lib/test/test_slice.py @@ -1,11 +1,13 @@ # tests for slice objects; in particular the indices method. -import unittest -from pickle import loads, dumps - import itertools import operator import sys +import unittest +import weakref + +from pickle import loads, dumps +from test import support def evaluate_slice_index(arg): @@ -240,5 +242,14 @@ self.assertEqual(s.indices(15), t.indices(15)) self.assertNotEqual(id(s), id(t)) + def test_cycle(self): + class myobj(): pass + o = myobj() + o.s = slice(o) + w = weakref.ref(o) + o = None + test_support.gc_collect() + self.assertIsNone(w()) + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #26659: Make the builtin slice type support cycle collection. + - Issue #26718: super.__init__ no longer leaks memory if called multiple times. NOTE: A direct call of super.__init__ is not endorsed! diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -119,7 +119,7 @@ slice_cache = NULL; _Py_NewReference((PyObject *)obj); } else { - obj = PyObject_New(PySliceObject, &PySlice_Type); + obj = PyObject_GC_New(PySliceObject, &PySlice_Type); if (obj == NULL) return NULL; } @@ -135,6 +135,7 @@ obj->start = start; obj->stop = stop; + _PyObject_GC_TRACK(obj); return (PyObject *) obj; } @@ -288,13 +289,14 @@ static void slice_dealloc(PySliceObject *r) { + _PyObject_GC_UNTRACK(r); Py_DECREF(r->step); Py_DECREF(r->start); Py_DECREF(r->stop); if (slice_cache == NULL) slice_cache = r; else - PyObject_Del(r); + PyObject_GC_Del(r); } static PyObject * @@ -586,6 +588,15 @@ return res; } +static int +slice_traverse(PySliceObject *v, visitproc visit, void *arg) +{ + Py_VISIT(v->start); + Py_VISIT(v->stop); + Py_VISIT(v->step); + return 0; +} + PyTypeObject PySlice_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "slice", /* Name of this type */ @@ -606,9 +617,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ slice_doc, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)slice_traverse, /* tp_traverse */ 0, /* tp_clear */ slice_richcompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 17:54:37 2016 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 16 Apr 2016 21:54:37 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_add_gc_support?= =?utf-8?q?_to_slice_=28closes_=2326659=29?= Message-ID: <20160416215437.411.85118.8AE64F80@psf.io> https://hg.python.org/cpython/rev/879da9400529 changeset: 101020:879da9400529 branch: 2.7 user: Benjamin Peterson date: Sat Apr 16 14:47:12 2016 -0700 summary: add gc support to slice (closes #26659) files: Lib/test/test_slice.py | 13 ++++++++++++- Misc/NEWS | 2 ++ Objects/sliceobject.c | 19 +++++++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_slice.py b/Lib/test/test_slice.py --- a/Lib/test/test_slice.py +++ b/Lib/test/test_slice.py @@ -1,8 +1,10 @@ # tests for slice objects; in particular the indices method. import unittest +import weakref + +from cPickle import loads, dumps from test import test_support -from cPickle import loads, dumps import sys @@ -128,6 +130,15 @@ self.assertEqual(s.indices(15), t.indices(15)) self.assertNotEqual(id(s), id(t)) + def test_cycle(self): + class myobj(): pass + o = myobj() + o.s = slice(o) + w = weakref.ref(o) + o = None + test_support.gc_collect() + self.assertIsNone(w()) + def test_main(): test_support.run_unittest(SliceTest) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #26659: Make the builtin slice type support cycle collection. + - Issue #26718: super.__init__ no longer leaks memory if called multiple times. NOTE: A direct call of super.__init__ is not endorsed! diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -60,7 +60,7 @@ PyObject * PySlice_New(PyObject *start, PyObject *stop, PyObject *step) { - PySliceObject *obj = PyObject_New(PySliceObject, &PySlice_Type); + PySliceObject *obj = PyObject_GC_New(PySliceObject, &PySlice_Type); if (obj == NULL) return NULL; @@ -76,6 +76,7 @@ obj->start = start; obj->stop = stop; + _PyObject_GC_TRACK(obj); return (PyObject *) obj; } @@ -219,10 +220,11 @@ static void slice_dealloc(PySliceObject *r) { + _PyObject_GC_UNTRACK(r); Py_DECREF(r->step); Py_DECREF(r->start); Py_DECREF(r->stop); - PyObject_Del(r); + PyObject_GC_Del(r); } static PyObject * @@ -320,6 +322,15 @@ return -1L; } +static int +slice_traverse(PySliceObject *v, visitproc visit, void *arg) +{ + Py_VISIT(v->start); + Py_VISIT(v->stop); + Py_VISIT(v->step); + return 0; +} + PyTypeObject PySlice_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "slice", /* Name of this type */ @@ -340,9 +351,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ slice_doc, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)slice_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 17:54:37 2016 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 16 Apr 2016 21:54:37 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy41ICgjMjY2NTkp?= Message-ID: <20160416215437.28303.70670.E3871709@psf.io> https://hg.python.org/cpython/rev/870fcc50f1bd changeset: 101022:870fcc50f1bd parent: 101017:3bb3e6316098 parent: 101021:9e2176d18965 user: Benjamin Peterson date: Sat Apr 16 14:54:27 2016 -0700 summary: merge 3.5 (#26659) files: Lib/test/test_slice.py | 17 ++++++++++++++--- Misc/NEWS | 2 ++ Objects/sliceobject.c | 19 +++++++++++++++---- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_slice.py b/Lib/test/test_slice.py --- a/Lib/test/test_slice.py +++ b/Lib/test/test_slice.py @@ -1,11 +1,13 @@ # tests for slice objects; in particular the indices method. -import unittest -from pickle import loads, dumps - import itertools import operator import sys +import unittest +import weakref + +from pickle import loads, dumps +from test import support def evaluate_slice_index(arg): @@ -240,5 +242,14 @@ self.assertEqual(s.indices(15), t.indices(15)) self.assertNotEqual(id(s), id(t)) + def test_cycle(self): + class myobj(): pass + o = myobj() + o.s = slice(o) + w = weakref.ref(o) + o = None + test_support.gc_collect() + self.assertIsNone(w()) + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #26659: Make the builtin slice type support cycle collection. + - Issue #26718: super.__init__ no longer leaks memory if called multiple times. NOTE: A direct call of super.__init__ is not endorsed! diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -119,7 +119,7 @@ slice_cache = NULL; _Py_NewReference((PyObject *)obj); } else { - obj = PyObject_New(PySliceObject, &PySlice_Type); + obj = PyObject_GC_New(PySliceObject, &PySlice_Type); if (obj == NULL) return NULL; } @@ -135,6 +135,7 @@ obj->start = start; obj->stop = stop; + _PyObject_GC_TRACK(obj); return (PyObject *) obj; } @@ -288,13 +289,14 @@ static void slice_dealloc(PySliceObject *r) { + _PyObject_GC_UNTRACK(r); Py_DECREF(r->step); Py_DECREF(r->start); Py_DECREF(r->stop); if (slice_cache == NULL) slice_cache = r; else - PyObject_Del(r); + PyObject_GC_Del(r); } static PyObject * @@ -586,6 +588,15 @@ return res; } +static int +slice_traverse(PySliceObject *v, visitproc visit, void *arg) +{ + Py_VISIT(v->start); + Py_VISIT(v->stop); + Py_VISIT(v->step); + return 0; +} + PyTypeObject PySlice_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "slice", /* Name of this type */ @@ -606,9 +617,9 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ slice_doc, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)slice_traverse, /* tp_traverse */ 0, /* tp_clear */ slice_richcompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 18:02:34 2016 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 16 Apr 2016 22:02:34 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy41?= Message-ID: <20160416220234.12741.24531.D3A8CE58@psf.io> https://hg.python.org/cpython/rev/c43534354929 changeset: 101024:c43534354929 parent: 101022:870fcc50f1bd parent: 101023:7b460808a407 user: Benjamin Peterson date: Sat Apr 16 15:02:29 2016 -0700 summary: merge 3.5 files: Lib/test/test_slice.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_slice.py b/Lib/test/test_slice.py --- a/Lib/test/test_slice.py +++ b/Lib/test/test_slice.py @@ -248,7 +248,7 @@ o.s = slice(o) w = weakref.ref(o) o = None - test_support.gc_collect() + support.gc_collect() self.assertIsNone(w()) if __name__ == "__main__": -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 18:02:34 2016 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 16 Apr 2016 22:02:34 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogdGVzdF9zdXBwb3J0?= =?utf-8?q?_-=3E_support?= Message-ID: <20160416220234.19497.11707.01EDB206@psf.io> https://hg.python.org/cpython/rev/7b460808a407 changeset: 101023:7b460808a407 branch: 3.5 parent: 101021:9e2176d18965 user: Benjamin Peterson date: Sat Apr 16 15:02:23 2016 -0700 summary: test_support -> support files: Lib/test/test_slice.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_slice.py b/Lib/test/test_slice.py --- a/Lib/test/test_slice.py +++ b/Lib/test/test_slice.py @@ -248,7 +248,7 @@ o.s = slice(o) w = weakref.ref(o) o = None - test_support.gc_collect() + support.gc_collect() self.assertIsNone(w()) if __name__ == "__main__": -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 18:12:42 2016 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 16 Apr 2016 22:12:42 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_fix_slice_cach?= =?utf-8?q?e_finalization_to_use_gc_del?= Message-ID: <20160416221242.19499.2185.0E88DEC0@psf.io> https://hg.python.org/cpython/rev/8ae1b986766d changeset: 101025:8ae1b986766d branch: 3.5 parent: 101023:7b460808a407 user: Benjamin Peterson date: Sat Apr 16 15:12:29 2016 -0700 summary: fix slice cache finalization to use gc del files: Objects/sliceobject.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -102,7 +102,7 @@ PySliceObject *obj = slice_cache; if (obj != NULL) { slice_cache = NULL; - PyObject_Del(obj); + PyObject_GC_Del(obj); } } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 18:12:42 2016 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 16 Apr 2016 22:12:42 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy41?= Message-ID: <20160416221242.70672.26463.0ECC0340@psf.io> https://hg.python.org/cpython/rev/c956d17d255d changeset: 101026:c956d17d255d parent: 101024:c43534354929 parent: 101025:8ae1b986766d user: Benjamin Peterson date: Sat Apr 16 15:12:37 2016 -0700 summary: merge 3.5 files: Objects/sliceobject.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -102,7 +102,7 @@ PySliceObject *obj = slice_cache; if (obj != NULL) { slice_cache = NULL; - PyObject_Del(obj); + PyObject_GC_Del(obj); } } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 19:51:51 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 23:51:51 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2Nzgy?= =?utf-8?q?=3A_Acknowledge_the_incomplete_status_of_=5F=5Fall=5F=5F_in_3?= =?utf-8?q?=2E5?= Message-ID: <20160416235151.407.39059.77EB2218@psf.io> https://hg.python.org/cpython/rev/386712b16c74 changeset: 101027:386712b16c74 branch: 3.5 parent: 101025:8ae1b986766d user: Martin Panter date: Sat Apr 16 23:38:25 2016 +0000 summary: Issue #26782: Acknowledge the incomplete status of __all__ in 3.5 Handle is probably meant to be excluded, and STARTUPINFO will be added to __all__ in 3.6. files: Lib/test/test_subprocess.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -2540,7 +2540,8 @@ def test__all__(self): """Ensure that __all__ is populated properly.""" - intentionally_excluded = set(("list2cmdline",)) + # STARTUPINFO added to __all__ in 3.6 + intentionally_excluded = {"list2cmdline", "STARTUPINFO", "Handle"} exported = set(subprocess.__all__) possible_exports = set() import types -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 19:51:52 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 23:51:52 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326782=3A_Add_STAR?= =?utf-8?q?TUPINFO_to_subprocess=2E=5F=5Fall=5F=5F_on_Windows?= Message-ID: <20160416235152.8326.8037.6FC674DE@psf.io> https://hg.python.org/cpython/rev/3e93ac5a7afa changeset: 101029:3e93ac5a7afa user: Martin Panter date: Sat Apr 16 23:42:37 2016 +0000 summary: Issue #26782: Add STARTUPINFO to subprocess.__all__ on Windows files: Doc/whatsnew/3.6.rst | 2 +- Lib/subprocess.py | 3 ++- Lib/test/test_subprocess.py | 3 +-- Misc/NEWS | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -500,7 +500,7 @@ attributes to match the documented APIs: :mod:`calendar`, :mod:`csv`, :mod:`~xml.etree.ElementTree`, :mod:`enum`, :mod:`fileinput`, :mod:`ftplib`, :mod:`logging`, - :mod:`optparse`, :mod:`tarfile`, :mod:`threading` and + :mod:`optparse`, :mod:`subprocess`, :mod:`tarfile`, :mod:`threading` and :mod:`wave`. This means they will export new symbols when ``import *`` is used. See :issue:`23883`. diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -471,7 +471,8 @@ __all__.extend(["CREATE_NEW_CONSOLE", "CREATE_NEW_PROCESS_GROUP", "STD_INPUT_HANDLE", "STD_OUTPUT_HANDLE", "STD_ERROR_HANDLE", "SW_HIDE", - "STARTF_USESTDHANDLES", "STARTF_USESHOWWINDOW"]) + "STARTF_USESTDHANDLES", "STARTF_USESHOWWINDOW", + "STARTUPINFO"]) class Handle(int): closed = False diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -2540,8 +2540,7 @@ def test__all__(self): """Ensure that __all__ is populated properly.""" - # STARTUPINFO added to __all__ in 3.6 - intentionally_excluded = {"list2cmdline", "STARTUPINFO", "Handle"} + intentionally_excluded = {"list2cmdline", "Handle"} exported = set(subprocess.__all__) possible_exports = set() import types diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -245,6 +245,8 @@ Library ------- +- Issue #26782: Add STARTUPINFO to subprocess.__all__ on Windows. + - Issue #26404: Add context manager to socketserver. Patch by Aviv Palivoda. - Issue #26735: Fix :func:`os.urandom` on Solaris 11.3 and newer when reading -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 19:51:52 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 16 Apr 2016 23:51:52 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326782=3A_Merge_test=5Fsubprocess_from_3=2E5?= Message-ID: <20160416235152.107504.12514.ECEECE60@psf.io> https://hg.python.org/cpython/rev/728370e7a29d changeset: 101028:728370e7a29d parent: 101026:c956d17d255d parent: 101027:386712b16c74 user: Martin Panter date: Sat Apr 16 23:40:15 2016 +0000 summary: Issue #26782: Merge test_subprocess from 3.5 files: Lib/test/test_subprocess.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -2540,7 +2540,8 @@ def test__all__(self): """Ensure that __all__ is populated properly.""" - intentionally_excluded = set(("list2cmdline",)) + # STARTUPINFO added to __all__ in 3.6 + intentionally_excluded = {"list2cmdline", "STARTUPINFO", "Handle"} exported = set(subprocess.__all__) possible_exports = set() import types -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 21:40:26 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 17 Apr 2016 01:40:26 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzQ4MDY6?= =?utf-8?q?_Avoid_masking_TypeError_when_*-unpacking_a_generator?= Message-ID: <20160417014022.89029.30387.8894B5D4@psf.io> https://hg.python.org/cpython/rev/eef8f72ddb00 changeset: 101030:eef8f72ddb00 branch: 2.7 parent: 101020:879da9400529 user: Martin Panter date: Sun Jan 31 06:30:56 2016 +0000 summary: Issue #4806: Avoid masking TypeError when *-unpacking a generator Based on patch by Hagen F?rstenau. files: Lib/test/test_extcall.py | 21 ++++++++++++++++----- Misc/NEWS | 4 ++++ Python/ceval.c | 6 ++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py --- a/Lib/test/test_extcall.py +++ b/Lib/test/test_extcall.py @@ -93,7 +93,7 @@ >>> g(*Nothing()) Traceback (most recent call last): ... - TypeError: g() argument after * must be a sequence, not instance + TypeError: g() argument after * must be an iterable, not instance >>> class Nothing: ... def __len__(self): return 5 @@ -102,7 +102,7 @@ >>> g(*Nothing()) Traceback (most recent call last): ... - TypeError: g() argument after * must be a sequence, not instance + TypeError: g() argument after * must be an iterable, not instance >>> class Nothing(): ... def __len__(self): return 5 @@ -128,6 +128,17 @@ >>> g(*Nothing()) 0 (1, 2, 3) {} +Check for issue #4806: Does a TypeError in a generator get propagated with the +right error message? + + >>> def broken(): raise TypeError("myerror") + ... + + >>> g(*(broken() for i in range(1))) + Traceback (most recent call last): + ... + TypeError: myerror + Make sure that the function doesn't stomp the dictionary >>> d = {'a': 1, 'b': 2, 'c': 3} @@ -167,17 +178,17 @@ >>> h(*h) Traceback (most recent call last): ... - TypeError: h() argument after * must be a sequence, not function + TypeError: h() argument after * must be an iterable, not function >>> dir(*h) Traceback (most recent call last): ... - TypeError: dir() argument after * must be a sequence, not function + TypeError: dir() argument after * must be an iterable, not function >>> None(*h) Traceback (most recent call last): ... - TypeError: NoneType object argument after * must be a sequence, \ + TypeError: NoneType object argument after * must be an iterable, \ not function >>> h(**h) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #4806: Avoid masking the original TypeError exception when using star + (*) unpacking and the exception was raised from a generator. Based on + patch by Hagen F?rstenau. + - Issue #26659: Make the builtin slice type support cycle collection. - Issue #26718: super.__init__ no longer leaks memory if called multiple times. diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4615,10 +4615,12 @@ PyObject *t = NULL; t = PySequence_Tuple(stararg); if (t == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) { + if (PyErr_ExceptionMatches(PyExc_TypeError) && + /* Don't mask TypeError raised from a generator */ + !PyGen_Check(stararg)) { PyErr_Format(PyExc_TypeError, "%.200s%.200s argument after * " - "must be a sequence, not %200s", + "must be an iterable, not %200s", PyEval_GetFuncName(func), PyEval_GetFuncDesc(func), stararg->ob_type->tp_name); -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 23:04:40 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 17 Apr 2016 03:04:40 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NzE3?= =?utf-8?q?=3A_Stop_encoding_Latin-1-ized_WSGI_paths_with_UTF-8?= Message-ID: <20160417030440.89045.92863.FA0A8B4D@psf.io> https://hg.python.org/cpython/rev/1f2cfcd5a83f changeset: 101031:1f2cfcd5a83f branch: 3.5 parent: 101027:386712b16c74 user: Martin Panter date: Sun Apr 17 02:17:03 2016 +0000 summary: Issue #26717: Stop encoding Latin-1-ized WSGI paths with UTF-8 Patch by Anthony Sottile. files: Lib/test/test_wsgiref.py | 24 ++++++++++++++++++++++++ Lib/wsgiref/simple_server.py | 2 +- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 4 files changed, 29 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py --- a/Lib/test/test_wsgiref.py +++ b/Lib/test/test_wsgiref.py @@ -1,3 +1,4 @@ +from unittest import mock from unittest import TestCase from wsgiref.util import setup_testing_defaults from wsgiref.headers import Headers @@ -221,6 +222,29 @@ b"data", out) + def test_cp1252_url(self): + def app(e, s): + s("200 OK", [ + ("Content-Type", "text/plain"), + ("Date", "Wed, 24 Dec 2008 13:29:32 GMT"), + ]) + # PEP3333 says environ variables are decoded as latin1. + # Encode as latin1 to get original bytes + return [e["PATH_INFO"].encode("latin1")] + + out, err = run_amock( + validator(app), data=b"GET /\x80%80 HTTP/1.0") + self.assertEqual( + [ + b"HTTP/1.0 200 OK", + mock.ANY, + b"Content-Type: text/plain", + b"Date: Wed, 24 Dec 2008 13:29:32 GMT", + b"", + b"/\x80\x80", + ], + out.splitlines()) + class UtilityTests(TestCase): diff --git a/Lib/wsgiref/simple_server.py b/Lib/wsgiref/simple_server.py --- a/Lib/wsgiref/simple_server.py +++ b/Lib/wsgiref/simple_server.py @@ -82,7 +82,7 @@ else: path,query = self.path,'' - env['PATH_INFO'] = urllib.parse.unquote_to_bytes(path).decode('iso-8859-1') + env['PATH_INFO'] = urllib.parse.unquote(path, 'iso-8859-1') env['QUERY_STRING'] = query host = self.address_string() diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1376,6 +1376,7 @@ Paul Sokolovsky Evgeny Sologubov Cody Somerville +Anthony Sottile Edoardo Spadolini Geoffrey Spear Clay Spence diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,9 @@ Library ------- +- Issue #26717: Stop encoding Latin-1-ized WSGI paths with UTF-8. Patch by + Anthony Sottile. + - Issue #26735: Fix :func:`os.urandom` on Solaris 11.3 and newer when reading more than 1,024 bytes: call ``getrandom()`` multiple times with a limit of 1024 bytes per call. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 23:04:41 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 17 Apr 2016 03:04:41 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326717=3A_Merge_wsgiref_fix_from_3=2E5?= Message-ID: <20160417030441.15376.48093.15CD68D5@psf.io> https://hg.python.org/cpython/rev/815a4ac67e68 changeset: 101032:815a4ac67e68 parent: 101029:3e93ac5a7afa parent: 101031:1f2cfcd5a83f user: Martin Panter date: Sun Apr 17 02:36:50 2016 +0000 summary: Issue #26717: Merge wsgiref fix from 3.5 files: Lib/test/test_wsgiref.py | 24 ++++++++++++++++++++++++ Lib/wsgiref/simple_server.py | 2 +- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 4 files changed, 29 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py --- a/Lib/test/test_wsgiref.py +++ b/Lib/test/test_wsgiref.py @@ -1,3 +1,4 @@ +from unittest import mock from unittest import TestCase from wsgiref.util import setup_testing_defaults from wsgiref.headers import Headers @@ -221,6 +222,29 @@ b"data", out) + def test_cp1252_url(self): + def app(e, s): + s("200 OK", [ + ("Content-Type", "text/plain"), + ("Date", "Wed, 24 Dec 2008 13:29:32 GMT"), + ]) + # PEP3333 says environ variables are decoded as latin1. + # Encode as latin1 to get original bytes + return [e["PATH_INFO"].encode("latin1")] + + out, err = run_amock( + validator(app), data=b"GET /\x80%80 HTTP/1.0") + self.assertEqual( + [ + b"HTTP/1.0 200 OK", + mock.ANY, + b"Content-Type: text/plain", + b"Date: Wed, 24 Dec 2008 13:29:32 GMT", + b"", + b"/\x80\x80", + ], + out.splitlines()) + class UtilityTests(TestCase): diff --git a/Lib/wsgiref/simple_server.py b/Lib/wsgiref/simple_server.py --- a/Lib/wsgiref/simple_server.py +++ b/Lib/wsgiref/simple_server.py @@ -82,7 +82,7 @@ else: path,query = self.path,'' - env['PATH_INFO'] = urllib.parse.unquote_to_bytes(path).decode('iso-8859-1') + env['PATH_INFO'] = urllib.parse.unquote(path, 'iso-8859-1') env['QUERY_STRING'] = query host = self.address_string() diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1385,6 +1385,7 @@ Paul Sokolovsky Evgeny Sologubov Cody Somerville +Anthony Sottile Edoardo Spadolini Geoffrey Spear Clay Spence diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -245,6 +245,9 @@ Library ------- +- Issue #26717: Stop encoding Latin-1-ized WSGI paths with UTF-8. Patch by + Anthony Sottile. + - Issue #26782: Add STARTUPINFO to subprocess.__all__ on Windows. - Issue #26404: Add context manager to socketserver. Patch by Aviv Palivoda. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 23:15:56 2016 From: python-checkins at python.org (steven.daprano) Date: Sun, 17 Apr 2016 03:15:56 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_a_few_minor_typos_to_s?= =?utf-8?q?ecrets_documentation=2E?= Message-ID: <20160417031556.12731.86400.FFBE1A15@psf.io> https://hg.python.org/cpython/rev/941dc59bdea1 changeset: 101033:941dc59bdea1 parent: 101029:3e93ac5a7afa user: Steven D'Aprano date: Sun Apr 17 13:05:10 2016 +1000 summary: Fix a few minor typos to secrets documentation. files: Doc/library/secrets.rst | 19 +++++++++---------- 1 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Doc/library/secrets.rst b/Doc/library/secrets.rst --- a/Doc/library/secrets.rst +++ b/Doc/library/secrets.rst @@ -88,7 +88,7 @@ .. function:: token_urlsafe([nbytes=None]) Return a random URL-safe text string, containing *nbytes* random - bytes. The text is Base64 encoded, so on average, each byte results + bytes. The text is Base64 encoded, so on average each byte results in approximately 1.3 characters. If *nbytes* is ``None`` or not supplied, a reasonable default is used. @@ -106,7 +106,7 @@ tokens need to have sufficient randomness. Unfortunately, what is considered sufficient will necessarily increase as computers get more powerful and able to make more guesses in a shorter period. As of 2015, -it is believed that 64 bytes (512 bits) of randomness is sufficient for +it is believed that 32 bytes (256 bits) of randomness is sufficient for the typical use-case expected for the :mod:`secrets` module. For those who want to manage their own token length, you can explicitly @@ -129,8 +129,8 @@ .. function:: compare_digest(a, b) Return ``True`` if strings *a* and *b* are equal, otherwise ``False``, - in such a way as to redice the risk of - `timing attacks `_ . + in such a way as to reduce the risk of + `timing attacks `_. See :func:`hmac.compare_digest` for additional details. @@ -151,11 +151,10 @@ .. note:: - Applications should - `not store passwords in a recoverable format `_ , - whether plain text or encrypted. They should always be salted and - hashed using a cryptographically-strong one-way (irreversible) hash - function. + Applications should not + `store passwords in a recoverable format `_, + whether plain text or encrypted. They should be salted and hashed + using a cryptographically-strong one-way (irreversible) hash function. Generate a ten-character alphanumeric password with at least one @@ -174,7 +173,7 @@ break -Generate an `XKCD-style passphrase `_ : +Generate an `XKCD-style passphrase `_: .. testcode:: -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 23:15:56 2016 From: python-checkins at python.org (steven.daprano) Date: Sun, 17 Apr 2016 03:15:56 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Shorten_secrets_module_doc?= =?utf-8?q?string=2C_add_function_docstrings=2E?= Message-ID: <20160417031556.107508.14179.F4E7BE5B@psf.io> https://hg.python.org/cpython/rev/504ba147cbdf changeset: 101034:504ba147cbdf user: Steven D'Aprano date: Sun Apr 17 13:13:36 2016 +1000 summary: Shorten secrets module docstring, add function docstrings. files: Lib/secrets.py | 106 ++++++++++-------------------------- 1 files changed, 30 insertions(+), 76 deletions(-) diff --git a/Lib/secrets.py b/Lib/secrets.py --- a/Lib/secrets.py +++ b/Lib/secrets.py @@ -1,84 +1,9 @@ """Generate cryptographically strong pseudo-random numbers suitable for managing secrets such as account authentication, tokens, and similar. + See PEP 506 for more information. - https://www.python.org/dev/peps/pep-0506/ - -Random numbers -============== - -The ``secrets`` module provides the following pseudo-random functions, based -on SystemRandom, which in turn uses the most secure source of randomness your -operating system provides. - - - choice(sequence) - Choose a random element from a non-empty sequence. - - randbelow(n) - Return a random int in the range [0, n). - - randbits(k) - Generates an int with k random bits. - - SystemRandom - Class for generating random numbers using sources provided by - the operating system. See the ``random`` module for documentation. - - -Token functions -=============== - -The ``secrets`` module provides a number of functions for generating secure -tokens, suitable for applications such as password resets, hard-to-guess -URLs, and similar. All the ``token_*`` functions take an optional single -argument specifying the number of bytes of randomness to use. If that is -not given, or is ``None``, a reasonable default is used. That default is -subject to change at any time, including during maintenance releases. - - - token_bytes(nbytes=None) - Return a random byte-string containing ``nbytes`` number of bytes. - - >>> secrets.token_bytes(16) #doctest:+SKIP - b'\\xebr\\x17D*t\\xae\\xd4\\xe3S\\xb6\\xe2\\xebP1\\x8b' - - - token_hex(nbytes=None) - Return a random text-string, in hexadecimal. The string has ``nbytes`` - random bytes, each byte converted to two hex digits. - - >>> secrets.token_hex(16) #doctest:+SKIP - 'f9bf78b9a18ce6d46a0cd2b0b86df9da' - - token_urlsafe(nbytes=None) - Return a random URL-safe text-string, containing ``nbytes`` random - bytes. On average, each byte results in approximately 1.3 characters - in the final result. - - >>> secrets.token_urlsafe(16) #doctest:+SKIP - 'Drmhze6EPcv0fN_81Bj-nA' - - -(The examples above assume Python 3. In Python 2, byte-strings will display -using regular quotes ``''`` with no prefix, and text-strings will have a -``u`` prefix.) - - -Other functions -=============== - - compare_digest(a, b) - Return True if strings a and b are equal, otherwise False. - Performs the equality comparison in such a way as to reduce the - risk of timing attacks. - - See http://codahale.com/a-lesson-in-timing-attacks/ for a - discussion on how timing attacks against ``==`` can reveal - secrets from your application. - - """ __all__ = ['choice', 'randbelow', 'randbits', 'SystemRandom', @@ -100,18 +25,47 @@ choice = _sysrand.choice def randbelow(exclusive_upper_bound): + """Return a random int in the range [0, n).""" return _sysrand._randbelow(exclusive_upper_bound) DEFAULT_ENTROPY = 32 # number of bytes to return by default def token_bytes(nbytes=None): + """Return a random byte string containing *nbytes* bytes. + + If *nbytes* is ``None`` or not supplied, a reasonable + default is used. + + >>> token_bytes(16) #doctest:+SKIP + b'\\xebr\\x17D*t\\xae\\xd4\\xe3S\\xb6\\xe2\\xebP1\\x8b' + + """ if nbytes is None: nbytes = DEFAULT_ENTROPY return os.urandom(nbytes) def token_hex(nbytes=None): + """Return a random text string, in hexadecimal. + + The string has *nbytes* random bytes, each byte converted to two + hex digits. If *nbytes* is ``None`` or not supplied, a reasonable + default is used. + + >>> token_hex(16) #doctest:+SKIP + 'f9bf78b9a18ce6d46a0cd2b0b86df9da' + + """ return binascii.hexlify(token_bytes(nbytes)).decode('ascii') def token_urlsafe(nbytes=None): + """Return a random URL-safe text string, in Base64 encoding. + + The string has *nbytes* random bytes. If *nbytes* is ``None`` + or not supplied, a reasonable default is used. + + >>> token_urlsafe(16) #doctest:+SKIP + 'Drmhze6EPcv0fN_81Bj-nA' + + """ tok = token_bytes(nbytes) return base64.urlsafe_b64encode(tok).rstrip(b'=').decode('ascii') -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 16 23:15:57 2016 From: python-checkins at python.org (steven.daprano) Date: Sun, 17 Apr 2016 03:15:57 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_Automated_merge_with_ssh=3A//hg=2Epython=2Eorg/cpython?= Message-ID: <20160417031556.88664.18794.D7512B08@psf.io> https://hg.python.org/cpython/rev/19356c6d23b9 changeset: 101035:19356c6d23b9 parent: 101032:815a4ac67e68 parent: 101034:504ba147cbdf user: Steven D'Aprano date: Sun Apr 17 13:14:48 2016 +1000 summary: Automated merge with ssh://hg.python.org/cpython files: Doc/library/secrets.rst | 19 ++-- Lib/secrets.py | 106 +++++++-------------------- 2 files changed, 39 insertions(+), 86 deletions(-) diff --git a/Doc/library/secrets.rst b/Doc/library/secrets.rst --- a/Doc/library/secrets.rst +++ b/Doc/library/secrets.rst @@ -88,7 +88,7 @@ .. function:: token_urlsafe([nbytes=None]) Return a random URL-safe text string, containing *nbytes* random - bytes. The text is Base64 encoded, so on average, each byte results + bytes. The text is Base64 encoded, so on average each byte results in approximately 1.3 characters. If *nbytes* is ``None`` or not supplied, a reasonable default is used. @@ -106,7 +106,7 @@ tokens need to have sufficient randomness. Unfortunately, what is considered sufficient will necessarily increase as computers get more powerful and able to make more guesses in a shorter period. As of 2015, -it is believed that 64 bytes (512 bits) of randomness is sufficient for +it is believed that 32 bytes (256 bits) of randomness is sufficient for the typical use-case expected for the :mod:`secrets` module. For those who want to manage their own token length, you can explicitly @@ -129,8 +129,8 @@ .. function:: compare_digest(a, b) Return ``True`` if strings *a* and *b* are equal, otherwise ``False``, - in such a way as to redice the risk of - `timing attacks `_ . + in such a way as to reduce the risk of + `timing attacks `_. See :func:`hmac.compare_digest` for additional details. @@ -151,11 +151,10 @@ .. note:: - Applications should - `not store passwords in a recoverable format `_ , - whether plain text or encrypted. They should always be salted and - hashed using a cryptographically-strong one-way (irreversible) hash - function. + Applications should not + `store passwords in a recoverable format `_, + whether plain text or encrypted. They should be salted and hashed + using a cryptographically-strong one-way (irreversible) hash function. Generate a ten-character alphanumeric password with at least one @@ -174,7 +173,7 @@ break -Generate an `XKCD-style passphrase `_ : +Generate an `XKCD-style passphrase `_: .. testcode:: diff --git a/Lib/secrets.py b/Lib/secrets.py --- a/Lib/secrets.py +++ b/Lib/secrets.py @@ -1,84 +1,9 @@ """Generate cryptographically strong pseudo-random numbers suitable for managing secrets such as account authentication, tokens, and similar. + See PEP 506 for more information. - https://www.python.org/dev/peps/pep-0506/ - -Random numbers -============== - -The ``secrets`` module provides the following pseudo-random functions, based -on SystemRandom, which in turn uses the most secure source of randomness your -operating system provides. - - - choice(sequence) - Choose a random element from a non-empty sequence. - - randbelow(n) - Return a random int in the range [0, n). - - randbits(k) - Generates an int with k random bits. - - SystemRandom - Class for generating random numbers using sources provided by - the operating system. See the ``random`` module for documentation. - - -Token functions -=============== - -The ``secrets`` module provides a number of functions for generating secure -tokens, suitable for applications such as password resets, hard-to-guess -URLs, and similar. All the ``token_*`` functions take an optional single -argument specifying the number of bytes of randomness to use. If that is -not given, or is ``None``, a reasonable default is used. That default is -subject to change at any time, including during maintenance releases. - - - token_bytes(nbytes=None) - Return a random byte-string containing ``nbytes`` number of bytes. - - >>> secrets.token_bytes(16) #doctest:+SKIP - b'\\xebr\\x17D*t\\xae\\xd4\\xe3S\\xb6\\xe2\\xebP1\\x8b' - - - token_hex(nbytes=None) - Return a random text-string, in hexadecimal. The string has ``nbytes`` - random bytes, each byte converted to two hex digits. - - >>> secrets.token_hex(16) #doctest:+SKIP - 'f9bf78b9a18ce6d46a0cd2b0b86df9da' - - token_urlsafe(nbytes=None) - Return a random URL-safe text-string, containing ``nbytes`` random - bytes. On average, each byte results in approximately 1.3 characters - in the final result. - - >>> secrets.token_urlsafe(16) #doctest:+SKIP - 'Drmhze6EPcv0fN_81Bj-nA' - - -(The examples above assume Python 3. In Python 2, byte-strings will display -using regular quotes ``''`` with no prefix, and text-strings will have a -``u`` prefix.) - - -Other functions -=============== - - compare_digest(a, b) - Return True if strings a and b are equal, otherwise False. - Performs the equality comparison in such a way as to reduce the - risk of timing attacks. - - See http://codahale.com/a-lesson-in-timing-attacks/ for a - discussion on how timing attacks against ``==`` can reveal - secrets from your application. - - """ __all__ = ['choice', 'randbelow', 'randbits', 'SystemRandom', @@ -100,18 +25,47 @@ choice = _sysrand.choice def randbelow(exclusive_upper_bound): + """Return a random int in the range [0, n).""" return _sysrand._randbelow(exclusive_upper_bound) DEFAULT_ENTROPY = 32 # number of bytes to return by default def token_bytes(nbytes=None): + """Return a random byte string containing *nbytes* bytes. + + If *nbytes* is ``None`` or not supplied, a reasonable + default is used. + + >>> token_bytes(16) #doctest:+SKIP + b'\\xebr\\x17D*t\\xae\\xd4\\xe3S\\xb6\\xe2\\xebP1\\x8b' + + """ if nbytes is None: nbytes = DEFAULT_ENTROPY return os.urandom(nbytes) def token_hex(nbytes=None): + """Return a random text string, in hexadecimal. + + The string has *nbytes* random bytes, each byte converted to two + hex digits. If *nbytes* is ``None`` or not supplied, a reasonable + default is used. + + >>> token_hex(16) #doctest:+SKIP + 'f9bf78b9a18ce6d46a0cd2b0b86df9da' + + """ return binascii.hexlify(token_bytes(nbytes)).decode('ascii') def token_urlsafe(nbytes=None): + """Return a random URL-safe text string, in Base64 encoding. + + The string has *nbytes* random bytes. If *nbytes* is ``None`` + or not supplied, a reasonable default is used. + + >>> token_urlsafe(16) #doctest:+SKIP + 'Drmhze6EPcv0fN_81Bj-nA' + + """ tok = token_bytes(nbytes) return base64.urlsafe_b64encode(tok).rstrip(b'=').decode('ascii') -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 17 02:40:14 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 17 Apr 2016 06:40:14 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2Nzc4?= =?utf-8?q?=3A_Fixed_=22a/an/and=22_typos_in_code_comment_and_documentatio?= =?utf-8?q?n=2E?= Message-ID: <20160417064014.19503.28417.8FBF6E4E@psf.io> https://hg.python.org/cpython/rev/395dd5630e6c changeset: 101036:395dd5630e6c branch: 3.5 parent: 101031:1f2cfcd5a83f user: Serhiy Storchaka date: Sun Apr 17 08:32:47 2016 +0300 summary: Issue #26778: Fixed "a/an/and" typos in code comment and documentation. files: Doc/c-api/set.rst | 6 ++-- Doc/c-api/unicode.rst | 4 +- Doc/distutils/apiref.rst | 2 +- Doc/library/asyncio-eventloop.rst | 2 +- Doc/library/ctypes.rst | 4 +- Doc/library/idle.rst | 2 +- Doc/library/shutil.rst | 2 +- Doc/library/tarfile.rst | 2 +- Doc/library/tkinter.tix.rst | 2 +- Doc/tutorial/datastructures.rst | 2 +- Doc/whatsnew/2.2.rst | 2 +- Doc/whatsnew/3.4.rst | 2 +- Include/listobject.h | 2 +- Include/unicodeobject.h | 2 +- Lib/_pydecimal.py | 2 +- Lib/_pyio.py | 2 +- Lib/asyncio/selector_events.py | 2 +- Lib/email/_header_value_parser.py | 6 ++-- Lib/email/headerregistry.py | 2 +- Lib/idlelib/AutoComplete.py | 2 +- Lib/idlelib/Debugger.py | 2 +- Lib/idlelib/WidgetRedirector.py | 2 +- Lib/idlelib/configDialog.py | 2 +- Lib/lib2to3/fixer_base.py | 2 +- Lib/lib2to3/refactor.py | 2 +- Lib/lzma.py | 2 +- Lib/mailbox.py | 2 +- Lib/multiprocessing/managers.py | 2 +- Lib/optparse.py | 2 +- Lib/pprint.py | 2 +- Lib/socket.py | 2 +- Lib/socketserver.py | 2 +- Lib/sqlite3/test/regression.py | 2 +- Lib/tarfile.py | 4 +- Lib/test/test_asyncio/test_selector_events.py | 2 +- Lib/test/test_asyncio/test_sslproto.py | 2 +- Lib/test/test_binop.py | 2 +- Lib/test/test_faulthandler.py | 2 +- Lib/test/test_pathlib.py | 2 +- Lib/test/test_sys.py | 2 +- Lib/test/test_threading.py | 2 +- Lib/test/test_tools/test_gprof2html.py | 2 +- Lib/test/test_zipapp.py | 2 +- Lib/tkinter/__init__.py | 2 +- Lib/tkinter/dnd.py | 2 +- Lib/tkinter/test/test_ttk/test_functions.py | 2 +- Lib/tkinter/tix.py | 6 ++-- Lib/tkinter/ttk.py | 2 +- Lib/xmlrpc/client.py | 2 +- Lib/zipapp.py | 7 ++-- Misc/HISTORY | 14 +++++----- Misc/NEWS | 4 +- Modules/_csv.c | 2 +- Modules/_ctypes/_ctypes.c | 2 +- Modules/_pickle.c | 2 +- Modules/_tracemalloc.c | 2 +- Modules/faulthandler.c | 2 +- Modules/itertoolsmodule.c | 2 +- Objects/bytearrayobject.c | 2 +- Objects/rangeobject.c | 2 +- Objects/stringlib/unicode_format.h | 2 +- PC/clinic/winreg.c.h | 6 ++-- PC/winreg.c | 8 ++-- Python/thread_nt.h | 2 +- 64 files changed, 88 insertions(+), 87 deletions(-) diff --git a/Doc/c-api/set.rst b/Doc/c-api/set.rst --- a/Doc/c-api/set.rst +++ b/Doc/c-api/set.rst @@ -128,7 +128,7 @@ of brand new frozensets before they are exposed to other code). Return 0 on success or -1 on failure. Raise a :exc:`TypeError` if the *key* is unhashable. Raise a :exc:`MemoryError` if there is no room to grow. Raise a - :exc:`SystemError` if *set* is an not an instance of :class:`set` or its + :exc:`SystemError` if *set* is not an instance of :class:`set` or its subtype. @@ -142,7 +142,7 @@ error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a :exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~set.discard` method, this function does not automatically convert unhashable sets into - temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is an not an + temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is not an instance of :class:`set` or its subtype. @@ -150,7 +150,7 @@ Return a new reference to an arbitrary object in the *set*, and removes the object from the *set*. Return *NULL* on failure. Raise :exc:`KeyError` if the - set is empty. Raise a :exc:`SystemError` if *set* is an not an instance of + set is empty. Raise a :exc:`SystemError` if *set* is not an instance of :class:`set` or its subtype. diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -367,7 +367,7 @@ .. c:macro:: Py_UNICODE_IS_HIGH_SURROGATE(ch) - Check if *ch* is an high surrogate (``0xD800 <= ch <= 0xDBFF``). + Check if *ch* is a high surrogate (``0xD800 <= ch <= 0xDBFF``). .. c:macro:: Py_UNICODE_IS_LOW_SURROGATE(ch) @@ -450,7 +450,7 @@ | :attr:`%%` | *n/a* | The literal % character. | +-------------------+---------------------+--------------------------------+ | :attr:`%c` | int | A single character, | - | | | represented as an C int. | + | | | represented as a C int. | +-------------------+---------------------+--------------------------------+ | :attr:`%d` | int | Exactly equivalent to | | | | ``printf("%d")``. | diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -837,7 +837,7 @@ .. module:: distutils.bcppcompiler -This module provides :class:`BorlandCCompiler`, an subclass of the abstract +This module provides :class:`BorlandCCompiler`, a subclass of the abstract :class:`CCompiler` class for the Borland C++ compiler. diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -513,7 +513,7 @@ The *address* must be already resolved to avoid the trap of hanging the entire event loop when the address requires doing a DNS lookup. For - example, it must be an IP address, not an hostname, for + example, it must be an IP address, not a hostname, for :py:data:`~socket.AF_INET` and :py:data:`~socket.AF_INET6` address families. Use :meth:`getaddrinfo` to resolve the hostname asynchronously. diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -671,7 +671,7 @@ TenPointsArrayType = POINT * 10 -Here is an example of an somewhat artificial data type, a structure containing 4 +Here is an example of a somewhat artificial data type, a structure containing 4 POINTs among other stuff:: >>> from ctypes import * @@ -1888,7 +1888,7 @@ .. function:: POINTER(type) This factory function creates and returns a new ctypes pointer type. Pointer - types are cached an reused internally, so calling this function repeatedly is + types are cached and reused internally, so calling this function repeatedly is cheap. *type* must be a ctypes type. diff --git a/Doc/library/idle.rst b/Doc/library/idle.rst --- a/Doc/library/idle.rst +++ b/Doc/library/idle.rst @@ -128,7 +128,7 @@ Search for the currently selected string, if there is one. Find in Files... - Open a file search dialog. Put results in an new output window. + Open a file search dialog. Put results in a new output window. Replace... Open a search-and-replace dialog. diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -342,7 +342,7 @@ Return the path to an executable which would be run if the given *cmd* was called. If no *cmd* would be called, return ``None``. - *mode* is a permission mask passed a to :func:`os.access`, by default + *mode* is a permission mask passed to :func:`os.access`, by default determining if the file exists and executable. When no *path* is specified, the results of :func:`os.environ` are used, diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst --- a/Doc/library/tarfile.rst +++ b/Doc/library/tarfile.rst @@ -129,7 +129,7 @@ | ``'r|bz2'`` | Open a bzip2 compressed *stream* for | | | reading. | +-------------+--------------------------------------------+ - | ``'r|xz'`` | Open a lzma compressed *stream* for | + | ``'r|xz'`` | Open an lzma compressed *stream* for | | | reading. | +-------------+--------------------------------------------+ | ``'w|'`` | Open an uncompressed *stream* for writing. | diff --git a/Doc/library/tkinter.tix.rst b/Doc/library/tkinter.tix.rst --- a/Doc/library/tkinter.tix.rst +++ b/Doc/library/tkinter.tix.rst @@ -267,7 +267,7 @@ The `ExFileSelectBox `_ - widget is usually embedded in a tixExFileSelectDialog widget. It provides an + widget is usually embedded in a tixExFileSelectDialog widget. It provides a convenient method for the user to select files. The style of the :class:`ExFileSelectBox` widget is very similar to the standard file dialog on MS Windows 3.1. diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -397,7 +397,7 @@ Though tuples may seem similar to lists, they are often used in different situations and for different purposes. -Tuples are :term:`immutable`, and usually contain an heterogeneous sequence of +Tuples are :term:`immutable`, and usually contain a heterogeneous sequence of elements that are accessed via unpacking (see later in this section) or indexing (or even by attribute in the case of :func:`namedtuples `). Lists are :term:`mutable`, and their elements are usually homogeneous and are diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst --- a/Doc/whatsnew/2.2.rst +++ b/Doc/whatsnew/2.2.rst @@ -720,7 +720,7 @@ (The controversy is over whether this is *really* a design flaw, and whether it's worth breaking existing code to fix this. It's caused endless discussions -on python-dev, and in July 2001 erupted into an storm of acidly sarcastic +on python-dev, and in July 2001 erupted into a storm of acidly sarcastic postings on :newsgroup:`comp.lang.python`. I won't argue for either side here and will stick to describing what's implemented in 2.2. Read :pep:`238` for a summary of arguments and counter-arguments.) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1457,7 +1457,7 @@ list of the loaded ``CA`` certificates. (Contributed by Christian Heimes in :issue:`18147`.) -If OpenSSL 0.9.8 or later is available, :class:`~ssl.SSLContext` has an new +If OpenSSL 0.9.8 or later is available, :class:`~ssl.SSLContext` has a new attribute :attr:`~ssl.SSLContext.verify_flags` that can be used to control the certificate verification process by setting it to some combination of the new constants :data:`~ssl.VERIFY_DEFAULT`, :data:`~ssl.VERIFY_CRL_CHECK_LEAF`, diff --git a/Include/listobject.h b/Include/listobject.h --- a/Include/listobject.h +++ b/Include/listobject.h @@ -2,7 +2,7 @@ /* List object interface */ /* -Another generally useful object type is an list of object pointers. +Another generally useful object type is a list of object pointers. This is a mutable type: the list items can be changed, and items can be added or removed. Out-of-range indices or non-list objects are ignored. diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -844,7 +844,7 @@ Py_ssize_t length /* New length */ ); -/* Decode obj to an Unicode object. +/* Decode obj to a Unicode object. bytes, bytearray and other bytes-like objects are decoded according to the given encoding and error handler. The encoding and error handler can be diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py --- a/Lib/_pydecimal.py +++ b/Lib/_pydecimal.py @@ -252,7 +252,7 @@ class ConversionSyntax(InvalidOperation): """Trying to convert badly formed string. - This occurs and signals invalid-operation if an string is being + This occurs and signals invalid-operation if a string is being converted to a number and it does not conform to the numeric string syntax. The result is [0,qNaN]. """ diff --git a/Lib/_pyio.py b/Lib/_pyio.py --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -439,7 +439,7 @@ return self.__closed def _checkClosed(self, msg=None): - """Internal: raise an ValueError if file is closed + """Internal: raise a ValueError if file is closed """ if self.closed: raise ValueError("I/O operation on closed file." diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -387,7 +387,7 @@ The address must be already resolved to avoid the trap of hanging the entire event loop when the address requires doing a DNS lookup. For - example, it must be an IP address, not an hostname, for AF_INET and + example, it must be an IP address, not a hostname, for AF_INET and AF_INET6 address families. Use getaddrinfo() to resolve the hostname asynchronously. diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -1522,7 +1522,7 @@ This is not the RFC ctext, since we are handling nested comments in comment and unquoting quoted-pairs here. We allow anything except the '()' characters, but if we find any ASCII other than the RFC defined printable - ASCII an NonPrintableDefect is added to the token's defects list. Since + ASCII, a NonPrintableDefect is added to the token's defects list. Since quoted pairs are converted to their unquoted values, what is returned is a 'ptext' token. In this case it is a WhiteSpaceTerminal, so it's value is ' '. @@ -1537,7 +1537,7 @@ """qcontent = qtext / quoted-pair We allow anything except the DQUOTE character, but if we find any ASCII - other than the RFC defined printable ASCII an NonPrintableDefect is + other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Any quoted pairs are converted to their unquoted values, so what is returned is a 'ptext' token. In this case it is a ValueTerminal. @@ -1882,7 +1882,7 @@ obs-dtext = obs-NO-WS-CTL / quoted-pair We allow anything except the excluded characters, but if we find any - ASCII other than the RFC defined printable ASCII an NonPrintableDefect is + ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Quoted pairs are converted to their unquoted values, so what is returned is a ptext token, in this case a ValueTerminal. If there were quoted-printables, an ObsoleteHeaderDefect is diff --git a/Lib/email/headerregistry.py b/Lib/email/headerregistry.py --- a/Lib/email/headerregistry.py +++ b/Lib/email/headerregistry.py @@ -109,7 +109,7 @@ def __init__(self, display_name=None, addresses=None): """Create an object representing an address group. - An address group consists of a display_name followed by colon and an + An address group consists of a display_name followed by colon and a list of addresses (see Address) terminated by a semi-colon. The Group is created by specifying a display_name and a possibly empty list of Address objects. A Group can also be used to represent a single diff --git a/Lib/idlelib/AutoComplete.py b/Lib/idlelib/AutoComplete.py --- a/Lib/idlelib/AutoComplete.py +++ b/Lib/idlelib/AutoComplete.py @@ -64,7 +64,7 @@ def try_open_completions_event(self, event): """Happens when it would be nice to open a completion list, but not - really necessary, for example after an dot, so function + really necessary, for example after a dot, so function calls won't be made. """ lastchar = self.text.get("insert-1c") diff --git a/Lib/idlelib/Debugger.py b/Lib/idlelib/Debugger.py --- a/Lib/idlelib/Debugger.py +++ b/Lib/idlelib/Debugger.py @@ -372,7 +372,7 @@ def __init__(self, master, flist, gui): if macosxSupport.isAquaTk(): # At least on with the stock AquaTk version on OSX 10.4 you'll - # get an shaking GUI that eventually kills IDLE if the width + # get a shaking GUI that eventually kills IDLE if the width # argument is specified. ScrolledList.__init__(self, master) else: diff --git a/Lib/idlelib/WidgetRedirector.py b/Lib/idlelib/WidgetRedirector.py --- a/Lib/idlelib/WidgetRedirector.py +++ b/Lib/idlelib/WidgetRedirector.py @@ -68,7 +68,7 @@ '''Return OriginalCommand(operation) after registering function. Registration adds an operation: function pair to ._operations. - It also adds an widget function attribute that masks the tkinter + It also adds a widget function attribute that masks the tkinter class instance method. Method masking operates independently from command dispatch. diff --git a/Lib/idlelib/configDialog.py b/Lib/idlelib/configDialog.py --- a/Lib/idlelib/configDialog.py +++ b/Lib/idlelib/configDialog.py @@ -1196,7 +1196,7 @@ All values are treated as text, and it is up to the user to supply reasonable values. The only exception to this are the 'enable*' options, - which are boolean, and can be toggled with an True/False button. + which are boolean, and can be toggled with a True/False button. """ parent = self.parent frame = self.tabPages.pages['Extensions'].frame diff --git a/Lib/lib2to3/fixer_base.py b/Lib/lib2to3/fixer_base.py --- a/Lib/lib2to3/fixer_base.py +++ b/Lib/lib2to3/fixer_base.py @@ -49,7 +49,7 @@ """Initializer. Subclass may override. Args: - options: an dict containing the options passed to RefactoringTool + options: a dict containing the options passed to RefactoringTool that could be used to customize the fixer through the command line. log: a list to append warnings and other messages to. """ diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py --- a/Lib/lib2to3/refactor.py +++ b/Lib/lib2to3/refactor.py @@ -184,7 +184,7 @@ Args: fixer_names: a list of fixers to import - options: an dict with configuration. + options: a dict with configuration. explicit: a list of fixers to run even if they are explicit. """ self.fixers = fixer_names diff --git a/Lib/lzma.py b/Lib/lzma.py --- a/Lib/lzma.py +++ b/Lib/lzma.py @@ -279,7 +279,7 @@ constructor: LZMAFile(filename, mode, ...). In this case, the encoding, errors and newline arguments must not be provided. - For text mode, a LZMAFile object is created, and wrapped in an + For text mode, an LZMAFile object is created, and wrapped in an io.TextIOWrapper instance with the specified encoding, error handling behavior, and line ending(s). diff --git a/Lib/mailbox.py b/Lib/mailbox.py --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1821,7 +1821,7 @@ _type_specific_attributes = ['_labels', '_visible'] def __init__(self, message=None): - """Initialize an BabylMessage instance.""" + """Initialize a BabylMessage instance.""" self._labels = [] self._visible = Message() Message.__init__(self, message) diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py --- a/Lib/multiprocessing/managers.py +++ b/Lib/multiprocessing/managers.py @@ -842,7 +842,7 @@ def MakeProxyType(name, exposed, _cache={}): ''' - Return an proxy type whose methods are given by `exposed` + Return a proxy type whose methods are given by `exposed` ''' exposed = tuple(exposed) try: diff --git a/Lib/optparse.py b/Lib/optparse.py --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -1361,7 +1361,7 @@ sys.argv[1:]). Any errors result in a call to 'error()', which by default prints the usage message to stderr and calls sys.exit() with an error message. On success returns a pair - (values, args) where 'values' is an Values instance (with all + (values, args) where 'values' is a Values instance (with all your option values) and 'args' is the list of arguments left over after parsing options. """ diff --git a/Lib/pprint.py b/Lib/pprint.py --- a/Lib/pprint.py +++ b/Lib/pprint.py @@ -72,7 +72,7 @@ class _safe_key: """Helper function for key functions when sorting unorderable objects. - The wrapped-object will fallback to an Py2.x style comparison for + The wrapped-object will fallback to a Py2.x style comparison for unorderable types (sorting first comparing the type name and then by the obj ids). Does not work recursively, so dict.items() must have _safe_key applied to both the key and the value. diff --git a/Lib/socket.py b/Lib/socket.py --- a/Lib/socket.py +++ b/Lib/socket.py @@ -685,7 +685,7 @@ global default timeout setting returned by :func:`getdefaulttimeout` is used. If *source_address* is set it must be a tuple of (host, port) for the socket to bind as a source address before making the connection. - An host of '' or port 0 tells the OS to use the default. + A host of '' or port 0 tells the OS to use the default. """ host, port = address diff --git a/Lib/socketserver.py b/Lib/socketserver.py --- a/Lib/socketserver.py +++ b/Lib/socketserver.py @@ -736,7 +736,7 @@ try: self.wfile.flush() except socket.error: - # An final socket error may have occurred here, such as + # A final socket error may have occurred here, such as # the local error ECONNABORTED. pass self.wfile.close() diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -73,7 +73,7 @@ def CheckStatementFinalizationOnCloseDb(self): # pysqlite versions <= 2.3.3 only finalized statements in the statement # cache when closing the database. statements that were still - # referenced in cursors weren't closed an could provoke " + # referenced in cursors weren't closed and could provoke " # "OperationalError: Unable to close due to unfinalised statements". con = sqlite.connect(":memory:") cursors = [] diff --git a/Lib/tarfile.py b/Lib/tarfile.py --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -1525,9 +1525,9 @@ 'x' or 'x:' create a tarfile exclusively without compression, raise an exception if the file is already created - 'x:gz' create an gzip compressed tarfile, raise an exception + 'x:gz' create a gzip compressed tarfile, raise an exception if the file is already created - 'x:bz2' create an bzip2 compressed tarfile, raise an exception + 'x:bz2' create a bzip2 compressed tarfile, raise an exception if the file is already created 'x:xz' create an lzma compressed tarfile, raise an exception if the file is already created diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py --- a/Lib/test/test_asyncio/test_selector_events.py +++ b/Lib/test/test_asyncio/test_selector_events.py @@ -1182,7 +1182,7 @@ self.assertIs(exc, waiter.exception()) def test_cancel_handshake(self): - # Python issue #23197: cancelling an handshake must not raise an + # Python issue #23197: cancelling a handshake must not raise an # exception or log an error, even if the handshake failed waiter = asyncio.Future(loop=self.loop) transport = self.ssl_transport(waiter=waiter) diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py --- a/Lib/test/test_asyncio/test_sslproto.py +++ b/Lib/test/test_asyncio/test_sslproto.py @@ -40,7 +40,7 @@ ssl_proto.connection_made(transport) def test_cancel_handshake(self): - # Python issue #23197: cancelling an handshake must not raise an + # Python issue #23197: cancelling a handshake must not raise an # exception or log an error, even if the handshake failed waiter = asyncio.Future(loop=self.loop) ssl_proto = self.ssl_protocol(waiter) diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py --- a/Lib/test/test_binop.py +++ b/Lib/test/test_binop.py @@ -58,7 +58,7 @@ den = property(_get_den, None) def __repr__(self): - """Convert a Rat to an string resembling a Rat constructor call.""" + """Convert a Rat to a string resembling a Rat constructor call.""" return "Rat(%d, %d)" % (self.__num, self.__den) def __str__(self): diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -683,7 +683,7 @@ sys.stderr = stderr def test_stderr_None(self): - # Issue #21497: provide an helpful error if sys.stderr is None, + # Issue #21497: provide a helpful error if sys.stderr is None, # instead of just an attribute error: "None has no attribute fileno". with self.check_stderr_none(): faulthandler.enable() diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -200,7 +200,7 @@ def _check_str_subclass(self, *args): # Issue #21127: it should be possible to construct a PurePath object - # from an str subclass instance, and it then gets converted to + # from a str subclass instance, and it then gets converted to # a pure str object. class StrSubclass(str): pass diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -644,7 +644,7 @@ self.assertEqual(os.path.abspath(sys.executable), sys.executable) # Issue #7774: Ensure that sys.executable is an empty string if argv[0] - # has been set to an non existent program name and Python is unable to + # has been set to a non existent program name and Python is unable to # retrieve the real program name # For a normal installation, it should work without 'cwd' diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -1082,7 +1082,7 @@ eventtype = staticmethod(threading.Event) class ConditionAsRLockTests(lock_tests.RLockTests): - # An Condition uses an RLock by default and exports its API. + # Condition uses an RLock by default and exports its API. locktype = staticmethod(threading.Condition) class ConditionTests(lock_tests.ConditionTests): diff --git a/Lib/test/test_tools/test_gprof2html.py b/Lib/test/test_tools/test_gprof2html.py --- a/Lib/test/test_tools/test_gprof2html.py +++ b/Lib/test/test_tools/test_gprof2html.py @@ -22,7 +22,7 @@ sys.argv = [] def test_gprof(self): - # Issue #14508: this used to fail with an NameError. + # Issue #14508: this used to fail with a NameError. with mock.patch.object(self.gprof, 'webbrowser') as wmock, \ tempfile.TemporaryDirectory() as tmpdir: fn = os.path.join(tmpdir, 'abc') diff --git a/Lib/test/test_zipapp.py b/Lib/test/test_zipapp.py --- a/Lib/test/test_zipapp.py +++ b/Lib/test/test_zipapp.py @@ -195,7 +195,7 @@ self.assertTrue(new_target.getvalue().startswith(b'#!python2.7\n')) def test_read_from_pathobj(self): - # Test that we can copy an archive using an pathlib.Path object + # Test that we can copy an archive using a pathlib.Path object # for the source. source = self.tmpdir / 'source' source.mkdir() diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -2772,7 +2772,7 @@ self.deletecommand(c) self.tk.call(self._w, 'delete', index1, index2) def entrycget(self, index, option): - """Return the resource value of an menu item for OPTION at INDEX.""" + """Return the resource value of a menu item for OPTION at INDEX.""" return self.tk.call(self._w, 'entrycget', index, '-' + option) def entryconfigure(self, index, cnf=None, **kw): """Configure a menu item at INDEX.""" diff --git a/Lib/tkinter/dnd.py b/Lib/tkinter/dnd.py --- a/Lib/tkinter/dnd.py +++ b/Lib/tkinter/dnd.py @@ -3,7 +3,7 @@ This is very preliminary. I currently only support dnd *within* one application, between different windows (or within the same window). -I an trying to make this as generic as possible -- not dependent on +I am trying to make this as generic as possible -- not dependent on the use of a particular widget or icon type, etc. I also hope that this will work with Pmw. diff --git a/Lib/tkinter/test/test_ttk/test_functions.py b/Lib/tkinter/test/test_ttk/test_functions.py --- a/Lib/tkinter/test/test_ttk/test_functions.py +++ b/Lib/tkinter/test/test_ttk/test_functions.py @@ -193,7 +193,7 @@ ## Testing type = vsapi # vsapi type expects at least a class name and a part_id, so this - # should raise an ValueError since it tries to get two elements from + # should raise a ValueError since it tries to get two elements from # an empty tuple self.assertRaises(ValueError, ttk._format_elemcreate, 'vsapi') diff --git a/Lib/tkinter/tix.py b/Lib/tkinter/tix.py --- a/Lib/tkinter/tix.py +++ b/Lib/tkinter/tix.py @@ -221,7 +221,7 @@ self.tk.eval('package require Tix') def destroy(self): - # For safety, remove an delete_window binding before destroy + # For safety, remove the delete_window binding before destroy self.protocol("WM_DELETE_WINDOW", "") tkinter.Tk.destroy(self) @@ -702,7 +702,7 @@ class ExFileSelectBox(TixWidget): """ExFileSelectBox - MS Windows style file select box. - It provides an convenient method for the user to select files. + It provides a convenient method for the user to select files. Subwidget Class --------- ----- @@ -760,7 +760,7 @@ # Should inherit from a Dialog class class ExFileSelectDialog(TixWidget): """ExFileSelectDialog - MS Windows style file select dialog. - It provides an convenient method for the user to select files. + It provides a convenient method for the user to select files. Subwidgets Class ---------- ----- diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py --- a/Lib/tkinter/ttk.py +++ b/Lib/tkinter/ttk.py @@ -1474,7 +1474,7 @@ can be accessed through instance.label""" def __init__(self, master=None, variable=None, from_=0, to=10, **kw): - """Construct an horizontal LabeledScale with parent master, a + """Construct a horizontal LabeledScale with parent master, a variable to be associated with the Ttk Scale widget and its range. If variable is not specified, a tkinter.IntVar is created. diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -1446,7 +1446,7 @@ # magic method dispatcher return _Method(self.__request, name) - # note: to call a remote object with an non-standard name, use + # note: to call a remote object with a non-standard name, use # result getattr(server, "strange-python-name")(args) def __call__(self, attr): diff --git a/Lib/zipapp.py b/Lib/zipapp.py --- a/Lib/zipapp.py +++ b/Lib/zipapp.py @@ -89,9 +89,10 @@ The created application archive will have a shebang line specifying that it should run with INTERPRETER (there will be no shebang line if INTERPRETER is None), and a __main__.py which runs MAIN (if MAIN is - not specified, an existing __main__.py will be used). It is an to specify - MAIN for anything other than a directory source with no __main__.py, and it - is an error to omit MAIN if the directory has no __main__.py. + not specified, an existing __main__.py will be used). It is an error + to specify MAIN for anything other than a directory source with no + __main__.py, and it is an error to omit MAIN if the directory has no + __main__.py. """ # Are we copying an existing archive? source_is_file = False diff --git a/Misc/HISTORY b/Misc/HISTORY --- a/Misc/HISTORY +++ b/Misc/HISTORY @@ -7220,7 +7220,7 @@ cElementTree module is updated too. - Issue #7774: Set sys.executable to an empty string if argv[0] has been set to - an non existent program name and Python is unable to retrieve the real program + a non existent program name and Python is unable to retrieve the real program name. - Issue #7880: Fix sysconfig when the python executable is a symbolic link. @@ -14013,7 +14013,7 @@ would not be removed while allocating a new weakref object. Since GC could be invoked at that time, however, that assumption was invalid. In a truly obscure case of GC being triggered during - creation for a new weakref object for an referent which already + creation for a new weakref object for a referent which already has a weakref without a callback which is only referenced from cyclic trash, a memory error can occur. This consistently created a segfault in a debug build, but provided less predictable behavior in @@ -18737,7 +18737,7 @@ - xml.dom.minidom offers a toprettyxml method. A number of DOM conformance issues have been resolved. In particular, Element now - has an hasAttributes method, and the handling of namespaces was + has a hasAttributes method, and the handling of namespaces was improved. - Ka-Ping Yee contributed two new modules: inspect.py, a module for @@ -20227,7 +20227,7 @@ Probably the most pervasive change is the addition of Unicode support. We've added a new fundamental datatype, the Unicode string, a new -build-in function unicode(), an numerous C APIs to deal with Unicode +built-in function unicode(), and numerous C APIs to deal with Unicode and encodings. See the file Misc/unicode.txt for details, or http://starship.python.net/crew/lemburg/unicode-proposal.txt. @@ -21712,7 +21712,7 @@ - The uu module now deals better with trailing garbage generated by some broke uuencoders. -- The telnet module now has an my_interact() method which uses threads +- The telnet module now has a my_interact() method which uses threads instead of select. The interact() method uses this by default on Windows (where the single-threaded version doesn't work). @@ -22769,7 +22769,7 @@ - New macros to access object members for PyFunction, PyCFunction objects. -- New APIs PyImport_AppendInittab() an PyImport_ExtendInittab() to +- New APIs PyImport_AppendInittab() and PyImport_ExtendInittab() to dynamically add one or many entries to the table of built-in modules. - New macro Py_InitModule3(name, methods, doc) which calls @@ -27179,7 +27179,7 @@ * repr(x) returns the same as `x`. (Some users found it easier to have this as a function.) -* round(x) returns the floating point number x rounded to an whole +* round(x) returns the floating point number x rounded to a whole number, represented as a floating point number. round(x, n) returns x rounded to n digits. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -1169,7 +1169,7 @@ - Issue #24407: Fix crash when dict is mutated while being updated. - Issue #24619: New approach for tokenizing async/await. As a consequence, - is is now possible to have one-line 'async def foo(): await ..' functions. + it is now possible to have one-line 'async def foo(): await ..' functions. - Issue #24687: Plug refleak on SyntaxError in function parameters annotations. @@ -3515,7 +3515,7 @@ - Issue #21000: Improve the command-line interface of json.tool. - Issue #20995: Enhance default ciphers used by the ssl module to enable - better security an prioritize perfect forward secrecy. + better security and prioritize perfect forward secrecy. - Issue #20884: Don't assume that __file__ is defined on importlib.__init__. diff --git a/Modules/_csv.c b/Modules/_csv.c --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -731,7 +731,7 @@ break; case QUOTE_IN_QUOTED_FIELD: - /* doublequote - seen a quote in an quoted field */ + /* doublequote - seen a quote in a quoted field */ if (dialect->quoting != QUOTE_NONE && c == dialect->quotechar) { /* save "" as " */ diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -3802,7 +3802,7 @@ return NULL; } /* there should be more checks? No, in Python */ - /* First arg is an pointer to an interface instance */ + /* First arg is a pointer to an interface instance */ if (!this->b_ptr || *(void **)this->b_ptr == NULL) { PyErr_SetString(PyExc_ValueError, "NULL COM pointer access"); diff --git a/Modules/_pickle.c b/Modules/_pickle.c --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -4629,7 +4629,7 @@ /* s contains x bytes of a little-endian integer. Return its value as a * C int. Obscure: when x is 1 or 2, this is an unsigned little-endian - * int, but when x is 4 it's a signed one. This is an historical source + * int, but when x is 4 it's a signed one. This is a historical source * of x-platform bugs. */ static long diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -519,7 +519,7 @@ the caller, because realloc() may already have shrinked the memory block and so removed bytes. - This case is very unlikely: an hash entry has just been + This case is very unlikely: a hash entry has just been released, so the hash table should have at least one free entry. The GIL and the table lock ensures that only one thread is diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -1051,7 +1051,7 @@ {"register", (PyCFunction)faulthandler_register_py, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("register(signum, file=sys.stderr, all_threads=True, chain=False): " - "register an handler for the signal 'signum': dump the " + "register a handler for the signal 'signum': dump the " "traceback of the current thread, or of all threads if " "all_threads is True, into file")}, {"unregister", diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -4483,7 +4483,7 @@ PyDoc_STRVAR(zip_longest_doc, "zip_longest(iter1 [,iter2 [...]], [fillvalue=None]) --> zip_longest object\n\ \n\ -Return an zip_longest object whose .__next__() method returns a tuple where\n\ +Return a zip_longest object whose .__next__() method returns a tuple where\n\ the i-th element comes from the i-th iterable argument. The .__next__()\n\ method continues until the longest iterable in the argument sequence\n\ is exhausted and then it raises StopIteration. When the shorter iterables\n\ diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -3091,7 +3091,7 @@ bytearray(int) -> bytes array of size given by the parameter initialized with null bytes\n\ bytearray() -> empty bytes array\n\ \n\ -Construct an mutable bytearray object from:\n\ +Construct a mutable bytearray object from:\n\ - an iterable yielding integers in range(256)\n\ - a text string encoded using the specified encoding\n\ - a bytes or a buffer object\n\ diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -5,7 +5,7 @@ /* Support objects whose length is > PY_SSIZE_T_MAX. - This could be sped up for small PyLongs if they fit in an Py_ssize_t. + This could be sped up for small PyLongs if they fit in a Py_ssize_t. This only matters on Win64. Though we could use PY_LONG_LONG which would presumably help perf. */ diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h --- a/Objects/stringlib/unicode_format.h +++ b/Objects/stringlib/unicode_format.h @@ -1226,7 +1226,7 @@ 0}; /* unicode_formatter_field_name_split is used to implement - string.Formatter.vformat. it takes an PEP 3101 "field name", and + string.Formatter.vformat. it takes a PEP 3101 "field name", and returns a tuple of (first, rest): "first", the part before the first '.' or '['; and "rest", an iterator for the rest of the field name. it's a wrapper around stringlib/string_format.h's diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h --- a/PC/clinic/winreg.c.h +++ b/PC/clinic/winreg.c.h @@ -120,7 +120,7 @@ "ConnectRegistry($module, computer_name, key, /)\n" "--\n" "\n" -"Establishes a connection to the registry on on another computer.\n" +"Establishes a connection to the registry on another computer.\n" "\n" " computer_name\n" " The name of the remote computer, of the form r\"\\\\computername\". If\n" @@ -913,7 +913,7 @@ " references to environment variables (for example,\n" " %PATH%).\n" " REG_LINK -- A Unicode symbolic link.\n" -" REG_MULTI_SZ -- An sequence of null-terminated strings, terminated\n" +" REG_MULTI_SZ -- A sequence of null-terminated strings, terminated\n" " by two null characters. Note that Python handles\n" " this termination automatically.\n" " REG_NONE -- No defined value type.\n" @@ -1056,4 +1056,4 @@ exit: return return_value; } -/*[clinic end generated code: output=71f5bc30b646807b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5e346dccc296f9f1 input=a9049054013a1b77]*/ diff --git a/PC/winreg.c b/PC/winreg.c --- a/PC/winreg.c +++ b/PC/winreg.c @@ -792,7 +792,7 @@ The predefined key to connect to. / -Establishes a connection to the registry on on another computer. +Establishes a connection to the registry on another computer. The return value is the handle of the opened key. If the function fails, an OSError exception is raised. @@ -801,7 +801,7 @@ static HKEY winreg_ConnectRegistry_impl(PyModuleDef *module, Py_UNICODE *computer_name, HKEY key) -/*[clinic end generated code: output=5c52f6f7ba6e7b46 input=9a056558ce318433]*/ +/*[clinic end generated code: output=5c52f6f7ba6e7b46 input=5f98a891a347e68e]*/ { HKEY retKey; long rc; @@ -1605,7 +1605,7 @@ references to environment variables (for example, %PATH%). REG_LINK -- A Unicode symbolic link. - REG_MULTI_SZ -- An sequence of null-terminated strings, terminated + REG_MULTI_SZ -- A sequence of null-terminated strings, terminated by two null characters. Note that Python handles this termination automatically. REG_NONE -- No defined value type. @@ -1631,7 +1631,7 @@ static PyObject * winreg_SetValueEx_impl(PyModuleDef *module, HKEY key, Py_UNICODE *value_name, PyObject *reserved, DWORD type, PyObject *value) -/*[clinic end generated code: output=ea092a935c361582 input=e73dec535ebeea7d]*/ +/*[clinic end generated code: output=ea092a935c361582 input=f1b16cbcc3ed4101]*/ { BYTE *data; DWORD len; diff --git a/Python/thread_nt.h b/Python/thread_nt.h --- a/Python/thread_nt.h +++ b/Python/thread_nt.h @@ -231,7 +231,7 @@ } /* - * Return the thread Id instead of an handle. The Id is said to uniquely identify the + * Return the thread Id instead of a handle. The Id is said to uniquely identify the * thread in the system */ long -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 17 02:40:15 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 17 Apr 2016 06:40:15 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2Nzc4?= =?utf-8?q?=3A_Fixed_=22a/an/and=22_typos_in_code_comment_and_documentatio?= =?utf-8?q?n=2E?= Message-ID: <20160417064014.88656.85749.F08CF13C@psf.io> https://hg.python.org/cpython/rev/bbcde8db4dc4 changeset: 101037:bbcde8db4dc4 branch: 2.7 parent: 101030:eef8f72ddb00 user: Serhiy Storchaka date: Sun Apr 17 09:37:36 2016 +0300 summary: Issue #26778: Fixed "a/an/and" typos in code comment and documentation. files: Demo/tix/samples/Balloon.py | 2 +- Demo/tix/samples/CmpImg.py | 2 +- Doc/c-api/object.rst | 2 +- Doc/c-api/set.rst | 6 ++-- Doc/c-api/unicode.rst | 2 +- Doc/distutils/apiref.rst | 2 +- Doc/howto/urllib2.rst | 2 +- Doc/library/ctypes.rst | 6 ++-- Doc/library/fl.rst | 2 +- Doc/library/idle.rst | 2 +- Doc/library/marshal.rst | 2 +- Doc/library/pyexpat.rst | 2 +- Doc/library/restricted.rst | 2 +- Doc/library/sgmllib.rst | 2 +- Doc/library/sunaudio.rst | 2 +- Doc/library/tarfile.rst | 4 +- Doc/library/tix.rst | 2 +- Doc/library/urllib.rst | 2 +- Doc/tutorial/datastructures.rst | 2 +- Doc/tutorial/introduction.rst | 2 +- Doc/whatsnew/2.2.rst | 2 +- Doc/whatsnew/2.3.rst | 2 +- Include/listobject.h | 2 +- Lib/SocketServer.py | 2 +- Lib/_pyio.py | 4 +- Lib/calendar.py | 2 +- Lib/decimal.py | 2 +- Lib/difflib.py | 2 +- Lib/distutils/cygwinccompiler.py | 4 +- Lib/getopt.py | 2 +- Lib/idlelib/AutoComplete.py | 2 +- Lib/idlelib/Debugger.py | 2 +- Lib/idlelib/WidgetRedirector.py | 2 +- Lib/idlelib/configDialog.py | 2 +- Lib/lib-tk/Tix.py | 6 ++-- Lib/lib-tk/Tkdnd.py | 2 +- Lib/lib-tk/Tkinter.py | 2 +- Lib/lib-tk/test/test_ttk/test_functions.py | 2 +- Lib/lib-tk/ttk.py | 4 +- Lib/lib2to3/fixer_base.py | 2 +- Lib/lib2to3/refactor.py | 2 +- Lib/mailbox.py | 2 +- Lib/multiprocessing/managers.py | 2 +- Lib/optparse.py | 2 +- Lib/plat-irix5/flp.py | 2 +- Lib/plat-irix6/flp.py | 2 +- Lib/plat-mac/lib-scriptpackages/Finder/Files.py | 2 +- Lib/plat-mac/lib-scriptpackages/SystemEvents/Processes_Suite.py | 2 +- Lib/socket.py | 2 +- Lib/sqlite3/test/factory.py | 2 +- Lib/sqlite3/test/regression.py | 2 +- Lib/test/test_binop.py | 4 +- Lib/test/test_cmd.py | 2 +- Lib/test/test_codecs.py | 2 +- Lib/test/test_doctest.py | 2 +- Lib/test/test_extcall.py | 2 +- Lib/test/test_mutants.py | 2 +- Lib/test/test_sys.py | 2 +- Lib/test/test_threading.py | 2 +- Lib/xmlrpclib.py | 4 +- Mac/Demo/applescript/Disk_Copy/Special_Events.py | 2 +- Misc/HISTORY | 12 +++++----- Modules/_csv.c | 2 +- Modules/_ctypes/_ctypes.c | 2 +- Modules/cPickle.c | 2 +- Objects/bytearrayobject.c | 2 +- Objects/stringlib/string_format.h | 2 +- PC/_winreg.c | 2 +- Python/thread_nt.h | 2 +- Python/thread_wince.h | 2 +- Tools/gdb/libpython.py | 4 +- Tools/msi/msi.py | 2 +- 72 files changed, 90 insertions(+), 90 deletions(-) diff --git a/Demo/tix/samples/Balloon.py b/Demo/tix/samples/Balloon.py --- a/Demo/tix/samples/Balloon.py +++ b/Demo/tix/samples/Balloon.py @@ -11,7 +11,7 @@ # program. # This file demonstrates the use of the tixBalloon widget, which provides -# a interesting way to give help tips about elements in your user interface. +# an interesting way to give help tips about elements in your user interface. # Your can display the help message in a "balloon" and a status bar widget. # diff --git a/Demo/tix/samples/CmpImg.py b/Demo/tix/samples/CmpImg.py --- a/Demo/tix/samples/CmpImg.py +++ b/Demo/tix/samples/CmpImg.py @@ -155,7 +155,7 @@ net = Tix.Button(w, padx=4, pady=1, width=120) # Create the first image: we create a line, then put a string, - # a space and a image into this line, from left to right. + # a space and an image into this line, from left to right. # The result: we have a one-line image that consists of three # individual items # diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -157,7 +157,7 @@ .. index:: builtin: bytes - Compute a bytes representation of object *o*. In 2.x, this is just a alias + Compute a bytes representation of object *o*. In 2.x, this is just an alias for :c:func:`PyObject_Str`. diff --git a/Doc/c-api/set.rst b/Doc/c-api/set.rst --- a/Doc/c-api/set.rst +++ b/Doc/c-api/set.rst @@ -140,7 +140,7 @@ Add *key* to a :class:`set` instance. Does not apply to :class:`frozenset` instances. Return 0 on success or -1 on failure. Raise a :exc:`TypeError` if the *key* is unhashable. Raise a :exc:`MemoryError` if there is no room to grow. - Raise a :exc:`SystemError` if *set* is an not an instance of :class:`set` or its + Raise a :exc:`SystemError` if *set* is not an instance of :class:`set` or its subtype. .. versionchanged:: 2.6 @@ -158,7 +158,7 @@ error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a :exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~set.discard` method, this function does not automatically convert unhashable sets into - temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is an not an + temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is not an instance of :class:`set` or its subtype. @@ -166,7 +166,7 @@ Return a new reference to an arbitrary object in the *set*, and removes the object from the *set*. Return *NULL* on failure. Raise :exc:`KeyError` if the - set is empty. Raise a :exc:`SystemError` if *set* is an not an instance of + set is empty. Raise a :exc:`SystemError` if *set* is not an instance of :class:`set` or its subtype. diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -260,7 +260,7 @@ | :attr:`%%` | *n/a* | The literal % character. | +-------------------+---------------------+--------------------------------+ | :attr:`%c` | int | A single character, | - | | | represented as an C int. | + | | | represented as a C int. | +-------------------+---------------------+--------------------------------+ | :attr:`%d` | int | Exactly equivalent to | | | | ``printf("%d")``. | diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -832,7 +832,7 @@ .. module:: distutils.bcppcompiler -This module provides :class:`BorlandCCompiler`, an subclass of the abstract +This module provides :class:`BorlandCCompiler`, a subclass of the abstract :class:`CCompiler` class for the Borland C++ compiler. diff --git a/Doc/howto/urllib2.rst b/Doc/howto/urllib2.rst --- a/Doc/howto/urllib2.rst +++ b/Doc/howto/urllib2.rst @@ -6,7 +6,7 @@ .. note:: - There is an French translation of an earlier revision of this + There is a French translation of an earlier revision of this HOWTO, available at `urllib2 - Le Manuel manquant `_. diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -657,7 +657,7 @@ TenPointsArrayType = POINT * 10 -Here is an example of an somewhat artificial data type, a structure containing 4 +Here is an example of a somewhat artificial data type, a structure containing 4 POINTs among other stuff:: >>> from ctypes import * @@ -1576,7 +1576,7 @@ tuple, this method allows adapting the actual argument to an object that the foreign function accepts. For example, a :class:`c_char_p` item in the :attr:`argtypes` tuple will convert a unicode string passed as - argument into an byte string using ctypes conversion rules. + argument into a byte string using ctypes conversion rules. New: It is now possible to put items in argtypes which are not ctypes types, but each item must have a :meth:`from_param` method which returns a @@ -1964,7 +1964,7 @@ .. function:: POINTER(type) This factory function creates and returns a new ctypes pointer type. Pointer - types are cached an reused internally, so calling this function repeatedly is + types are cached and reused internally, so calling this function repeatedly is cheap. *type* must be a ctypes type. diff --git a/Doc/library/fl.rst b/Doc/library/fl.rst --- a/Doc/library/fl.rst +++ b/Doc/library/fl.rst @@ -310,7 +310,7 @@ .. method:: form.add_input(type, x, y, w, h, name) - Add a input object to the form. --- Methods: :meth:`set_input`, + Add an input object to the form. --- Methods: :meth:`set_input`, :meth:`get_input`, :meth:`set_input_color`, :meth:`set_input_return`. diff --git a/Doc/library/idle.rst b/Doc/library/idle.rst --- a/Doc/library/idle.rst +++ b/Doc/library/idle.rst @@ -128,7 +128,7 @@ Search for the currently selected string, if there is one. Find in Files... - Open a file search dialog. Put results in an new output window. + Open a file search dialog. Put results in a new output window. Replace... Open a search-and-replace dialog. diff --git a/Doc/library/marshal.rst b/Doc/library/marshal.rst --- a/Doc/library/marshal.rst +++ b/Doc/library/marshal.rst @@ -66,7 +66,7 @@ .. function:: dump(value, file[, version]) Write the value on the open file. The value must be a supported type. The - file must be a open file object such as ``sys.stdout`` or returned by + file must be an open file object such as ``sys.stdout`` or returned by :func:`open` or :func:`os.popen`. It may not be a wrapper such as TemporaryFile on Windows. It must be opened in binary mode (``'wb'`` or ``'w+b'``). diff --git a/Doc/library/pyexpat.rst b/Doc/library/pyexpat.rst --- a/Doc/library/pyexpat.rst +++ b/Doc/library/pyexpat.rst @@ -788,7 +788,7 @@ .. data:: XML_ERROR_UNDEFINED_ENTITY :noindex: - A reference was made to a entity which was not defined. + A reference was made to an entity which was not defined. .. data:: XML_ERROR_UNKNOWN_ENCODING diff --git a/Doc/library/restricted.rst b/Doc/library/restricted.rst --- a/Doc/library/restricted.rst +++ b/Doc/library/restricted.rst @@ -34,7 +34,7 @@ *mode* parameter is ``'w'``. It might also perform a :c:func:`chroot`\ -like operation on the *filename* parameter, such that root is always relative to some safe "sandbox" area of the filesystem. In this case, the untrusted code would -still see an built-in :func:`open` function in its environment, with the same +still see a built-in :func:`open` function in its environment, with the same calling interface. The semantics would be identical too, with :exc:`IOError`\ s being raised when the supervisor determined that an unallowable parameter is being used. diff --git a/Doc/library/sgmllib.rst b/Doc/library/sgmllib.rst --- a/Doc/library/sgmllib.rst +++ b/Doc/library/sgmllib.rst @@ -162,7 +162,7 @@ .. method:: SGMLParser.handle_entityref(ref) This method is called to process a general entity reference of the form - ``&ref;`` where *ref* is an general entity reference. It converts *ref* by + ``&ref;`` where *ref* is a general entity reference. It converts *ref* by passing it to :meth:`convert_entityref`. If a translation is returned, it calls the method :meth:`handle_data` with the translation; otherwise, it calls the method ``unknown_entityref(ref)``. The default :attr:`entitydefs` defines diff --git a/Doc/library/sunaudio.rst b/Doc/library/sunaudio.rst --- a/Doc/library/sunaudio.rst +++ b/Doc/library/sunaudio.rst @@ -123,7 +123,7 @@ .. method:: audio device.setinfo(status) This method sets the audio device status parameters. The *status* parameter is - an device status object as returned by :func:`getinfo` and possibly modified by + a device status object as returned by :func:`getinfo` and possibly modified by the program. diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst --- a/Doc/library/tarfile.rst +++ b/Doc/library/tarfile.rst @@ -110,10 +110,10 @@ +-------------+--------------------------------------------+ | ``'w|'`` | Open an uncompressed *stream* for writing. | +-------------+--------------------------------------------+ - | ``'w|gz'`` | Open an gzip compressed *stream* for | + | ``'w|gz'`` | Open a gzip compressed *stream* for | | | writing. | +-------------+--------------------------------------------+ - | ``'w|bz2'`` | Open an bzip2 compressed *stream* for | + | ``'w|bz2'`` | Open a bzip2 compressed *stream* for | | | writing. | +-------------+--------------------------------------------+ diff --git a/Doc/library/tix.rst b/Doc/library/tix.rst --- a/Doc/library/tix.rst +++ b/Doc/library/tix.rst @@ -276,7 +276,7 @@ The `ExFileSelectBox `_ - widget is usually embedded in a tixExFileSelectDialog widget. It provides an + widget is usually embedded in a tixExFileSelectDialog widget. It provides a convenient method for the user to select files. The style of the :class:`ExFileSelectBox` widget is very similar to the standard file dialog on MS Windows 3.1. diff --git a/Doc/library/urllib.rst b/Doc/library/urllib.rst --- a/Doc/library/urllib.rst +++ b/Doc/library/urllib.rst @@ -280,7 +280,7 @@ .. function:: url2pathname(path) - Convert the path component *path* from an percent-encoded URL to the local syntax for a + Convert the path component *path* from a percent-encoded URL to the local syntax for a path. This does not accept a complete URL. This function uses :func:`unquote` to decode *path*. diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -452,7 +452,7 @@ Though tuples may seem similar to lists, they are often used in different situations and for different purposes. -Tuples are :term:`immutable`, and usually contain an heterogeneous sequence of +Tuples are :term:`immutable`, and usually contain a heterogeneous sequence of elements that are accessed via unpacking (see later in this section) or indexing (or even by attribute in the case of :func:`namedtuples `). Lists are :term:`mutable`, and their elements are usually homogeneous and are diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -307,7 +307,7 @@ indices, if both are within bounds. For example, the length of ``word[1:3]`` is 2. -Attempting to use a index that is too large will result in an error:: +Attempting to use an index that is too large will result in an error:: >>> word[42] # the word only has 6 characters Traceback (most recent call last): diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst --- a/Doc/whatsnew/2.2.rst +++ b/Doc/whatsnew/2.2.rst @@ -720,7 +720,7 @@ (The controversy is over whether this is *really* a design flaw, and whether it's worth breaking existing code to fix this. It's caused endless discussions -on python-dev, and in July 2001 erupted into an storm of acidly sarcastic +on python-dev, and in July 2001 erupted into a storm of acidly sarcastic postings on :newsgroup:`comp.lang.python`. I won't argue for either side here and will stick to describing what's implemented in 2.2. Read :pep:`238` for a summary of arguments and counter-arguments.) diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -411,7 +411,7 @@ A new built-in function, :func:`enumerate`, will make certain loops a bit clearer. ``enumerate(thing)``, where *thing* is either an iterator or a -sequence, returns a iterator that will return ``(0, thing[0])``, ``(1, +sequence, returns an iterator that will return ``(0, thing[0])``, ``(1, thing[1])``, ``(2, thing[2])``, and so forth. A common idiom to change every element of a list looks like this:: diff --git a/Include/listobject.h b/Include/listobject.h --- a/Include/listobject.h +++ b/Include/listobject.h @@ -2,7 +2,7 @@ /* List object interface */ /* -Another generally useful object type is an list of object pointers. +Another generally useful object type is a list of object pointers. This is a mutable type: the list items can be changed, and items can be added or removed. Out-of-range indices or non-list objects are ignored. diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py --- a/Lib/SocketServer.py +++ b/Lib/SocketServer.py @@ -707,7 +707,7 @@ try: self.wfile.flush() except socket.error: - # An final socket error may have occurred here, such as + # A final socket error may have occurred here, such as # the local error ECONNABORTED. pass self.wfile.close() diff --git a/Lib/_pyio.py b/Lib/_pyio.py --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -420,7 +420,7 @@ return self.__closed def _checkClosed(self, msg=None): - """Internal: raise an ValueError if file is closed + """Internal: raise a ValueError if file is closed """ if self.closed: raise ValueError("I/O operation on closed file." @@ -2022,7 +2022,7 @@ def __repr__(self): # TextIOWrapper tells the encoding in its repr. In StringIO, - # that's a implementation detail. + # that's an implementation detail. return object.__repr__(self) @property diff --git a/Lib/calendar.py b/Lib/calendar.py --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -142,7 +142,7 @@ def iterweekdays(self): """ - Return a iterator for one week of weekday numbers starting with the + Return an iterator for one week of weekday numbers starting with the configured first one. """ for i in range(self.firstweekday, self.firstweekday + 7): diff --git a/Lib/decimal.py b/Lib/decimal.py --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -224,7 +224,7 @@ class ConversionSyntax(InvalidOperation): """Trying to convert badly formed string. - This occurs and signals invalid-operation if an string is being + This occurs and signals invalid-operation if a string is being converted to a number and it does not conform to the numeric string syntax. The result is [0,qNaN]. """ diff --git a/Lib/difflib.py b/Lib/difflib.py --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -1487,7 +1487,7 @@ yield _make_line(lines,'-',0), None, True continue elif s.startswith(('--?+', '--+', '- ')): - # in delete block and see a intraline change or unchanged line + # in delete block and see an intraline change or unchanged line # coming: yield the delete line and then blanks from_line,to_line = _make_line(lines,'-',0), None num_blanks_to_yield,num_blanks_pending = num_blanks_pending-1,0 diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py --- a/Lib/distutils/cygwinccompiler.py +++ b/Lib/distutils/cygwinccompiler.py @@ -10,9 +10,9 @@ # # * if you use a msvc compiled python version (1.5.2) # 1. you have to insert a __GNUC__ section in its config.h -# 2. you have to generate a import library for its dll +# 2. you have to generate an import library for its dll # - create a def-file for python??.dll -# - create a import library using +# - create an import library using # dlltool --dllname python15.dll --def python15.def \ # --output-lib libpython15.a # diff --git a/Lib/getopt.py b/Lib/getopt.py --- a/Lib/getopt.py +++ b/Lib/getopt.py @@ -28,7 +28,7 @@ # - RETURN_IN_ORDER option # - GNU extension with '-' as first character of option string # - optional arguments, specified by double colons -# - a option string with a W followed by semicolon should +# - an option string with a W followed by semicolon should # treat "-W foo" as "--foo" __all__ = ["GetoptError","error","getopt","gnu_getopt"] diff --git a/Lib/idlelib/AutoComplete.py b/Lib/idlelib/AutoComplete.py --- a/Lib/idlelib/AutoComplete.py +++ b/Lib/idlelib/AutoComplete.py @@ -67,7 +67,7 @@ def try_open_completions_event(self, event): """Happens when it would be nice to open a completion list, but not - really necessary, for example after an dot, so function + really necessary, for example after a dot, so function calls won't be made. """ lastchar = self.text.get("insert-1c") diff --git a/Lib/idlelib/Debugger.py b/Lib/idlelib/Debugger.py --- a/Lib/idlelib/Debugger.py +++ b/Lib/idlelib/Debugger.py @@ -373,7 +373,7 @@ def __init__(self, master, flist, gui): if macosxSupport.isAquaTk(): # At least on with the stock AquaTk version on OSX 10.4 you'll - # get an shaking GUI that eventually kills IDLE if the width + # get a shaking GUI that eventually kills IDLE if the width # argument is specified. ScrolledList.__init__(self, master) else: diff --git a/Lib/idlelib/WidgetRedirector.py b/Lib/idlelib/WidgetRedirector.py --- a/Lib/idlelib/WidgetRedirector.py +++ b/Lib/idlelib/WidgetRedirector.py @@ -68,7 +68,7 @@ '''Return OriginalCommand(operation) after registering function. Registration adds an operation: function pair to ._operations. - It also adds an widget function attribute that masks the Tkinter + It also adds a widget function attribute that masks the Tkinter class instance method. Method masking operates independently from command dispatch. diff --git a/Lib/idlelib/configDialog.py b/Lib/idlelib/configDialog.py --- a/Lib/idlelib/configDialog.py +++ b/Lib/idlelib/configDialog.py @@ -1213,7 +1213,7 @@ All values are treated as text, and it is up to the user to supply reasonable values. The only exception to this are the 'enable*' options, - which are boolean, and can be toggled with an True/False button. + which are boolean, and can be toggled with a True/False button. """ parent = self.parent frame = self.tabPages.pages['Extensions'].frame diff --git a/Lib/lib-tk/Tix.py b/Lib/lib-tk/Tix.py --- a/Lib/lib-tk/Tix.py +++ b/Lib/lib-tk/Tix.py @@ -221,7 +221,7 @@ self.tk.eval('package require Tix') def destroy(self): - # For safety, remove an delete_window binding before destroy + # For safety, remove the delete_window binding before destroy self.protocol("WM_DELETE_WINDOW", "") Tkinter.Tk.destroy(self) @@ -702,7 +702,7 @@ class ExFileSelectBox(TixWidget): """ExFileSelectBox - MS Windows style file select box. - It provides an convenient method for the user to select files. + It provides a convenient method for the user to select files. Subwidget Class --------- ----- @@ -760,7 +760,7 @@ # Should inherit from a Dialog class class ExFileSelectDialog(TixWidget): """ExFileSelectDialog - MS Windows style file select dialog. - It provides an convenient method for the user to select files. + It provides a convenient method for the user to select files. Subwidgets Class ---------- ----- diff --git a/Lib/lib-tk/Tkdnd.py b/Lib/lib-tk/Tkdnd.py --- a/Lib/lib-tk/Tkdnd.py +++ b/Lib/lib-tk/Tkdnd.py @@ -3,7 +3,7 @@ This is very preliminary. I currently only support dnd *within* one application, between different windows (or within the same window). -I an trying to make this as generic as possible -- not dependent on +I am trying to make this as generic as possible -- not dependent on the use of a particular widget or icon type, etc. I also hope that this will work with Pmw. diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -2778,7 +2778,7 @@ self.deletecommand(c) self.tk.call(self._w, 'delete', index1, index2) def entrycget(self, index, option): - """Return the resource value of an menu item for OPTION at INDEX.""" + """Return the resource value of a menu item for OPTION at INDEX.""" return self.tk.call(self._w, 'entrycget', index, '-' + option) def entryconfigure(self, index, cnf=None, **kw): """Configure a menu item at INDEX.""" diff --git a/Lib/lib-tk/test/test_ttk/test_functions.py b/Lib/lib-tk/test/test_ttk/test_functions.py --- a/Lib/lib-tk/test/test_ttk/test_functions.py +++ b/Lib/lib-tk/test/test_ttk/test_functions.py @@ -195,7 +195,7 @@ ## Testing type = vsapi # vsapi type expects at least a class name and a part_id, so this - # should raise an ValueError since it tries to get two elements from + # should raise a ValueError since it tries to get two elements from # an empty tuple self.assertRaises(ValueError, ttk._format_elemcreate, 'vsapi') diff --git a/Lib/lib-tk/ttk.py b/Lib/lib-tk/ttk.py --- a/Lib/lib-tk/ttk.py +++ b/Lib/lib-tk/ttk.py @@ -291,7 +291,7 @@ """Format options then call Tk command with args and options and return the appropriate result. - If no option is specified, a dict is returned. If a option is + If no option is specified, a dict is returned. If an option is specified with the None value, the value for that option is returned. Otherwise, the function just sets the passed options and the caller shouldn't be expecting a return value anyway.""" @@ -1476,7 +1476,7 @@ can be accessed through instance.label""" def __init__(self, master=None, variable=None, from_=0, to=10, **kw): - """Construct an horizontal LabeledScale with parent master, a + """Construct a horizontal LabeledScale with parent master, a variable to be associated with the Ttk Scale widget and its range. If variable is not specified, a Tkinter.IntVar is created. diff --git a/Lib/lib2to3/fixer_base.py b/Lib/lib2to3/fixer_base.py --- a/Lib/lib2to3/fixer_base.py +++ b/Lib/lib2to3/fixer_base.py @@ -50,7 +50,7 @@ """Initializer. Subclass may override. Args: - options: an dict containing the options passed to RefactoringTool + options: a dict containing the options passed to RefactoringTool that could be used to customize the fixer through the command line. log: a list to append warnings and other messages to. """ diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py --- a/Lib/lib2to3/refactor.py +++ b/Lib/lib2to3/refactor.py @@ -184,7 +184,7 @@ Args: fixer_names: a list of fixers to import - options: an dict with configuration. + options: a dict with configuration. explicit: a list of fixers to run even if they are explicit. """ self.fixers = fixer_names diff --git a/Lib/mailbox.py b/Lib/mailbox.py --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1774,7 +1774,7 @@ """Message with Babyl-specific properties.""" def __init__(self, message=None): - """Initialize an BabylMessage instance.""" + """Initialize a BabylMessage instance.""" self._labels = [] self._visible = Message() Message.__init__(self, message) diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py --- a/Lib/multiprocessing/managers.py +++ b/Lib/multiprocessing/managers.py @@ -884,7 +884,7 @@ def MakeProxyType(name, exposed, _cache={}): ''' - Return an proxy type whose methods are given by `exposed` + Return a proxy type whose methods are given by `exposed` ''' exposed = tuple(exposed) try: diff --git a/Lib/optparse.py b/Lib/optparse.py --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -1375,7 +1375,7 @@ sys.argv[1:]). Any errors result in a call to 'error()', which by default prints the usage message to stderr and calls sys.exit() with an error message. On success returns a pair - (values, args) where 'values' is an Values instance (with all + (values, args) where 'values' is a Values instance (with all your option values) and 'args' is the list of arguments left over after parsing options. """ diff --git a/Lib/plat-irix5/flp.py b/Lib/plat-irix5/flp.py --- a/Lib/plat-irix5/flp.py +++ b/Lib/plat-irix5/flp.py @@ -329,7 +329,7 @@ ################################################################# # -# External - Create a form an link to an instance variable. +# External - Create a form and link to an instance variable. # def create_full_form(inst, (fdata, odatalist)): form = create_form(fdata) diff --git a/Lib/plat-irix6/flp.py b/Lib/plat-irix6/flp.py --- a/Lib/plat-irix6/flp.py +++ b/Lib/plat-irix6/flp.py @@ -328,7 +328,7 @@ ################################################################# # -# External - Create a form an link to an instance variable. +# External - Create a form and link to an instance variable. # def create_full_form(inst, (fdata, odatalist)): form = create_form(fdata) diff --git a/Lib/plat-mac/lib-scriptpackages/Finder/Files.py b/Lib/plat-mac/lib-scriptpackages/Finder/Files.py --- a/Lib/plat-mac/lib-scriptpackages/Finder/Files.py +++ b/Lib/plat-mac/lib-scriptpackages/Finder/Files.py @@ -102,7 +102,7 @@ files = file class internet_location_file(aetools.ComponentItem): - """internet location file - An file containing an internet location """ + """internet location file - A file containing an internet location """ want = 'inlf' class _Prop_location(aetools.NProperty): """location - the internet location """ diff --git a/Lib/plat-mac/lib-scriptpackages/SystemEvents/Processes_Suite.py b/Lib/plat-mac/lib-scriptpackages/SystemEvents/Processes_Suite.py --- a/Lib/plat-mac/lib-scriptpackages/SystemEvents/Processes_Suite.py +++ b/Lib/plat-mac/lib-scriptpackages/SystemEvents/Processes_Suite.py @@ -58,7 +58,7 @@ application_processes = application_process class desk_accessory_process(aetools.ComponentItem): - """desk accessory process - A process launched from an desk accessory file """ + """desk accessory process - A process launched from a desk accessory file """ want = 'pcda' class _Prop_desk_accessory_file(aetools.NProperty): """desk accessory file - a reference to the desk accessory file from which this process was launched """ diff --git a/Lib/socket.py b/Lib/socket.py --- a/Lib/socket.py +++ b/Lib/socket.py @@ -549,7 +549,7 @@ global default timeout setting returned by :func:`getdefaulttimeout` is used. If *source_address* is set it must be a tuple of (host, port) for the socket to bind as a source address before making the connection. - An host of '' or port 0 tells the OS to use the default. + A host of '' or port 0 tells the OS to use the default. """ host, port = address diff --git a/Lib/sqlite3/test/factory.py b/Lib/sqlite3/test/factory.py --- a/Lib/sqlite3/test/factory.py +++ b/Lib/sqlite3/test/factory.py @@ -229,7 +229,7 @@ self.assertEqual(row[0], "a\x00b") def CheckCustom(self): - # A custom factory should receive an str argument + # A custom factory should receive a str argument self.con.text_factory = lambda x: x row = self.con.execute("select value from test").fetchone() self.assertIs(type(row[0]), str) diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -73,7 +73,7 @@ def CheckStatementFinalizationOnCloseDb(self): # pysqlite versions <= 2.3.3 only finalized statements in the statement # cache when closing the database. statements that were still - # referenced in cursors weren't closed an could provoke " + # referenced in cursors weren't closed and could provoke " # "OperationalError: Unable to close due to unfinalised statements". con = sqlite.connect(":memory:") cursors = [] diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py --- a/Lib/test/test_binop.py +++ b/Lib/test/test_binop.py @@ -56,7 +56,7 @@ den = property(_get_den, None) def __repr__(self): - """Convert a Rat to an string resembling a Rat constructor call.""" + """Convert a Rat to a string resembling a Rat constructor call.""" return "Rat(%d, %d)" % (self.__num, self.__den) def __str__(self): @@ -78,7 +78,7 @@ raise ValueError, "can't convert %s to int" % repr(self) def __long__(self): - """Convert a Rat to an long; self.den must be 1.""" + """Convert a Rat to a long; self.den must be 1.""" if self.__den == 1: return long(self.__num) raise ValueError, "can't convert %s to long" % repr(self) diff --git a/Lib/test/test_cmd.py b/Lib/test/test_cmd.py --- a/Lib/test/test_cmd.py +++ b/Lib/test/test_cmd.py @@ -110,7 +110,7 @@ 5 12 19 6 13 - This is a interactive test, put some commands in the cmdqueue attribute + This is an interactive test, put some commands in the cmdqueue attribute and let it execute This test includes the preloop(), postloop(), default(), emptyline(), parseline(), do_help() functions diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -47,7 +47,7 @@ self.assertEqual(r.bytebuffer, "") self.assertEqual(r.charbuffer, u"") - # do the check again, this time using a incremental decoder + # do the check again, this time using an incremental decoder d = codecs.getincrementaldecoder(self.encoding)() result = u"" for (c, partialresult) in zip(input.encode(self.encoding), partialresults): diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -951,7 +951,7 @@ HTTPException: message TestResults(failed=1, attempted=2) -But in Python 2 the module path is not included, an therefore a test must look +But in Python 2 the module path is not included, and therefore a test must look like the following test to succeed in Python 2. But that test will fail under Python 3. diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py --- a/Lib/test/test_extcall.py +++ b/Lib/test/test_extcall.py @@ -282,7 +282,7 @@ >>> f(**x) 1 2 -A obscure message: +An obscure message: >>> def f(a, b): ... pass diff --git a/Lib/test/test_mutants.py b/Lib/test/test_mutants.py --- a/Lib/test/test_mutants.py +++ b/Lib/test/test_mutants.py @@ -4,7 +4,7 @@ # From SF bug #422121: Insecurities in dict comparison. -# Safety of code doing comparisons has been an historical Python weak spot. +# Safety of code doing comparisons has been a historical Python weak spot. # The problem is that comparison of structures written in C *naturally* # wants to hold on to things like the size of the container, or "the # biggest" containee so far, across a traversal of the container; but diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -463,7 +463,7 @@ self.assertEqual(os.path.abspath(sys.executable), sys.executable) # Issue #7774: Ensure that sys.executable is an empty string if argv[0] - # has been set to an non existent program name and Python is unable to + # has been set to a non existent program name and Python is unable to # retrieve the real program name import subprocess # For a normal installation, it should work without 'cwd' diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -876,7 +876,7 @@ eventtype = staticmethod(threading.Event) class ConditionAsRLockTests(lock_tests.RLockTests): - # An Condition uses an RLock by default and exports its API. + # Condition uses an RLock by default and exports its API. locktype = staticmethod(threading.Condition) class ConditionTests(lock_tests.ConditionTests): diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py --- a/Lib/xmlrpclib.py +++ b/Lib/xmlrpclib.py @@ -358,7 +358,7 @@ # tuple. # # @param value The time, given as an ISO 8601 string, a time -# tuple, or a integer time value. +# tuple, or an integer time value. def _strftime(value): if datetime: @@ -1616,7 +1616,7 @@ # magic method dispatcher return _Method(self.__request, name) - # note: to call a remote object with an non-standard name, use + # note: to call a remote object with a non-standard name, use # result getattr(server, "strange-python-name")(args) def __call__(self, attr): diff --git a/Mac/Demo/applescript/Disk_Copy/Special_Events.py b/Mac/Demo/applescript/Disk_Copy/Special_Events.py --- a/Mac/Demo/applescript/Disk_Copy/Special_Events.py +++ b/Mac/Demo/applescript/Disk_Copy/Special_Events.py @@ -20,7 +20,7 @@ } def mount(self, _object, _attributes={}, **_arguments): - """mount: Mounts an Disk Copy image as a disk volume + """mount: Mounts a Disk Copy image as a disk volume Required argument: a reference to the disk image to be mounted Keyword argument access_mode: the access mode for mounted volume (default is "any", i.e. best possible) Keyword argument checksum_verification: Verify the checksum before mounting? diff --git a/Misc/HISTORY b/Misc/HISTORY --- a/Misc/HISTORY +++ b/Misc/HISTORY @@ -3096,7 +3096,7 @@ would not be removed while allocating a new weakref object. Since GC could be invoked at that time, however, that assumption was invalid. In a truly obscure case of GC being triggered during - creation for a new weakref object for an referent which already + creation for a new weakref object for a referent which already has a weakref without a callback which is only referenced from cyclic trash, a memory error can occur. This consistently created a segfault in a debug build, but provided less predictable behavior in @@ -7825,7 +7825,7 @@ - xml.dom.minidom offers a toprettyxml method. A number of DOM conformance issues have been resolved. In particular, Element now - has an hasAttributes method, and the handling of namespaces was + has a hasAttributes method, and the handling of namespaces was improved. - Ka-Ping Yee contributed two new modules: inspect.py, a module for @@ -9315,7 +9315,7 @@ Probably the most pervasive change is the addition of Unicode support. We've added a new fundamental datatype, the Unicode string, a new -build-in function unicode(), an numerous C APIs to deal with Unicode +built-in function unicode(), a numerous C APIs to deal with Unicode and encodings. See the file Misc/unicode.txt for details, or http://starship.python.net/crew/lemburg/unicode-proposal.txt. @@ -10800,7 +10800,7 @@ - The uu module now deals better with trailing garbage generated by some broke uuencoders. -- The telnet module now has an my_interact() method which uses threads +- The telnet module now has a my_interact() method which uses threads instead of select. The interact() method uses this by default on Windows (where the single-threaded version doesn't work). @@ -11857,7 +11857,7 @@ - New macros to access object members for PyFunction, PyCFunction objects. -- New APIs PyImport_AppendInittab() an PyImport_ExtendInittab() to +- New APIs PyImport_AppendInittab() and PyImport_ExtendInittab() to dynamically add one or many entries to the table of built-in modules. - New macro Py_InitModule3(name, methods, doc) which calls @@ -16267,7 +16267,7 @@ * repr(x) returns the same as `x`. (Some users found it easier to have this as a function.) -* round(x) returns the floating point number x rounded to an whole +* round(x) returns the floating point number x rounded to a whole number, represented as a floating point number. round(x, n) returns x rounded to n digits. diff --git a/Modules/_csv.c b/Modules/_csv.c --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -717,7 +717,7 @@ break; case QUOTE_IN_QUOTED_FIELD: - /* doublequote - seen a quote in an quoted field */ + /* doublequote - seen a quote in a quoted field */ if (dialect->quoting != QUOTE_NONE && c == dialect->quotechar) { /* save "" as " */ diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -3899,7 +3899,7 @@ return NULL; } /* there should be more checks? No, in Python */ - /* First arg is an pointer to an interface instance */ + /* First arg is a pointer to an interface instance */ if (!this->b_ptr || *(void **)this->b_ptr == NULL) { PyErr_SetString(PyExc_ValueError, "NULL COM pointer access"); diff --git a/Modules/cPickle.c b/Modules/cPickle.c --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -3444,7 +3444,7 @@ /* s contains x bytes of a little-endian integer. Return its value as a * C int. Obscure: when x is 1 or 2, this is an unsigned little-endian - * int, but when x is 4 it's a signed one. This is an historical source + * int, but when x is 4 it's a signed one. This is a historical source * of x-platform bugs. */ static long diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2883,7 +2883,7 @@ bytearray(bytes_or_bytearray) -> mutable copy of bytes_or_bytearray.\n\ bytearray(memory_view) -> bytearray.\n\ \n\ -Construct an mutable bytearray object from:\n\ +Construct a mutable bytearray object from:\n\ - an iterable yielding integers in range(256)\n\ - a text string encoded using the specified encoding\n\ - a bytes or a bytearray object\n\ diff --git a/Objects/stringlib/string_format.h b/Objects/stringlib/string_format.h --- a/Objects/stringlib/string_format.h +++ b/Objects/stringlib/string_format.h @@ -1310,7 +1310,7 @@ 0}; /* unicode_formatter_field_name_split is used to implement - string.Formatter.vformat. it takes an PEP 3101 "field name", and + string.Formatter.vformat. it takes a PEP 3101 "field name", and returns a tuple of (first, rest): "first", the part before the first '.' or '['; and "rest", an iterator for the rest of the field name. it's a wrapper around stringlib/string_format.h's diff --git a/PC/_winreg.c b/PC/_winreg.c --- a/PC/_winreg.c +++ b/PC/_winreg.c @@ -301,7 +301,7 @@ " REG_EXPAND_SZ -- A null-terminated string that contains unexpanded references\n" " to environment variables (for example, %PATH%).\n" " REG_LINK -- A Unicode symbolic link.\n" -" REG_MULTI_SZ -- An sequence of null-terminated strings, terminated by\n" +" REG_MULTI_SZ -- A sequence of null-terminated strings, terminated by\n" " two null characters. Note that Python handles this\n" " termination automatically.\n" " REG_NONE -- No defined value type.\n" diff --git a/Python/thread_nt.h b/Python/thread_nt.h --- a/Python/thread_nt.h +++ b/Python/thread_nt.h @@ -178,7 +178,7 @@ } /* - * Return the thread Id instead of an handle. The Id is said to uniquely identify the + * Return the thread Id instead of a handle. The Id is said to uniquely identify the * thread in the system */ long diff --git a/Python/thread_wince.h b/Python/thread_wince.h --- a/Python/thread_wince.h +++ b/Python/thread_wince.h @@ -42,7 +42,7 @@ } /* - * Return the thread Id instead of an handle. The Id is said to uniquely identify the + * Return the thread Id instead of a handle. The Id is said to uniquely identify the * thread in the system */ long PyThread_get_thread_ident(void) diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -84,7 +84,7 @@ def safety_limit(val): - # Given a integer value from the process being debugged, limit it to some + # Given an integer value from the process being debugged, limit it to some # safety threshold so that arbitrary breakage within said process doesn't # break the gdb process too much (e.g. sizes of iterations, sizes of lists) return min(val, 1000) @@ -132,7 +132,7 @@ class PyObjectPtr(object): """ - Class wrapping a gdb.Value that's a either a (PyObject*) within the + Class wrapping a gdb.Value that's either a (PyObject*) within the inferior process, or some subclass pointer e.g. (PyStringObject*) There will be a subclass for every refined PyObject type that we care diff --git a/Tools/msi/msi.py b/Tools/msi/msi.py --- a/Tools/msi/msi.py +++ b/Tools/msi/msi.py @@ -259,7 +259,7 @@ # either both per-machine or per-user. migrate_features = 1 # See "Upgrade Table". We remove releases with the same major and - # minor version. For an snapshot, we remove all earlier snapshots. For + # minor version. For a snapshot, we remove all earlier snapshots. For # a release, we remove all snapshots, and all earlier releases. if snapshot: add_data(db, "Upgrade", -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 17 02:40:15 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 17 Apr 2016 06:40:15 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326778=3A_Fixed_=22a/an/and=22_typos_in_code_com?= =?utf-8?q?ment=2C_documentation_and_error?= Message-ID: <20160417064015.107504.24841.44159878@psf.io> https://hg.python.org/cpython/rev/932b330e22d8 changeset: 101038:932b330e22d8 parent: 101035:19356c6d23b9 parent: 101036:395dd5630e6c user: Serhiy Storchaka date: Sun Apr 17 09:39:28 2016 +0300 summary: Issue #26778: Fixed "a/an/and" typos in code comment, documentation and error messages. files: Doc/c-api/set.rst | 6 ++-- Doc/c-api/unicode.rst | 4 +- Doc/distutils/apiref.rst | 2 +- Doc/library/asyncio-eventloop.rst | 2 +- Doc/library/ctypes.rst | 4 +- Doc/library/idle.rst | 2 +- Doc/library/shutil.rst | 2 +- Doc/library/tarfile.rst | 2 +- Doc/library/tkinter.tix.rst | 2 +- Doc/tutorial/datastructures.rst | 2 +- Doc/whatsnew/2.2.rst | 2 +- Doc/whatsnew/3.4.rst | 2 +- Doc/whatsnew/3.6.rst | 2 +- Include/listobject.h | 2 +- Include/unicodeobject.h | 2 +- Lib/_pydecimal.py | 2 +- Lib/_pyio.py | 2 +- Lib/asyncio/selector_events.py | 2 +- Lib/email/_header_value_parser.py | 6 ++-- Lib/email/headerregistry.py | 2 +- Lib/idlelib/AutoComplete.py | 2 +- Lib/idlelib/Debugger.py | 2 +- Lib/idlelib/WidgetRedirector.py | 2 +- Lib/idlelib/configDialog.py | 2 +- Lib/lib2to3/fixer_base.py | 2 +- Lib/lib2to3/refactor.py | 2 +- Lib/lzma.py | 2 +- Lib/mailbox.py | 2 +- Lib/multiprocessing/managers.py | 2 +- Lib/optparse.py | 2 +- Lib/pprint.py | 2 +- Lib/socket.py | 2 +- Lib/socketserver.py | 2 +- Lib/sqlite3/test/regression.py | 2 +- Lib/tarfile.py | 4 +- Lib/test/test_asyncio/test_selector_events.py | 2 +- Lib/test/test_asyncio/test_sslproto.py | 2 +- Lib/test/test_binop.py | 2 +- Lib/test/test_faulthandler.py | 2 +- Lib/test/test_pathlib.py | 2 +- Lib/test/test_sys.py | 2 +- Lib/test/test_threading.py | 2 +- Lib/test/test_tools/test_gprof2html.py | 2 +- Lib/test/test_zipapp.py | 2 +- Lib/tkinter/__init__.py | 2 +- Lib/tkinter/dnd.py | 2 +- Lib/tkinter/test/test_ttk/test_functions.py | 2 +- Lib/tkinter/tix.py | 6 ++-- Lib/tkinter/ttk.py | 2 +- Lib/xmlrpc/client.py | 2 +- Lib/zipapp.py | 7 ++-- Misc/HISTORY | 14 +++++----- Misc/NEWS | 4 +- Modules/_csv.c | 2 +- Modules/_ctypes/_ctypes.c | 2 +- Modules/_io/stringio.c | 2 +- Modules/_io/textio.c | 2 +- Modules/_pickle.c | 4 +- Modules/_tracemalloc.c | 2 +- Modules/faulthandler.c | 2 +- Modules/itertoolsmodule.c | 2 +- Modules/selectmodule.c | 2 +- Objects/bytearrayobject.c | 2 +- Objects/rangeobject.c | 2 +- Objects/stringlib/unicode_format.h | 2 +- PC/clinic/winreg.c.h | 6 ++-- PC/winreg.c | 8 ++-- Python/thread_nt.h | 2 +- 68 files changed, 93 insertions(+), 92 deletions(-) diff --git a/Doc/c-api/set.rst b/Doc/c-api/set.rst --- a/Doc/c-api/set.rst +++ b/Doc/c-api/set.rst @@ -128,7 +128,7 @@ of brand new frozensets before they are exposed to other code). Return 0 on success or -1 on failure. Raise a :exc:`TypeError` if the *key* is unhashable. Raise a :exc:`MemoryError` if there is no room to grow. Raise a - :exc:`SystemError` if *set* is an not an instance of :class:`set` or its + :exc:`SystemError` if *set* is not an instance of :class:`set` or its subtype. @@ -142,7 +142,7 @@ error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a :exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~set.discard` method, this function does not automatically convert unhashable sets into - temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is an not an + temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is not an instance of :class:`set` or its subtype. @@ -150,7 +150,7 @@ Return a new reference to an arbitrary object in the *set*, and removes the object from the *set*. Return *NULL* on failure. Raise :exc:`KeyError` if the - set is empty. Raise a :exc:`SystemError` if *set* is an not an instance of + set is empty. Raise a :exc:`SystemError` if *set* is not an instance of :class:`set` or its subtype. diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -367,7 +367,7 @@ .. c:macro:: Py_UNICODE_IS_HIGH_SURROGATE(ch) - Check if *ch* is an high surrogate (``0xD800 <= ch <= 0xDBFF``). + Check if *ch* is a high surrogate (``0xD800 <= ch <= 0xDBFF``). .. c:macro:: Py_UNICODE_IS_LOW_SURROGATE(ch) @@ -450,7 +450,7 @@ | :attr:`%%` | *n/a* | The literal % character. | +-------------------+---------------------+--------------------------------+ | :attr:`%c` | int | A single character, | - | | | represented as an C int. | + | | | represented as a C int. | +-------------------+---------------------+--------------------------------+ | :attr:`%d` | int | Exactly equivalent to | | | | ``printf("%d")``. | diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -837,7 +837,7 @@ .. module:: distutils.bcppcompiler -This module provides :class:`BorlandCCompiler`, an subclass of the abstract +This module provides :class:`BorlandCCompiler`, a subclass of the abstract :class:`CCompiler` class for the Borland C++ compiler. diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -513,7 +513,7 @@ The *address* must be already resolved to avoid the trap of hanging the entire event loop when the address requires doing a DNS lookup. For - example, it must be an IP address, not an hostname, for + example, it must be an IP address, not a hostname, for :py:data:`~socket.AF_INET` and :py:data:`~socket.AF_INET6` address families. Use :meth:`getaddrinfo` to resolve the hostname asynchronously. diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -671,7 +671,7 @@ TenPointsArrayType = POINT * 10 -Here is an example of an somewhat artificial data type, a structure containing 4 +Here is an example of a somewhat artificial data type, a structure containing 4 POINTs among other stuff:: >>> from ctypes import * @@ -1888,7 +1888,7 @@ .. function:: POINTER(type) This factory function creates and returns a new ctypes pointer type. Pointer - types are cached an reused internally, so calling this function repeatedly is + types are cached and reused internally, so calling this function repeatedly is cheap. *type* must be a ctypes type. diff --git a/Doc/library/idle.rst b/Doc/library/idle.rst --- a/Doc/library/idle.rst +++ b/Doc/library/idle.rst @@ -128,7 +128,7 @@ Search for the currently selected string, if there is one. Find in Files... - Open a file search dialog. Put results in an new output window. + Open a file search dialog. Put results in a new output window. Replace... Open a search-and-replace dialog. diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -342,7 +342,7 @@ Return the path to an executable which would be run if the given *cmd* was called. If no *cmd* would be called, return ``None``. - *mode* is a permission mask passed a to :func:`os.access`, by default + *mode* is a permission mask passed to :func:`os.access`, by default determining if the file exists and executable. When no *path* is specified, the results of :func:`os.environ` are used, diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst --- a/Doc/library/tarfile.rst +++ b/Doc/library/tarfile.rst @@ -129,7 +129,7 @@ | ``'r|bz2'`` | Open a bzip2 compressed *stream* for | | | reading. | +-------------+--------------------------------------------+ - | ``'r|xz'`` | Open a lzma compressed *stream* for | + | ``'r|xz'`` | Open an lzma compressed *stream* for | | | reading. | +-------------+--------------------------------------------+ | ``'w|'`` | Open an uncompressed *stream* for writing. | diff --git a/Doc/library/tkinter.tix.rst b/Doc/library/tkinter.tix.rst --- a/Doc/library/tkinter.tix.rst +++ b/Doc/library/tkinter.tix.rst @@ -267,7 +267,7 @@ The `ExFileSelectBox `_ - widget is usually embedded in a tixExFileSelectDialog widget. It provides an + widget is usually embedded in a tixExFileSelectDialog widget. It provides a convenient method for the user to select files. The style of the :class:`ExFileSelectBox` widget is very similar to the standard file dialog on MS Windows 3.1. diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -397,7 +397,7 @@ Though tuples may seem similar to lists, they are often used in different situations and for different purposes. -Tuples are :term:`immutable`, and usually contain an heterogeneous sequence of +Tuples are :term:`immutable`, and usually contain a heterogeneous sequence of elements that are accessed via unpacking (see later in this section) or indexing (or even by attribute in the case of :func:`namedtuples `). Lists are :term:`mutable`, and their elements are usually homogeneous and are diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst --- a/Doc/whatsnew/2.2.rst +++ b/Doc/whatsnew/2.2.rst @@ -720,7 +720,7 @@ (The controversy is over whether this is *really* a design flaw, and whether it's worth breaking existing code to fix this. It's caused endless discussions -on python-dev, and in July 2001 erupted into an storm of acidly sarcastic +on python-dev, and in July 2001 erupted into a storm of acidly sarcastic postings on :newsgroup:`comp.lang.python`. I won't argue for either side here and will stick to describing what's implemented in 2.2. Read :pep:`238` for a summary of arguments and counter-arguments.) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1457,7 +1457,7 @@ list of the loaded ``CA`` certificates. (Contributed by Christian Heimes in :issue:`18147`.) -If OpenSSL 0.9.8 or later is available, :class:`~ssl.SSLContext` has an new +If OpenSSL 0.9.8 or later is available, :class:`~ssl.SSLContext` has a new attribute :attr:`~ssl.SSLContext.verify_flags` that can be used to control the certificate verification process by setting it to some combination of the new constants :data:`~ssl.VERIFY_DEFAULT`, :data:`~ssl.VERIFY_CRL_CHECK_LEAF`, diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -214,7 +214,7 @@ faulthandler ------------ -On Windows, the :mod:`faulthandler` module now installs an handler for Windows +On Windows, the :mod:`faulthandler` module now installs a handler for Windows exceptions: see :func:`faulthandler.enable`. (Contributed by Victor Stinner in :issue:`23848`.) diff --git a/Include/listobject.h b/Include/listobject.h --- a/Include/listobject.h +++ b/Include/listobject.h @@ -2,7 +2,7 @@ /* List object interface */ /* -Another generally useful object type is an list of object pointers. +Another generally useful object type is a list of object pointers. This is a mutable type: the list items can be changed, and items can be added or removed. Out-of-range indices or non-list objects are ignored. diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -844,7 +844,7 @@ Py_ssize_t length /* New length */ ); -/* Decode obj to an Unicode object. +/* Decode obj to a Unicode object. bytes, bytearray and other bytes-like objects are decoded according to the given encoding and error handler. The encoding and error handler can be diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py --- a/Lib/_pydecimal.py +++ b/Lib/_pydecimal.py @@ -252,7 +252,7 @@ class ConversionSyntax(InvalidOperation): """Trying to convert badly formed string. - This occurs and signals invalid-operation if an string is being + This occurs and signals invalid-operation if a string is being converted to a number and it does not conform to the numeric string syntax. The result is [0,qNaN]. """ diff --git a/Lib/_pyio.py b/Lib/_pyio.py --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -439,7 +439,7 @@ return self.__closed def _checkClosed(self, msg=None): - """Internal: raise an ValueError if file is closed + """Internal: raise a ValueError if file is closed """ if self.closed: raise ValueError("I/O operation on closed file." diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -387,7 +387,7 @@ The address must be already resolved to avoid the trap of hanging the entire event loop when the address requires doing a DNS lookup. For - example, it must be an IP address, not an hostname, for AF_INET and + example, it must be an IP address, not a hostname, for AF_INET and AF_INET6 address families. Use getaddrinfo() to resolve the hostname asynchronously. diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -1522,7 +1522,7 @@ This is not the RFC ctext, since we are handling nested comments in comment and unquoting quoted-pairs here. We allow anything except the '()' characters, but if we find any ASCII other than the RFC defined printable - ASCII an NonPrintableDefect is added to the token's defects list. Since + ASCII, a NonPrintableDefect is added to the token's defects list. Since quoted pairs are converted to their unquoted values, what is returned is a 'ptext' token. In this case it is a WhiteSpaceTerminal, so it's value is ' '. @@ -1537,7 +1537,7 @@ """qcontent = qtext / quoted-pair We allow anything except the DQUOTE character, but if we find any ASCII - other than the RFC defined printable ASCII an NonPrintableDefect is + other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Any quoted pairs are converted to their unquoted values, so what is returned is a 'ptext' token. In this case it is a ValueTerminal. @@ -1882,7 +1882,7 @@ obs-dtext = obs-NO-WS-CTL / quoted-pair We allow anything except the excluded characters, but if we find any - ASCII other than the RFC defined printable ASCII an NonPrintableDefect is + ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Quoted pairs are converted to their unquoted values, so what is returned is a ptext token, in this case a ValueTerminal. If there were quoted-printables, an ObsoleteHeaderDefect is diff --git a/Lib/email/headerregistry.py b/Lib/email/headerregistry.py --- a/Lib/email/headerregistry.py +++ b/Lib/email/headerregistry.py @@ -109,7 +109,7 @@ def __init__(self, display_name=None, addresses=None): """Create an object representing an address group. - An address group consists of a display_name followed by colon and an + An address group consists of a display_name followed by colon and a list of addresses (see Address) terminated by a semi-colon. The Group is created by specifying a display_name and a possibly empty list of Address objects. A Group can also be used to represent a single diff --git a/Lib/idlelib/AutoComplete.py b/Lib/idlelib/AutoComplete.py --- a/Lib/idlelib/AutoComplete.py +++ b/Lib/idlelib/AutoComplete.py @@ -64,7 +64,7 @@ def try_open_completions_event(self, event): """Happens when it would be nice to open a completion list, but not - really necessary, for example after an dot, so function + really necessary, for example after a dot, so function calls won't be made. """ lastchar = self.text.get("insert-1c") diff --git a/Lib/idlelib/Debugger.py b/Lib/idlelib/Debugger.py --- a/Lib/idlelib/Debugger.py +++ b/Lib/idlelib/Debugger.py @@ -372,7 +372,7 @@ def __init__(self, master, flist, gui): if macosxSupport.isAquaTk(): # At least on with the stock AquaTk version on OSX 10.4 you'll - # get an shaking GUI that eventually kills IDLE if the width + # get a shaking GUI that eventually kills IDLE if the width # argument is specified. ScrolledList.__init__(self, master) else: diff --git a/Lib/idlelib/WidgetRedirector.py b/Lib/idlelib/WidgetRedirector.py --- a/Lib/idlelib/WidgetRedirector.py +++ b/Lib/idlelib/WidgetRedirector.py @@ -68,7 +68,7 @@ '''Return OriginalCommand(operation) after registering function. Registration adds an operation: function pair to ._operations. - It also adds an widget function attribute that masks the tkinter + It also adds a widget function attribute that masks the tkinter class instance method. Method masking operates independently from command dispatch. diff --git a/Lib/idlelib/configDialog.py b/Lib/idlelib/configDialog.py --- a/Lib/idlelib/configDialog.py +++ b/Lib/idlelib/configDialog.py @@ -1196,7 +1196,7 @@ All values are treated as text, and it is up to the user to supply reasonable values. The only exception to this are the 'enable*' options, - which are boolean, and can be toggled with an True/False button. + which are boolean, and can be toggled with a True/False button. """ parent = self.parent frame = self.tabPages.pages['Extensions'].frame diff --git a/Lib/lib2to3/fixer_base.py b/Lib/lib2to3/fixer_base.py --- a/Lib/lib2to3/fixer_base.py +++ b/Lib/lib2to3/fixer_base.py @@ -49,7 +49,7 @@ """Initializer. Subclass may override. Args: - options: an dict containing the options passed to RefactoringTool + options: a dict containing the options passed to RefactoringTool that could be used to customize the fixer through the command line. log: a list to append warnings and other messages to. """ diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py --- a/Lib/lib2to3/refactor.py +++ b/Lib/lib2to3/refactor.py @@ -184,7 +184,7 @@ Args: fixer_names: a list of fixers to import - options: an dict with configuration. + options: a dict with configuration. explicit: a list of fixers to run even if they are explicit. """ self.fixers = fixer_names diff --git a/Lib/lzma.py b/Lib/lzma.py --- a/Lib/lzma.py +++ b/Lib/lzma.py @@ -279,7 +279,7 @@ constructor: LZMAFile(filename, mode, ...). In this case, the encoding, errors and newline arguments must not be provided. - For text mode, a LZMAFile object is created, and wrapped in an + For text mode, an LZMAFile object is created, and wrapped in an io.TextIOWrapper instance with the specified encoding, error handling behavior, and line ending(s). diff --git a/Lib/mailbox.py b/Lib/mailbox.py --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1821,7 +1821,7 @@ _type_specific_attributes = ['_labels', '_visible'] def __init__(self, message=None): - """Initialize an BabylMessage instance.""" + """Initialize a BabylMessage instance.""" self._labels = [] self._visible = Message() Message.__init__(self, message) diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py --- a/Lib/multiprocessing/managers.py +++ b/Lib/multiprocessing/managers.py @@ -842,7 +842,7 @@ def MakeProxyType(name, exposed, _cache={}): ''' - Return an proxy type whose methods are given by `exposed` + Return a proxy type whose methods are given by `exposed` ''' exposed = tuple(exposed) try: diff --git a/Lib/optparse.py b/Lib/optparse.py --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -1362,7 +1362,7 @@ sys.argv[1:]). Any errors result in a call to 'error()', which by default prints the usage message to stderr and calls sys.exit() with an error message. On success returns a pair - (values, args) where 'values' is an Values instance (with all + (values, args) where 'values' is a Values instance (with all your option values) and 'args' is the list of arguments left over after parsing options. """ diff --git a/Lib/pprint.py b/Lib/pprint.py --- a/Lib/pprint.py +++ b/Lib/pprint.py @@ -72,7 +72,7 @@ class _safe_key: """Helper function for key functions when sorting unorderable objects. - The wrapped-object will fallback to an Py2.x style comparison for + The wrapped-object will fallback to a Py2.x style comparison for unorderable types (sorting first comparing the type name and then by the obj ids). Does not work recursively, so dict.items() must have _safe_key applied to both the key and the value. diff --git a/Lib/socket.py b/Lib/socket.py --- a/Lib/socket.py +++ b/Lib/socket.py @@ -685,7 +685,7 @@ global default timeout setting returned by :func:`getdefaulttimeout` is used. If *source_address* is set it must be a tuple of (host, port) for the socket to bind as a source address before making the connection. - An host of '' or port 0 tells the OS to use the default. + A host of '' or port 0 tells the OS to use the default. """ host, port = address diff --git a/Lib/socketserver.py b/Lib/socketserver.py --- a/Lib/socketserver.py +++ b/Lib/socketserver.py @@ -747,7 +747,7 @@ try: self.wfile.flush() except socket.error: - # An final socket error may have occurred here, such as + # A final socket error may have occurred here, such as # the local error ECONNABORTED. pass self.wfile.close() diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -73,7 +73,7 @@ def CheckStatementFinalizationOnCloseDb(self): # pysqlite versions <= 2.3.3 only finalized statements in the statement # cache when closing the database. statements that were still - # referenced in cursors weren't closed an could provoke " + # referenced in cursors weren't closed and could provoke " # "OperationalError: Unable to close due to unfinalised statements". con = sqlite.connect(":memory:") cursors = [] diff --git a/Lib/tarfile.py b/Lib/tarfile.py --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -1528,9 +1528,9 @@ 'x' or 'x:' create a tarfile exclusively without compression, raise an exception if the file is already created - 'x:gz' create an gzip compressed tarfile, raise an exception + 'x:gz' create a gzip compressed tarfile, raise an exception if the file is already created - 'x:bz2' create an bzip2 compressed tarfile, raise an exception + 'x:bz2' create a bzip2 compressed tarfile, raise an exception if the file is already created 'x:xz' create an lzma compressed tarfile, raise an exception if the file is already created diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py --- a/Lib/test/test_asyncio/test_selector_events.py +++ b/Lib/test/test_asyncio/test_selector_events.py @@ -1182,7 +1182,7 @@ self.assertIs(exc, waiter.exception()) def test_cancel_handshake(self): - # Python issue #23197: cancelling an handshake must not raise an + # Python issue #23197: cancelling a handshake must not raise an # exception or log an error, even if the handshake failed waiter = asyncio.Future(loop=self.loop) transport = self.ssl_transport(waiter=waiter) diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py --- a/Lib/test/test_asyncio/test_sslproto.py +++ b/Lib/test/test_asyncio/test_sslproto.py @@ -40,7 +40,7 @@ ssl_proto.connection_made(transport) def test_cancel_handshake(self): - # Python issue #23197: cancelling an handshake must not raise an + # Python issue #23197: cancelling a handshake must not raise an # exception or log an error, even if the handshake failed waiter = asyncio.Future(loop=self.loop) ssl_proto = self.ssl_protocol(waiter) diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py --- a/Lib/test/test_binop.py +++ b/Lib/test/test_binop.py @@ -58,7 +58,7 @@ den = property(_get_den, None) def __repr__(self): - """Convert a Rat to an string resembling a Rat constructor call.""" + """Convert a Rat to a string resembling a Rat constructor call.""" return "Rat(%d, %d)" % (self.__num, self.__den) def __str__(self): diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -715,7 +715,7 @@ sys.stderr = stderr def test_stderr_None(self): - # Issue #21497: provide an helpful error if sys.stderr is None, + # Issue #21497: provide a helpful error if sys.stderr is None, # instead of just an attribute error: "None has no attribute fileno". with self.check_stderr_none(): faulthandler.enable() diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -200,7 +200,7 @@ def _check_str_subclass(self, *args): # Issue #21127: it should be possible to construct a PurePath object - # from an str subclass instance, and it then gets converted to + # from a str subclass instance, and it then gets converted to # a pure str object. class StrSubclass(str): pass diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -644,7 +644,7 @@ self.assertEqual(os.path.abspath(sys.executable), sys.executable) # Issue #7774: Ensure that sys.executable is an empty string if argv[0] - # has been set to an non existent program name and Python is unable to + # has been set to a non existent program name and Python is unable to # retrieve the real program name # For a normal installation, it should work without 'cwd' diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -1083,7 +1083,7 @@ eventtype = staticmethod(threading.Event) class ConditionAsRLockTests(lock_tests.RLockTests): - # An Condition uses an RLock by default and exports its API. + # Condition uses an RLock by default and exports its API. locktype = staticmethod(threading.Condition) class ConditionTests(lock_tests.ConditionTests): diff --git a/Lib/test/test_tools/test_gprof2html.py b/Lib/test/test_tools/test_gprof2html.py --- a/Lib/test/test_tools/test_gprof2html.py +++ b/Lib/test/test_tools/test_gprof2html.py @@ -22,7 +22,7 @@ sys.argv = [] def test_gprof(self): - # Issue #14508: this used to fail with an NameError. + # Issue #14508: this used to fail with a NameError. with mock.patch.object(self.gprof, 'webbrowser') as wmock, \ tempfile.TemporaryDirectory() as tmpdir: fn = os.path.join(tmpdir, 'abc') diff --git a/Lib/test/test_zipapp.py b/Lib/test/test_zipapp.py --- a/Lib/test/test_zipapp.py +++ b/Lib/test/test_zipapp.py @@ -195,7 +195,7 @@ self.assertTrue(new_target.getvalue().startswith(b'#!python2.7\n')) def test_read_from_pathobj(self): - # Test that we can copy an archive using an pathlib.Path object + # Test that we can copy an archive using a pathlib.Path object # for the source. source = self.tmpdir / 'source' source.mkdir() diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -2771,7 +2771,7 @@ self.deletecommand(c) self.tk.call(self._w, 'delete', index1, index2) def entrycget(self, index, option): - """Return the resource value of an menu item for OPTION at INDEX.""" + """Return the resource value of a menu item for OPTION at INDEX.""" return self.tk.call(self._w, 'entrycget', index, '-' + option) def entryconfigure(self, index, cnf=None, **kw): """Configure a menu item at INDEX.""" diff --git a/Lib/tkinter/dnd.py b/Lib/tkinter/dnd.py --- a/Lib/tkinter/dnd.py +++ b/Lib/tkinter/dnd.py @@ -3,7 +3,7 @@ This is very preliminary. I currently only support dnd *within* one application, between different windows (or within the same window). -I an trying to make this as generic as possible -- not dependent on +I am trying to make this as generic as possible -- not dependent on the use of a particular widget or icon type, etc. I also hope that this will work with Pmw. diff --git a/Lib/tkinter/test/test_ttk/test_functions.py b/Lib/tkinter/test/test_ttk/test_functions.py --- a/Lib/tkinter/test/test_ttk/test_functions.py +++ b/Lib/tkinter/test/test_ttk/test_functions.py @@ -193,7 +193,7 @@ ## Testing type = vsapi # vsapi type expects at least a class name and a part_id, so this - # should raise an ValueError since it tries to get two elements from + # should raise a ValueError since it tries to get two elements from # an empty tuple self.assertRaises(ValueError, ttk._format_elemcreate, 'vsapi') diff --git a/Lib/tkinter/tix.py b/Lib/tkinter/tix.py --- a/Lib/tkinter/tix.py +++ b/Lib/tkinter/tix.py @@ -221,7 +221,7 @@ self.tk.eval('package require Tix') def destroy(self): - # For safety, remove an delete_window binding before destroy + # For safety, remove the delete_window binding before destroy self.protocol("WM_DELETE_WINDOW", "") tkinter.Tk.destroy(self) @@ -702,7 +702,7 @@ class ExFileSelectBox(TixWidget): """ExFileSelectBox - MS Windows style file select box. - It provides an convenient method for the user to select files. + It provides a convenient method for the user to select files. Subwidget Class --------- ----- @@ -760,7 +760,7 @@ # Should inherit from a Dialog class class ExFileSelectDialog(TixWidget): """ExFileSelectDialog - MS Windows style file select dialog. - It provides an convenient method for the user to select files. + It provides a convenient method for the user to select files. Subwidgets Class ---------- ----- diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py --- a/Lib/tkinter/ttk.py +++ b/Lib/tkinter/ttk.py @@ -1478,7 +1478,7 @@ can be accessed through instance.label""" def __init__(self, master=None, variable=None, from_=0, to=10, **kw): - """Construct an horizontal LabeledScale with parent master, a + """Construct a horizontal LabeledScale with parent master, a variable to be associated with the Ttk Scale widget and its range. If variable is not specified, a tkinter.IntVar is created. diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -1446,7 +1446,7 @@ # magic method dispatcher return _Method(self.__request, name) - # note: to call a remote object with an non-standard name, use + # note: to call a remote object with a non-standard name, use # result getattr(server, "strange-python-name")(args) def __call__(self, attr): diff --git a/Lib/zipapp.py b/Lib/zipapp.py --- a/Lib/zipapp.py +++ b/Lib/zipapp.py @@ -89,9 +89,10 @@ The created application archive will have a shebang line specifying that it should run with INTERPRETER (there will be no shebang line if INTERPRETER is None), and a __main__.py which runs MAIN (if MAIN is - not specified, an existing __main__.py will be used). It is an to specify - MAIN for anything other than a directory source with no __main__.py, and it - is an error to omit MAIN if the directory has no __main__.py. + not specified, an existing __main__.py will be used). It is an error + to specify MAIN for anything other than a directory source with no + __main__.py, and it is an error to omit MAIN if the directory has no + __main__.py. """ # Are we copying an existing archive? source_is_file = False diff --git a/Misc/HISTORY b/Misc/HISTORY --- a/Misc/HISTORY +++ b/Misc/HISTORY @@ -7220,7 +7220,7 @@ cElementTree module is updated too. - Issue #7774: Set sys.executable to an empty string if argv[0] has been set to - an non existent program name and Python is unable to retrieve the real program + a non existent program name and Python is unable to retrieve the real program name. - Issue #7880: Fix sysconfig when the python executable is a symbolic link. @@ -14013,7 +14013,7 @@ would not be removed while allocating a new weakref object. Since GC could be invoked at that time, however, that assumption was invalid. In a truly obscure case of GC being triggered during - creation for a new weakref object for an referent which already + creation for a new weakref object for a referent which already has a weakref without a callback which is only referenced from cyclic trash, a memory error can occur. This consistently created a segfault in a debug build, but provided less predictable behavior in @@ -18737,7 +18737,7 @@ - xml.dom.minidom offers a toprettyxml method. A number of DOM conformance issues have been resolved. In particular, Element now - has an hasAttributes method, and the handling of namespaces was + has a hasAttributes method, and the handling of namespaces was improved. - Ka-Ping Yee contributed two new modules: inspect.py, a module for @@ -20227,7 +20227,7 @@ Probably the most pervasive change is the addition of Unicode support. We've added a new fundamental datatype, the Unicode string, a new -build-in function unicode(), an numerous C APIs to deal with Unicode +built-in function unicode(), and numerous C APIs to deal with Unicode and encodings. See the file Misc/unicode.txt for details, or http://starship.python.net/crew/lemburg/unicode-proposal.txt. @@ -21712,7 +21712,7 @@ - The uu module now deals better with trailing garbage generated by some broke uuencoders. -- The telnet module now has an my_interact() method which uses threads +- The telnet module now has a my_interact() method which uses threads instead of select. The interact() method uses this by default on Windows (where the single-threaded version doesn't work). @@ -22769,7 +22769,7 @@ - New macros to access object members for PyFunction, PyCFunction objects. -- New APIs PyImport_AppendInittab() an PyImport_ExtendInittab() to +- New APIs PyImport_AppendInittab() and PyImport_ExtendInittab() to dynamically add one or many entries to the table of built-in modules. - New macro Py_InitModule3(name, methods, doc) which calls @@ -27179,7 +27179,7 @@ * repr(x) returns the same as `x`. (Some users found it easier to have this as a function.) -* round(x) returns the floating point number x rounded to an whole +* round(x) returns the floating point number x rounded to a whole number, represented as a floating point number. round(x, n) returns x rounded to n digits. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -1779,7 +1779,7 @@ - Issue #24407: Fix crash when dict is mutated while being updated. - Issue #24619: New approach for tokenizing async/await. As a consequence, - is is now possible to have one-line 'async def foo(): await ..' functions. + it is now possible to have one-line 'async def foo(): await ..' functions. - Issue #24687: Plug refleak on SyntaxError in function parameters annotations. @@ -4124,7 +4124,7 @@ - Issue #21000: Improve the command-line interface of json.tool. - Issue #20995: Enhance default ciphers used by the ssl module to enable - better security an prioritize perfect forward secrecy. + better security and prioritize perfect forward secrecy. - Issue #20884: Don't assume that __file__ is defined on importlib.__init__. diff --git a/Modules/_csv.c b/Modules/_csv.c --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -731,7 +731,7 @@ break; case QUOTE_IN_QUOTED_FIELD: - /* doublequote - seen a quote in an quoted field */ + /* doublequote - seen a quote in a quoted field */ if (dialect->quoting != QUOTE_NONE && c == dialect->quotechar) { /* save "" as " */ diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -3802,7 +3802,7 @@ return NULL; } /* there should be more checks? No, in Python */ - /* First arg is an pointer to an interface instance */ + /* First arg is a pointer to an interface instance */ if (!this->b_ptr || *(void **)this->b_ptr == NULL) { PyErr_SetString(PyExc_ValueError, "NULL COM pointer access"); diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -438,7 +438,7 @@ _PyIO_str_readline, NULL); if (line && !PyUnicode_Check(line)) { PyErr_Format(PyExc_IOError, - "readline() should have returned an str object, " + "readline() should have returned a str object, " "not '%.200s'", Py_TYPE(line)->tp_name); Py_DECREF(line); return NULL; diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -2689,7 +2689,7 @@ _PyIO_str_readline, NULL); if (line && !PyUnicode_Check(line)) { PyErr_Format(PyExc_IOError, - "readline() should have returned an str object, " + "readline() should have returned a str object, " "not '%.200s'", Py_TYPE(line)->tp_name); Py_DECREF(line); return NULL; diff --git a/Modules/_pickle.c b/Modules/_pickle.c --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -4465,7 +4465,7 @@ } else { PyErr_Format(PyExc_TypeError, - "'memo' attribute must be an PicklerMemoProxy object" + "'memo' attribute must be a PicklerMemoProxy object" "or dict, not %.200s", Py_TYPE(obj)->tp_name); return -1; } @@ -4703,7 +4703,7 @@ /* s contains x bytes of a little-endian integer. Return its value as a * C int. Obscure: when x is 1 or 2, this is an unsigned little-endian - * int, but when x is 4 it's a signed one. This is an historical source + * int, but when x is 4 it's a signed one. This is a historical source * of x-platform bugs. */ static long diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -719,7 +719,7 @@ the caller, because realloc() may already have shrinked the memory block and so removed bytes. - This case is very unlikely: an hash entry has just been + This case is very unlikely: a hash entry has just been released, so the hash table should have at least one free entry. The GIL and the table lock ensures that only one thread is diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -1178,7 +1178,7 @@ {"register", (PyCFunction)faulthandler_register_py, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("register(signum, file=sys.stderr, all_threads=True, chain=False): " - "register an handler for the signal 'signum': dump the " + "register a handler for the signal 'signum': dump the " "traceback of the current thread, or of all threads if " "all_threads is True, into file")}, {"unregister", diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -4484,7 +4484,7 @@ PyDoc_STRVAR(zip_longest_doc, "zip_longest(iter1 [,iter2 [...]], [fillvalue=None]) --> zip_longest object\n\ \n\ -Return an zip_longest object whose .__next__() method returns a tuple where\n\ +Return a zip_longest object whose .__next__() method returns a tuple where\n\ the i-th element comes from the i-th iterable argument. The .__next__()\n\ method continues until the longest iterable in the argument sequence\n\ is exhausted and then it raises StopIteration. When the shorter iterables\n\ diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -2127,7 +2127,7 @@ if (_PyTime_FromSecondsObject(&timeout, otimeout, _PyTime_ROUND_CEILING) < 0) { PyErr_Format(PyExc_TypeError, - "timeout argument must be an number " + "timeout argument must be a number " "or None, got %.200s", Py_TYPE(otimeout)->tp_name); return NULL; diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -3018,7 +3018,7 @@ bytearray(int) -> bytes array of size given by the parameter initialized with null bytes\n\ bytearray() -> empty bytes array\n\ \n\ -Construct an mutable bytearray object from:\n\ +Construct a mutable bytearray object from:\n\ - an iterable yielding integers in range(256)\n\ - a text string encoded using the specified encoding\n\ - a bytes or a buffer object\n\ diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -5,7 +5,7 @@ /* Support objects whose length is > PY_SSIZE_T_MAX. - This could be sped up for small PyLongs if they fit in an Py_ssize_t. + This could be sped up for small PyLongs if they fit in a Py_ssize_t. This only matters on Win64. Though we could use PY_LONG_LONG which would presumably help perf. */ diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h --- a/Objects/stringlib/unicode_format.h +++ b/Objects/stringlib/unicode_format.h @@ -1226,7 +1226,7 @@ 0}; /* unicode_formatter_field_name_split is used to implement - string.Formatter.vformat. it takes an PEP 3101 "field name", and + string.Formatter.vformat. it takes a PEP 3101 "field name", and returns a tuple of (first, rest): "first", the part before the first '.' or '['; and "rest", an iterator for the rest of the field name. it's a wrapper around stringlib/string_format.h's diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h --- a/PC/clinic/winreg.c.h +++ b/PC/clinic/winreg.c.h @@ -120,7 +120,7 @@ "ConnectRegistry($module, computer_name, key, /)\n" "--\n" "\n" -"Establishes a connection to the registry on on another computer.\n" +"Establishes a connection to the registry on another computer.\n" "\n" " computer_name\n" " The name of the remote computer, of the form r\"\\\\computername\". If\n" @@ -913,7 +913,7 @@ " references to environment variables (for example,\n" " %PATH%).\n" " REG_LINK -- A Unicode symbolic link.\n" -" REG_MULTI_SZ -- An sequence of null-terminated strings, terminated\n" +" REG_MULTI_SZ -- A sequence of null-terminated strings, terminated\n" " by two null characters. Note that Python handles\n" " this termination automatically.\n" " REG_NONE -- No defined value type.\n" @@ -1056,4 +1056,4 @@ exit: return return_value; } -/*[clinic end generated code: output=71f5bc30b646807b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5e346dccc296f9f1 input=a9049054013a1b77]*/ diff --git a/PC/winreg.c b/PC/winreg.c --- a/PC/winreg.c +++ b/PC/winreg.c @@ -792,7 +792,7 @@ The predefined key to connect to. / -Establishes a connection to the registry on on another computer. +Establishes a connection to the registry on another computer. The return value is the handle of the opened key. If the function fails, an OSError exception is raised. @@ -801,7 +801,7 @@ static HKEY winreg_ConnectRegistry_impl(PyModuleDef *module, Py_UNICODE *computer_name, HKEY key) -/*[clinic end generated code: output=5c52f6f7ba6e7b46 input=9a056558ce318433]*/ +/*[clinic end generated code: output=5c52f6f7ba6e7b46 input=5f98a891a347e68e]*/ { HKEY retKey; long rc; @@ -1605,7 +1605,7 @@ references to environment variables (for example, %PATH%). REG_LINK -- A Unicode symbolic link. - REG_MULTI_SZ -- An sequence of null-terminated strings, terminated + REG_MULTI_SZ -- A sequence of null-terminated strings, terminated by two null characters. Note that Python handles this termination automatically. REG_NONE -- No defined value type. @@ -1631,7 +1631,7 @@ static PyObject * winreg_SetValueEx_impl(PyModuleDef *module, HKEY key, Py_UNICODE *value_name, PyObject *reserved, DWORD type, PyObject *value) -/*[clinic end generated code: output=ea092a935c361582 input=e73dec535ebeea7d]*/ +/*[clinic end generated code: output=ea092a935c361582 input=f1b16cbcc3ed4101]*/ { BYTE *data; DWORD len; diff --git a/Python/thread_nt.h b/Python/thread_nt.h --- a/Python/thread_nt.h +++ b/Python/thread_nt.h @@ -231,7 +231,7 @@ } /* - * Return the thread Id instead of an handle. The Id is said to uniquely identify the + * Return the thread Id instead of a handle. The Id is said to uniquely identify the * thread in the system */ long -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Sun Apr 17 05:46:34 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sun, 17 Apr 2016 09:46:34 +0000 Subject: [Python-checkins] Daily reference leaks (19356c6d23b9): sum=6 Message-ID: <20160417094633.70529.2047.DE92BF6F@psf.io> results for 19356c6d23b9 on branch "default" -------------------------------------------- test_collections leaked [2, 0, 0] references, sum=2 test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflog1HDExH', '--timeout', '7200'] From python-checkins at python.org Sun Apr 17 10:52:12 2016 From: python-checkins at python.org (victor.stinner) Date: Sun, 17 Apr 2016 14:52:12 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Avoid_fcntl=28=29_if_possi?= =?utf-8?q?ble_in_set=5Finheritable=28=29?= Message-ID: <20160417145211.89025.81409.FC076F05@psf.io> https://hg.python.org/cpython/rev/d268f108ba80 changeset: 101039:d268f108ba80 user: Victor Stinner date: Sun Apr 17 16:51:52 2016 +0200 summary: Avoid fcntl() if possible in set_inheritable() Issue #26770: set_inheritable() avoids calling fcntl() twice if the FD_CLOEXEC is already set/cleared. This change only impacts platforms using the fcntl() implementation of set_inheritable() (not Linux nor Windows). files: Python/fileutils.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Python/fileutils.c b/Python/fileutils.c --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -798,7 +798,7 @@ int request; int err; #endif - int flags; + int flags, new_flags; int res; #endif @@ -884,10 +884,18 @@ return -1; } - if (inheritable) - flags &= ~FD_CLOEXEC; - else - flags |= FD_CLOEXEC; + if (inheritable) { + new_flags = flags & ~FD_CLOEXEC; + } + else { + new_flags = flags | FD_CLOEXEC; + } + + if (new_flags == flags) { + /* FD_CLOEXEC flag already set/cleared: nothing to do */ + return 0; + } + res = fcntl(fd, F_SETFD, flags); if (res < 0) { if (raise) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 17 13:32:13 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 17 Apr 2016 17:32:13 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326745=3A_Removed_?= =?utf-8?q?redundant_code_in_=5FPyObject=5FGenericSetAttrWithDict=2E?= Message-ID: <20160417173213.19515.35730.A532683A@psf.io> https://hg.python.org/cpython/rev/e5149789e4ea changeset: 101040:e5149789e4ea user: Serhiy Storchaka date: Sun Apr 17 20:31:51 2016 +0300 summary: Issue #26745: Removed redundant code in _PyObject_GenericSetAttrWithDict. Based on patch by Xiang Zhang. files: Objects/object.c | 51 ++++++++++++++--------------------- 1 files changed, 21 insertions(+), 30 deletions(-) diff --git a/Objects/object.c b/Objects/object.c --- a/Objects/object.c +++ b/Objects/object.c @@ -1040,8 +1040,7 @@ name->ob_type->tp_name); return NULL; } - else - Py_INCREF(name); + Py_INCREF(name); if (tp->tp_dict == NULL) { if (PyType_Ready(tp) < 0) @@ -1049,10 +1048,10 @@ } descr = _PyType_Lookup(tp, name); - Py_XINCREF(descr); f = NULL; if (descr != NULL) { + Py_INCREF(descr); f = descr->ob_type->tp_descr_get; if (f != NULL && PyDescr_IsData(descr)) { res = f(descr, obj, (PyObject *)obj->ob_type); @@ -1072,8 +1071,9 @@ if (tsize < 0) tsize = -tsize; size = _PyObject_VAR_SIZE(tp, tsize); + assert(size <= PY_SSIZE_T_MAX); - dictoffset += (long)size; + dictoffset += (Py_ssize_t)size; assert(dictoffset > 0); assert(dictoffset % SIZEOF_VOID_P == 0); } @@ -1141,12 +1141,11 @@ Py_INCREF(name); descr = _PyType_Lookup(tp, name); - Py_XINCREF(descr); - f = NULL; if (descr != NULL) { + Py_INCREF(descr); f = descr->ob_type->tp_descr_set; - if (f != NULL && PyDescr_IsData(descr)) { + if (f != NULL) { res = f(descr, obj, value); goto done; } @@ -1154,40 +1153,32 @@ if (dict == NULL) { dictptr = _PyObject_GetDictPtr(obj); - if (dictptr != NULL) { - res = _PyObjectDict_SetItem(Py_TYPE(obj), dictptr, name, value); - if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) - PyErr_SetObject(PyExc_AttributeError, name); + if (dictptr == NULL) { + if (descr == NULL) { + PyErr_Format(PyExc_AttributeError, + "'%.100s' object has no attribute '%U'", + tp->tp_name, name); + } + else { + PyErr_Format(PyExc_AttributeError, + "'%.50s' object attribute '%U' is read-only", + tp->tp_name, name); + } goto done; } + res = _PyObjectDict_SetItem(tp, dictptr, name, value); } - if (dict != NULL) { + else { Py_INCREF(dict); if (value == NULL) res = PyDict_DelItem(dict, name); else res = PyDict_SetItem(dict, name, value); Py_DECREF(dict); - if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) - PyErr_SetObject(PyExc_AttributeError, name); - goto done; } + if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) + PyErr_SetObject(PyExc_AttributeError, name); - if (f != NULL) { - res = f(descr, obj, value); - goto done; - } - - if (descr == NULL) { - PyErr_Format(PyExc_AttributeError, - "'%.100s' object has no attribute '%U'", - tp->tp_name, name); - goto done; - } - - PyErr_Format(PyExc_AttributeError, - "'%.50s' object attribute '%U' is read-only", - tp->tp_name, name); done: Py_XDECREF(descr); Py_DECREF(name); -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 17 20:54:13 2016 From: python-checkins at python.org (guido.van.rossum) Date: Mon, 18 Apr 2016 00:54:13 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogU3luYyB0ZXN0X3R5?= =?utf-8?q?ping=2Epy_with_upstream_git_repo_=28typing=2Epy_was_already_syn?= =?utf-8?b?Y2VkKS4=?= Message-ID: <20160418005412.70529.57205.CA7A1373@psf.io> https://hg.python.org/cpython/rev/31cd179c9451 changeset: 101041:31cd179c9451 branch: 3.5 parent: 101036:395dd5630e6c user: Guido van Rossum date: Sun Apr 17 17:52:05 2016 -0700 summary: Sync test_typing.py with upstream git repo (typing.py was already synced). files: Lib/test/test_typing.py | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1,3 +1,4 @@ +import contextlib import pickle import re import sys @@ -1309,6 +1310,21 @@ assert len(MMB[KT, VT]()) == 0 +class OtherABCTests(TestCase): + + @skipUnless(hasattr(typing, 'ContextManager'), + 'requires typing.ContextManager') + def test_contextmanager(self): + @contextlib.contextmanager + def manager(): + yield 42 + + cm = manager() + assert isinstance(cm, typing.ContextManager) + assert isinstance(cm, typing.ContextManager[int]) + assert not isinstance(42, typing.ContextManager) + + class NamedTupleTests(TestCase): def test_basics(self): @@ -1447,12 +1463,16 @@ assert 'ValuesView' in a assert 'cast' in a assert 'overload' in a + if hasattr(contextlib, 'AbstractContextManager'): + assert 'ContextManager' in a # Check that io and re are not exported. assert 'io' not in a assert 're' not in a # Spot-check that stdlib modules aren't exported. assert 'os' not in a assert 'sys' not in a + # Check that Text is defined. + assert 'Text' in a if __name__ == '__main__': -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 17 20:54:13 2016 From: python-checkins at python.org (guido.van.rossum) Date: Mon, 18 Apr 2016 00:54:13 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Sync_test=5Ftyping=2Epy_with_upstream_git_repo_=28typing?= =?utf-8?q?=2Epy_was_already_synced=29=2E?= Message-ID: <20160418005413.107500.76460.8A9BC1D2@psf.io> https://hg.python.org/cpython/rev/9a269279f131 changeset: 101042:9a269279f131 parent: 101040:e5149789e4ea parent: 101041:31cd179c9451 user: Guido van Rossum date: Sun Apr 17 17:53:50 2016 -0700 summary: Sync test_typing.py with upstream git repo (typing.py was already synced). (3.5->3.6) files: Lib/test/test_typing.py | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1471,6 +1471,8 @@ # Spot-check that stdlib modules aren't exported. assert 'os' not in a assert 'sys' not in a + # Check that Text is defined. + assert 'Text' in a if __name__ == '__main__': -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 18 00:21:07 2016 From: python-checkins at python.org (raymond.hettinger) Date: Mon, 18 Apr 2016 04:21:07 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_spelling_error?= Message-ID: <20160418042107.17779.12593.FE04B609@psf.io> https://hg.python.org/cpython/rev/831d3ebf61a6 changeset: 101043:831d3ebf61a6 user: Raymond Hettinger date: Sun Apr 17 21:21:01 2016 -0700 summary: Fix spelling error files: README | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/README b/README --- a/README +++ b/README @@ -187,7 +187,7 @@ ------------------------- If you have a proposal to change Python, you may want to send an email to the -comp.lang.python or python-ideas mailing lists for inital feedback. A Python +comp.lang.python or python-ideas mailing lists for initial feedback. A Python Enhancement Proposal (PEP) may be submitted if your idea gains ground. All current PEPs, as well as guidelines for submitting a new PEP, are listed at http://www.python.org/dev/peps/. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 18 01:26:03 2016 From: python-checkins at python.org (georg.brandl) Date: Mon, 18 Apr 2016 05:26:03 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_=2325987=3A_add_versionadd?= =?utf-8?q?ed_to_Reversible=2E?= Message-ID: <20160418052602.12755.48091.2228C6E9@psf.io> https://hg.python.org/cpython/rev/7d9f7d7a21ae changeset: 101044:7d9f7d7a21ae user: Georg Brandl date: Mon Apr 18 07:25:54 2016 +0200 summary: #25987: add versionadded to Reversible. files: Doc/library/collections.abc.rst | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Doc/library/collections.abc.rst b/Doc/library/collections.abc.rst --- a/Doc/library/collections.abc.rst +++ b/Doc/library/collections.abc.rst @@ -112,6 +112,8 @@ ABC for classes that provide the :meth:`__reversed__` method. + .. versionadded:: 3.6 + .. class:: Generator ABC for generator classes that implement the protocol defined in -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 18 04:02:43 2016 From: python-checkins at python.org (martin.panter) Date: Mon, 18 Apr 2016 08:02:43 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326657=3A_Merge_http=2Eserver_fix_from_3=2E5?= Message-ID: <20160418080242.19505.15802.7DC1B105@psf.io> https://hg.python.org/cpython/rev/5d8042ab3361 changeset: 101046:5d8042ab3361 parent: 101044:7d9f7d7a21ae parent: 101045:8054a68dfce2 user: Martin Panter date: Mon Apr 18 07:16:17 2016 +0000 summary: Issue #26657: Merge http.server fix from 3.5 files: Lib/http/server.py | 6 +++--- Lib/test/test_httpservers.py | 19 +++++++++++++++++++ Misc/NEWS | 4 ++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Lib/http/server.py b/Lib/http/server.py --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -768,9 +768,9 @@ words = filter(None, words) path = os.getcwd() for word in words: - drive, word = os.path.splitdrive(word) - head, word = os.path.split(word) - if word in (os.curdir, os.pardir): continue + if os.path.dirname(word) or word in (os.curdir, os.pardir): + # Ignore components that are not a simple file/directory name + continue path = os.path.join(path, word) if trailing_slash: path += '/' diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -12,6 +12,7 @@ import sys import re import base64 +import ntpath import shutil import urllib.parse import html @@ -960,6 +961,24 @@ path = self.handler.translate_path('//filename?foo=bar') self.assertEqual(path, self.translated) + def test_windows_colon(self): + with support.swap_attr(server.os, 'path', ntpath): + path = self.handler.translate_path('c:c:c:foo/filename') + path = path.replace(ntpath.sep, os.sep) + self.assertEqual(path, self.translated) + + path = self.handler.translate_path('\\c:../filename') + path = path.replace(ntpath.sep, os.sep) + self.assertEqual(path, self.translated) + + path = self.handler.translate_path('c:\\c:..\\foo/filename') + path = path.replace(ntpath.sep, os.sep) + self.assertEqual(path, self.translated) + + path = self.handler.translate_path('c:c:foo\\c:c:bar/filename') + path = path.replace(ntpath.sep, os.sep) + self.assertEqual(path, self.translated) + class MiscTestCase(unittest.TestCase): def test_all(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -245,6 +245,10 @@ Library ------- +- Issue #26657: Fix directory traversal vulnerability with http.server on + Windows. This fixes a regression that was introduced in 3.3.4rc1 and + 3.4.0rc1. Based on patch by Philipp Hagemeister. + - Issue #26717: Stop encoding Latin-1-ized WSGI paths with UTF-8. Patch by Anthony Sottile. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 18 04:02:43 2016 From: python-checkins at python.org (martin.panter) Date: Mon, 18 Apr 2016 08:02:43 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2NjU3?= =?utf-8?q?=3A_Fix_SimpleHTTPServer_Windows_directory_traversal_vulnerabil?= =?utf-8?q?ity?= Message-ID: <20160418080243.19491.50304.10E8CA0C@psf.io> https://hg.python.org/cpython/rev/8aa032b26552 changeset: 101047:8aa032b26552 branch: 2.7 parent: 101037:bbcde8db4dc4 user: Martin Panter date: Mon Apr 18 03:45:18 2016 +0000 summary: Issue #26657: Fix SimpleHTTPServer Windows directory traversal vulnerability Based on patch by Philipp Hagemeister. This fixes a regression caused by revision 6b314f5c9404. files: Lib/SimpleHTTPServer.py | 6 +++--- Lib/test/test_httpservers.py | 20 ++++++++++++++++++++ Misc/NEWS | 4 ++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Lib/SimpleHTTPServer.py b/Lib/SimpleHTTPServer.py --- a/Lib/SimpleHTTPServer.py +++ b/Lib/SimpleHTTPServer.py @@ -167,9 +167,9 @@ words = filter(None, words) path = os.getcwd() for word in words: - drive, word = os.path.splitdrive(word) - head, word = os.path.split(word) - if word in (os.curdir, os.pardir): continue + if os.path.dirname(word) or word in (os.curdir, os.pardir): + # Ignore components that are not a simple file/directory name + continue path = os.path.join(path, word) if trailing_slash: path += '/' diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -8,6 +8,7 @@ import sys import re import base64 +import ntpath import shutil import urllib import httplib @@ -604,6 +605,25 @@ path = self.handler.translate_path('//filename?foo=bar') self.assertEqual(path, self.translated) + def test_windows_colon(self): + import SimpleHTTPServer + with test_support.swap_attr(SimpleHTTPServer.os, 'path', ntpath): + path = self.handler.translate_path('c:c:c:foo/filename') + path = path.replace(ntpath.sep, os.sep) + self.assertEqual(path, self.translated) + + path = self.handler.translate_path('\\c:../filename') + path = path.replace(ntpath.sep, os.sep) + self.assertEqual(path, self.translated) + + path = self.handler.translate_path('c:\\c:..\\foo/filename') + path = path.replace(ntpath.sep, os.sep) + self.assertEqual(path, self.translated) + + path = self.handler.translate_path('c:c:foo\\c:c:bar/filename') + path = path.replace(ntpath.sep, os.sep) + self.assertEqual(path, self.translated) + def test_main(verbose=None): try: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,10 @@ Library ------- +- Issue #26657: Fix directory traversal vulnerability with SimpleHTTPServer + on Windows. This fixes a regression that was introduced in 2.7.7. Based + on patch by Philipp Hagemeister. + - Issue #19377: Add .svg to mimetypes.types_map. - Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 18 04:02:53 2016 From: python-checkins at python.org (martin.panter) Date: Mon, 18 Apr 2016 08:02:53 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NjU3?= =?utf-8?q?=3A_Fix_Windows_directory_traversal_vulnerability_with_http=2Es?= =?utf-8?q?erver?= Message-ID: <20160418080242.107502.79317.F1043ADB@psf.io> https://hg.python.org/cpython/rev/8054a68dfce2 changeset: 101045:8054a68dfce2 branch: 3.5 parent: 101041:31cd179c9451 user: Martin Panter date: Mon Apr 18 03:45:18 2016 +0000 summary: Issue #26657: Fix Windows directory traversal vulnerability with http.server Based on patch by Philipp Hagemeister. This fixes a regression caused by revision f4377699fd47. files: Lib/http/server.py | 6 +++--- Lib/test/test_httpservers.py | 19 +++++++++++++++++++ Misc/NEWS | 4 ++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Lib/http/server.py b/Lib/http/server.py --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -774,9 +774,9 @@ words = filter(None, words) path = os.getcwd() for word in words: - drive, word = os.path.splitdrive(word) - head, word = os.path.split(word) - if word in (os.curdir, os.pardir): continue + if os.path.dirname(word) or word in (os.curdir, os.pardir): + # Ignore components that are not a simple file/directory name + continue path = os.path.join(path, word) if trailing_slash: path += '/' diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -12,6 +12,7 @@ import sys import re import base64 +import ntpath import shutil import urllib.parse import html @@ -918,6 +919,24 @@ path = self.handler.translate_path('//filename?foo=bar') self.assertEqual(path, self.translated) + def test_windows_colon(self): + with support.swap_attr(server.os, 'path', ntpath): + path = self.handler.translate_path('c:c:c:foo/filename') + path = path.replace(ntpath.sep, os.sep) + self.assertEqual(path, self.translated) + + path = self.handler.translate_path('\\c:../filename') + path = path.replace(ntpath.sep, os.sep) + self.assertEqual(path, self.translated) + + path = self.handler.translate_path('c:\\c:..\\foo/filename') + path = path.replace(ntpath.sep, os.sep) + self.assertEqual(path, self.translated) + + path = self.handler.translate_path('c:c:foo\\c:c:bar/filename') + path = path.replace(ntpath.sep, os.sep) + self.assertEqual(path, self.translated) + class MiscTestCase(unittest.TestCase): def test_all(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,10 @@ Library ------- +- Issue #26657: Fix directory traversal vulnerability with http.server on + Windows. This fixes a regression that was introduced in 3.3.4rc1 and + 3.4.0rc1. Based on patch by Philipp Hagemeister. + - Issue #26717: Stop encoding Latin-1-ized WSGI paths with UTF-8. Patch by Anthony Sottile. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 18 04:30:38 2016 From: python-checkins at python.org (victor.stinner) Date: Mon, 18 Apr 2016 08:30:38 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy41ICh0ZXN0X2FzeW5jaW8p?= Message-ID: <20160418083037.26083.50059.0D3ACB9C@psf.io> https://hg.python.org/cpython/rev/43567d214534 changeset: 101049:43567d214534 parent: 101046:5d8042ab3361 parent: 101048:730a95c2d38f user: Victor Stinner date: Mon Apr 18 10:29:19 2016 +0200 summary: Merge 3.5 (test_asyncio) files: Lib/test/test_asyncio/test_tasks.py | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2395,7 +2395,9 @@ resp = yield from long_running_task() self.assertEqual(resp, 'done') dt = self.loop.time() - t0 - self.assertTrue(0.09 < dt < 0.11, dt) + # tolerate a time delta for clocks with bad resolution + # and slow buildbots + self.assertTrue(0.09 < dt < 0.15, dt) self.loop.run_until_complete(go()) def test_raise_runtimeerror_if_no_task(self): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 18 04:30:40 2016 From: python-checkins at python.org (victor.stinner) Date: Mon, 18 Apr 2016 08:30:40 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogRml4IHRlc3RfYXN5?= =?utf-8?b?bmNpby50ZXN0X3RpbWVvdXRfZGlzYWJsZSgp?= Message-ID: <20160418083037.89225.20872.AA186695@psf.io> https://hg.python.org/cpython/rev/730a95c2d38f changeset: 101048:730a95c2d38f branch: 3.5 parent: 101045:8054a68dfce2 user: Victor Stinner date: Mon Apr 18 10:28:42 2016 +0200 summary: Fix test_asyncio.test_timeout_disable() Issue #26777: Fix random failing of the test on the "AMD64 FreeBSD 9.x 3.5" buildbot: File ".../Lib/test/test_asyncio/test_tasks.py", line 2398, in go self.assertTrue(0.09 < dt < 0.11, dt) AssertionError: False is not true : 0.11902812402695417 Replace "< 0.11" with "< 0.15". files: Lib/test/test_asyncio/test_tasks.py | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2395,7 +2395,9 @@ resp = yield from long_running_task() self.assertEqual(resp, 'done') dt = self.loop.time() - t0 - self.assertTrue(0.09 < dt < 0.11, dt) + # tolerate a time delta for clocks with bad resolution + # and slow buildbots + self.assertTrue(0.09 < dt < 0.15, dt) self.loop.run_until_complete(go()) def test_raise_runtimeerror_if_no_task(self): -- Repository URL: https://hg.python.org/cpython From lp_benchmark_robot at intel.com Mon Apr 18 07:38:30 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Mon, 18 Apr 2016 12:38:30 +0100 Subject: [Python-checkins] BAD Benchmark Results for Python Default 2016-04-18 Message-ID: <49fadda0-d309-49d2-ad9f-700c60a46d10@irsmsx151.ger.corp.intel.com> Results for project Python default, build date 2016-04-18 02:03:36 +0000 commit: 9a269279f131 previous commit: b128e019ec32 revision date: 2016-04-18 00:53:50 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.26% -1.69% 8.74% 16.56% :-| pybench 6.16% -0.53% -0.11% 7.11% :-( regex_v8 2.92% -0.60% -3.46% 2.44% :-( nbody 0.15% -1.28% -3.07% 11.69% :-( json_dump_v2 0.23% -1.49% -4.45% 11.53% :-| normal_startup 0.91% -0.16% 0.05% 5.00% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/bad-benchmark-results-for-python-default-2016-04-18/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Mon Apr 18 07:38:56 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Mon, 18 Apr 2016 12:38:56 +0100 Subject: [Python-checkins] UGLY Benchmark Results for Python 2.7 2016-04-18 Message-ID: <3c6d5ed5-c332-4bcb-89ff-9f721751e8da@irsmsx151.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-18 02:47:58 +0000 commit: bbcde8db4dc4 previous commit: 3a3b30c310e5 revision date: 2016-04-17 06:37:36 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.11% 0.12% 6.79% 2.85% :-) pybench 0.16% -0.32% 5.92% 5.01% :-| regex_v8 0.72% 0.71% -1.92% 9.85% :-) nbody 0.14% -0.51% 6.75% 5.50% :-) json_dump_v2 0.54% -1.31% 2.24% 10.73% :-( normal_startup 1.81% 1.03% -5.18% 1.82% :-) ssbench 0.16% -0.37% 2.19% 1.89% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/ugly-benchmark-results-for-python-2-7-2016-04-18/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Mon Apr 18 10:40:12 2016 From: python-checkins at python.org (guido.van.rossum) Date: Mon, 18 Apr 2016 14:40:12 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogdHlwaW5nLnB5OiBD?= =?utf-8?q?onsider_ellipsis_in_TupleMeta=2E=5F=5Feq=5F=5F=2E_By_Kalle_Tuur?= =?utf-8?q?e=2E?= Message-ID: <20160418144008.107512.64583.376EF7E4@psf.io> https://hg.python.org/cpython/rev/9e9f01260b27 changeset: 101050:9e9f01260b27 branch: 3.5 parent: 101048:730a95c2d38f user: Guido van Rossum date: Mon Apr 18 07:37:41 2016 -0700 summary: typing.py: Consider ellipsis in TupleMeta.__eq__. By Kalle Tuure. github.com/python/typing/pull/201. files: Lib/test/test_typing.py | 6 ++++++ Lib/typing.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -359,6 +359,12 @@ self.assertTrue(issubclass(tuple, Tuple)) self.assertFalse(issubclass(Tuple, tuple)) # Can't have it both ways. + def test_equality(self): + assert Tuple[int] == Tuple[int] + assert Tuple[int, ...] == Tuple[int, ...] + assert Tuple[int] != Tuple[int, int] + assert Tuple[int] != Tuple[int, ...] + def test_tuple_subclass(self): class MyTuple(tuple): pass diff --git a/Lib/typing.py b/Lib/typing.py --- a/Lib/typing.py +++ b/Lib/typing.py @@ -705,7 +705,8 @@ def __eq__(self, other): if not isinstance(other, TupleMeta): return NotImplemented - return self.__tuple_params__ == other.__tuple_params__ + return (self.__tuple_params__ == other.__tuple_params__ and + self.__tuple_use_ellipsis__ == other.__tuple_use_ellipsis__) def __hash__(self): return hash(self.__tuple_params__) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 18 10:40:12 2016 From: python-checkins at python.org (guido.van.rossum) Date: Mon, 18 Apr 2016 14:40:12 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_typing=2Epy=3A_merge_3=2E5-=3E3=2E6_=28Tuple/ellipsis/eq?= =?utf-8?q?uality=29=2E?= Message-ID: <20160418144008.89225.1208.37B4BF33@psf.io> https://hg.python.org/cpython/rev/98cda226d208 changeset: 101051:98cda226d208 parent: 101049:43567d214534 parent: 101050:9e9f01260b27 user: Guido van Rossum date: Mon Apr 18 07:39:54 2016 -0700 summary: typing.py: merge 3.5->3.6 (Tuple/ellipsis/equality). files: Lib/test/test_typing.py | 6 ++++++ Lib/typing.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -359,6 +359,12 @@ self.assertTrue(issubclass(tuple, Tuple)) self.assertFalse(issubclass(Tuple, tuple)) # Can't have it both ways. + def test_equality(self): + assert Tuple[int] == Tuple[int] + assert Tuple[int, ...] == Tuple[int, ...] + assert Tuple[int] != Tuple[int, int] + assert Tuple[int] != Tuple[int, ...] + def test_tuple_subclass(self): class MyTuple(tuple): pass diff --git a/Lib/typing.py b/Lib/typing.py --- a/Lib/typing.py +++ b/Lib/typing.py @@ -705,7 +705,8 @@ def __eq__(self, other): if not isinstance(other, TupleMeta): return NotImplemented - return self.__tuple_params__ == other.__tuple_params__ + return (self.__tuple_params__ == other.__tuple_params__ and + self.__tuple_use_ellipsis__ == other.__tuple_use_ellipsis__) def __hash__(self): return hash(self.__tuple_params__) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 18 14:19:56 2016 From: python-checkins at python.org (berker.peksag) Date: Mon, 18 Apr 2016 18:19:56 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NjE1?= =?utf-8?q?=3A_Add_missing_=5F=5Fqualname=5F=5F_entry_to_functools=2Eupdat?= =?utf-8?q?e=5Fwrapper=28=29_docs?= Message-ID: <20160418181948.15350.66083.4918C818@psf.io> https://hg.python.org/cpython/rev/11d8f5d1968d changeset: 101052:11d8f5d1968d branch: 3.5 parent: 101050:9e9f01260b27 user: Berker Peksag date: Mon Apr 18 21:20:50 2016 +0300 summary: Issue #26615: Add missing __qualname__ entry to functools.update_wrapper() docs Patch by Xiang Zhang. files: Doc/library/functools.rst | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -375,10 +375,10 @@ assigned directly to the matching attributes on the wrapper function and which attributes of the wrapper function are updated with the corresponding attributes from the original function. The default values for these arguments are the - module level constants *WRAPPER_ASSIGNMENTS* (which assigns to the wrapper - function's *__name__*, *__module__*, *__annotations__* and *__doc__*, the - documentation string) and *WRAPPER_UPDATES* (which updates the wrapper - function's *__dict__*, i.e. the instance dictionary). + module level constants ``WRAPPER_ASSIGNMENTS`` (which assigns to the wrapper + function's ``__module__``, ``__name__``, ``__qualname__``, ``__annotations__`` + and ``__doc__``, the documentation string) and ``WRAPPER_UPDATES`` (which + updates the wrapper function's ``__dict__``, i.e. the instance dictionary). To allow access to the original function for introspection and other purposes (e.g. bypassing a caching decorator such as :func:`lru_cache`), this function -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 18 14:19:56 2016 From: python-checkins at python.org (berker.peksag) Date: Mon, 18 Apr 2016 18:19:56 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326615=3A_Add_missing_=5F=5Fqualname=5F=5F_entry?= =?utf-8?q?_to_functools=2Eupdate=5Fwrapper=28=29_docs?= Message-ID: <20160418181949.107496.16710.954FB4A4@psf.io> https://hg.python.org/cpython/rev/ee9921b29fd8 changeset: 101053:ee9921b29fd8 parent: 101051:98cda226d208 parent: 101052:11d8f5d1968d user: Berker Peksag date: Mon Apr 18 21:21:10 2016 +0300 summary: Issue #26615: Add missing __qualname__ entry to functools.update_wrapper() docs Patch by Xiang Zhang. files: Doc/library/functools.rst | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -375,10 +375,10 @@ assigned directly to the matching attributes on the wrapper function and which attributes of the wrapper function are updated with the corresponding attributes from the original function. The default values for these arguments are the - module level constants *WRAPPER_ASSIGNMENTS* (which assigns to the wrapper - function's *__name__*, *__module__*, *__annotations__* and *__doc__*, the - documentation string) and *WRAPPER_UPDATES* (which updates the wrapper - function's *__dict__*, i.e. the instance dictionary). + module level constants ``WRAPPER_ASSIGNMENTS`` (which assigns to the wrapper + function's ``__module__``, ``__name__``, ``__qualname__``, ``__annotations__`` + and ``__doc__``, the documentation string) and ``WRAPPER_UPDATES`` (which + updates the wrapper function's ``__dict__``, i.e. the instance dictionary). To allow access to the original function for introspection and other purposes (e.g. bypassing a caching decorator such as :func:`lru_cache`), this function -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 18 14:41:25 2016 From: python-checkins at python.org (berker.peksag) Date: Mon, 18 Apr 2016 18:41:25 +0000 Subject: [Python-checkins] =?utf-8?q?devguide=3A_Issue_=2326755=3A_Clarify?= =?utf-8?q?_when_version=7Badded=2Cchanged=7D_directives_should_be_used_in?= Message-ID: <20160418184123.565.66644.6407338F@psf.io> https://hg.python.org/devguide/rev/6ef3d77b3c27 changeset: 796:6ef3d77b3c27 user: Berker Peksag date: Mon Apr 18 21:42:47 2016 +0300 summary: Issue #26755: Clarify when version{added,changed} directives should be used in docs files: documenting.rst | 23 +++++++++++++---------- 1 files changed, 13 insertions(+), 10 deletions(-) diff --git a/documenting.rst b/documenting.rst --- a/documenting.rst +++ b/documenting.rst @@ -1204,23 +1204,26 @@ entire module, it should be placed at the top of the module section before any prose. - The first argument must be given and is the version in question; if the - addition is only part of the described API element, you should add a second - argument consisting of a *brief* explanation of the change. + The first argument must be given and is the version in question. The second + argument is optional and can be used to describe the details of the feature. Example:: - .. versionadded:: 3.1 - The *spam* parameter. - - Note that there must be no blank line between the directive head and the - explanation; this is to make these blocks visually continuous in the markup. + .. versionadded:: 3.5 .. describe:: versionchanged Similar to ``versionadded``, but describes when and what changed in the named - feature in some way (changed side effects, platform support, etc.). This one - *must* have the second argument (explanation of the change). + feature in some way (new parameters, changed side effects, platform support, + etc.). This one *must* have the second argument (explanation of the change). + + Example:: + + .. versionchanged:: 3.1 + The *spam* parameter was added. + + Note that there must be no blank line between the directive head and the + explanation; this is to make these blocks visually continuous in the markup. -------------- -- Repository URL: https://hg.python.org/devguide From python-checkins at python.org Tue Apr 19 02:54:46 2016 From: python-checkins at python.org (lars.gustaebel) Date: Tue, 19 Apr 2016 06:54:46 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI0ODM4?= =?utf-8?q?=3A_tarfile=27s_ustar_and_gnu_formats_now_correctly_calculate_n?= =?utf-8?q?ame_and?= Message-ID: <20160419065445.12739.61659.6A87EE6E@psf.io> https://hg.python.org/cpython/rev/d08d6b776694 changeset: 101054:d08d6b776694 branch: 3.5 parent: 101052:11d8f5d1968d user: Lars Gust?bel date: Tue Apr 19 08:43:17 2016 +0200 summary: Issue #24838: tarfile's ustar and gnu formats now correctly calculate name and link field limits for multibyte character encodings like utf-8. files: Lib/tarfile.py | 29 ++++---- Lib/test/test_tarfile.py | 87 ++++++++++++++++++++++++++- Misc/NEWS | 3 + 3 files changed, 100 insertions(+), 19 deletions(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -812,11 +812,11 @@ """ info["magic"] = POSIX_MAGIC - if len(info["linkname"]) > LENGTH_LINK: + if len(info["linkname"].encode(encoding, errors)) > LENGTH_LINK: raise ValueError("linkname is too long") - if len(info["name"]) > LENGTH_NAME: - info["prefix"], info["name"] = self._posix_split_name(info["name"]) + if len(info["name"].encode(encoding, errors)) > LENGTH_NAME: + info["prefix"], info["name"] = self._posix_split_name(info["name"], encoding, errors) return self._create_header(info, USTAR_FORMAT, encoding, errors) @@ -826,10 +826,10 @@ info["magic"] = GNU_MAGIC buf = b"" - if len(info["linkname"]) > LENGTH_LINK: + if len(info["linkname"].encode(encoding, errors)) > LENGTH_LINK: buf += self._create_gnu_long_header(info["linkname"], GNUTYPE_LONGLINK, encoding, errors) - if len(info["name"]) > LENGTH_NAME: + if len(info["name"].encode(encoding, errors)) > LENGTH_NAME: buf += self._create_gnu_long_header(info["name"], GNUTYPE_LONGNAME, encoding, errors) return buf + self._create_header(info, GNU_FORMAT, encoding, errors) @@ -889,19 +889,20 @@ """ return cls._create_pax_generic_header(pax_headers, XGLTYPE, "utf-8") - def _posix_split_name(self, name): + def _posix_split_name(self, name, encoding, errors): """Split a name longer than 100 chars into a prefix and a name part. """ - prefix = name[:LENGTH_PREFIX + 1] - while prefix and prefix[-1] != "/": - prefix = prefix[:-1] + components = name.split("/") + for i in range(1, len(components)): + prefix = "/".join(components[:i]) + name = "/".join(components[i:]) + if len(prefix.encode(encoding, errors)) <= LENGTH_PREFIX and \ + len(name.encode(encoding, errors)) <= LENGTH_NAME: + break + else: + raise ValueError("name is too long") - name = name[len(prefix):] - prefix = prefix[:-1] - - if not prefix or len(name) > LENGTH_NAME: - raise ValueError("name is too long") return prefix, name @staticmethod diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -1667,9 +1667,7 @@ tar.close() -class UstarUnicodeTest(unittest.TestCase): - - format = tarfile.USTAR_FORMAT +class UnicodeTest: def test_iso8859_1_filename(self): self._test_unicode_filename("iso8859-1") @@ -1750,7 +1748,86 @@ tar.close() -class GNUUnicodeTest(UstarUnicodeTest): +class UstarUnicodeTest(UnicodeTest, unittest.TestCase): + + format = tarfile.USTAR_FORMAT + + # Test whether the utf-8 encoded version of a filename exceeds the 100 + # bytes name field limit (every occurrence of '\xff' will be expanded to 2 + # bytes). + def test_unicode_name1(self): + self._test_ustar_name("0123456789" * 10) + self._test_ustar_name("0123456789" * 10 + "0", ValueError) + self._test_ustar_name("0123456789" * 9 + "01234567\xff") + self._test_ustar_name("0123456789" * 9 + "012345678\xff", ValueError) + + def test_unicode_name2(self): + self._test_ustar_name("0123456789" * 9 + "012345\xff\xff") + self._test_ustar_name("0123456789" * 9 + "0123456\xff\xff", ValueError) + + # Test whether the utf-8 encoded version of a filename exceeds the 155 + # bytes prefix + '/' + 100 bytes name limit. + def test_unicode_longname1(self): + self._test_ustar_name("0123456789" * 15 + "01234/" + "0123456789" * 10) + self._test_ustar_name("0123456789" * 15 + "0123/4" + "0123456789" * 10, ValueError) + self._test_ustar_name("0123456789" * 15 + "012\xff/" + "0123456789" * 10) + self._test_ustar_name("0123456789" * 15 + "0123\xff/" + "0123456789" * 10, ValueError) + + def test_unicode_longname2(self): + self._test_ustar_name("0123456789" * 15 + "01\xff/2" + "0123456789" * 10, ValueError) + self._test_ustar_name("0123456789" * 15 + "01\xff\xff/" + "0123456789" * 10, ValueError) + + def test_unicode_longname3(self): + self._test_ustar_name("0123456789" * 15 + "01\xff\xff/2" + "0123456789" * 10, ValueError) + self._test_ustar_name("0123456789" * 15 + "01234/" + "0123456789" * 9 + "01234567\xff") + self._test_ustar_name("0123456789" * 15 + "01234/" + "0123456789" * 9 + "012345678\xff", ValueError) + + def test_unicode_longname4(self): + self._test_ustar_name("0123456789" * 15 + "01234/" + "0123456789" * 9 + "012345\xff\xff") + self._test_ustar_name("0123456789" * 15 + "01234/" + "0123456789" * 9 + "0123456\xff\xff", ValueError) + + def _test_ustar_name(self, name, exc=None): + with tarfile.open(tmpname, "w", format=self.format, encoding="utf-8") as tar: + t = tarfile.TarInfo(name) + if exc is None: + tar.addfile(t) + else: + self.assertRaises(exc, tar.addfile, t) + + if exc is None: + with tarfile.open(tmpname, "r") as tar: + for t in tar: + self.assertEqual(name, t.name) + break + + # Test the same as above for the 100 bytes link field. + def test_unicode_link1(self): + self._test_ustar_link("0123456789" * 10) + self._test_ustar_link("0123456789" * 10 + "0", ValueError) + self._test_ustar_link("0123456789" * 9 + "01234567\xff") + self._test_ustar_link("0123456789" * 9 + "012345678\xff", ValueError) + + def test_unicode_link2(self): + self._test_ustar_link("0123456789" * 9 + "012345\xff\xff") + self._test_ustar_link("0123456789" * 9 + "0123456\xff\xff", ValueError) + + def _test_ustar_link(self, name, exc=None): + with tarfile.open(tmpname, "w", format=self.format, encoding="utf-8") as tar: + t = tarfile.TarInfo("foo") + t.linkname = name + if exc is None: + tar.addfile(t) + else: + self.assertRaises(exc, tar.addfile, t) + + if exc is None: + with tarfile.open(tmpname, "r") as tar: + for t in tar: + self.assertEqual(name, t.linkname) + break + + +class GNUUnicodeTest(UnicodeTest, unittest.TestCase): format = tarfile.GNU_FORMAT @@ -1768,7 +1845,7 @@ self.fail("unable to read bad GNU tar pax header") -class PAXUnicodeTest(UstarUnicodeTest): +class PAXUnicodeTest(UnicodeTest, unittest.TestCase): format = tarfile.PAX_FORMAT diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,9 @@ Library ------- +- Issue #24838: tarfile's ustar and gnu formats now correctly calculate name + and link field limits for multibyte character encodings like utf-8. + - Issue #26657: Fix directory traversal vulnerability with http.server on Windows. This fixes a regression that was introduced in 3.3.4rc1 and 3.4.0rc1. Based on patch by Philipp Hagemeister. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 02:54:46 2016 From: python-checkins at python.org (lars.gustaebel) Date: Tue, 19 Apr 2016 06:54:46 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2324838=3A_Merge_tarfile_fix_from_3=2E5=2E?= Message-ID: <20160419065446.17490.34403.7FE13B24@psf.io> https://hg.python.org/cpython/rev/e281a57d5b29 changeset: 101055:e281a57d5b29 parent: 101053:ee9921b29fd8 parent: 101054:d08d6b776694 user: Lars Gust?bel date: Tue Apr 19 08:53:14 2016 +0200 summary: Issue #24838: Merge tarfile fix from 3.5. files: Lib/tarfile.py | 29 ++++---- Lib/test/test_tarfile.py | 87 ++++++++++++++++++++++++++- Misc/NEWS | 3 + 3 files changed, 100 insertions(+), 19 deletions(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -815,11 +815,11 @@ """ info["magic"] = POSIX_MAGIC - if len(info["linkname"]) > LENGTH_LINK: + if len(info["linkname"].encode(encoding, errors)) > LENGTH_LINK: raise ValueError("linkname is too long") - if len(info["name"]) > LENGTH_NAME: - info["prefix"], info["name"] = self._posix_split_name(info["name"]) + if len(info["name"].encode(encoding, errors)) > LENGTH_NAME: + info["prefix"], info["name"] = self._posix_split_name(info["name"], encoding, errors) return self._create_header(info, USTAR_FORMAT, encoding, errors) @@ -829,10 +829,10 @@ info["magic"] = GNU_MAGIC buf = b"" - if len(info["linkname"]) > LENGTH_LINK: + if len(info["linkname"].encode(encoding, errors)) > LENGTH_LINK: buf += self._create_gnu_long_header(info["linkname"], GNUTYPE_LONGLINK, encoding, errors) - if len(info["name"]) > LENGTH_NAME: + if len(info["name"].encode(encoding, errors)) > LENGTH_NAME: buf += self._create_gnu_long_header(info["name"], GNUTYPE_LONGNAME, encoding, errors) return buf + self._create_header(info, GNU_FORMAT, encoding, errors) @@ -892,19 +892,20 @@ """ return cls._create_pax_generic_header(pax_headers, XGLTYPE, "utf-8") - def _posix_split_name(self, name): + def _posix_split_name(self, name, encoding, errors): """Split a name longer than 100 chars into a prefix and a name part. """ - prefix = name[:LENGTH_PREFIX + 1] - while prefix and prefix[-1] != "/": - prefix = prefix[:-1] + components = name.split("/") + for i in range(1, len(components)): + prefix = "/".join(components[:i]) + name = "/".join(components[i:]) + if len(prefix.encode(encoding, errors)) <= LENGTH_PREFIX and \ + len(name.encode(encoding, errors)) <= LENGTH_NAME: + break + else: + raise ValueError("name is too long") - name = name[len(prefix):] - prefix = prefix[:-1] - - if not prefix or len(name) > LENGTH_NAME: - raise ValueError("name is too long") return prefix, name @staticmethod diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -1667,9 +1667,7 @@ tar.close() -class UstarUnicodeTest(unittest.TestCase): - - format = tarfile.USTAR_FORMAT +class UnicodeTest: def test_iso8859_1_filename(self): self._test_unicode_filename("iso8859-1") @@ -1750,7 +1748,86 @@ tar.close() -class GNUUnicodeTest(UstarUnicodeTest): +class UstarUnicodeTest(UnicodeTest, unittest.TestCase): + + format = tarfile.USTAR_FORMAT + + # Test whether the utf-8 encoded version of a filename exceeds the 100 + # bytes name field limit (every occurrence of '\xff' will be expanded to 2 + # bytes). + def test_unicode_name1(self): + self._test_ustar_name("0123456789" * 10) + self._test_ustar_name("0123456789" * 10 + "0", ValueError) + self._test_ustar_name("0123456789" * 9 + "01234567\xff") + self._test_ustar_name("0123456789" * 9 + "012345678\xff", ValueError) + + def test_unicode_name2(self): + self._test_ustar_name("0123456789" * 9 + "012345\xff\xff") + self._test_ustar_name("0123456789" * 9 + "0123456\xff\xff", ValueError) + + # Test whether the utf-8 encoded version of a filename exceeds the 155 + # bytes prefix + '/' + 100 bytes name limit. + def test_unicode_longname1(self): + self._test_ustar_name("0123456789" * 15 + "01234/" + "0123456789" * 10) + self._test_ustar_name("0123456789" * 15 + "0123/4" + "0123456789" * 10, ValueError) + self._test_ustar_name("0123456789" * 15 + "012\xff/" + "0123456789" * 10) + self._test_ustar_name("0123456789" * 15 + "0123\xff/" + "0123456789" * 10, ValueError) + + def test_unicode_longname2(self): + self._test_ustar_name("0123456789" * 15 + "01\xff/2" + "0123456789" * 10, ValueError) + self._test_ustar_name("0123456789" * 15 + "01\xff\xff/" + "0123456789" * 10, ValueError) + + def test_unicode_longname3(self): + self._test_ustar_name("0123456789" * 15 + "01\xff\xff/2" + "0123456789" * 10, ValueError) + self._test_ustar_name("0123456789" * 15 + "01234/" + "0123456789" * 9 + "01234567\xff") + self._test_ustar_name("0123456789" * 15 + "01234/" + "0123456789" * 9 + "012345678\xff", ValueError) + + def test_unicode_longname4(self): + self._test_ustar_name("0123456789" * 15 + "01234/" + "0123456789" * 9 + "012345\xff\xff") + self._test_ustar_name("0123456789" * 15 + "01234/" + "0123456789" * 9 + "0123456\xff\xff", ValueError) + + def _test_ustar_name(self, name, exc=None): + with tarfile.open(tmpname, "w", format=self.format, encoding="utf-8") as tar: + t = tarfile.TarInfo(name) + if exc is None: + tar.addfile(t) + else: + self.assertRaises(exc, tar.addfile, t) + + if exc is None: + with tarfile.open(tmpname, "r") as tar: + for t in tar: + self.assertEqual(name, t.name) + break + + # Test the same as above for the 100 bytes link field. + def test_unicode_link1(self): + self._test_ustar_link("0123456789" * 10) + self._test_ustar_link("0123456789" * 10 + "0", ValueError) + self._test_ustar_link("0123456789" * 9 + "01234567\xff") + self._test_ustar_link("0123456789" * 9 + "012345678\xff", ValueError) + + def test_unicode_link2(self): + self._test_ustar_link("0123456789" * 9 + "012345\xff\xff") + self._test_ustar_link("0123456789" * 9 + "0123456\xff\xff", ValueError) + + def _test_ustar_link(self, name, exc=None): + with tarfile.open(tmpname, "w", format=self.format, encoding="utf-8") as tar: + t = tarfile.TarInfo("foo") + t.linkname = name + if exc is None: + tar.addfile(t) + else: + self.assertRaises(exc, tar.addfile, t) + + if exc is None: + with tarfile.open(tmpname, "r") as tar: + for t in tar: + self.assertEqual(name, t.linkname) + break + + +class GNUUnicodeTest(UnicodeTest, unittest.TestCase): format = tarfile.GNU_FORMAT @@ -1768,7 +1845,7 @@ self.fail("unable to read bad GNU tar pax header") -class PAXUnicodeTest(UstarUnicodeTest): +class PAXUnicodeTest(UnicodeTest, unittest.TestCase): format = tarfile.PAX_FORMAT diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -245,6 +245,9 @@ Library ------- +- Issue #24838: tarfile's ustar and gnu formats now correctly calculate name + and link field limits for multibyte character encodings like utf-8. + - Issue #26657: Fix directory traversal vulnerability with http.server on Windows. This fixes a regression that was introduced in 3.3.4rc1 and 3.4.0rc1. Based on patch by Philipp Hagemeister. -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Tue Apr 19 05:47:27 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Tue, 19 Apr 2016 09:47:27 +0000 Subject: [Python-checkins] Daily reference leaks (ee9921b29fd8): sum=4 Message-ID: <20160419094727.8336.31364.1496D964@psf.io> results for ee9921b29fd8 on branch "default" -------------------------------------------- test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogJDfSTn', '--timeout', '7200'] From python-checkins at python.org Tue Apr 19 06:01:22 2016 From: python-checkins at python.org (lars.gustaebel) Date: Tue, 19 Apr 2016 10:01:22 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI0ODM4?= =?utf-8?q?=3A_Fix_test=5Ftarfile=2Epy_for_non-utf8_filesystem_encodings?= =?utf-8?q?=2E?= Message-ID: <20160419100121.26079.10542.F7D08221@psf.io> https://hg.python.org/cpython/rev/78ede2baa146 changeset: 101056:78ede2baa146 branch: 3.5 parent: 101054:d08d6b776694 user: Lars Gust?bel date: Tue Apr 19 11:58:41 2016 +0200 summary: Issue #24838: Fix test_tarfile.py for non-utf8 filesystem encodings. files: Lib/test/test_tarfile.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -1795,7 +1795,7 @@ self.assertRaises(exc, tar.addfile, t) if exc is None: - with tarfile.open(tmpname, "r") as tar: + with tarfile.open(tmpname, "r", encoding="utf-8") as tar: for t in tar: self.assertEqual(name, t.name) break @@ -1821,7 +1821,7 @@ self.assertRaises(exc, tar.addfile, t) if exc is None: - with tarfile.open(tmpname, "r") as tar: + with tarfile.open(tmpname, "r", encoding="utf-8") as tar: for t in tar: self.assertEqual(name, t.linkname) break -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 06:01:39 2016 From: python-checkins at python.org (lars.gustaebel) Date: Tue, 19 Apr 2016 10:01:39 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2324838=3A_Merge_test=5Ftarfile=2Epy_fix_from_3?= =?utf-8?b?LjUu?= Message-ID: <20160419100121.102703.89118.81618ED3@psf.io> https://hg.python.org/cpython/rev/08835d1e7a50 changeset: 101057:08835d1e7a50 parent: 101055:e281a57d5b29 parent: 101056:78ede2baa146 user: Lars Gust?bel date: Tue Apr 19 11:59:39 2016 +0200 summary: Issue #24838: Merge test_tarfile.py fix from 3.5. files: Lib/test/test_tarfile.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -1795,7 +1795,7 @@ self.assertRaises(exc, tar.addfile, t) if exc is None: - with tarfile.open(tmpname, "r") as tar: + with tarfile.open(tmpname, "r", encoding="utf-8") as tar: for t in tar: self.assertEqual(name, t.name) break @@ -1821,7 +1821,7 @@ self.assertRaises(exc, tar.addfile, t) if exc is None: - with tarfile.open(tmpname, "r") as tar: + with tarfile.open(tmpname, "r", encoding="utf-8") as tar: for t in tar: self.assertEqual(name, t.linkname) break -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 06:21:37 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 19 Apr 2016 10:21:37 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP_509=3A_fix_typos_reported?= =?utf-8?q?_by_Brett?= Message-ID: <20160419102137.411.94049.21508702@psf.io> https://hg.python.org/peps/rev/90fcde1f7017 changeset: 6286:90fcde1f7017 user: Victor Stinner date: Thu Apr 14 18:43:28 2016 +0200 summary: PEP 509: fix typos reported by Brett files: pep-0509.txt | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pep-0509.txt b/pep-0509.txt --- a/pep-0509.txt +++ b/pep-0509.txt @@ -74,7 +74,7 @@ self.version = dict_get_version(dict) def check(self): - """Return True if the dictionary entry did not changed + """Return True if the dictionary entry did not change and the dictionary was not replaced.""" # read the version of the dict structure @@ -166,7 +166,7 @@ ======= Add a ``ma_version_tag`` field to the ``PyDictObject`` structure with -the C type ``PY_INT64_T``, 64-bit unsigned integer. Add also a global +the C type ``PY_UINT64_T``, 64-bit unsigned integer. Add also a global dictionary version. Each time a dictionary is created, the global version is incremented and the dictionary version is initialized to the global version. The global version is also incremented and copied to the @@ -326,7 +326,7 @@ references to the dictionary and to the key are needed). Changes: add a ``me_version`` field to the ``PyDictKeyEntry`` structure, -the field has the C type ``PY_INT64_T``. When a key is created or +the field has the C type ``PY_UINT64_T``. When a key is created or modified, the entry version is set to the dictionary version which is incremented at any change (create, modify, delete). @@ -344,7 +344,7 @@ self.entry_version = dict_get_entry_version(dict, key) def check(self): - """Return True if the dictionary entry did not changed + """Return True if the dictionary entry did not change and the dictionary was not replaced.""" # read the version of the dict structure -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Tue Apr 19 06:21:43 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 19 Apr 2016 10:21:43 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP_509?= Message-ID: <20160419102137.70523.58937.E81ED676@psf.io> https://hg.python.org/peps/rev/a30e820a8003 changeset: 6287:a30e820a8003 user: Victor Stinner date: Tue Apr 19 10:43:02 2016 +0200 summary: PEP 509 * __setitem__() now always increases the version: remove the micro-optimization dict[key] is new_value * be more explict on version++: explain that the operation must be atomic, and that dict methods are already atomic thanks to the GIL * "Guard against changing dict during iteration": don't guess if the new dict version can be used or not. Let's discuss that later. * rephrase/complete some sections * add links to new threads on python-dev files: pep-0509.txt | 199 ++++++++++++++++++++------------------ 1 files changed, 103 insertions(+), 96 deletions(-) diff --git a/pep-0509.txt b/pep-0509.txt --- a/pep-0509.txt +++ b/pep-0509.txt @@ -22,11 +22,11 @@ ========= In Python, the builtin ``dict`` type is used by many instructions. For -example, the ``LOAD_GLOBAL`` instruction searchs for a variable in the +example, the ``LOAD_GLOBAL`` instruction looks up a variable in the global namespace, or in the builtins namespace (two dict lookups). Python uses ``dict`` for the builtins namespace, globals namespace, type -namespaces, instance namespaces, etc. The local namespace (namespace of -a function) is usually optimized to an array, but it can be a dict too. +namespaces, instance namespaces, etc. The local namespace (function +namespace) is usually optimized to an array, but it can be a dict too. Python is hard to optimize because almost everything is mutable: builtin functions, function code, global variables, local variables, ... can be @@ -35,26 +35,29 @@ these checks "guards". The speedup of optimizations depends on the speed of guard checks. This -PEP proposes to add a version to dictionaries to implement fast guards -on namespaces. +PEP proposes to add a private version to dictionaries to implement fast +guards on namespaces. Dictionary lookups can be skipped if the version does not change which -is the common case for most namespaces. Since the version is globally -unique, the version is also enough to check if the namespace dictionary -was not replaced with a new dictionary. The performance of a guard does -not depend on the number of watched dictionary entries, complexity of -O(1), if the dictionary version does not change. +is the common case for most namespaces. The version is globally unique, +so checking the version is also enough to check if the namespace +dictionary was not replaced with a new dictionary. + +When the dictionary version does not change, the performance of a guard +does not depend on the number of watched dictionary entries: the +complexity is O(1). Example of optimization: copy the value of a global variable to function constants. This optimization requires a guard on the global variable to -check if it was modified. If the variable is modified, the variable must -be loaded at runtime when the function is called, instead of using the -constant. +check if it was modified. If the global variable is not modified, the +function uses the cached copy. If the global variable is modified, the +function uses a regular lookup, and maybe also deoptimize the function +(to remove the overhead of the guard check for next function calls). See the `PEP 510 -- Specialized functions with guards `_ for the concrete usage of -guards to specialize functions and for the rationale on Python static -optimizers. +guards to specialize functions and for a more general rationale on +Python static optimizers. Guard example @@ -77,7 +80,7 @@ """Return True if the dictionary entry did not change and the dictionary was not replaced.""" - # read the version of the dict structure + # read the version of the dictionary version = dict_get_version(self.dict) if version == self.version: # Fast-path: dictionary lookup avoided @@ -98,21 +101,21 @@ Usage of the dict version ========================= -Speedup method calls 1.2x -------------------------- +Speedup method calls +-------------------- Yury Selivanov wrote a `patch to optimize method calls `_. The patch depends on the -`implement per-opcode cache in ceval +`"implement per-opcode cache in ceval" `_ patch which requires dictionary versions to invalidate the cache if the globals dictionary or the builtins dictionary has been modified. The cache also requires that the dictionary version is globally unique. -It is possible to define a function in a namespace and call it -in a different namespace: using ``exec()`` with the *globals* parameter -for example. In this case, the globals dictionary was changed and the -cache must be invalidated. +It is possible to define a function in a namespace and call it in a +different namespace, using ``exec()`` with the *globals* parameter for +example. In this case, the globals dictionary was replaced and the cache +must also be invalidated. Specialized functions using guards @@ -123,28 +126,37 @@ specialized functions with guards. It allows to implement static optimizers for Python without breaking the Python semantics. -Example of a static Python optimizer: the `fatoptimizer -`_ of the `FAT Python -`_ project -implements many optimizations which require guards on namespaces. -Examples: +The `fatoptimizer `_ of the `FAT +Python `_ project +is an example of a static Python optimizer. It implements many +optimizations which require guards on namespaces: * Call pure builtins: to replace ``len("abc")`` with ``3``, guards on ``builtins.__dict__['len']`` and ``globals()['len']`` are required * Loop unrolling: to unroll the loop ``for i in range(...): ...``, guards on ``builtins.__dict__['range']`` and ``globals()['range']`` are required +* etc. Pyjion ------ According of Brett Cannon, one of the two main developers of Pyjion, -Pyjion can also benefit from dictionary version to implement -optimizations. +Pyjion can benefit from dictionary version to implement optimizations. -Pyjion is a JIT compiler for Python based upon CoreCLR (Microsoft .NET -Core runtime). +`Pyjion `_ is a JIT compiler for +Python based upon CoreCLR (Microsoft .NET Core runtime). + + +Cython +------ + +Cython can benefit from dictionary version to implement optimizations. + +`Cython `_ is an optimising static compiler for both +the Python programming language and the extended Cython programming +language. Unladen Swallow @@ -153,8 +165,8 @@ Even if dictionary version was not explicitly mentioned, optimizing globals and builtins lookup was part of the Unladen Swallow plan: "Implement one of the several proposed schemes for speeding lookups of -globals and builtins." Source: `Unladen Swallow ProjectPlan -`_. +globals and builtins." (source: `Unladen Swallow ProjectPlan +`_). Unladen Swallow is a fork of CPython 2.6.1 adding a JIT compiler implemented with LLVM. The project stopped in 2011: `Unladen Swallow @@ -172,23 +184,16 @@ global version. The global version is also incremented and copied to the dictionary version at each dictionary change: -* ``clear()`` if the dict was non-empty +* ``clear()`` if the dict is non-empty * ``pop(key)`` if the key exists * ``popitem()`` if the dict is non-empty -* ``setdefault(key, value)`` if the `key` does not exist -* ``__detitem__(key)`` if the key exists -* ``__setitem__(key, value)`` if the `key` doesn't exist or if the value - is not ``dict[key]`` -* ``update(...)`` if new values are different than existing values: - values are compared by identity, not by their content; the version can - be incremented multiple times +* ``setdefault(key, value)`` if the key does not exist +* ``__delitem__(key)`` if the key exists +* ``__setitem__(key, value)`` always increases the version +* ``update(...)`` if called with arguments -The ``PyDictObject`` structure is not part of the stable ABI. - -The field is called ``ma_version_tag`` rather than ``ma_version`` to -suggest to compare it using ``version_tag == old_version_tag`` rather -than ``version <= old_version`` which makes the integer overflow much -likely. +The version increase must be atomic. In CPython, the Global Interpreter +Lock (GIL) already protects ``dict`` methods to make them atomic. Example using an hypothetical ``dict_get_version(dict)`` function:: @@ -205,25 +210,23 @@ >>> dict_get_version(d) 103 -The version is not incremented if an existing key is set to the same -value. For efficiency, values are compared by their identity: -``new_value is old_value``, not by their content: -``new_value == old_value``. Example:: +``dict.__setitem__(key, value)`` and ``dict.update(...)`` always +increases the version, even if the new value is identical or is equal to +the current value (even if ``(dict[key] is value) or (dict[key] == +value)``). - >>> d = {} - >>> value = object() - >>> d['key'] = value - >>> dict_get_version(d) - 40 - >>> d['key'] = value - >>> dict_get_version(d) - 40 +The field is called ``ma_version_tag``, rather than ``ma_version``, to +suggest to compare it using ``version_tag == old_version_tag``, rather +than ``version <= old_version`` which is wrong most of the time after an +integer overflow. -.. note:: - CPython uses some singleton like integers in the range [-5; 257], - empty tuple, empty strings, Unicode strings of a single character in - the range [U+0000; U+00FF], etc. When a key is set twice to the same - singleton, the version is not modified. + +Backwards Compatibility +======================= + +Since the ``PyDictObject`` structure is not part of the stable ABI and +the new dictionary version not exposed at the Python scope, changes are +backward compatible. Implementation and Performance @@ -234,7 +237,10 @@ this PEP. On pybench and timeit microbenchmarks, the patch does not seem to add -any overhead on dictionary operations. +any overhead on dictionary operations. For example, the following timeit +micro-benchmarks takes 318 nanoseconds before and after the change:: + + python3.6 -m timeit 'd={1: 0}; d[2]=0; d[3]=0; d[4]=0; del d[1]; del d[2]; d.clear()' When the version does not change, ``PyDict_GetItem()`` takes 14.8 ns for a dictionary lookup, whereas a guard check only takes 3.8 ns. Moreover, @@ -286,19 +292,19 @@ all mapping types. Implementing a new mapping type would require extra work for no benefit, since the version is only required on the ``dict`` type in practice. -* All Python implementations must implement this new property, it gives - more work to other implementations, whereas they may not use the - dictionary version at all. -* Exposing the dictionary version at Python level can lead the +* All Python implementations would have to implement this new property, + it gives more work to other implementations, whereas they may not use + the dictionary version at all. +* Exposing the dictionary version at the Python level can lead the false assumption on performances. Checking ``dict.__version__`` at the Python level is not faster than a dictionary lookup. A dictionary - lookup has a cost of 48.7 ns and checking a guard has a cost of 47.5 - ns, the difference is only 1.2 ns (3%):: + lookup in Python has a cost of 48.7 ns and checking the version has a + cost of 47.5 ns, the difference is only 1.2 ns (3%):: - $ ./python -m timeit -s 'd = {str(i):i for i in range(100)}' 'd["33"] == 33' + $ python3.6 -m timeit -s 'd = {str(i):i for i in range(100)}' 'd["33"] == 33' 10000000 loops, best of 3: 0.0487 usec per loop - $ ./python -m timeit -s 'd = {str(i):i for i in range(100)}' 'd.__version__ == 100' + $ python3.6 -m timeit -s 'd = {str(i):i for i in range(100)}' 'd.__version__ == 100' 10000000 loops, best of 3: 0.0475 usec per loop * The ``__version__`` can be wrapped on integer overflow. It is error @@ -313,6 +319,7 @@ `abc.get_cache_token() `_. * ``__version__`` +* ``__version_tag__`` * ``__timestamp__`` @@ -322,16 +329,16 @@ A single version per dictionary requires to keep a strong reference to the value which can keep the value alive longer than expected. If we add also a version per dictionary entry, the guard can only store the entry -version to avoid the strong reference to the value (only strong -references to the dictionary and to the key are needed). +version (a simple integer) to avoid the strong reference to the value: +only strong references to the dictionary and to the key are needed. -Changes: add a ``me_version`` field to the ``PyDictKeyEntry`` structure, -the field has the C type ``PY_UINT64_T``. When a key is created or -modified, the entry version is set to the dictionary version which is -incremented at any change (create, modify, delete). +Changes: add a ``me_version_tag`` field to the ``PyDictKeyEntry`` +structure, the field has the C type ``PY_UINT64_T``. When a key is +created or modified, the entry version is set to the dictionary version +which is incremented at any change (create, modify, delete). Pseudo-code of an fast guard to check if a dictionary key was modified -using hypothetical ``dict_get_version(dict)`` +using hypothetical ``dict_get_version(dict)`` and ``dict_get_entry_version(dict)`` functions:: UNSET = object() @@ -347,18 +354,19 @@ """Return True if the dictionary entry did not change and the dictionary was not replaced.""" - # read the version of the dict structure + # read the version of the dictionary dict_version = dict_get_version(self.dict) if dict_version == self.version: # Fast-path: dictionary lookup avoided return True - # lookup in the dictionary + # lookup in the dictionary to read the entry version entry_version = get_dict_key_version(dict, key) if entry_version == self.entry_version: # another key was modified: # cache the new dictionary version self.dict_version = dict_version + self.entry_version = entry_version return True # the key was modified @@ -366,7 +374,7 @@ The main drawback of this option is the impact on the memory footprint. It increases the size of each dictionary entry, so the overhead depends -on the number of buckets (dictionary entries, used or unused yet). For +on the number of buckets (dictionary entries, used or not used). For example, it increases the size of each dictionary entry by 8 bytes on 64-bit system. @@ -386,8 +394,8 @@ use the ``verdict`` for namespaces (module namespace, type namespace, instance namespace, etc.) instead of ``dict``. -Leave the ``dict`` type unchanged to not add any overhead (memory -footprint) when guards are not needed. +Leave the ``dict`` type unchanged to not add any overhead (CPU, memory +footprint) when guards are not used. Technical issue: a lot of C code in the wild, including CPython core, expecting the exact ``dict`` type. Issues: @@ -396,7 +404,7 @@ use ``globals={}``. It is not possible to cast the ``dict`` to a ``dict`` subtype because the caller expects the ``globals`` parameter to be modified (``dict`` is mutable). -* Functions call directly ``PyDict_xxx()`` functions, instead of calling +* C functions call directly ``PyDict_xxx()`` functions, instead of calling ``PyObject_xxx()`` if the object is a ``dict`` subtype * ``PyDict_CheckExact()`` check fails on ``dict`` subtype, whereas some functions require the exact ``dict`` type. @@ -427,7 +435,7 @@ version tag" (``tp_version_tag``) and a "valid version tag" flag to types (the ``PyTypeObject`` structure). -The type version tag is not available at the Python level. +The type version tag is not exposed at the Python level. The version tag has the C type ``unsigned int``. The cache is a global hash table of 4096 entries, shared by all types. The cache is global to @@ -478,7 +486,8 @@ the field has the C type ``size_t``. Thread on python-dev: `About dictionary lookup caching -`_. +`_ +(December 2006). Guard against changing dict during iteration @@ -488,13 +497,7 @@ iteration (issue #19332) `_ which adds a ``ma_count`` field to the ``PyDictObject`` structure (``dict`` type), the field has the C type ``size_t``. This field is incremented -when the dictionary is modified, and so is very similar to the proposed -dictionary version. - -Sadly, the dictionary version proposed in this PEP doesn't help to -detect dictionary mutation. The dictionary version changes when values -are replaced, whereas modifying dictionary values while iterating on -dictionary keys is legit in Python. +when the dictionary is modified. PySizer @@ -515,6 +518,10 @@ Thread on the mailing lists: +* python-dev: `Updated PEP 509 + `_ +* python-dev: `RFC: PEP 509: Add a private version to dict + `_ * python-dev: `PEP 509: Add a private version to dict `_ (january 2016) -- Repository URL: https://hg.python.org/peps From lp_benchmark_robot at intel.com Tue Apr 19 09:55:46 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Tue, 19 Apr 2016 14:55:46 +0100 Subject: [Python-checkins] GOOD Benchmark Results for Python Default 2016-04-19 Message-ID: Results for project Python default, build date 2016-04-19 02:01:50 +0000 commit: ee9921b29fd8 previous commit: 9a269279f131 revision date: 2016-04-18 18:21:10 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.25% 1.68% 10.27% 14.18% :-| pybench 6.17% 0.05% -0.07% 5.40% :-( regex_v8 2.93% 0.14% -3.32% 3.12% :-( nbody 0.75% -0.28% -3.36% 12.29% :-( json_dump_v2 0.20% 0.01% -4.44% 12.54% :-| normal_startup 0.84% 0.25% 0.42% 5.11% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/good-benchmark-results-for-python-default-2016-04-19/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Tue Apr 19 09:56:11 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Tue, 19 Apr 2016 14:56:11 +0100 Subject: [Python-checkins] NEUTRAL Benchmark Results for Python 2.7 2016-04-19 Message-ID: <56cef7aa-be5d-462e-9d6e-db4840358a6c@irsmsx103.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-19 02:46:32 +0000 commit: 8aa032b26552 previous commit: bbcde8db4dc4 revision date: 2016-04-18 03:45:18 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.11% -0.43% 6.39% 3.79% :-) pybench 0.13% 0.00% 5.92% 4.52% :-( regex_v8 0.84% -0.21% -2.13% 10.55% :-) nbody 0.14% 0.16% 6.91% 3.95% :-) json_dump_v2 0.54% -0.06% 2.18% 9.69% :-( normal_startup 1.98% -0.20% -5.39% 2.07% :-) ssbench 0.23% 0.35% 2.55% 1.25% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/neutral-benchmark-results-for-python-2-7-2016-04-19/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Tue Apr 19 09:58:47 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 19 Apr 2016 13:58:47 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogc2V0dXAucHk6IGFk?= =?utf-8?q?d_missing_libm_dependency?= Message-ID: <20160419135843.52470.71948.9B749A0E@psf.io> https://hg.python.org/cpython/rev/f92fea23161d changeset: 101058:f92fea23161d branch: 3.5 parent: 101056:78ede2baa146 user: Victor Stinner date: Tue Apr 19 15:58:11 2016 +0200 summary: setup.py: add missing libm dependency Issue #21668: Link audioop, _datetime, _ctypes_test modules to libm, except on Mac OS X. Patch written by Xavier de Gaye. files: Misc/NEWS | 5 ++++- setup.py | 29 +++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -400,12 +400,15 @@ Build ----- +- Issue #21668: Link audioop, _datetime, _ctypes_test modules to libm, + except on Mac OS X. Patch written by Xavier de Gaye. + - Issue #25702: A --with-lto configure option has been added that will enable link time optimizations at build time during a make profile-opt. Some compilers and toolchains are known to not produce stable code when using LTO, be sure to test things thoroughly before relying on it. It can provide a few % speed up over profile-opt alone. - + - Issue #26624: Adds validation of ucrtbase[d].dll version with warning for old versions. diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -480,6 +480,13 @@ finally: os.unlink(tmpfile) + def detect_math_libs(self): + # Check for MacOS X, which doesn't need libm.a at all + if host_platform == 'darwin': + return [] + else: + return ['m'] + def detect_modules(self): # Ensure that /usr/local is always used, but the local build # directories (i.e. '.' and 'Include') must be first. See issue @@ -584,10 +591,7 @@ if item.startswith('-L'): lib_dirs.append(item[2:]) - # Check for MacOS X, which doesn't need libm.a at all - math_libs = ['m'] - if host_platform == 'darwin': - math_libs = [] + math_libs = self.detect_math_libs() # XXX Omitted modules: gl, pure, dl, SGI-specific modules @@ -620,7 +624,10 @@ # time operations and variables exts.append( Extension('time', ['timemodule.c'], libraries=time_libs) ) - exts.append( Extension('_datetime', ['_datetimemodule.c']) ) + # math_libs is needed by delta_new() that uses round() and by accum() + # that uses modf(). + exts.append( Extension('_datetime', ['_datetimemodule.c'], + libraries=math_libs) ) # random number generator implemented in C exts.append( Extension("_random", ["_randommodule.c"]) ) # bisect @@ -691,11 +698,14 @@ # Multimedia modules # These don't work for 64-bit platforms!!! # These represent audio samples or images as strings: - + # # Operations on audio samples # According to #993173, this one should actually work fine on # 64-bit platforms. - exts.append( Extension('audioop', ['audioop.c']) ) + # + # audioop needs math_libs for floor() in multiple functions. + exts.append( Extension('audioop', ['audioop.c'], + libraries=math_libs) ) # readline do_readline = self.compiler.find_library_file(lib_dirs, 'readline') @@ -1937,6 +1947,7 @@ '_ctypes/stgdict.c', '_ctypes/cfield.c'] depends = ['_ctypes/ctypes.h'] + math_libs = self.detect_math_libs() if host_platform == 'darwin': sources.append('_ctypes/malloc_closure.c') @@ -1967,8 +1978,10 @@ libraries=[], sources=sources, depends=depends) + # function my_sqrt() needs math library for sqrt() ext_test = Extension('_ctypes_test', - sources=['_ctypes/_ctypes_test.c']) + sources=['_ctypes/_ctypes_test.c'], + libraries=math_libs) self.extensions.extend([ext, ext_test]) if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 09:58:47 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 19 Apr 2016 13:58:47 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_3=2E5=3A_Issue_=2321668?= Message-ID: <20160419135844.88646.99290.A73D0AC8@psf.io> https://hg.python.org/cpython/rev/3a9b47b062b9 changeset: 101059:3a9b47b062b9 parent: 101057:08835d1e7a50 parent: 101058:f92fea23161d user: Victor Stinner date: Tue Apr 19 15:58:33 2016 +0200 summary: Merge 3.5: Issue #21668 files: Misc/NEWS | 5 ++++- setup.py | 29 +++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -990,12 +990,15 @@ Build ----- +- Issue #21668: Link audioop, _datetime, _ctypes_test modules to libm, + except on Mac OS X. Patch written by Xavier de Gaye. + - Issue #25702: A --with-lto configure option has been added that will enable link time optimizations at build time during a make profile-opt. Some compilers and toolchains are known to not produce stable code when using LTO, be sure to test things thoroughly before relying on it. It can provide a few % speed up over profile-opt alone. - + - Issue #26624: Adds validation of ucrtbase[d].dll version with warning for old versions. diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -480,6 +480,13 @@ finally: os.unlink(tmpfile) + def detect_math_libs(self): + # Check for MacOS X, which doesn't need libm.a at all + if host_platform == 'darwin': + return [] + else: + return ['m'] + def detect_modules(self): # Ensure that /usr/local is always used, but the local build # directories (i.e. '.' and 'Include') must be first. See issue @@ -584,10 +591,7 @@ if item.startswith('-L'): lib_dirs.append(item[2:]) - # Check for MacOS X, which doesn't need libm.a at all - math_libs = ['m'] - if host_platform == 'darwin': - math_libs = [] + math_libs = self.detect_math_libs() # XXX Omitted modules: gl, pure, dl, SGI-specific modules @@ -620,7 +624,10 @@ # time operations and variables exts.append( Extension('time', ['timemodule.c'], libraries=time_libs) ) - exts.append( Extension('_datetime', ['_datetimemodule.c']) ) + # math_libs is needed by delta_new() that uses round() and by accum() + # that uses modf(). + exts.append( Extension('_datetime', ['_datetimemodule.c'], + libraries=math_libs) ) # random number generator implemented in C exts.append( Extension("_random", ["_randommodule.c"]) ) # bisect @@ -691,11 +698,14 @@ # Multimedia modules # These don't work for 64-bit platforms!!! # These represent audio samples or images as strings: - + # # Operations on audio samples # According to #993173, this one should actually work fine on # 64-bit platforms. - exts.append( Extension('audioop', ['audioop.c']) ) + # + # audioop needs math_libs for floor() in multiple functions. + exts.append( Extension('audioop', ['audioop.c'], + libraries=math_libs) ) # readline do_readline = self.compiler.find_library_file(lib_dirs, 'readline') @@ -1937,6 +1947,7 @@ '_ctypes/stgdict.c', '_ctypes/cfield.c'] depends = ['_ctypes/ctypes.h'] + math_libs = self.detect_math_libs() if host_platform == 'darwin': sources.append('_ctypes/malloc_closure.c') @@ -1967,8 +1978,10 @@ libraries=[], sources=sources, depends=depends) + # function my_sqrt() needs math library for sqrt() ext_test = Extension('_ctypes_test', - sources=['_ctypes/_ctypes_test.c']) + sources=['_ctypes/_ctypes_test.c'], + libraries=math_libs) self.extensions.extend([ext, ext_test]) if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 11:03:13 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 19 Apr 2016 15:03:13 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Don=27t_define_=5FPyMem=5F?= =?utf-8?q?PymallocEnabled=28=29_if_pymalloc_is_disabled?= Message-ID: <20160419150309.70525.45375.2C19BF85@psf.io> https://hg.python.org/cpython/rev/c4c14e34e528 changeset: 101060:c4c14e34e528 user: Victor Stinner date: Tue Apr 19 17:02:55 2016 +0200 summary: Don't define _PyMem_PymallocEnabled() if pymalloc is disabled Isse #26516. files: Objects/obmalloc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -286,13 +286,13 @@ #endif }; +#ifdef WITH_PYMALLOC static int _PyMem_DebugEnabled(void) { return (_PyObject.malloc == _PyMem_DebugMalloc); } -#ifdef WITH_PYMALLOC int _PyMem_PymallocEnabled(void) { -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 12:50:06 2016 From: python-checkins at python.org (zach.ware) Date: Tue, 19 Apr 2016 16:50:06 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Replace_assert?= =?utf-8?q?_statements_with_self=2EassertXxx=28=29_calls?= Message-ID: <20160419165001.89035.64582.1F66F170@psf.io> https://hg.python.org/cpython/rev/fd981e5c2faa changeset: 101061:fd981e5c2faa branch: 3.5 parent: 101058:f92fea23161d user: Zachary Ware date: Tue Apr 19 11:49:37 2016 -0500 summary: Replace assert statements with self.assertXxx() calls Sync with upstream, see github.com/python/typing/pull/205 files: Lib/test/test_typing.py | 584 ++++++++++++++------------- 1 files changed, 304 insertions(+), 280 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -20,6 +20,23 @@ import typing +class BaseTestCase(TestCase): + + def assertIsSubclass(self, cls, class_or_tuple, msg=None): + if not issubclass(cls, class_or_tuple): + message = '%r is not a subclass of %r' % (cls, class_or_tuple) + if msg is not None: + message += ' : %s' % msg + raise self.failureException(message) + + def assertNotIsSubclass(self, cls, class_or_tuple, msg=None): + if issubclass(cls, class_or_tuple): + message = '%r is a subclass of %r' % (cls, class_or_tuple) + if msg is not None: + message += ' : %s' % msg + raise self.failureException(message) + + class Employee: pass @@ -36,7 +53,7 @@ pass -class AnyTests(TestCase): +class AnyTests(BaseTestCase): def test_any_instance_type_error(self): with self.assertRaises(TypeError): @@ -79,40 +96,40 @@ def test_any_is_subclass(self): # Any should be considered a subclass of everything. - assert issubclass(Any, Any) - assert issubclass(Any, typing.List) - assert issubclass(Any, typing.List[int]) - assert issubclass(Any, typing.List[T]) - assert issubclass(Any, typing.Mapping) - assert issubclass(Any, typing.Mapping[str, int]) - assert issubclass(Any, typing.Mapping[KT, VT]) - assert issubclass(Any, Generic) - assert issubclass(Any, Generic[T]) - assert issubclass(Any, Generic[KT, VT]) - assert issubclass(Any, AnyStr) - assert issubclass(Any, Union) - assert issubclass(Any, Union[int, str]) - assert issubclass(Any, typing.Match) - assert issubclass(Any, typing.Match[str]) + self.assertIsSubclass(Any, Any) + self.assertIsSubclass(Any, typing.List) + self.assertIsSubclass(Any, typing.List[int]) + self.assertIsSubclass(Any, typing.List[T]) + self.assertIsSubclass(Any, typing.Mapping) + self.assertIsSubclass(Any, typing.Mapping[str, int]) + self.assertIsSubclass(Any, typing.Mapping[KT, VT]) + self.assertIsSubclass(Any, Generic) + self.assertIsSubclass(Any, Generic[T]) + self.assertIsSubclass(Any, Generic[KT, VT]) + self.assertIsSubclass(Any, AnyStr) + self.assertIsSubclass(Any, Union) + self.assertIsSubclass(Any, Union[int, str]) + self.assertIsSubclass(Any, typing.Match) + self.assertIsSubclass(Any, typing.Match[str]) # These expressions must simply not fail. typing.Match[Any] typing.Pattern[Any] typing.IO[Any] -class TypeVarTests(TestCase): +class TypeVarTests(BaseTestCase): def test_basic_plain(self): T = TypeVar('T') # Every class is a subclass of T. - assert issubclass(int, T) - assert issubclass(str, T) + self.assertIsSubclass(int, T) + self.assertIsSubclass(str, T) # T equals itself. - assert T == T + self.assertEqual(T, T) # T is a subclass of itself. - assert issubclass(T, T) + self.assertIsSubclass(T, T) # T is an instance of TypeVar - assert isinstance(T, TypeVar) + self.assertIsInstance(T, TypeVar) def test_typevar_instance_type_error(self): T = TypeVar('T') @@ -122,13 +139,13 @@ def test_basic_constrained(self): A = TypeVar('A', str, bytes) # Only str and bytes are subclasses of A. - assert issubclass(str, A) - assert issubclass(bytes, A) - assert not issubclass(int, A) + self.assertIsSubclass(str, A) + self.assertIsSubclass(bytes, A) + self.assertNotIsSubclass(int, A) # A equals itself. - assert A == A + self.assertEqual(A, A) # A is a subclass of itself. - assert issubclass(A, A) + self.assertIsSubclass(A, A) def test_constrained_error(self): with self.assertRaises(TypeError): @@ -138,18 +155,18 @@ def test_union_unique(self): X = TypeVar('X') Y = TypeVar('Y') - assert X != Y - assert Union[X] == X - assert Union[X] != Union[X, Y] - assert Union[X, X] == X - assert Union[X, int] != Union[X] - assert Union[X, int] != Union[int] - assert Union[X, int].__union_params__ == (X, int) - assert Union[X, int].__union_set_params__ == {X, int} + self.assertNotEqual(X, Y) + self.assertEqual(Union[X], X) + self.assertNotEqual(Union[X], Union[X, Y]) + self.assertEqual(Union[X, X], X) + self.assertNotEqual(Union[X, int], Union[X]) + self.assertNotEqual(Union[X, int], Union[int]) + self.assertEqual(Union[X, int].__union_params__, (X, int)) + self.assertEqual(Union[X, int].__union_set_params__, {X, int}) def test_union_constrained(self): A = TypeVar('A', str, bytes) - assert Union[A, str] != Union[A] + self.assertNotEqual(Union[A, str], Union[A]) def test_repr(self): self.assertEqual(repr(T), '~T') @@ -194,9 +211,9 @@ def test_bound(self): X = TypeVar('X', bound=Employee) - assert issubclass(Employee, X) - assert issubclass(Manager, X) - assert not issubclass(int, X) + self.assertIsSubclass(Employee, X) + self.assertIsSubclass(Manager, X) + self.assertNotIsSubclass(int, X) def test_bound_errors(self): with self.assertRaises(TypeError): @@ -205,7 +222,7 @@ TypeVar('X', str, float, bound=Employee) -class UnionTests(TestCase): +class UnionTests(BaseTestCase): def test_basics(self): u = Union[int, float] @@ -308,8 +325,8 @@ Union[()] def test_issubclass_union(self): - assert issubclass(Union[int, str], Union) - assert not issubclass(int, Union) + self.assertIsSubclass(Union[int, str], Union) + self.assertNotIsSubclass(int, Union) def test_union_instance_type_error(self): with self.assertRaises(TypeError): @@ -321,21 +338,21 @@ A -class TypeVarUnionTests(TestCase): +class TypeVarUnionTests(BaseTestCase): def test_simpler(self): A = TypeVar('A', int, str, float) B = TypeVar('B', int, str) - assert issubclass(A, A) - assert issubclass(B, B) - assert not issubclass(B, A) - assert issubclass(A, Union[int, str, float]) - assert not issubclass(Union[int, str, float], A) - assert not issubclass(Union[int, str], B) - assert issubclass(B, Union[int, str]) - assert not issubclass(A, B) - assert not issubclass(Union[int, str, float], B) - assert not issubclass(A, Union[int, str]) + self.assertIsSubclass(A, A) + self.assertIsSubclass(B, B) + self.assertNotIsSubclass(B, A) + self.assertIsSubclass(A, Union[int, str, float]) + self.assertNotIsSubclass(Union[int, str, float], A) + self.assertNotIsSubclass(Union[int, str], B) + self.assertIsSubclass(B, Union[int, str]) + self.assertNotIsSubclass(A, B) + self.assertNotIsSubclass(Union[int, str, float], B) + self.assertNotIsSubclass(A, Union[int, str]) def test_var_union_subclass(self): self.assertTrue(issubclass(T, Union[int, T])) @@ -343,11 +360,11 @@ def test_var_union(self): TU = TypeVar('TU', Union[int, float], None) - assert issubclass(int, TU) - assert issubclass(float, TU) + self.assertIsSubclass(int, TU) + self.assertIsSubclass(float, TU) -class TupleTests(TestCase): +class TupleTests(BaseTestCase): def test_basics(self): self.assertTrue(issubclass(Tuple[int, str], Tuple)) @@ -360,10 +377,10 @@ self.assertFalse(issubclass(Tuple, tuple)) # Can't have it both ways. def test_equality(self): - assert Tuple[int] == Tuple[int] - assert Tuple[int, ...] == Tuple[int, ...] - assert Tuple[int] != Tuple[int, int] - assert Tuple[int] != Tuple[int, ...] + self.assertEqual(Tuple[int], Tuple[int]) + self.assertEqual(Tuple[int, ...], Tuple[int, ...]) + self.assertNotEqual(Tuple[int], Tuple[int, int]) + self.assertNotEqual(Tuple[int], Tuple[int, ...]) def test_tuple_subclass(self): class MyTuple(tuple): @@ -384,10 +401,10 @@ class C(B): pass - assert not issubclass(Tuple[B], Tuple[B, ...]) - assert issubclass(Tuple[C, ...], Tuple[B, ...]) - assert not issubclass(Tuple[C, ...], Tuple[B]) - assert not issubclass(Tuple[C], Tuple[B, ...]) + self.assertNotIsSubclass(Tuple[B], Tuple[B, ...]) + self.assertIsSubclass(Tuple[C, ...], Tuple[B, ...]) + self.assertNotIsSubclass(Tuple[C, ...], Tuple[B]) + self.assertNotIsSubclass(Tuple[C], Tuple[B, ...]) def test_repr(self): self.assertEqual(repr(Tuple), 'typing.Tuple') @@ -402,7 +419,7 @@ issubclass(42, Tuple[int]) -class CallableTests(TestCase): +class CallableTests(BaseTestCase): def test_self_subclass(self): self.assertTrue(issubclass(Callable[[int], int], Callable)) @@ -447,20 +464,20 @@ def test_callable_instance_works(self): def f(): pass - assert isinstance(f, Callable) - assert not isinstance(None, Callable) + self.assertIsInstance(f, Callable) + self.assertNotIsInstance(None, Callable) def test_callable_instance_type_error(self): def f(): pass with self.assertRaises(TypeError): - assert isinstance(f, Callable[[], None]) + self.assertIsInstance(f, Callable[[], None]) with self.assertRaises(TypeError): - assert isinstance(f, Callable[[], Any]) + self.assertIsInstance(f, Callable[[], Any]) with self.assertRaises(TypeError): - assert not isinstance(None, Callable[[], None]) + self.assertNotIsInstance(None, Callable[[], None]) with self.assertRaises(TypeError): - assert not isinstance(None, Callable[[], Any]) + self.assertNotIsInstance(None, Callable[[], Any]) def test_repr(self): ct0 = Callable[[], bool] @@ -513,15 +530,15 @@ return default -class ProtocolTests(TestCase): +class ProtocolTests(BaseTestCase): def test_supports_int(self): - assert issubclass(int, typing.SupportsInt) - assert not issubclass(str, typing.SupportsInt) + self.assertIsSubclass(int, typing.SupportsInt) + self.assertNotIsSubclass(str, typing.SupportsInt) def test_supports_float(self): - assert issubclass(float, typing.SupportsFloat) - assert not issubclass(str, typing.SupportsFloat) + self.assertIsSubclass(float, typing.SupportsFloat) + self.assertNotIsSubclass(str, typing.SupportsFloat) def test_supports_complex(self): @@ -530,8 +547,8 @@ def __complex__(self): return 0j - assert issubclass(C, typing.SupportsComplex) - assert not issubclass(str, typing.SupportsComplex) + self.assertIsSubclass(C, typing.SupportsComplex) + self.assertNotIsSubclass(str, typing.SupportsComplex) def test_supports_bytes(self): @@ -540,40 +557,40 @@ def __bytes__(self): return b'' - assert issubclass(B, typing.SupportsBytes) - assert not issubclass(str, typing.SupportsBytes) + self.assertIsSubclass(B, typing.SupportsBytes) + self.assertNotIsSubclass(str, typing.SupportsBytes) def test_supports_abs(self): - assert issubclass(float, typing.SupportsAbs) - assert issubclass(int, typing.SupportsAbs) - assert not issubclass(str, typing.SupportsAbs) + self.assertIsSubclass(float, typing.SupportsAbs) + self.assertIsSubclass(int, typing.SupportsAbs) + self.assertNotIsSubclass(str, typing.SupportsAbs) def test_supports_round(self): issubclass(float, typing.SupportsRound) - assert issubclass(float, typing.SupportsRound) - assert issubclass(int, typing.SupportsRound) - assert not issubclass(str, typing.SupportsRound) + self.assertIsSubclass(float, typing.SupportsRound) + self.assertIsSubclass(int, typing.SupportsRound) + self.assertNotIsSubclass(str, typing.SupportsRound) def test_reversible(self): - assert issubclass(list, typing.Reversible) - assert not issubclass(int, typing.Reversible) + self.assertIsSubclass(list, typing.Reversible) + self.assertNotIsSubclass(int, typing.Reversible) def test_protocol_instance_type_error(self): with self.assertRaises(TypeError): isinstance(0, typing.SupportsAbs) -class GenericTests(TestCase): +class GenericTests(BaseTestCase): def test_basics(self): X = SimpleMapping[str, Any] - assert X.__parameters__ == () + self.assertEqual(X.__parameters__, ()) with self.assertRaises(TypeError): X[str] with self.assertRaises(TypeError): X[str, str] Y = SimpleMapping[XK, str] - assert Y.__parameters__ == (XK,) + self.assertEqual(Y.__parameters__, (XK,)) Y[str] with self.assertRaises(TypeError): Y[str, str] @@ -600,21 +617,21 @@ pass X = C[Tuple[S, T]] - assert X == C[Tuple[S, T]] - assert X != C[Tuple[T, S]] + self.assertEqual(X, C[Tuple[S, T]]) + self.assertNotEqual(X, C[Tuple[T, S]]) Y = X[T, int] - assert Y == X[T, int] - assert Y != X[S, int] - assert Y != X[T, str] + self.assertEqual(Y, X[T, int]) + self.assertNotEqual(Y, X[S, int]) + self.assertNotEqual(Y, X[T, str]) Z = Y[str] - assert Z == Y[str] - assert Z != Y[int] - assert Z != Y[T] + self.assertEqual(Z, Y[str]) + self.assertNotEqual(Z, Y[int]) + self.assertNotEqual(Z, Y[T]) - assert str(Z).endswith( - '.C<~T>[typing.Tuple[~S, ~T]]<~S, ~T>[~T, int]<~T>[str]') + self.assertTrue(str(Z).endswith( + '.C<~T>[typing.Tuple[~S, ~T]]<~S, ~T>[~T, int]<~T>[str]')) def test_dict(self): T = TypeVar('T') @@ -666,28 +683,30 @@ class C(Generic[T]): pass - assert C.__module__ == __name__ + self.assertEqual(C.__module__, __name__) if not PY32: - assert C.__qualname__ == 'GenericTests.test_repr_2..C' - assert repr(C).split('.')[-1] == 'C<~T>' + self.assertEqual(C.__qualname__, + 'GenericTests.test_repr_2..C') + self.assertEqual(repr(C).split('.')[-1], 'C<~T>') X = C[int] - assert X.__module__ == __name__ + self.assertEqual(X.__module__, __name__) if not PY32: - assert X.__qualname__ == 'C' - assert repr(X).split('.')[-1] == 'C<~T>[int]' + self.assertEqual(X.__qualname__, 'C') + self.assertEqual(repr(X).split('.')[-1], 'C<~T>[int]') class Y(C[int]): pass - assert Y.__module__ == __name__ + self.assertEqual(Y.__module__, __name__) if not PY32: - assert Y.__qualname__ == 'GenericTests.test_repr_2..Y' - assert repr(Y).split('.')[-1] == 'Y' + self.assertEqual(Y.__qualname__, + 'GenericTests.test_repr_2..Y') + self.assertEqual(repr(Y).split('.')[-1], 'Y') def test_eq_1(self): - assert Generic == Generic - assert Generic[T] == Generic[T] - assert Generic[KT] != Generic[VT] + self.assertEqual(Generic, Generic) + self.assertEqual(Generic[T], Generic[T]) + self.assertNotEqual(Generic[KT], Generic[VT]) def test_eq_2(self): @@ -697,10 +716,10 @@ class B(Generic[T]): pass - assert A == A - assert A != B - assert A[T] == A[T] - assert A[T] != B[T] + self.assertEqual(A, A) + self.assertNotEqual(A, B) + self.assertEqual(A[T], A[T]) + self.assertNotEqual(A[T], B[T]) def test_multiple_inheritance(self): @@ -713,7 +732,7 @@ class C(A[T, VT], Generic[VT, T, KT], B[KT, T]): pass - assert C.__parameters__ == (VT, T, KT) + self.assertEqual(C.__parameters__, (VT, T, KT)) def test_nested(self): @@ -743,7 +762,7 @@ a.set([]) a.append(1) a.append(42) - assert a.get() == [1, 42] + self.assertEqual(a.get(), [1, 42]) def test_type_erasure(self): T = TypeVar('T') @@ -760,12 +779,12 @@ a = Node(x) b = Node[T](x) c = Node[Any](x) - assert type(a) is Node - assert type(b) is Node - assert type(c) is Node - assert a.label == x - assert b.label == x - assert c.label == x + self.assertIs(type(a), Node) + self.assertIs(type(b), Node) + self.assertIs(type(c), Node) + self.assertEqual(a.label, x) + self.assertEqual(b.label, x) + self.assertEqual(c.label, x) foo(42) @@ -778,7 +797,7 @@ class D(C): pass - assert D.__parameters__ == () + self.assertEqual(D.__parameters__, ()) with self.assertRaises(Exception): D[int] @@ -788,61 +807,63 @@ D[T] -class VarianceTests(TestCase): +class VarianceTests(BaseTestCase): def test_invariance(self): # Because of invariance, List[subclass of X] is not a subclass # of List[X], and ditto for MutableSequence. - assert not issubclass(typing.List[Manager], typing.List[Employee]) - assert not issubclass(typing.MutableSequence[Manager], + self.assertNotIsSubclass(typing.List[Manager], typing.List[Employee]) + self.assertNotIsSubclass(typing.MutableSequence[Manager], typing.MutableSequence[Employee]) # It's still reflexive. - assert issubclass(typing.List[Employee], typing.List[Employee]) - assert issubclass(typing.MutableSequence[Employee], + self.assertIsSubclass(typing.List[Employee], typing.List[Employee]) + self.assertIsSubclass(typing.MutableSequence[Employee], typing.MutableSequence[Employee]) def test_covariance_tuple(self): # Check covariace for Tuple (which are really special cases). - assert issubclass(Tuple[Manager], Tuple[Employee]) - assert not issubclass(Tuple[Employee], Tuple[Manager]) + self.assertIsSubclass(Tuple[Manager], Tuple[Employee]) + self.assertNotIsSubclass(Tuple[Employee], Tuple[Manager]) # And pairwise. - assert issubclass(Tuple[Manager, Manager], Tuple[Employee, Employee]) - assert not issubclass(Tuple[Employee, Employee], + self.assertIsSubclass(Tuple[Manager, Manager], + Tuple[Employee, Employee]) + self.assertNotIsSubclass(Tuple[Employee, Employee], Tuple[Manager, Employee]) # And using ellipsis. - assert issubclass(Tuple[Manager, ...], Tuple[Employee, ...]) - assert not issubclass(Tuple[Employee, ...], Tuple[Manager, ...]) + self.assertIsSubclass(Tuple[Manager, ...], Tuple[Employee, ...]) + self.assertNotIsSubclass(Tuple[Employee, ...], Tuple[Manager, ...]) def test_covariance_sequence(self): # Check covariance for Sequence (which is just a generic class # for this purpose, but using a covariant type variable). - assert issubclass(typing.Sequence[Manager], typing.Sequence[Employee]) - assert not issubclass(typing.Sequence[Employee], + self.assertIsSubclass(typing.Sequence[Manager], + typing.Sequence[Employee]) + self.assertNotIsSubclass(typing.Sequence[Employee], typing.Sequence[Manager]) def test_covariance_mapping(self): # Ditto for Mapping (covariant in the value, invariant in the key). - assert issubclass(typing.Mapping[Employee, Manager], + self.assertIsSubclass(typing.Mapping[Employee, Manager], typing.Mapping[Employee, Employee]) - assert not issubclass(typing.Mapping[Manager, Employee], + self.assertNotIsSubclass(typing.Mapping[Manager, Employee], typing.Mapping[Employee, Employee]) - assert not issubclass(typing.Mapping[Employee, Manager], + self.assertNotIsSubclass(typing.Mapping[Employee, Manager], typing.Mapping[Manager, Manager]) - assert not issubclass(typing.Mapping[Manager, Employee], + self.assertNotIsSubclass(typing.Mapping[Manager, Employee], typing.Mapping[Manager, Manager]) -class CastTests(TestCase): +class CastTests(BaseTestCase): def test_basics(self): - assert cast(int, 42) == 42 - assert cast(float, 42) == 42 - assert type(cast(float, 42)) is int - assert cast(Any, 42) == 42 - assert cast(list, 42) == 42 - assert cast(Union[str, float], 42) == 42 - assert cast(AnyStr, 42) == 42 - assert cast(None, 42) == 42 + self.assertEqual(cast(int, 42), 42) + self.assertEqual(cast(float, 42), 42) + self.assertIs(type(cast(float, 42)), int) + self.assertEqual(cast(Any, 42), 42) + self.assertEqual(cast(list, 42), 42) + self.assertEqual(cast(Union[str, float], 42), 42) + self.assertEqual(cast(AnyStr, 42), 42) + self.assertEqual(cast(None, 42), 42) def test_errors(self): # Bogus calls are not expected to fail. @@ -850,7 +871,7 @@ cast('hello', 42) -class ForwardRefTests(TestCase): +class ForwardRefTests(BaseTestCase): def test_basics(self): @@ -876,15 +897,17 @@ t = Node[int] both_hints = get_type_hints(t.add_both, globals(), locals()) - assert both_hints['left'] == both_hints['right'] == Optional[Node[T]] - assert both_hints['stuff'] == Optional[int] - assert 'blah' not in both_hints + self.assertEqual(both_hints['left'], Optional[Node[T]]) + self.assertEqual(both_hints['right'], Optional[Node[T]]) + self.assertEqual(both_hints['left'], both_hints['right']) + self.assertEqual(both_hints['stuff'], Optional[int]) + self.assertNotIn('blah', both_hints) left_hints = get_type_hints(t.add_left, globals(), locals()) - assert left_hints['node'] == Optional[Node[T]] + self.assertEqual(left_hints['node'], Optional[Node[T]]) right_hints = get_type_hints(t.add_right, globals(), locals()) - assert right_hints['node'] == Optional[Node[T]] + self.assertEqual(right_hints['node'], Optional[Node[T]]) def test_forwardref_instance_type_error(self): fr = typing._ForwardRef('int') @@ -1007,10 +1030,10 @@ ns = {} exec(code, ns) hints = get_type_hints(ns['C'].foo) - assert hints == {'a': ns['C'], 'return': ns['D']} + self.assertEqual(hints, {'a': ns['C'], 'return': ns['D']}) -class OverloadTests(TestCase): +class OverloadTests(BaseTestCase): def test_overload_exists(self): from typing import overload @@ -1076,29 +1099,29 @@ exec(PY35_TESTS) -class CollectionsAbcTests(TestCase): +class CollectionsAbcTests(BaseTestCase): def test_hashable(self): - assert isinstance(42, typing.Hashable) - assert not isinstance([], typing.Hashable) + self.assertIsInstance(42, typing.Hashable) + self.assertNotIsInstance([], typing.Hashable) def test_iterable(self): - assert isinstance([], typing.Iterable) + self.assertIsInstance([], typing.Iterable) # Due to ABC caching, the second time takes a separate code # path and could fail. So call this a few times. - assert isinstance([], typing.Iterable) - assert isinstance([], typing.Iterable) - assert isinstance([], typing.Iterable[int]) - assert not isinstance(42, typing.Iterable) + self.assertIsInstance([], typing.Iterable) + self.assertIsInstance([], typing.Iterable) + self.assertIsInstance([], typing.Iterable[int]) + self.assertNotIsInstance(42, typing.Iterable) # Just in case, also test issubclass() a few times. - assert issubclass(list, typing.Iterable) - assert issubclass(list, typing.Iterable) + self.assertIsSubclass(list, typing.Iterable) + self.assertIsSubclass(list, typing.Iterable) def test_iterator(self): it = iter([]) - assert isinstance(it, typing.Iterator) - assert isinstance(it, typing.Iterator[int]) - assert not isinstance(42, typing.Iterator) + self.assertIsInstance(it, typing.Iterator) + self.assertIsInstance(it, typing.Iterator[int]) + self.assertNotIsInstance(42, typing.Iterator) @skipUnless(PY35, 'Python 3.5 required') def test_awaitable(self): @@ -1109,12 +1132,12 @@ globals(), ns) foo = ns['foo'] g = foo() - assert issubclass(type(g), typing.Awaitable[int]) - assert isinstance(g, typing.Awaitable) - assert not isinstance(foo, typing.Awaitable) - assert issubclass(typing.Awaitable[Manager], + self.assertIsSubclass(type(g), typing.Awaitable[int]) + self.assertIsInstance(g, typing.Awaitable) + self.assertNotIsInstance(foo, typing.Awaitable) + self.assertIsSubclass(typing.Awaitable[Manager], typing.Awaitable[Employee]) - assert not issubclass(typing.Awaitable[Employee], + self.assertNotIsSubclass(typing.Awaitable[Employee], typing.Awaitable[Manager]) g.send(None) # Run foo() till completion, to avoid warning. @@ -1122,70 +1145,70 @@ def test_async_iterable(self): base_it = range(10) # type: Iterator[int] it = AsyncIteratorWrapper(base_it) - assert isinstance(it, typing.AsyncIterable) - assert isinstance(it, typing.AsyncIterable) - assert issubclass(typing.AsyncIterable[Manager], + self.assertIsInstance(it, typing.AsyncIterable) + self.assertIsInstance(it, typing.AsyncIterable) + self.assertIsSubclass(typing.AsyncIterable[Manager], typing.AsyncIterable[Employee]) - assert not isinstance(42, typing.AsyncIterable) + self.assertNotIsInstance(42, typing.AsyncIterable) @skipUnless(PY35, 'Python 3.5 required') def test_async_iterator(self): base_it = range(10) # type: Iterator[int] it = AsyncIteratorWrapper(base_it) - assert isinstance(it, typing.AsyncIterator) - assert issubclass(typing.AsyncIterator[Manager], + self.assertIsInstance(it, typing.AsyncIterator) + self.assertIsSubclass(typing.AsyncIterator[Manager], typing.AsyncIterator[Employee]) - assert not isinstance(42, typing.AsyncIterator) + self.assertNotIsInstance(42, typing.AsyncIterator) def test_sized(self): - assert isinstance([], typing.Sized) - assert not isinstance(42, typing.Sized) + self.assertIsInstance([], typing.Sized) + self.assertNotIsInstance(42, typing.Sized) def test_container(self): - assert isinstance([], typing.Container) - assert not isinstance(42, typing.Container) + self.assertIsInstance([], typing.Container) + self.assertNotIsInstance(42, typing.Container) def test_abstractset(self): - assert isinstance(set(), typing.AbstractSet) - assert not isinstance(42, typing.AbstractSet) + self.assertIsInstance(set(), typing.AbstractSet) + self.assertNotIsInstance(42, typing.AbstractSet) def test_mutableset(self): - assert isinstance(set(), typing.MutableSet) - assert not isinstance(frozenset(), typing.MutableSet) + self.assertIsInstance(set(), typing.MutableSet) + self.assertNotIsInstance(frozenset(), typing.MutableSet) def test_mapping(self): - assert isinstance({}, typing.Mapping) - assert not isinstance(42, typing.Mapping) + self.assertIsInstance({}, typing.Mapping) + self.assertNotIsInstance(42, typing.Mapping) def test_mutablemapping(self): - assert isinstance({}, typing.MutableMapping) - assert not isinstance(42, typing.MutableMapping) + self.assertIsInstance({}, typing.MutableMapping) + self.assertNotIsInstance(42, typing.MutableMapping) def test_sequence(self): - assert isinstance([], typing.Sequence) - assert not isinstance(42, typing.Sequence) + self.assertIsInstance([], typing.Sequence) + self.assertNotIsInstance(42, typing.Sequence) def test_mutablesequence(self): - assert isinstance([], typing.MutableSequence) - assert not isinstance((), typing.MutableSequence) + self.assertIsInstance([], typing.MutableSequence) + self.assertNotIsInstance((), typing.MutableSequence) def test_bytestring(self): - assert isinstance(b'', typing.ByteString) - assert isinstance(bytearray(b''), typing.ByteString) + self.assertIsInstance(b'', typing.ByteString) + self.assertIsInstance(bytearray(b''), typing.ByteString) def test_list(self): - assert issubclass(list, typing.List) + self.assertIsSubclass(list, typing.List) def test_set(self): - assert issubclass(set, typing.Set) - assert not issubclass(frozenset, typing.Set) + self.assertIsSubclass(set, typing.Set) + self.assertNotIsSubclass(frozenset, typing.Set) def test_frozenset(self): - assert issubclass(frozenset, typing.FrozenSet) - assert not issubclass(set, typing.FrozenSet) + self.assertIsSubclass(frozenset, typing.FrozenSet) + self.assertNotIsSubclass(set, typing.FrozenSet) def test_dict(self): - assert issubclass(dict, typing.Dict) + self.assertIsSubclass(dict, typing.Dict) def test_no_list_instantiation(self): with self.assertRaises(TypeError): @@ -1201,7 +1224,7 @@ pass a = MyList() - assert isinstance(a, MyList) + self.assertIsInstance(a, MyList) def test_no_dict_instantiation(self): with self.assertRaises(TypeError): @@ -1217,7 +1240,7 @@ pass d = MyDict() - assert isinstance(d, MyDict) + self.assertIsInstance(d, MyDict) def test_no_defaultdict_instantiation(self): with self.assertRaises(TypeError): @@ -1233,7 +1256,7 @@ pass dd = MyDefDict() - assert isinstance(dd, MyDefDict) + self.assertIsInstance(dd, MyDefDict) def test_no_set_instantiation(self): with self.assertRaises(TypeError): @@ -1249,7 +1272,7 @@ pass d = MySet() - assert isinstance(d, MySet) + self.assertIsInstance(d, MySet) def test_no_frozenset_instantiation(self): with self.assertRaises(TypeError): @@ -1265,7 +1288,7 @@ pass d = MyFrozenSet() - assert isinstance(d, MyFrozenSet) + self.assertIsInstance(d, MyFrozenSet) def test_no_tuple_instantiation(self): with self.assertRaises(TypeError): @@ -1279,10 +1302,10 @@ def foo(): yield 42 g = foo() - assert issubclass(type(g), typing.Generator) - assert issubclass(typing.Generator[Manager, Employee, Manager], + self.assertIsSubclass(type(g), typing.Generator) + self.assertIsSubclass(typing.Generator[Manager, Employee, Manager], typing.Generator[Employee, Manager, Employee]) - assert not issubclass(typing.Generator[Manager, Manager, Manager], + self.assertNotIsSubclass(typing.Generator[Manager, Manager, Manager], typing.Generator[Employee, Employee, Employee]) def test_no_generator_instantiation(self): @@ -1305,18 +1328,18 @@ def __len__(self): return 0 - assert len(MMC()) == 0 + self.assertEqual(len(MMC()), 0) class MMB(typing.MutableMapping[KT, VT]): def __len__(self): return 0 - assert len(MMB()) == 0 - assert len(MMB[str, str]()) == 0 - assert len(MMB[KT, VT]()) == 0 + self.assertEqual(len(MMB()), 0) + self.assertEqual(len(MMB[str, str]()), 0) + self.assertEqual(len(MMB[KT, VT]()), 0) -class OtherABCTests(TestCase): +class OtherABCTests(BaseTestCase): @skipUnless(hasattr(typing, 'ContextManager'), 'requires typing.ContextManager') @@ -1326,27 +1349,27 @@ yield 42 cm = manager() - assert isinstance(cm, typing.ContextManager) - assert isinstance(cm, typing.ContextManager[int]) - assert not isinstance(42, typing.ContextManager) + self.assertIsInstance(cm, typing.ContextManager) + self.assertIsInstance(cm, typing.ContextManager[int]) + self.assertNotIsInstance(42, typing.ContextManager) -class NamedTupleTests(TestCase): +class NamedTupleTests(BaseTestCase): def test_basics(self): Emp = NamedTuple('Emp', [('name', str), ('id', int)]) - assert issubclass(Emp, tuple) + self.assertIsSubclass(Emp, tuple) joe = Emp('Joe', 42) jim = Emp(name='Jim', id=1) - assert isinstance(joe, Emp) - assert isinstance(joe, tuple) - assert joe.name == 'Joe' - assert joe.id == 42 - assert jim.name == 'Jim' - assert jim.id == 1 - assert Emp.__name__ == 'Emp' - assert Emp._fields == ('name', 'id') - assert Emp._field_types == dict(name=str, id=int) + self.assertIsInstance(joe, Emp) + self.assertIsInstance(joe, tuple) + self.assertEqual(joe.name, 'Joe') + self.assertEqual(joe.id, 42) + self.assertEqual(jim.name, 'Jim') + self.assertEqual(jim.id, 1) + self.assertEqual(Emp.__name__, 'Emp') + self.assertEqual(Emp._fields, ('name', 'id')) + self.assertEqual(Emp._field_types, dict(name=str, id=int)) def test_pickle(self): global Emp # pickle wants to reference the class by name @@ -1358,7 +1381,7 @@ self.assertEqual(jane2, jane) -class IOTests(TestCase): +class IOTests(BaseTestCase): def test_io(self): @@ -1366,7 +1389,7 @@ return a.readline() a = stuff.__annotations__['a'] - assert a.__parameters__ == (AnyStr,) + self.assertEqual(a.__parameters__, (AnyStr,)) def test_textio(self): @@ -1374,7 +1397,7 @@ return a.readline() a = stuff.__annotations__['a'] - assert a.__parameters__ == () + self.assertEqual(a.__parameters__, ()) def test_binaryio(self): @@ -1382,40 +1405,40 @@ return a.readline() a = stuff.__annotations__['a'] - assert a.__parameters__ == () + self.assertEqual(a.__parameters__, ()) def test_io_submodule(self): from typing.io import IO, TextIO, BinaryIO, __all__, __name__ - assert IO is typing.IO - assert TextIO is typing.TextIO - assert BinaryIO is typing.BinaryIO - assert set(__all__) == set(['IO', 'TextIO', 'BinaryIO']) - assert __name__ == 'typing.io' + self.assertIs(IO, typing.IO) + self.assertIs(TextIO, typing.TextIO) + self.assertIs(BinaryIO, typing.BinaryIO) + self.assertEqual(set(__all__), set(['IO', 'TextIO', 'BinaryIO'])) + self.assertEqual(__name__, 'typing.io') -class RETests(TestCase): +class RETests(BaseTestCase): # Much of this is really testing _TypeAlias. def test_basics(self): pat = re.compile('[a-z]+', re.I) - assert issubclass(pat.__class__, Pattern) - assert issubclass(type(pat), Pattern) - assert issubclass(type(pat), Pattern[str]) + self.assertIsSubclass(pat.__class__, Pattern) + self.assertIsSubclass(type(pat), Pattern) + self.assertIsSubclass(type(pat), Pattern[str]) mat = pat.search('12345abcde.....') - assert issubclass(mat.__class__, Match) - assert issubclass(mat.__class__, Match[str]) - assert issubclass(mat.__class__, Match[bytes]) # Sad but true. - assert issubclass(type(mat), Match) - assert issubclass(type(mat), Match[str]) + self.assertIsSubclass(mat.__class__, Match) + self.assertIsSubclass(mat.__class__, Match[str]) + self.assertIsSubclass(mat.__class__, Match[bytes]) # Sad but true. + self.assertIsSubclass(type(mat), Match) + self.assertIsSubclass(type(mat), Match[str]) p = Pattern[Union[str, bytes]] - assert issubclass(Pattern[str], Pattern) - assert issubclass(Pattern[str], p) + self.assertIsSubclass(Pattern[str], Pattern) + self.assertIsSubclass(Pattern[str], p) m = Match[Union[bytes, str]] - assert issubclass(Match[bytes], Match) - assert issubclass(Match[bytes], m) + self.assertIsSubclass(Match[bytes], Match) + self.assertIsSubclass(Match[bytes], m) def test_errors(self): with self.assertRaises(TypeError): @@ -1436,19 +1459,19 @@ isinstance(42, Pattern[str]) def test_repr(self): - assert repr(Pattern) == 'Pattern[~AnyStr]' - assert repr(Pattern[str]) == 'Pattern[str]' - assert repr(Pattern[bytes]) == 'Pattern[bytes]' - assert repr(Match) == 'Match[~AnyStr]' - assert repr(Match[str]) == 'Match[str]' - assert repr(Match[bytes]) == 'Match[bytes]' + self.assertEqual(repr(Pattern), 'Pattern[~AnyStr]') + self.assertEqual(repr(Pattern[str]), 'Pattern[str]') + self.assertEqual(repr(Pattern[bytes]), 'Pattern[bytes]') + self.assertEqual(repr(Match), 'Match[~AnyStr]') + self.assertEqual(repr(Match[str]), 'Match[str]') + self.assertEqual(repr(Match[bytes]), 'Match[bytes]') def test_re_submodule(self): from typing.re import Match, Pattern, __all__, __name__ - assert Match is typing.Match - assert Pattern is typing.Pattern - assert set(__all__) == set(['Match', 'Pattern']) - assert __name__ == 'typing.re' + self.assertIs(Match, typing.Match) + self.assertIs(Pattern, typing.Pattern) + self.assertEqual(set(__all__), set(['Match', 'Pattern'])) + self.assertEqual(__name__, 'typing.re') def test_cannot_subclass(self): with self.assertRaises(TypeError) as ex: @@ -1456,29 +1479,30 @@ class A(typing.Match): pass - assert str(ex.exception) == "A type alias cannot be subclassed" + self.assertEqual(str(ex.exception), + "A type alias cannot be subclassed") -class AllTests(TestCase): +class AllTests(BaseTestCase): """Tests for __all__.""" def test_all(self): from typing import __all__ as a # Just spot-check the first and last of every category. - assert 'AbstractSet' in a - assert 'ValuesView' in a - assert 'cast' in a - assert 'overload' in a + self.assertIn('AbstractSet', a) + self.assertIn('ValuesView', a) + self.assertIn('cast', a) + self.assertIn('overload', a) if hasattr(contextlib, 'AbstractContextManager'): - assert 'ContextManager' in a + self.assertIn('ContextManager', a) # Check that io and re are not exported. - assert 'io' not in a - assert 're' not in a + self.assertNotIn('io', a) + self.assertNotIn('re', a) # Spot-check that stdlib modules aren't exported. - assert 'os' not in a - assert 'sys' not in a + self.assertNotIn('os', a) + self.assertNotIn('sys', a) # Check that Text is defined. - assert 'Text' in a + self.assertIn('Text', a) if __name__ == '__main__': -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 12:50:06 2016 From: python-checkins at python.org (zach.ware) Date: Tue, 19 Apr 2016 16:50:06 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_with_3=2E5?= Message-ID: <20160419165002.88666.66896.6830504E@psf.io> https://hg.python.org/cpython/rev/8f16a0f3419b changeset: 101062:8f16a0f3419b parent: 101060:c4c14e34e528 parent: 101061:fd981e5c2faa user: Zachary Ware date: Tue Apr 19 11:49:56 2016 -0500 summary: Merge with 3.5 files: Lib/test/test_typing.py | 584 ++++++++++++++------------- 1 files changed, 304 insertions(+), 280 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -20,6 +20,23 @@ import typing +class BaseTestCase(TestCase): + + def assertIsSubclass(self, cls, class_or_tuple, msg=None): + if not issubclass(cls, class_or_tuple): + message = '%r is not a subclass of %r' % (cls, class_or_tuple) + if msg is not None: + message += ' : %s' % msg + raise self.failureException(message) + + def assertNotIsSubclass(self, cls, class_or_tuple, msg=None): + if issubclass(cls, class_or_tuple): + message = '%r is a subclass of %r' % (cls, class_or_tuple) + if msg is not None: + message += ' : %s' % msg + raise self.failureException(message) + + class Employee: pass @@ -36,7 +53,7 @@ pass -class AnyTests(TestCase): +class AnyTests(BaseTestCase): def test_any_instance_type_error(self): with self.assertRaises(TypeError): @@ -79,40 +96,40 @@ def test_any_is_subclass(self): # Any should be considered a subclass of everything. - assert issubclass(Any, Any) - assert issubclass(Any, typing.List) - assert issubclass(Any, typing.List[int]) - assert issubclass(Any, typing.List[T]) - assert issubclass(Any, typing.Mapping) - assert issubclass(Any, typing.Mapping[str, int]) - assert issubclass(Any, typing.Mapping[KT, VT]) - assert issubclass(Any, Generic) - assert issubclass(Any, Generic[T]) - assert issubclass(Any, Generic[KT, VT]) - assert issubclass(Any, AnyStr) - assert issubclass(Any, Union) - assert issubclass(Any, Union[int, str]) - assert issubclass(Any, typing.Match) - assert issubclass(Any, typing.Match[str]) + self.assertIsSubclass(Any, Any) + self.assertIsSubclass(Any, typing.List) + self.assertIsSubclass(Any, typing.List[int]) + self.assertIsSubclass(Any, typing.List[T]) + self.assertIsSubclass(Any, typing.Mapping) + self.assertIsSubclass(Any, typing.Mapping[str, int]) + self.assertIsSubclass(Any, typing.Mapping[KT, VT]) + self.assertIsSubclass(Any, Generic) + self.assertIsSubclass(Any, Generic[T]) + self.assertIsSubclass(Any, Generic[KT, VT]) + self.assertIsSubclass(Any, AnyStr) + self.assertIsSubclass(Any, Union) + self.assertIsSubclass(Any, Union[int, str]) + self.assertIsSubclass(Any, typing.Match) + self.assertIsSubclass(Any, typing.Match[str]) # These expressions must simply not fail. typing.Match[Any] typing.Pattern[Any] typing.IO[Any] -class TypeVarTests(TestCase): +class TypeVarTests(BaseTestCase): def test_basic_plain(self): T = TypeVar('T') # Every class is a subclass of T. - assert issubclass(int, T) - assert issubclass(str, T) + self.assertIsSubclass(int, T) + self.assertIsSubclass(str, T) # T equals itself. - assert T == T + self.assertEqual(T, T) # T is a subclass of itself. - assert issubclass(T, T) + self.assertIsSubclass(T, T) # T is an instance of TypeVar - assert isinstance(T, TypeVar) + self.assertIsInstance(T, TypeVar) def test_typevar_instance_type_error(self): T = TypeVar('T') @@ -122,13 +139,13 @@ def test_basic_constrained(self): A = TypeVar('A', str, bytes) # Only str and bytes are subclasses of A. - assert issubclass(str, A) - assert issubclass(bytes, A) - assert not issubclass(int, A) + self.assertIsSubclass(str, A) + self.assertIsSubclass(bytes, A) + self.assertNotIsSubclass(int, A) # A equals itself. - assert A == A + self.assertEqual(A, A) # A is a subclass of itself. - assert issubclass(A, A) + self.assertIsSubclass(A, A) def test_constrained_error(self): with self.assertRaises(TypeError): @@ -138,18 +155,18 @@ def test_union_unique(self): X = TypeVar('X') Y = TypeVar('Y') - assert X != Y - assert Union[X] == X - assert Union[X] != Union[X, Y] - assert Union[X, X] == X - assert Union[X, int] != Union[X] - assert Union[X, int] != Union[int] - assert Union[X, int].__union_params__ == (X, int) - assert Union[X, int].__union_set_params__ == {X, int} + self.assertNotEqual(X, Y) + self.assertEqual(Union[X], X) + self.assertNotEqual(Union[X], Union[X, Y]) + self.assertEqual(Union[X, X], X) + self.assertNotEqual(Union[X, int], Union[X]) + self.assertNotEqual(Union[X, int], Union[int]) + self.assertEqual(Union[X, int].__union_params__, (X, int)) + self.assertEqual(Union[X, int].__union_set_params__, {X, int}) def test_union_constrained(self): A = TypeVar('A', str, bytes) - assert Union[A, str] != Union[A] + self.assertNotEqual(Union[A, str], Union[A]) def test_repr(self): self.assertEqual(repr(T), '~T') @@ -194,9 +211,9 @@ def test_bound(self): X = TypeVar('X', bound=Employee) - assert issubclass(Employee, X) - assert issubclass(Manager, X) - assert not issubclass(int, X) + self.assertIsSubclass(Employee, X) + self.assertIsSubclass(Manager, X) + self.assertNotIsSubclass(int, X) def test_bound_errors(self): with self.assertRaises(TypeError): @@ -205,7 +222,7 @@ TypeVar('X', str, float, bound=Employee) -class UnionTests(TestCase): +class UnionTests(BaseTestCase): def test_basics(self): u = Union[int, float] @@ -308,8 +325,8 @@ Union[()] def test_issubclass_union(self): - assert issubclass(Union[int, str], Union) - assert not issubclass(int, Union) + self.assertIsSubclass(Union[int, str], Union) + self.assertNotIsSubclass(int, Union) def test_union_instance_type_error(self): with self.assertRaises(TypeError): @@ -321,21 +338,21 @@ A -class TypeVarUnionTests(TestCase): +class TypeVarUnionTests(BaseTestCase): def test_simpler(self): A = TypeVar('A', int, str, float) B = TypeVar('B', int, str) - assert issubclass(A, A) - assert issubclass(B, B) - assert not issubclass(B, A) - assert issubclass(A, Union[int, str, float]) - assert not issubclass(Union[int, str, float], A) - assert not issubclass(Union[int, str], B) - assert issubclass(B, Union[int, str]) - assert not issubclass(A, B) - assert not issubclass(Union[int, str, float], B) - assert not issubclass(A, Union[int, str]) + self.assertIsSubclass(A, A) + self.assertIsSubclass(B, B) + self.assertNotIsSubclass(B, A) + self.assertIsSubclass(A, Union[int, str, float]) + self.assertNotIsSubclass(Union[int, str, float], A) + self.assertNotIsSubclass(Union[int, str], B) + self.assertIsSubclass(B, Union[int, str]) + self.assertNotIsSubclass(A, B) + self.assertNotIsSubclass(Union[int, str, float], B) + self.assertNotIsSubclass(A, Union[int, str]) def test_var_union_subclass(self): self.assertTrue(issubclass(T, Union[int, T])) @@ -343,11 +360,11 @@ def test_var_union(self): TU = TypeVar('TU', Union[int, float], None) - assert issubclass(int, TU) - assert issubclass(float, TU) + self.assertIsSubclass(int, TU) + self.assertIsSubclass(float, TU) -class TupleTests(TestCase): +class TupleTests(BaseTestCase): def test_basics(self): self.assertTrue(issubclass(Tuple[int, str], Tuple)) @@ -360,10 +377,10 @@ self.assertFalse(issubclass(Tuple, tuple)) # Can't have it both ways. def test_equality(self): - assert Tuple[int] == Tuple[int] - assert Tuple[int, ...] == Tuple[int, ...] - assert Tuple[int] != Tuple[int, int] - assert Tuple[int] != Tuple[int, ...] + self.assertEqual(Tuple[int], Tuple[int]) + self.assertEqual(Tuple[int, ...], Tuple[int, ...]) + self.assertNotEqual(Tuple[int], Tuple[int, int]) + self.assertNotEqual(Tuple[int], Tuple[int, ...]) def test_tuple_subclass(self): class MyTuple(tuple): @@ -384,10 +401,10 @@ class C(B): pass - assert not issubclass(Tuple[B], Tuple[B, ...]) - assert issubclass(Tuple[C, ...], Tuple[B, ...]) - assert not issubclass(Tuple[C, ...], Tuple[B]) - assert not issubclass(Tuple[C], Tuple[B, ...]) + self.assertNotIsSubclass(Tuple[B], Tuple[B, ...]) + self.assertIsSubclass(Tuple[C, ...], Tuple[B, ...]) + self.assertNotIsSubclass(Tuple[C, ...], Tuple[B]) + self.assertNotIsSubclass(Tuple[C], Tuple[B, ...]) def test_repr(self): self.assertEqual(repr(Tuple), 'typing.Tuple') @@ -402,7 +419,7 @@ issubclass(42, Tuple[int]) -class CallableTests(TestCase): +class CallableTests(BaseTestCase): def test_self_subclass(self): self.assertTrue(issubclass(Callable[[int], int], Callable)) @@ -447,20 +464,20 @@ def test_callable_instance_works(self): def f(): pass - assert isinstance(f, Callable) - assert not isinstance(None, Callable) + self.assertIsInstance(f, Callable) + self.assertNotIsInstance(None, Callable) def test_callable_instance_type_error(self): def f(): pass with self.assertRaises(TypeError): - assert isinstance(f, Callable[[], None]) + self.assertIsInstance(f, Callable[[], None]) with self.assertRaises(TypeError): - assert isinstance(f, Callable[[], Any]) + self.assertIsInstance(f, Callable[[], Any]) with self.assertRaises(TypeError): - assert not isinstance(None, Callable[[], None]) + self.assertNotIsInstance(None, Callable[[], None]) with self.assertRaises(TypeError): - assert not isinstance(None, Callable[[], Any]) + self.assertNotIsInstance(None, Callable[[], Any]) def test_repr(self): ct0 = Callable[[], bool] @@ -513,15 +530,15 @@ return default -class ProtocolTests(TestCase): +class ProtocolTests(BaseTestCase): def test_supports_int(self): - assert issubclass(int, typing.SupportsInt) - assert not issubclass(str, typing.SupportsInt) + self.assertIsSubclass(int, typing.SupportsInt) + self.assertNotIsSubclass(str, typing.SupportsInt) def test_supports_float(self): - assert issubclass(float, typing.SupportsFloat) - assert not issubclass(str, typing.SupportsFloat) + self.assertIsSubclass(float, typing.SupportsFloat) + self.assertNotIsSubclass(str, typing.SupportsFloat) def test_supports_complex(self): @@ -530,8 +547,8 @@ def __complex__(self): return 0j - assert issubclass(C, typing.SupportsComplex) - assert not issubclass(str, typing.SupportsComplex) + self.assertIsSubclass(C, typing.SupportsComplex) + self.assertNotIsSubclass(str, typing.SupportsComplex) def test_supports_bytes(self): @@ -540,40 +557,40 @@ def __bytes__(self): return b'' - assert issubclass(B, typing.SupportsBytes) - assert not issubclass(str, typing.SupportsBytes) + self.assertIsSubclass(B, typing.SupportsBytes) + self.assertNotIsSubclass(str, typing.SupportsBytes) def test_supports_abs(self): - assert issubclass(float, typing.SupportsAbs) - assert issubclass(int, typing.SupportsAbs) - assert not issubclass(str, typing.SupportsAbs) + self.assertIsSubclass(float, typing.SupportsAbs) + self.assertIsSubclass(int, typing.SupportsAbs) + self.assertNotIsSubclass(str, typing.SupportsAbs) def test_supports_round(self): issubclass(float, typing.SupportsRound) - assert issubclass(float, typing.SupportsRound) - assert issubclass(int, typing.SupportsRound) - assert not issubclass(str, typing.SupportsRound) + self.assertIsSubclass(float, typing.SupportsRound) + self.assertIsSubclass(int, typing.SupportsRound) + self.assertNotIsSubclass(str, typing.SupportsRound) def test_reversible(self): - assert issubclass(list, typing.Reversible) - assert not issubclass(int, typing.Reversible) + self.assertIsSubclass(list, typing.Reversible) + self.assertNotIsSubclass(int, typing.Reversible) def test_protocol_instance_type_error(self): with self.assertRaises(TypeError): isinstance(0, typing.SupportsAbs) -class GenericTests(TestCase): +class GenericTests(BaseTestCase): def test_basics(self): X = SimpleMapping[str, Any] - assert X.__parameters__ == () + self.assertEqual(X.__parameters__, ()) with self.assertRaises(TypeError): X[str] with self.assertRaises(TypeError): X[str, str] Y = SimpleMapping[XK, str] - assert Y.__parameters__ == (XK,) + self.assertEqual(Y.__parameters__, (XK,)) Y[str] with self.assertRaises(TypeError): Y[str, str] @@ -600,21 +617,21 @@ pass X = C[Tuple[S, T]] - assert X == C[Tuple[S, T]] - assert X != C[Tuple[T, S]] + self.assertEqual(X, C[Tuple[S, T]]) + self.assertNotEqual(X, C[Tuple[T, S]]) Y = X[T, int] - assert Y == X[T, int] - assert Y != X[S, int] - assert Y != X[T, str] + self.assertEqual(Y, X[T, int]) + self.assertNotEqual(Y, X[S, int]) + self.assertNotEqual(Y, X[T, str]) Z = Y[str] - assert Z == Y[str] - assert Z != Y[int] - assert Z != Y[T] + self.assertEqual(Z, Y[str]) + self.assertNotEqual(Z, Y[int]) + self.assertNotEqual(Z, Y[T]) - assert str(Z).endswith( - '.C<~T>[typing.Tuple[~S, ~T]]<~S, ~T>[~T, int]<~T>[str]') + self.assertTrue(str(Z).endswith( + '.C<~T>[typing.Tuple[~S, ~T]]<~S, ~T>[~T, int]<~T>[str]')) def test_dict(self): T = TypeVar('T') @@ -666,28 +683,30 @@ class C(Generic[T]): pass - assert C.__module__ == __name__ + self.assertEqual(C.__module__, __name__) if not PY32: - assert C.__qualname__ == 'GenericTests.test_repr_2..C' - assert repr(C).split('.')[-1] == 'C<~T>' + self.assertEqual(C.__qualname__, + 'GenericTests.test_repr_2..C') + self.assertEqual(repr(C).split('.')[-1], 'C<~T>') X = C[int] - assert X.__module__ == __name__ + self.assertEqual(X.__module__, __name__) if not PY32: - assert X.__qualname__ == 'C' - assert repr(X).split('.')[-1] == 'C<~T>[int]' + self.assertEqual(X.__qualname__, 'C') + self.assertEqual(repr(X).split('.')[-1], 'C<~T>[int]') class Y(C[int]): pass - assert Y.__module__ == __name__ + self.assertEqual(Y.__module__, __name__) if not PY32: - assert Y.__qualname__ == 'GenericTests.test_repr_2..Y' - assert repr(Y).split('.')[-1] == 'Y' + self.assertEqual(Y.__qualname__, + 'GenericTests.test_repr_2..Y') + self.assertEqual(repr(Y).split('.')[-1], 'Y') def test_eq_1(self): - assert Generic == Generic - assert Generic[T] == Generic[T] - assert Generic[KT] != Generic[VT] + self.assertEqual(Generic, Generic) + self.assertEqual(Generic[T], Generic[T]) + self.assertNotEqual(Generic[KT], Generic[VT]) def test_eq_2(self): @@ -697,10 +716,10 @@ class B(Generic[T]): pass - assert A == A - assert A != B - assert A[T] == A[T] - assert A[T] != B[T] + self.assertEqual(A, A) + self.assertNotEqual(A, B) + self.assertEqual(A[T], A[T]) + self.assertNotEqual(A[T], B[T]) def test_multiple_inheritance(self): @@ -713,7 +732,7 @@ class C(A[T, VT], Generic[VT, T, KT], B[KT, T]): pass - assert C.__parameters__ == (VT, T, KT) + self.assertEqual(C.__parameters__, (VT, T, KT)) def test_nested(self): @@ -743,7 +762,7 @@ a.set([]) a.append(1) a.append(42) - assert a.get() == [1, 42] + self.assertEqual(a.get(), [1, 42]) def test_type_erasure(self): T = TypeVar('T') @@ -760,12 +779,12 @@ a = Node(x) b = Node[T](x) c = Node[Any](x) - assert type(a) is Node - assert type(b) is Node - assert type(c) is Node - assert a.label == x - assert b.label == x - assert c.label == x + self.assertIs(type(a), Node) + self.assertIs(type(b), Node) + self.assertIs(type(c), Node) + self.assertEqual(a.label, x) + self.assertEqual(b.label, x) + self.assertEqual(c.label, x) foo(42) @@ -778,7 +797,7 @@ class D(C): pass - assert D.__parameters__ == () + self.assertEqual(D.__parameters__, ()) with self.assertRaises(Exception): D[int] @@ -788,61 +807,63 @@ D[T] -class VarianceTests(TestCase): +class VarianceTests(BaseTestCase): def test_invariance(self): # Because of invariance, List[subclass of X] is not a subclass # of List[X], and ditto for MutableSequence. - assert not issubclass(typing.List[Manager], typing.List[Employee]) - assert not issubclass(typing.MutableSequence[Manager], + self.assertNotIsSubclass(typing.List[Manager], typing.List[Employee]) + self.assertNotIsSubclass(typing.MutableSequence[Manager], typing.MutableSequence[Employee]) # It's still reflexive. - assert issubclass(typing.List[Employee], typing.List[Employee]) - assert issubclass(typing.MutableSequence[Employee], + self.assertIsSubclass(typing.List[Employee], typing.List[Employee]) + self.assertIsSubclass(typing.MutableSequence[Employee], typing.MutableSequence[Employee]) def test_covariance_tuple(self): # Check covariace for Tuple (which are really special cases). - assert issubclass(Tuple[Manager], Tuple[Employee]) - assert not issubclass(Tuple[Employee], Tuple[Manager]) + self.assertIsSubclass(Tuple[Manager], Tuple[Employee]) + self.assertNotIsSubclass(Tuple[Employee], Tuple[Manager]) # And pairwise. - assert issubclass(Tuple[Manager, Manager], Tuple[Employee, Employee]) - assert not issubclass(Tuple[Employee, Employee], + self.assertIsSubclass(Tuple[Manager, Manager], + Tuple[Employee, Employee]) + self.assertNotIsSubclass(Tuple[Employee, Employee], Tuple[Manager, Employee]) # And using ellipsis. - assert issubclass(Tuple[Manager, ...], Tuple[Employee, ...]) - assert not issubclass(Tuple[Employee, ...], Tuple[Manager, ...]) + self.assertIsSubclass(Tuple[Manager, ...], Tuple[Employee, ...]) + self.assertNotIsSubclass(Tuple[Employee, ...], Tuple[Manager, ...]) def test_covariance_sequence(self): # Check covariance for Sequence (which is just a generic class # for this purpose, but using a covariant type variable). - assert issubclass(typing.Sequence[Manager], typing.Sequence[Employee]) - assert not issubclass(typing.Sequence[Employee], + self.assertIsSubclass(typing.Sequence[Manager], + typing.Sequence[Employee]) + self.assertNotIsSubclass(typing.Sequence[Employee], typing.Sequence[Manager]) def test_covariance_mapping(self): # Ditto for Mapping (covariant in the value, invariant in the key). - assert issubclass(typing.Mapping[Employee, Manager], + self.assertIsSubclass(typing.Mapping[Employee, Manager], typing.Mapping[Employee, Employee]) - assert not issubclass(typing.Mapping[Manager, Employee], + self.assertNotIsSubclass(typing.Mapping[Manager, Employee], typing.Mapping[Employee, Employee]) - assert not issubclass(typing.Mapping[Employee, Manager], + self.assertNotIsSubclass(typing.Mapping[Employee, Manager], typing.Mapping[Manager, Manager]) - assert not issubclass(typing.Mapping[Manager, Employee], + self.assertNotIsSubclass(typing.Mapping[Manager, Employee], typing.Mapping[Manager, Manager]) -class CastTests(TestCase): +class CastTests(BaseTestCase): def test_basics(self): - assert cast(int, 42) == 42 - assert cast(float, 42) == 42 - assert type(cast(float, 42)) is int - assert cast(Any, 42) == 42 - assert cast(list, 42) == 42 - assert cast(Union[str, float], 42) == 42 - assert cast(AnyStr, 42) == 42 - assert cast(None, 42) == 42 + self.assertEqual(cast(int, 42), 42) + self.assertEqual(cast(float, 42), 42) + self.assertIs(type(cast(float, 42)), int) + self.assertEqual(cast(Any, 42), 42) + self.assertEqual(cast(list, 42), 42) + self.assertEqual(cast(Union[str, float], 42), 42) + self.assertEqual(cast(AnyStr, 42), 42) + self.assertEqual(cast(None, 42), 42) def test_errors(self): # Bogus calls are not expected to fail. @@ -850,7 +871,7 @@ cast('hello', 42) -class ForwardRefTests(TestCase): +class ForwardRefTests(BaseTestCase): def test_basics(self): @@ -876,15 +897,17 @@ t = Node[int] both_hints = get_type_hints(t.add_both, globals(), locals()) - assert both_hints['left'] == both_hints['right'] == Optional[Node[T]] - assert both_hints['stuff'] == Optional[int] - assert 'blah' not in both_hints + self.assertEqual(both_hints['left'], Optional[Node[T]]) + self.assertEqual(both_hints['right'], Optional[Node[T]]) + self.assertEqual(both_hints['left'], both_hints['right']) + self.assertEqual(both_hints['stuff'], Optional[int]) + self.assertNotIn('blah', both_hints) left_hints = get_type_hints(t.add_left, globals(), locals()) - assert left_hints['node'] == Optional[Node[T]] + self.assertEqual(left_hints['node'], Optional[Node[T]]) right_hints = get_type_hints(t.add_right, globals(), locals()) - assert right_hints['node'] == Optional[Node[T]] + self.assertEqual(right_hints['node'], Optional[Node[T]]) def test_forwardref_instance_type_error(self): fr = typing._ForwardRef('int') @@ -1007,10 +1030,10 @@ ns = {} exec(code, ns) hints = get_type_hints(ns['C'].foo) - assert hints == {'a': ns['C'], 'return': ns['D']} + self.assertEqual(hints, {'a': ns['C'], 'return': ns['D']}) -class OverloadTests(TestCase): +class OverloadTests(BaseTestCase): def test_overload_exists(self): from typing import overload @@ -1076,29 +1099,29 @@ exec(PY35_TESTS) -class CollectionsAbcTests(TestCase): +class CollectionsAbcTests(BaseTestCase): def test_hashable(self): - assert isinstance(42, typing.Hashable) - assert not isinstance([], typing.Hashable) + self.assertIsInstance(42, typing.Hashable) + self.assertNotIsInstance([], typing.Hashable) def test_iterable(self): - assert isinstance([], typing.Iterable) + self.assertIsInstance([], typing.Iterable) # Due to ABC caching, the second time takes a separate code # path and could fail. So call this a few times. - assert isinstance([], typing.Iterable) - assert isinstance([], typing.Iterable) - assert isinstance([], typing.Iterable[int]) - assert not isinstance(42, typing.Iterable) + self.assertIsInstance([], typing.Iterable) + self.assertIsInstance([], typing.Iterable) + self.assertIsInstance([], typing.Iterable[int]) + self.assertNotIsInstance(42, typing.Iterable) # Just in case, also test issubclass() a few times. - assert issubclass(list, typing.Iterable) - assert issubclass(list, typing.Iterable) + self.assertIsSubclass(list, typing.Iterable) + self.assertIsSubclass(list, typing.Iterable) def test_iterator(self): it = iter([]) - assert isinstance(it, typing.Iterator) - assert isinstance(it, typing.Iterator[int]) - assert not isinstance(42, typing.Iterator) + self.assertIsInstance(it, typing.Iterator) + self.assertIsInstance(it, typing.Iterator[int]) + self.assertNotIsInstance(42, typing.Iterator) @skipUnless(PY35, 'Python 3.5 required') def test_awaitable(self): @@ -1109,12 +1132,12 @@ globals(), ns) foo = ns['foo'] g = foo() - assert issubclass(type(g), typing.Awaitable[int]) - assert isinstance(g, typing.Awaitable) - assert not isinstance(foo, typing.Awaitable) - assert issubclass(typing.Awaitable[Manager], + self.assertIsSubclass(type(g), typing.Awaitable[int]) + self.assertIsInstance(g, typing.Awaitable) + self.assertNotIsInstance(foo, typing.Awaitable) + self.assertIsSubclass(typing.Awaitable[Manager], typing.Awaitable[Employee]) - assert not issubclass(typing.Awaitable[Employee], + self.assertNotIsSubclass(typing.Awaitable[Employee], typing.Awaitable[Manager]) g.send(None) # Run foo() till completion, to avoid warning. @@ -1122,70 +1145,70 @@ def test_async_iterable(self): base_it = range(10) # type: Iterator[int] it = AsyncIteratorWrapper(base_it) - assert isinstance(it, typing.AsyncIterable) - assert isinstance(it, typing.AsyncIterable) - assert issubclass(typing.AsyncIterable[Manager], + self.assertIsInstance(it, typing.AsyncIterable) + self.assertIsInstance(it, typing.AsyncIterable) + self.assertIsSubclass(typing.AsyncIterable[Manager], typing.AsyncIterable[Employee]) - assert not isinstance(42, typing.AsyncIterable) + self.assertNotIsInstance(42, typing.AsyncIterable) @skipUnless(PY35, 'Python 3.5 required') def test_async_iterator(self): base_it = range(10) # type: Iterator[int] it = AsyncIteratorWrapper(base_it) - assert isinstance(it, typing.AsyncIterator) - assert issubclass(typing.AsyncIterator[Manager], + self.assertIsInstance(it, typing.AsyncIterator) + self.assertIsSubclass(typing.AsyncIterator[Manager], typing.AsyncIterator[Employee]) - assert not isinstance(42, typing.AsyncIterator) + self.assertNotIsInstance(42, typing.AsyncIterator) def test_sized(self): - assert isinstance([], typing.Sized) - assert not isinstance(42, typing.Sized) + self.assertIsInstance([], typing.Sized) + self.assertNotIsInstance(42, typing.Sized) def test_container(self): - assert isinstance([], typing.Container) - assert not isinstance(42, typing.Container) + self.assertIsInstance([], typing.Container) + self.assertNotIsInstance(42, typing.Container) def test_abstractset(self): - assert isinstance(set(), typing.AbstractSet) - assert not isinstance(42, typing.AbstractSet) + self.assertIsInstance(set(), typing.AbstractSet) + self.assertNotIsInstance(42, typing.AbstractSet) def test_mutableset(self): - assert isinstance(set(), typing.MutableSet) - assert not isinstance(frozenset(), typing.MutableSet) + self.assertIsInstance(set(), typing.MutableSet) + self.assertNotIsInstance(frozenset(), typing.MutableSet) def test_mapping(self): - assert isinstance({}, typing.Mapping) - assert not isinstance(42, typing.Mapping) + self.assertIsInstance({}, typing.Mapping) + self.assertNotIsInstance(42, typing.Mapping) def test_mutablemapping(self): - assert isinstance({}, typing.MutableMapping) - assert not isinstance(42, typing.MutableMapping) + self.assertIsInstance({}, typing.MutableMapping) + self.assertNotIsInstance(42, typing.MutableMapping) def test_sequence(self): - assert isinstance([], typing.Sequence) - assert not isinstance(42, typing.Sequence) + self.assertIsInstance([], typing.Sequence) + self.assertNotIsInstance(42, typing.Sequence) def test_mutablesequence(self): - assert isinstance([], typing.MutableSequence) - assert not isinstance((), typing.MutableSequence) + self.assertIsInstance([], typing.MutableSequence) + self.assertNotIsInstance((), typing.MutableSequence) def test_bytestring(self): - assert isinstance(b'', typing.ByteString) - assert isinstance(bytearray(b''), typing.ByteString) + self.assertIsInstance(b'', typing.ByteString) + self.assertIsInstance(bytearray(b''), typing.ByteString) def test_list(self): - assert issubclass(list, typing.List) + self.assertIsSubclass(list, typing.List) def test_set(self): - assert issubclass(set, typing.Set) - assert not issubclass(frozenset, typing.Set) + self.assertIsSubclass(set, typing.Set) + self.assertNotIsSubclass(frozenset, typing.Set) def test_frozenset(self): - assert issubclass(frozenset, typing.FrozenSet) - assert not issubclass(set, typing.FrozenSet) + self.assertIsSubclass(frozenset, typing.FrozenSet) + self.assertNotIsSubclass(set, typing.FrozenSet) def test_dict(self): - assert issubclass(dict, typing.Dict) + self.assertIsSubclass(dict, typing.Dict) def test_no_list_instantiation(self): with self.assertRaises(TypeError): @@ -1201,7 +1224,7 @@ pass a = MyList() - assert isinstance(a, MyList) + self.assertIsInstance(a, MyList) def test_no_dict_instantiation(self): with self.assertRaises(TypeError): @@ -1217,7 +1240,7 @@ pass d = MyDict() - assert isinstance(d, MyDict) + self.assertIsInstance(d, MyDict) def test_no_defaultdict_instantiation(self): with self.assertRaises(TypeError): @@ -1233,7 +1256,7 @@ pass dd = MyDefDict() - assert isinstance(dd, MyDefDict) + self.assertIsInstance(dd, MyDefDict) def test_no_set_instantiation(self): with self.assertRaises(TypeError): @@ -1249,7 +1272,7 @@ pass d = MySet() - assert isinstance(d, MySet) + self.assertIsInstance(d, MySet) def test_no_frozenset_instantiation(self): with self.assertRaises(TypeError): @@ -1265,7 +1288,7 @@ pass d = MyFrozenSet() - assert isinstance(d, MyFrozenSet) + self.assertIsInstance(d, MyFrozenSet) def test_no_tuple_instantiation(self): with self.assertRaises(TypeError): @@ -1279,10 +1302,10 @@ def foo(): yield 42 g = foo() - assert issubclass(type(g), typing.Generator) - assert issubclass(typing.Generator[Manager, Employee, Manager], + self.assertIsSubclass(type(g), typing.Generator) + self.assertIsSubclass(typing.Generator[Manager, Employee, Manager], typing.Generator[Employee, Manager, Employee]) - assert not issubclass(typing.Generator[Manager, Manager, Manager], + self.assertNotIsSubclass(typing.Generator[Manager, Manager, Manager], typing.Generator[Employee, Employee, Employee]) def test_no_generator_instantiation(self): @@ -1305,18 +1328,18 @@ def __len__(self): return 0 - assert len(MMC()) == 0 + self.assertEqual(len(MMC()), 0) class MMB(typing.MutableMapping[KT, VT]): def __len__(self): return 0 - assert len(MMB()) == 0 - assert len(MMB[str, str]()) == 0 - assert len(MMB[KT, VT]()) == 0 + self.assertEqual(len(MMB()), 0) + self.assertEqual(len(MMB[str, str]()), 0) + self.assertEqual(len(MMB[KT, VT]()), 0) -class OtherABCTests(TestCase): +class OtherABCTests(BaseTestCase): @skipUnless(hasattr(typing, 'ContextManager'), 'requires typing.ContextManager') @@ -1326,27 +1349,27 @@ yield 42 cm = manager() - assert isinstance(cm, typing.ContextManager) - assert isinstance(cm, typing.ContextManager[int]) - assert not isinstance(42, typing.ContextManager) + self.assertIsInstance(cm, typing.ContextManager) + self.assertIsInstance(cm, typing.ContextManager[int]) + self.assertNotIsInstance(42, typing.ContextManager) -class NamedTupleTests(TestCase): +class NamedTupleTests(BaseTestCase): def test_basics(self): Emp = NamedTuple('Emp', [('name', str), ('id', int)]) - assert issubclass(Emp, tuple) + self.assertIsSubclass(Emp, tuple) joe = Emp('Joe', 42) jim = Emp(name='Jim', id=1) - assert isinstance(joe, Emp) - assert isinstance(joe, tuple) - assert joe.name == 'Joe' - assert joe.id == 42 - assert jim.name == 'Jim' - assert jim.id == 1 - assert Emp.__name__ == 'Emp' - assert Emp._fields == ('name', 'id') - assert Emp._field_types == dict(name=str, id=int) + self.assertIsInstance(joe, Emp) + self.assertIsInstance(joe, tuple) + self.assertEqual(joe.name, 'Joe') + self.assertEqual(joe.id, 42) + self.assertEqual(jim.name, 'Jim') + self.assertEqual(jim.id, 1) + self.assertEqual(Emp.__name__, 'Emp') + self.assertEqual(Emp._fields, ('name', 'id')) + self.assertEqual(Emp._field_types, dict(name=str, id=int)) def test_pickle(self): global Emp # pickle wants to reference the class by name @@ -1358,7 +1381,7 @@ self.assertEqual(jane2, jane) -class IOTests(TestCase): +class IOTests(BaseTestCase): def test_io(self): @@ -1366,7 +1389,7 @@ return a.readline() a = stuff.__annotations__['a'] - assert a.__parameters__ == (AnyStr,) + self.assertEqual(a.__parameters__, (AnyStr,)) def test_textio(self): @@ -1374,7 +1397,7 @@ return a.readline() a = stuff.__annotations__['a'] - assert a.__parameters__ == () + self.assertEqual(a.__parameters__, ()) def test_binaryio(self): @@ -1382,40 +1405,40 @@ return a.readline() a = stuff.__annotations__['a'] - assert a.__parameters__ == () + self.assertEqual(a.__parameters__, ()) def test_io_submodule(self): from typing.io import IO, TextIO, BinaryIO, __all__, __name__ - assert IO is typing.IO - assert TextIO is typing.TextIO - assert BinaryIO is typing.BinaryIO - assert set(__all__) == set(['IO', 'TextIO', 'BinaryIO']) - assert __name__ == 'typing.io' + self.assertIs(IO, typing.IO) + self.assertIs(TextIO, typing.TextIO) + self.assertIs(BinaryIO, typing.BinaryIO) + self.assertEqual(set(__all__), set(['IO', 'TextIO', 'BinaryIO'])) + self.assertEqual(__name__, 'typing.io') -class RETests(TestCase): +class RETests(BaseTestCase): # Much of this is really testing _TypeAlias. def test_basics(self): pat = re.compile('[a-z]+', re.I) - assert issubclass(pat.__class__, Pattern) - assert issubclass(type(pat), Pattern) - assert issubclass(type(pat), Pattern[str]) + self.assertIsSubclass(pat.__class__, Pattern) + self.assertIsSubclass(type(pat), Pattern) + self.assertIsSubclass(type(pat), Pattern[str]) mat = pat.search('12345abcde.....') - assert issubclass(mat.__class__, Match) - assert issubclass(mat.__class__, Match[str]) - assert issubclass(mat.__class__, Match[bytes]) # Sad but true. - assert issubclass(type(mat), Match) - assert issubclass(type(mat), Match[str]) + self.assertIsSubclass(mat.__class__, Match) + self.assertIsSubclass(mat.__class__, Match[str]) + self.assertIsSubclass(mat.__class__, Match[bytes]) # Sad but true. + self.assertIsSubclass(type(mat), Match) + self.assertIsSubclass(type(mat), Match[str]) p = Pattern[Union[str, bytes]] - assert issubclass(Pattern[str], Pattern) - assert issubclass(Pattern[str], p) + self.assertIsSubclass(Pattern[str], Pattern) + self.assertIsSubclass(Pattern[str], p) m = Match[Union[bytes, str]] - assert issubclass(Match[bytes], Match) - assert issubclass(Match[bytes], m) + self.assertIsSubclass(Match[bytes], Match) + self.assertIsSubclass(Match[bytes], m) def test_errors(self): with self.assertRaises(TypeError): @@ -1436,19 +1459,19 @@ isinstance(42, Pattern[str]) def test_repr(self): - assert repr(Pattern) == 'Pattern[~AnyStr]' - assert repr(Pattern[str]) == 'Pattern[str]' - assert repr(Pattern[bytes]) == 'Pattern[bytes]' - assert repr(Match) == 'Match[~AnyStr]' - assert repr(Match[str]) == 'Match[str]' - assert repr(Match[bytes]) == 'Match[bytes]' + self.assertEqual(repr(Pattern), 'Pattern[~AnyStr]') + self.assertEqual(repr(Pattern[str]), 'Pattern[str]') + self.assertEqual(repr(Pattern[bytes]), 'Pattern[bytes]') + self.assertEqual(repr(Match), 'Match[~AnyStr]') + self.assertEqual(repr(Match[str]), 'Match[str]') + self.assertEqual(repr(Match[bytes]), 'Match[bytes]') def test_re_submodule(self): from typing.re import Match, Pattern, __all__, __name__ - assert Match is typing.Match - assert Pattern is typing.Pattern - assert set(__all__) == set(['Match', 'Pattern']) - assert __name__ == 'typing.re' + self.assertIs(Match, typing.Match) + self.assertIs(Pattern, typing.Pattern) + self.assertEqual(set(__all__), set(['Match', 'Pattern'])) + self.assertEqual(__name__, 'typing.re') def test_cannot_subclass(self): with self.assertRaises(TypeError) as ex: @@ -1456,29 +1479,30 @@ class A(typing.Match): pass - assert str(ex.exception) == "A type alias cannot be subclassed" + self.assertEqual(str(ex.exception), + "A type alias cannot be subclassed") -class AllTests(TestCase): +class AllTests(BaseTestCase): """Tests for __all__.""" def test_all(self): from typing import __all__ as a # Just spot-check the first and last of every category. - assert 'AbstractSet' in a - assert 'ValuesView' in a - assert 'cast' in a - assert 'overload' in a + self.assertIn('AbstractSet', a) + self.assertIn('ValuesView', a) + self.assertIn('cast', a) + self.assertIn('overload', a) if hasattr(contextlib, 'AbstractContextManager'): - assert 'ContextManager' in a + self.assertIn('ContextManager', a) # Check that io and re are not exported. - assert 'io' not in a - assert 're' not in a + self.assertNotIn('io', a) + self.assertNotIn('re', a) # Spot-check that stdlib modules aren't exported. - assert 'os' not in a - assert 'sys' not in a + self.assertNotIn('os', a) + self.assertNotIn('sys', a) # Check that Text is defined. - assert 'Text' in a + self.assertIn('Text', a) if __name__ == '__main__': -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 14:19:14 2016 From: python-checkins at python.org (paul.moore) Date: Tue, 19 Apr 2016 18:19:14 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Mention_types=2ESimpleName?= =?utf-8?q?space_in_collections=2Enamedtuple_doc?= Message-ID: <20160419181913.12739.16055.A50109E4@psf.io> https://hg.python.org/cpython/rev/c3232d1d8ca0 changeset: 101063:c3232d1d8ca0 user: Paul Moore date: Tue Apr 19 19:17:16 2016 +0100 summary: Mention types.SimpleNamespace in collections.namedtuple doc Issue #26805. files: Doc/library/collections.rst | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -792,6 +792,11 @@ Named tuple instances do not have per-instance dictionaries, so they are lightweight and require no more memory than regular tuples. + For simple uses, where the only requirement is to be able to refer to a set + of values by name using attribute-style access, the + :class:`types.SimpleNamespace` type can be a suitable alternative to using + a namedtuple. + .. versionchanged:: 3.1 Added support for *rename*. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 15:59:21 2016 From: python-checkins at python.org (jesus.cea) Date: Tue, 19 Apr 2016 19:59:21 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_MERGE=3A_Trivial_typo?= Message-ID: <20160419195921.29022.66498.6817815C@psf.io> https://hg.python.org/cpython/rev/ac78c0bc2c3e changeset: 101065:ac78c0bc2c3e parent: 101063:c3232d1d8ca0 parent: 101064:376bee0d1b37 user: Jesus Cea date: Tue Apr 19 21:50:40 2016 +0200 summary: MERGE: Trivial typo files: Doc/library/asyncio-stream.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/asyncio-stream.rst b/Doc/library/asyncio-stream.rst --- a/Doc/library/asyncio-stream.rst +++ b/Doc/library/asyncio-stream.rst @@ -223,7 +223,7 @@ .. class:: StreamReaderProtocol(stream_reader, client_connected_cb=None, loop=None) Trivial helper class to adapt between :class:`Protocol` and - :class:`StreamReader`. Sublclass of :class:`Protocol`. + :class:`StreamReader`. Subclass of :class:`Protocol`. *stream_reader* is a :class:`StreamReader` instance, *client_connected_cb* is an optional function called with (stream_reader, stream_writer) when a -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 15:59:21 2016 From: python-checkins at python.org (jesus.cea) Date: Tue, 19 Apr 2016 19:59:21 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Trivial_typo?= Message-ID: <20160419195921.11424.37618.F297D6F9@psf.io> https://hg.python.org/cpython/rev/376bee0d1b37 changeset: 101064:376bee0d1b37 branch: 3.5 parent: 101061:fd981e5c2faa user: Jesus Cea date: Tue Apr 19 21:50:19 2016 +0200 summary: Trivial typo files: Doc/library/asyncio-stream.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/asyncio-stream.rst b/Doc/library/asyncio-stream.rst --- a/Doc/library/asyncio-stream.rst +++ b/Doc/library/asyncio-stream.rst @@ -223,7 +223,7 @@ .. class:: StreamReaderProtocol(stream_reader, client_connected_cb=None, loop=None) Trivial helper class to adapt between :class:`Protocol` and - :class:`StreamReader`. Sublclass of :class:`Protocol`. + :class:`StreamReader`. Subclass of :class:`Protocol`. *stream_reader* is a :class:`StreamReader` instance, *client_connected_cb* is an optional function called with (stream_reader, stream_writer) when a -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 16:29:34 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 19 Apr 2016 20:29:34 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogRml4IHNodXRpbC5n?= =?utf-8?q?et=5Fterminal=5Fsize=28=29_error_handling?= Message-ID: <20160419202926.107504.39404.D555D408@psf.io> https://hg.python.org/cpython/rev/e3763b5964b6 changeset: 101066:e3763b5964b6 branch: 3.5 parent: 101064:376bee0d1b37 user: Victor Stinner date: Tue Apr 19 22:24:56 2016 +0200 summary: Fix shutil.get_terminal_size() error handling Issue #26801: Fix error handling in shutil.get_terminal_size(), catch AttributeError instead of NameError. Patch written by Emanuel Barry. test_shutil: skip the functional test using "stty size" command if os.get_terminal_size() is missing. files: Lib/shutil.py | 2 +- Lib/test/test_shutil.py | 2 ++ Misc/ACKS | 1 + Misc/NEWS | 4 ++++ 4 files changed, 8 insertions(+), 1 deletions(-) diff --git a/Lib/shutil.py b/Lib/shutil.py --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -1069,7 +1069,7 @@ if columns <= 0 or lines <= 0: try: size = os.get_terminal_size(sys.__stdout__.fileno()) - except (NameError, OSError): + except (AttributeError, OSError): size = os.terminal_size(fallback) if columns <= 0: columns = size.columns diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1837,6 +1837,8 @@ self.assertEqual(size.lines, 888) @unittest.skipUnless(os.isatty(sys.__stdout__.fileno()), "not on tty") + @unittest.skipUnless(hasattr(os, 'get_terminal_size'), + 'need os.get_terminal_size()') def test_stty_match(self): """Check if stty returns the same results ignoring env diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -90,6 +90,7 @@ Richard Barran Cesar Eduardo Barros Des Barry +Emanuel Barry Ulf Bartelt Campbell Barton Don Bashford diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,10 @@ Library ------- +- Issue #26801: Fix error handling in :func:`shutil.get_terminal_size`, catch + :exc:`AttributeError` instead of :exc:`NameError`. Patch written by Emanuel + Barry. + - Issue #24838: tarfile's ustar and gnu formats now correctly calculate name and link field limits for multibyte character encodings like utf-8. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 16:29:34 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 19 Apr 2016 20:29:34 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_3=2E5=3A_issue_=2326801?= Message-ID: <20160419202926.107516.67526.33E66DA4@psf.io> https://hg.python.org/cpython/rev/75f40345d784 changeset: 101067:75f40345d784 parent: 101065:ac78c0bc2c3e parent: 101066:e3763b5964b6 user: Victor Stinner date: Tue Apr 19 22:29:11 2016 +0200 summary: Merge 3.5: issue #26801 files: Lib/shutil.py | 2 +- Lib/test/test_shutil.py | 2 ++ Misc/ACKS | 1 + Misc/NEWS | 4 ++++ 4 files changed, 8 insertions(+), 1 deletions(-) diff --git a/Lib/shutil.py b/Lib/shutil.py --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -1072,7 +1072,7 @@ if columns <= 0 or lines <= 0: try: size = os.get_terminal_size(sys.__stdout__.fileno()) - except (NameError, OSError): + except (AttributeError, OSError): size = os.terminal_size(fallback) if columns <= 0: columns = size.columns diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1837,6 +1837,8 @@ self.assertEqual(size.lines, 888) @unittest.skipUnless(os.isatty(sys.__stdout__.fileno()), "not on tty") + @unittest.skipUnless(hasattr(os, 'get_terminal_size'), + 'need os.get_terminal_size()') def test_stty_match(self): """Check if stty returns the same results ignoring env diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -90,6 +90,7 @@ Richard Barran Cesar Eduardo Barros Des Barry +Emanuel Barry Ulf Bartelt Campbell Barton Don Bashford diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -245,6 +245,10 @@ Library ------- +- Issue #26801: Fix error handling in :func:`shutil.get_terminal_size`, catch + :exc:`AttributeError` instead of :exc:`NameError`. Patch written by Emanuel + Barry. + - Issue #24838: tarfile's ustar and gnu formats now correctly calculate name and link field limits for multibyte character encodings like utf-8. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 16:37:44 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Tue, 19 Apr 2016 20:37:44 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326802=3A_Optimize?= =?utf-8?q?d_calling_a_function_with_*args_only_positional_arguments=2E?= Message-ID: <20160419203735.8330.59131.A6E22FD4@psf.io> https://hg.python.org/cpython/rev/15b20201cfa5 changeset: 101068:15b20201cfa5 user: Serhiy Storchaka date: Tue Apr 19 23:37:17 2016 +0300 summary: Issue #26802: Optimized calling a function with *args only positional arguments. Patch by Joe Jevnik. files: Python/ceval.c | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4890,6 +4890,21 @@ { PyObject *callargs, *w; + if (!nstack) { + if (!stararg) { + /* There are no positional arguments on the stack and there is no + sequence to be unpacked. */ + return PyTuple_New(0); + } + if (PyTuple_CheckExact(stararg)) { + /* No arguments are passed on the stack and the sequence is not a + tuple subclass so we can just pass the stararg tuple directly + to the function. */ + Py_INCREF(stararg); + return stararg; + } + } + callargs = PyTuple_New(nstack + nstar); if (callargs == NULL) { return NULL; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 18:00:00 2016 From: python-checkins at python.org (paul.moore) Date: Tue, 19 Apr 2016 22:00:00 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Mention_types?= =?utf-8?q?=2ESimpleNamespace_in_collections=2Enamedtuple_doc?= Message-ID: <20160419215958.70519.39971.5E1B78AC@psf.io> https://hg.python.org/cpython/rev/3115b6ce1006 changeset: 101069:3115b6ce1006 branch: 3.5 parent: 101066:e3763b5964b6 user: Paul Moore date: Tue Apr 19 19:17:16 2016 +0100 summary: Mention types.SimpleNamespace in collections.namedtuple doc Issue #26805. files: Doc/library/collections.rst | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -792,6 +792,11 @@ Named tuple instances do not have per-instance dictionaries, so they are lightweight and require no more memory than regular tuples. + For simple uses, where the only requirement is to be able to refer to a set + of values by name using attribute-style access, the + :class:`types.SimpleNamespace` type can be a suitable alternative to using + a namedtuple. + .. versionchanged:: 3.1 Added support for *rename*. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 18:00:00 2016 From: python-checkins at python.org (paul.moore) Date: Tue, 19 Apr 2016 22:00:00 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_with_3=2E5?= Message-ID: <20160419215958.11465.26674.8436AC06@psf.io> https://hg.python.org/cpython/rev/cf47006924d4 changeset: 101070:cf47006924d4 parent: 101068:15b20201cfa5 parent: 101069:3115b6ce1006 user: Paul Moore date: Tue Apr 19 22:59:48 2016 +0100 summary: Merge with 3.5 files: -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 18:31:55 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 19 Apr 2016 22:31:55 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Null_merge_3=2E5_=28changes_already_applied_to_test=5Fgd?= =?utf-8?q?b=29?= Message-ID: <20160419223153.15621.64308.8A74CBCA@psf.io> https://hg.python.org/cpython/rev/715b67949349 changeset: 101073:715b67949349 parent: 101071:6535481d610e parent: 101072:8d38e95a2e4e user: Victor Stinner date: Wed Apr 20 00:31:04 2016 +0200 summary: Null merge 3.5 (changes already applied to test_gdb) files: -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 18:31:55 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 19 Apr 2016 22:31:55 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Optimize_func=28*tuple=29_?= =?utf-8?q?function_call?= Message-ID: <20160419223152.15366.92960.8324124D@psf.io> https://hg.python.org/cpython/rev/6535481d610e changeset: 101071:6535481d610e user: Victor Stinner date: Tue Apr 19 22:54:37 2016 +0200 summary: Optimize func(*tuple) function call Issue #26802: Optimize function calls only using unpacking like "func(*tuple)" (no other positional argument, no keyword): avoid copying the tuple. Patch written by Joe Jevnik. files: Misc/NEWS | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #26802: Optimize function calls only using unpacking like + ``func(*tuple)`` (no other positional argument, no keyword): avoid copying + the tuple. Patch written by Joe Jevnik. + - Issue #26659: Make the builtin slice type support cycle collection. - Issue #26718: super.__init__ no longer leaks memory if called multiple times. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 18:31:55 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 19 Apr 2016 22:31:55 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Backport_test?= =?utf-8?q?=5Fgdb_fix_for_s390x_buildbots?= Message-ID: <20160419223153.123879.35554.EEE4D4CF@psf.io> https://hg.python.org/cpython/rev/8d38e95a2e4e changeset: 101072:8d38e95a2e4e branch: 3.5 parent: 101069:3115b6ce1006 user: Victor Stinner date: Wed Apr 20 00:30:14 2016 +0200 summary: Backport test_gdb fix for s390x buildbots files: Lib/test/test_gdb.py | 24 +++++++----------------- 1 files changed, 7 insertions(+), 17 deletions(-) diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -198,27 +198,17 @@ # Ignore some benign messages on stderr. ignore_patterns = ( 'Function "%s" not defined.' % breakpoint, - "warning: no loadable sections found in added symbol-file" - " system-supplied DSO", - "warning: Unable to find libthread_db matching" - " inferior's thread library, thread debugging will" - " not be available.", - "warning: Cannot initialize thread debugging" - " library: Debugger service failed", - 'warning: Could not load shared library symbols for ' - 'linux-vdso.so', - 'warning: Could not load shared library symbols for ' - 'linux-gate.so', - 'warning: Could not load shared library symbols for ' - 'linux-vdso64.so', 'Do you need "set solib-search-path" or ' '"set sysroot"?', - 'warning: Source file is more recent than executable.', - # Issue #19753: missing symbols on System Z - 'Missing separate debuginfo for ', - 'Try: zypper install -C ', + # BFD: /usr/lib/debug/(...): unable to initialize decompress + # status for section .debug_aranges + 'BFD: ', + # ignore all warnings + 'warning: ', ) for line in errlines: + if not line: + continue if not line.startswith(ignore_patterns): unexpected_errlines.append(line) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 19:42:00 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 19 Apr 2016 23:42:00 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Fix_spelling_?= =?utf-8?q?=28inital=29=2C_grammar_=28may_translates=29_in_documentation?= =?utf-8?q?=2C_comments?= Message-ID: <20160419234159.28498.98278.D0E1C8B7@psf.io> https://hg.python.org/cpython/rev/a54f6e207b22 changeset: 101074:a54f6e207b22 branch: 3.5 parent: 101072:8d38e95a2e4e user: Martin Panter date: Tue Apr 19 04:03:41 2016 +0000 summary: Fix spelling (inital), grammar (may translates) in documentation, comments files: Doc/library/tempfile.rst | 2 +- Doc/library/test.rst | 2 +- Doc/whatsnew/2.2.rst | 2 +- Lib/gzip.py | 2 +- Lib/optparse.py | 2 +- Lib/test/test_tracemalloc.py | 2 +- Misc/HISTORY | 2 +- Misc/NEWS | 6 +++--- Modules/_io/stringio.c | 4 ++-- Objects/typeobject.c | 4 ++-- Programs/_testembed.c | 2 +- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -256,7 +256,7 @@ module. If ``tempdir`` is unset or ``None`` at any call to any of the above - functions except :func:`gettempprefix` it is initalized following the + functions except :func:`gettempprefix` it is initialized following the algorithm described in :func:`gettempdir`. .. _tempfile-examples: diff --git a/Doc/library/test.rst b/Doc/library/test.rst --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -550,7 +550,7 @@ or passed to an external program (i.e. the ``-accept`` argument to openssl's s_server mode). Always prefer :func:`bind_port` over :func:`find_unused_port` where possible. Using a hard coded port is - discouraged since it can makes multiple instances of the test impossible to + discouraged since it can make multiple instances of the test impossible to run simultaneously, which is a problem for buildbots. diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst --- a/Doc/whatsnew/2.2.rst +++ b/Doc/whatsnew/2.2.rst @@ -758,7 +758,7 @@ operators. * Python 2.2 supports some command-line arguments for testing whether code will - works with the changed division semantics. Running python with :option:`-Q + work with the changed division semantics. Running python with :option:`-Q warn` will cause a warning to be issued whenever division is applied to two integers. You can use this to find code that's affected by the change and fix it. By default, Python 2.2 will simply perform classic division without a diff --git a/Lib/gzip.py b/Lib/gzip.py --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -133,7 +133,7 @@ a file object. When fileobj is not None, the filename argument is only used to be - included in the gzip file header, which may includes the original + included in the gzip file header, which may include the original filename of the uncompressed file. It defaults to the filename of fileobj, if discernible; otherwise, it defaults to the empty string, and in this case the original filename is not included in the header. diff --git a/Lib/optparse.py b/Lib/optparse.py --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -900,7 +900,7 @@ _short_opt : { string : Option } dictionary mapping short option strings, eg. "-f" or "-X", to the Option instances that implement them. If an Option - has multiple short option strings, it will appears in this + has multiple short option strings, it will appear in this dictionary multiple times. [1] _long_opt : { string : Option } dictionary mapping long option strings, eg. "--file" or diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py --- a/Lib/test/test_tracemalloc.py +++ b/Lib/test/test_tracemalloc.py @@ -253,7 +253,7 @@ snapshot.dump(support.TESTFN) self.addCleanup(support.unlink, support.TESTFN) - # load() should recreates the attribute + # load() should recreate the attribute snapshot2 = tracemalloc.Snapshot.load(support.TESTFN) self.assertEqual(snapshot2.test_attr, "new") diff --git a/Misc/HISTORY b/Misc/HISTORY --- a/Misc/HISTORY +++ b/Misc/HISTORY @@ -23743,7 +23743,7 @@ - Changed the checks made in Py_Initialize() and Py_Finalize(). It is now legal to call these more than once. The first call to Py_Initialize() initializes, the first call to Py_Finalize() -finalizes. There's also a new API, Py_IsInitalized() which checks +finalizes. There's also a new API, Py_IsInitialized() which checks whether we are already initialized (in case you want to leave things as they were). diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -5238,8 +5238,8 @@ - Issue #19448: Add private API to SSL module to lookup ASN.1 objects by OID, NID, short name and long name. -- Issue #19282: dbm.open now supports the context management protocol. (Inital - patch by Claudiu Popa) +- Issue #19282: dbm.open now supports the context management protocol. + (Initial patch by Claudiu Popa) - Issue #8311: Added support for writing any bytes-like objects in the aifc, sunau, and wave modules. @@ -5333,7 +5333,7 @@ - Issue #19227: Remove pthread_atfork() handler. The handler was added to solve #18747 but has caused issues. -- Issue #19420: Fix reference leak in module initalization code of +- Issue #19420: Fix reference leak in module initialization code of _hashopenssl.c - Issue #19329: Optimized compiling charsets in regular expressions. diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -913,8 +913,8 @@ Py_DECREF(initarg); /* Restore the buffer state. Even if __init__ did initialize the buffer, - we have to initialize it again since __init__ may translates the - newlines in the inital_value string. We clearly do not want that + we have to initialize it again since __init__ may translate the + newlines in the initial_value string. We clearly do not want that because the string value in the state tuple has already been translated once by __init__. So we do not take any chance and replace object's buffer completely. */ diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3901,7 +3901,7 @@ } } - /* The list is stored on the class so it may mutates while we + /* The list is stored on the class so it may mutate while we iterate over it */ if (slotnames_size != Py_SIZE(slotnames)) { PyErr_Format(PyExc_RuntimeError, @@ -4035,7 +4035,7 @@ } /* The object does not have __getnewargs_ex__ and __getnewargs__. This may - means __new__ does not takes any arguments on this object, or that the + mean __new__ does not takes any arguments on this object, or that the object does not implement the reduce protocol for pickling or copying. */ *args = NULL; diff --git a/Programs/_testembed.c b/Programs/_testembed.c --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -17,7 +17,7 @@ /***************************************************** - * Test repeated initalisation and subinterpreters + * Test repeated initialisation and subinterpreters *****************************************************/ static void print_subinterp(void) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 19:42:00 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 19 Apr 2016 23:42:00 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Additional_grammar_fix?= Message-ID: <20160419234200.15360.76463.EA823DEC@psf.io> https://hg.python.org/cpython/rev/e745fe5c722c changeset: 101076:e745fe5c722c user: Martin Panter date: Tue Apr 19 04:05:59 2016 +0000 summary: Additional grammar fix files: Lib/test/test_traceback.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -175,7 +175,7 @@ text, charset, 5) do_test(" \t\f\n# coding: {0}\n".format(charset), text, charset, 5) - # Issue #18960: coding spec should has no effect + # Issue #18960: coding spec should have no effect do_test("x=0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5) def test_print_traceback_at_exit(self): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 19:42:00 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 19 Apr 2016 23:42:00 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_spelling_?= =?utf-8?q?=28inital=29=2C_grammar_=28may_translates=29_in_documentation?= =?utf-8?q?=2C_comments?= Message-ID: <20160419234200.12727.98342.0A656D3B@psf.io> https://hg.python.org/cpython/rev/ac236f1e8fd4 changeset: 101077:ac236f1e8fd4 branch: 2.7 parent: 101047:8aa032b26552 user: Martin Panter date: Tue Apr 19 04:03:41 2016 +0000 summary: Fix spelling (inital), grammar (may translates) in documentation, comments files: Doc/whatsnew/2.2.rst | 2 +- Lib/gzip.py | 2 +- Lib/optparse.py | 2 +- Misc/HISTORY | 2 +- Modules/_io/stringio.c | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst --- a/Doc/whatsnew/2.2.rst +++ b/Doc/whatsnew/2.2.rst @@ -758,7 +758,7 @@ operators. * Python 2.2 supports some command-line arguments for testing whether code will - works with the changed division semantics. Running python with :option:`-Q + work with the changed division semantics. Running python with :option:`-Q warn <-Q>` will cause a warning to be issued whenever division is applied to two integers. You can use this to find code that's affected by the change and fix it. By default, Python 2.2 will simply perform classic division without a diff --git a/Lib/gzip.py b/Lib/gzip.py --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -55,7 +55,7 @@ a file object. When fileobj is not None, the filename argument is only used to be - included in the gzip file header, which may includes the original + included in the gzip file header, which may include the original filename of the uncompressed file. It defaults to the filename of fileobj, if discernible; otherwise, it defaults to the empty string, and in this case the original filename is not included in the header. diff --git a/Lib/optparse.py b/Lib/optparse.py --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -914,7 +914,7 @@ _short_opt : { string : Option } dictionary mapping short option strings, eg. "-f" or "-X", to the Option instances that implement them. If an Option - has multiple short option strings, it will appears in this + has multiple short option strings, it will appear in this dictionary multiple times. [1] _long_opt : { string : Option } dictionary mapping long option strings, eg. "--file" or diff --git a/Misc/HISTORY b/Misc/HISTORY --- a/Misc/HISTORY +++ b/Misc/HISTORY @@ -12831,7 +12831,7 @@ - Changed the checks made in Py_Initialize() and Py_Finalize(). It is now legal to call these more than once. The first call to Py_Initialize() initializes, the first call to Py_Finalize() -finalizes. There's also a new API, Py_IsInitalized() which checks +finalizes. There's also a new API, Py_IsInitialized() which checks whether we are already initialized (in case you want to leave things as they were). diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -736,8 +736,8 @@ Py_DECREF(initarg); /* Restore the buffer state. Even if __init__ did initialize the buffer, - we have to initialize it again since __init__ may translates the - newlines in the inital_value string. We clearly do not want that + we have to initialize it again since __init__ may translate the + newlines in the initial_value string. We clearly do not want that because the string value in the state tuple has already been translated once by __init__. So we do not take any chance and replace object's buffer completely. */ -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 19 19:42:00 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 19 Apr 2016 23:42:00 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_doc_and_comment_fixes_from_3=2E5?= Message-ID: <20160419234200.8332.34898.9E520709@psf.io> https://hg.python.org/cpython/rev/33e571b14b7e changeset: 101075:33e571b14b7e parent: 101073:715b67949349 parent: 101074:a54f6e207b22 user: Martin Panter date: Tue Apr 19 23:23:16 2016 +0000 summary: Merge doc and comment fixes from 3.5 files: Doc/library/tempfile.rst | 2 +- Doc/library/test.rst | 2 +- Doc/whatsnew/2.2.rst | 2 +- Lib/gzip.py | 2 +- Lib/optparse.py | 2 +- Lib/test/test_tracemalloc.py | 2 +- Misc/HISTORY | 2 +- Misc/NEWS | 6 +++--- Modules/_io/stringio.c | 4 ++-- Objects/typeobject.c | 4 ++-- Programs/_testembed.c | 2 +- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -256,7 +256,7 @@ module. If ``tempdir`` is unset or ``None`` at any call to any of the above - functions except :func:`gettempprefix` it is initalized following the + functions except :func:`gettempprefix` it is initialized following the algorithm described in :func:`gettempdir`. .. _tempfile-examples: diff --git a/Doc/library/test.rst b/Doc/library/test.rst --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -550,7 +550,7 @@ or passed to an external program (i.e. the ``-accept`` argument to openssl's s_server mode). Always prefer :func:`bind_port` over :func:`find_unused_port` where possible. Using a hard coded port is - discouraged since it can makes multiple instances of the test impossible to + discouraged since it can make multiple instances of the test impossible to run simultaneously, which is a problem for buildbots. diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst --- a/Doc/whatsnew/2.2.rst +++ b/Doc/whatsnew/2.2.rst @@ -758,7 +758,7 @@ operators. * Python 2.2 supports some command-line arguments for testing whether code will - works with the changed division semantics. Running python with :option:`-Q + work with the changed division semantics. Running python with :option:`-Q warn` will cause a warning to be issued whenever division is applied to two integers. You can use this to find code that's affected by the change and fix it. By default, Python 2.2 will simply perform classic division without a diff --git a/Lib/gzip.py b/Lib/gzip.py --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -133,7 +133,7 @@ a file object. When fileobj is not None, the filename argument is only used to be - included in the gzip file header, which may includes the original + included in the gzip file header, which may include the original filename of the uncompressed file. It defaults to the filename of fileobj, if discernible; otherwise, it defaults to the empty string, and in this case the original filename is not included in the header. diff --git a/Lib/optparse.py b/Lib/optparse.py --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -901,7 +901,7 @@ _short_opt : { string : Option } dictionary mapping short option strings, eg. "-f" or "-X", to the Option instances that implement them. If an Option - has multiple short option strings, it will appears in this + has multiple short option strings, it will appear in this dictionary multiple times. [1] _long_opt : { string : Option } dictionary mapping long option strings, eg. "--file" or diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py --- a/Lib/test/test_tracemalloc.py +++ b/Lib/test/test_tracemalloc.py @@ -261,7 +261,7 @@ snapshot.dump(support.TESTFN) self.addCleanup(support.unlink, support.TESTFN) - # load() should recreates the attribute + # load() should recreate the attribute snapshot2 = tracemalloc.Snapshot.load(support.TESTFN) self.assertEqual(snapshot2.test_attr, "new") diff --git a/Misc/HISTORY b/Misc/HISTORY --- a/Misc/HISTORY +++ b/Misc/HISTORY @@ -23743,7 +23743,7 @@ - Changed the checks made in Py_Initialize() and Py_Finalize(). It is now legal to call these more than once. The first call to Py_Initialize() initializes, the first call to Py_Finalize() -finalizes. There's also a new API, Py_IsInitalized() which checks +finalizes. There's also a new API, Py_IsInitialized() which checks whether we are already initialized (in case you want to leave things as they were). diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -5851,8 +5851,8 @@ - Issue #19448: Add private API to SSL module to lookup ASN.1 objects by OID, NID, short name and long name. -- Issue #19282: dbm.open now supports the context management protocol. (Inital - patch by Claudiu Popa) +- Issue #19282: dbm.open now supports the context management protocol. + (Initial patch by Claudiu Popa) - Issue #8311: Added support for writing any bytes-like objects in the aifc, sunau, and wave modules. @@ -5946,7 +5946,7 @@ - Issue #19227: Remove pthread_atfork() handler. The handler was added to solve #18747 but has caused issues. -- Issue #19420: Fix reference leak in module initalization code of +- Issue #19420: Fix reference leak in module initialization code of _hashopenssl.c - Issue #19329: Optimized compiling charsets in regular expressions. diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -913,8 +913,8 @@ Py_DECREF(initarg); /* Restore the buffer state. Even if __init__ did initialize the buffer, - we have to initialize it again since __init__ may translates the - newlines in the inital_value string. We clearly do not want that + we have to initialize it again since __init__ may translate the + newlines in the initial_value string. We clearly do not want that because the string value in the state tuple has already been translated once by __init__. So we do not take any chance and replace object's buffer completely. */ diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3925,7 +3925,7 @@ } } - /* The list is stored on the class so it may mutates while we + /* The list is stored on the class so it may mutate while we iterate over it */ if (slotnames_size != Py_SIZE(slotnames)) { PyErr_Format(PyExc_RuntimeError, @@ -4059,7 +4059,7 @@ } /* The object does not have __getnewargs_ex__ and __getnewargs__. This may - means __new__ does not takes any arguments on this object, or that the + mean __new__ does not takes any arguments on this object, or that the object does not implement the reduce protocol for pickling or copying. */ *args = NULL; diff --git a/Programs/_testembed.c b/Programs/_testembed.c --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -17,7 +17,7 @@ /***************************************************** - * Test repeated initalisation and subinterpreters + * Test repeated initialisation and subinterpreters *****************************************************/ static void print_subinterp(void) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 20 02:15:34 2016 From: python-checkins at python.org (senthil.kumaran) Date: Wed, 20 Apr 2016 06:15:34 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP-8_Update_on_Knuth_style_b?= =?utf-8?q?reaking_of_a_long_formula=2E_=23issue26780?= Message-ID: <20160420061532.109607.72608.15A75691@psf.io> https://hg.python.org/peps/rev/9afe77ad549b changeset: 6288:9afe77ad549b user: Senthil Kumaran date: Tue Apr 19 23:14:50 2016 -0700 summary: PEP-8 Update on Knuth style breaking of a long formula. #issue26780 Patch by Brandon Rhodes provides clarity and rationale for this suggestion. Also fixes the example to use "+", "-" operators which have same precedence level. Reviewed by Guido van Rossum. files: pep-0008.txt | 55 +++++++++++++++++++++++---------------- 1 files changed, 32 insertions(+), 23 deletions(-) diff --git a/pep-0008.txt b/pep-0008.txt --- a/pep-0008.txt +++ b/pep-0008.txt @@ -253,31 +253,40 @@ Should a line break before or after a binary operator? ------------------------------------------------------ -For decades the recommended style has been to break after binary -operators. However, recent research unearthed recommendations by -Donald Knuth to break *before* binary operators, in his writings about -typesetting [3]_. Therefore it is permissible to break before or -after a binary operator, as long as the convention is consistent -locally. For new code Knuth's style is suggested. +For decades the recommended style was to break after binary operators. +But this can hurt readability in two ways: the operators tend to get +scattered across different columns on the screen, and each operator is +moved away from its operand and onto the previous line. Here, the eye +has to do extra work to tell which items are added and which are +subtracted:: -Some examples of code breaking before binary Boolean operators:: + # No: operators sit far away from their operands + income = (gross_wages + + taxable_interest + + (dividends - qualified_dividends) - + ira_deduction - + student_loan_interest) - class Rectangle(Blob): +To solve this readability problem, mathematicians and their publishers +follow the opposite convention. Donald Knuth explains the traditional +rule in his *Computers and Typesetting* series: "Although formulas +within a paragraph always break after binary operations and relations, +displayed formulas always break before binary operations" [3]_. - def __init__(self, width, height, - color='black', emphasis=None, highlight=0): - if (width == 0 - and height == 0 - and color == 'red' - and emphasis == 'strong' - or highlight > 100): - raise ValueError("sorry, you lose") - if (width == 0 and height == 0 - and (color == 'red' or emphasis is None)): - raise ValueError("I don't think so -- values are %s, %s" % - (width, height)) - Blob.__init__(self, width, height, - color, emphasis, highlight) +Following the tradition from mathematics usually results in more +readable code:: + + # Yes: easy to match operators with operands + income = (gross_wages + + taxable_interest + + (dividends - qualified_dividends) + - ira_deduction + - student_loan_interest) + +In Python code, it is permissible to break before or after a binary +operator, as long as the convention is consistent locally. For new +code Knuth's style is suggested. + Blank Lines ----------- @@ -1327,7 +1336,7 @@ .. [2] Barry's GNU Mailman style guide http://barry.warsaw.us/software/STYLEGUIDE.txt -.. [3] http://rhodesmill.org/brandon/slides/2012-11-pyconca/#laying-down-the-law +.. [3] Donald Knuth's *The TeXBook*, pages 195 and 196. .. [4] http://www.wikipedia.com/wiki/CamelCase -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Wed Apr 20 03:58:19 2016 From: python-checkins at python.org (victor.stinner) Date: Wed, 20 Apr 2016 07:58:19 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2321668=3A_Fix_auth?= =?utf-8?q?or_of_the_patch=2E?= Message-ID: <20160420075817.53846.56726.9921024E@psf.io> https://hg.python.org/cpython/rev/f76753f26982 changeset: 101078:f76753f26982 parent: 101076:e745fe5c722c user: Victor Stinner date: Wed Apr 20 09:58:12 2016 +0200 summary: Issue #21668: Fix author of the patch. Sorry, it was hard to retrieve the original author of the patch in this issue with a long history and many authors. files: Misc/NEWS | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -999,7 +999,7 @@ ----- - Issue #21668: Link audioop, _datetime, _ctypes_test modules to libm, - except on Mac OS X. Patch written by Xavier de Gaye. + except on Mac OS X. Patch written by Chi Hsuan Yen. - Issue #25702: A --with-lto configure option has been added that will enable link time optimizations at build time during a make profile-opt. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 20 04:02:10 2016 From: python-checkins at python.org (victor.stinner) Date: Wed, 20 Apr 2016 08:02:10 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2321668=3A_Add_also?= =?utf-8?q?_Chi_Hsuan_Yen_to_Misc/ACKS?= Message-ID: <20160420080209.19499.18793.0EFD522C@psf.io> https://hg.python.org/cpython/rev/7530caa5ed1a changeset: 101079:7530caa5ed1a user: Victor Stinner date: Wed Apr 20 10:02:04 2016 +0200 summary: Issue #21668: Add also Chi Hsuan Yen to Misc/ACKS files: Misc/ACKS | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1630,6 +1630,7 @@ Arnon Yaari Hirokazu Yamamoto Ka-Ping Yee +Chi Hsuan Yen Jason Yeo EungJun Yi Bob Yodlowski -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Wed Apr 20 05:47:58 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 20 Apr 2016 09:47:58 +0000 Subject: [Python-checkins] Daily reference leaks (e745fe5c722c): sum=4 Message-ID: <20160420094752.90477.44601.A19F7EA7@psf.io> results for e745fe5c722c on branch "default" -------------------------------------------- test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflog5YuZ9s', '--timeout', '7200'] From lp_benchmark_robot at intel.com Wed Apr 20 08:21:40 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Wed, 20 Apr 2016 13:21:40 +0100 Subject: [Python-checkins] GOOD Benchmark Results for Python Default 2016-04-20 Message-ID: <24dacea3-18eb-4099-8c92-24556c7b01d6@irsmsx102.ger.corp.intel.com> Results for project Python default, build date 2016-04-20 02:01:46 +0000 commit: e745fe5c722c previous commit: ee9921b29fd8 revision date: 2016-04-19 04:05:59 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.20% -0.73% 9.62% 14.23% :-| pybench 6.25% 0.36% 0.29% 5.99% :-( regex_v8 2.64% -0.53% -3.87% 4.20% :-( nbody 0.87% 1.00% -2.32% 11.27% :-) json_dump_v2 0.25% 2.55% -1.78% 10.14% :-| normal_startup 0.74% -0.52% -0.79% 5.17% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/good-benchmark-results-for-python-default-2016-04-20/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Wed Apr 20 08:24:21 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Wed, 20 Apr 2016 13:24:21 +0100 Subject: [Python-checkins] NEUTRAL Benchmark Results for Python 2.7 2016-04-20 Message-ID: <90487611-1208-4e33-b913-85117380cd02@irsmsx102.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-20 02:46:36 +0000 commit: ac236f1e8fd4 previous commit: 8aa032b26552 revision date: 2016-04-19 04:03:41 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.14% -0.30% 6.11% 4.59% :-) pybench 0.11% -0.03% 5.89% 4.68% :-( regex_v8 0.95% -0.17% -2.30% 11.26% :-) nbody 0.32% 0.02% 6.93% 4.03% :-) json_dump_v2 0.50% -0.09% 2.09% 11.66% :-( normal_startup 1.89% 0.04% -5.35% 2.47% :-) ssbench 0.17% -0.00% 2.54% 0.82% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/neutral-benchmark-results-for-python-2-7-2016-04-20/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Wed Apr 20 12:15:01 2016 From: python-checkins at python.org (victor.stinner) Date: Wed, 20 Apr 2016 16:15:01 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogcHl0aG9uLWdkYi5w?= =?utf-8?q?y=3A_get_C_types_at_runtime?= Message-ID: <20160420161501.26079.24917.7B40C390@psf.io> https://hg.python.org/cpython/rev/e1c6f8895fd8 changeset: 101080:e1c6f8895fd8 branch: 3.5 parent: 101074:a54f6e207b22 user: Victor Stinner date: Wed Apr 20 18:07:21 2016 +0200 summary: python-gdb.py: get C types at runtime Issue #26799: Fix python-gdb.py: don't get once C types when the Python code is loaded, but get C types on demande. The C types can change if python-gdb.py is loaded before the Python executable. Patch written by Thomas Ilsche. files: Misc/ACKS | 1 + Misc/NEWS | 5 +++ Tools/gdb/libpython.py | 47 +++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -648,6 +648,7 @@ Mihai Ibanescu Ali Ikinci Aaron Iles +Thomas Ilsche Lars Immisch Bobby Impollonia Naoki Inada diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -467,6 +467,11 @@ Tools/Demos ----------- +- Issue #26799: Fix python-gdb.py: don't get once C types when the Python code + is loaded, but get C types on demande. The C types can change if + python-gdb.py is loaded before the Python executable. Patch written by Thomas + Ilsche. + - Issue #26271: Fix the Freeze tool to properly use flags passed through configure. Patch by Daniel Shaulov. diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -56,16 +56,35 @@ long = int # Look up the gdb.Type for some standard types: -_type_char_ptr = gdb.lookup_type('char').pointer() # char* -_type_unsigned_char_ptr = gdb.lookup_type('unsigned char').pointer() # unsigned char* -_type_void_ptr = gdb.lookup_type('void').pointer() # void* -_type_unsigned_short_ptr = gdb.lookup_type('unsigned short').pointer() -_type_unsigned_int_ptr = gdb.lookup_type('unsigned int').pointer() +# Those need to be refreshed as types (pointer sizes) may change when +# gdb loads different executables + + +def _type_char_ptr(): + return gdb.lookup_type('char').pointer() # char* + + +def _type_unsigned_char_ptr(): + return gdb.lookup_type('unsigned char').pointer() # unsigned char* + + +def _type_void_ptr(): + return gdb.lookup_type('void').pointer() # void* + + +def _type_unsigned_short_ptr(): + return gdb.lookup_type('unsigned short').pointer() + + +def _type_unsigned_int_ptr(): + return gdb.lookup_type('unsigned int').pointer() # value computed later, see PyUnicodeObjectPtr.proxy() _is_pep393 = None -SIZEOF_VOID_P = _type_void_ptr.sizeof + +def _sizeof_void_p(): + return _type_void_ptr().sizeof Py_TPFLAGS_HEAPTYPE = (1 << 9) @@ -460,8 +479,8 @@ return ( ( typeobj.field('tp_basicsize') + nitems * typeobj.field('tp_itemsize') + - (SIZEOF_VOID_P - 1) - ) & ~(SIZEOF_VOID_P - 1) + (_sizeof_void_p() - 1) + ) & ~(_sizeof_void_p() - 1) ).cast(_PyObject_VAR_SIZE._type_size_t) _PyObject_VAR_SIZE._type_size_t = None @@ -485,9 +504,9 @@ size = _PyObject_VAR_SIZE(typeobj, tsize) dictoffset += size assert dictoffset > 0 - assert dictoffset % SIZEOF_VOID_P == 0 + assert dictoffset % _sizeof_void_p() == 0 - dictptr = self._gdbval.cast(_type_char_ptr) + dictoffset + dictptr = self._gdbval.cast(_type_char_ptr()) + dictoffset PyObjectPtrPtr = PyObjectPtr.get_gdb_type().pointer() dictptr = dictptr.cast(PyObjectPtrPtr) return PyObjectPtr.from_pyobject_ptr(dictptr.dereference()) @@ -1004,7 +1023,7 @@ def __str__(self): field_ob_size = self.field('ob_size') field_ob_sval = self.field('ob_sval') - char_ptr = field_ob_sval.address.cast(_type_unsigned_char_ptr) + char_ptr = field_ob_sval.address.cast(_type_unsigned_char_ptr()) return ''.join([chr(char_ptr[i]) for i in safe_range(field_ob_size)]) def proxyval(self, visited): @@ -1135,11 +1154,11 @@ field_str = self.field('data')['any'] repr_kind = int(state['kind']) if repr_kind == 1: - field_str = field_str.cast(_type_unsigned_char_ptr) + field_str = field_str.cast(_type_unsigned_char_ptr()) elif repr_kind == 2: - field_str = field_str.cast(_type_unsigned_short_ptr) + field_str = field_str.cast(_type_unsigned_short_ptr()) elif repr_kind == 4: - field_str = field_str.cast(_type_unsigned_int_ptr) + field_str = field_str.cast(_type_unsigned_int_ptr()) else: # Python 3.2 and earlier field_length = long(self.field('length')) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 20 12:15:01 2016 From: python-checkins at python.org (victor.stinner) Date: Wed, 20 Apr 2016 16:15:01 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_3=2E5=3A_Issue_=2326799?= Message-ID: <20160420161501.19653.69757.55D3E062@psf.io> https://hg.python.org/cpython/rev/6425728d8dc6 changeset: 101081:6425728d8dc6 parent: 101079:7530caa5ed1a parent: 101080:e1c6f8895fd8 user: Victor Stinner date: Wed Apr 20 18:12:38 2016 +0200 summary: Merge 3.5: Issue #26799 files: Misc/ACKS | 1 + Misc/NEWS | 5 +++ Tools/gdb/libpython.py | 47 +++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -651,6 +651,7 @@ Mihai Ibanescu Ali Ikinci Aaron Iles +Thomas Ilsche Lars Immisch Bobby Impollonia Naoki Inada diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -1065,6 +1065,11 @@ Tools/Demos ----------- +- Issue #26799: Fix python-gdb.py: don't get once C types when the Python code + is loaded, but get C types on demande. The C types can change if + python-gdb.py is loaded before the Python executable. Patch written by Thomas + Ilsche. + - Issue #26271: Fix the Freeze tool to properly use flags passed through configure. Patch by Daniel Shaulov. diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -56,16 +56,35 @@ long = int # Look up the gdb.Type for some standard types: -_type_char_ptr = gdb.lookup_type('char').pointer() # char* -_type_unsigned_char_ptr = gdb.lookup_type('unsigned char').pointer() # unsigned char* -_type_void_ptr = gdb.lookup_type('void').pointer() # void* -_type_unsigned_short_ptr = gdb.lookup_type('unsigned short').pointer() -_type_unsigned_int_ptr = gdb.lookup_type('unsigned int').pointer() +# Those need to be refreshed as types (pointer sizes) may change when +# gdb loads different executables + + +def _type_char_ptr(): + return gdb.lookup_type('char').pointer() # char* + + +def _type_unsigned_char_ptr(): + return gdb.lookup_type('unsigned char').pointer() # unsigned char* + + +def _type_void_ptr(): + return gdb.lookup_type('void').pointer() # void* + + +def _type_unsigned_short_ptr(): + return gdb.lookup_type('unsigned short').pointer() + + +def _type_unsigned_int_ptr(): + return gdb.lookup_type('unsigned int').pointer() # value computed later, see PyUnicodeObjectPtr.proxy() _is_pep393 = None -SIZEOF_VOID_P = _type_void_ptr.sizeof + +def _sizeof_void_p(): + return _type_void_ptr().sizeof Py_TPFLAGS_HEAPTYPE = (1 << 9) @@ -460,8 +479,8 @@ return ( ( typeobj.field('tp_basicsize') + nitems * typeobj.field('tp_itemsize') + - (SIZEOF_VOID_P - 1) - ) & ~(SIZEOF_VOID_P - 1) + (_sizeof_void_p() - 1) + ) & ~(_sizeof_void_p() - 1) ).cast(_PyObject_VAR_SIZE._type_size_t) _PyObject_VAR_SIZE._type_size_t = None @@ -485,9 +504,9 @@ size = _PyObject_VAR_SIZE(typeobj, tsize) dictoffset += size assert dictoffset > 0 - assert dictoffset % SIZEOF_VOID_P == 0 + assert dictoffset % _sizeof_void_p() == 0 - dictptr = self._gdbval.cast(_type_char_ptr) + dictoffset + dictptr = self._gdbval.cast(_type_char_ptr()) + dictoffset PyObjectPtrPtr = PyObjectPtr.get_gdb_type().pointer() dictptr = dictptr.cast(PyObjectPtrPtr) return PyObjectPtr.from_pyobject_ptr(dictptr.dereference()) @@ -1004,7 +1023,7 @@ def __str__(self): field_ob_size = self.field('ob_size') field_ob_sval = self.field('ob_sval') - char_ptr = field_ob_sval.address.cast(_type_unsigned_char_ptr) + char_ptr = field_ob_sval.address.cast(_type_unsigned_char_ptr()) return ''.join([chr(char_ptr[i]) for i in safe_range(field_ob_size)]) def proxyval(self, visited): @@ -1135,11 +1154,11 @@ field_str = self.field('data')['any'] repr_kind = int(state['kind']) if repr_kind == 1: - field_str = field_str.cast(_type_unsigned_char_ptr) + field_str = field_str.cast(_type_unsigned_char_ptr()) elif repr_kind == 2: - field_str = field_str.cast(_type_unsigned_short_ptr) + field_str = field_str.cast(_type_unsigned_short_ptr()) elif repr_kind == 4: - field_str = field_str.cast(_type_unsigned_int_ptr) + field_str = field_str.cast(_type_unsigned_int_ptr()) else: # Python 3.2 and earlier field_length = long(self.field('length')) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 20 12:24:08 2016 From: python-checkins at python.org (victor.stinner) Date: Wed, 20 Apr 2016 16:24:08 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy41?= Message-ID: <20160420162408.26103.93416.AB0B2565@psf.io> https://hg.python.org/cpython/rev/b6d7645e4b0c changeset: 101084:b6d7645e4b0c parent: 101081:6425728d8dc6 parent: 101083:952c89a10be6 user: Victor Stinner date: Wed Apr 20 18:23:59 2016 +0200 summary: Merge 3.5 files: Misc/NEWS | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -1065,8 +1065,8 @@ Tools/Demos ----------- -- Issue #26799: Fix python-gdb.py: don't get once C types when the Python code - is loaded, but get C types on demande. The C types can change if +- Issue #26799: Fix python-gdb.py: don't get C types once when the Python code + is loaded, but get C types on demand. The C types can change if python-gdb.py is loaded before the Python executable. Patch written by Thomas Ilsche. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 20 12:24:46 2016 From: python-checkins at python.org (victor.stinner) Date: Wed, 20 Apr 2016 16:24:46 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_python-gdb?= =?utf-8?q?=2Epy=3A_get_C_types_on_demand?= Message-ID: <20160420162407.109607.99002.DDF522EC@psf.io> https://hg.python.org/cpython/rev/e4561aad29e6 changeset: 101082:e4561aad29e6 branch: 2.7 parent: 101077:ac236f1e8fd4 user: Victor Stinner date: Wed Apr 20 18:23:13 2016 +0200 summary: Fix python-gdb.py: get C types on demand Issue #26799: Fix python-gdb.py: don't get C types once when the Python code is loaded, but get C types on demand. The C types can change if python-gdb.py is loaded before the Python executable. Patch written by Thomas Ilsche. files: Misc/ACKS | 1 + Misc/NEWS | 8 ++++++++ Tools/gdb/libpython.py | 26 +++++++++++++++++--------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -618,6 +618,7 @@ Mihai Ibanescu Ali Ikinci Aaron Iles +Thomas Ilsche Lars Immisch Bobby Impollonia Meador Inge diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -255,6 +255,14 @@ - Issue #25136: Support Apple Xcode 7's new textual SDK stub libraries. +Tools/Demos +----------- + +- Issue #26799: Fix python-gdb.py: don't get C types once when the Python code + is loaded, but get C types on demand. The C types can change if + python-gdb.py is loaded before the Python executable. Patch written by Thomas + Ilsche. + C API ----- diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -55,11 +55,19 @@ long = int # Look up the gdb.Type for some standard types: -_type_char_ptr = gdb.lookup_type('char').pointer() # char* -_type_unsigned_char_ptr = gdb.lookup_type('unsigned char').pointer() # unsigned char* -_type_void_ptr = gdb.lookup_type('void').pointer() # void* +# Those need to be refreshed as types (pointer sizes) may change when +# gdb loads different executables -SIZEOF_VOID_P = _type_void_ptr.sizeof +def _type_char_ptr(): + return gdb.lookup_type('char').pointer() # char* + + +def _type_unsigned_char_ptr(): + return gdb.lookup_type('unsigned char').pointer() # unsigned char* + + +def _sizeof_void_p(): + return gdb.lookup_type('void').pointer().sizeof Py_TPFLAGS_HEAPTYPE = (1 << 9) @@ -439,8 +447,8 @@ return ( ( typeobj.field('tp_basicsize') + nitems * typeobj.field('tp_itemsize') + - (SIZEOF_VOID_P - 1) - ) & ~(SIZEOF_VOID_P - 1) + (_sizeof_void_p() - 1) + ) & ~(_sizeof_void_p() - 1) ).cast(_PyObject_VAR_SIZE._type_size_t) _PyObject_VAR_SIZE._type_size_t = None @@ -464,9 +472,9 @@ size = _PyObject_VAR_SIZE(typeobj, tsize) dictoffset += size assert dictoffset > 0 - assert dictoffset % SIZEOF_VOID_P == 0 + assert dictoffset % _sizeof_void_p() == 0 - dictptr = self._gdbval.cast(_type_char_ptr) + dictoffset + dictptr = self._gdbval.cast(_type_char_ptr()) + dictoffset PyObjectPtrPtr = PyObjectPtr.get_gdb_type().pointer() dictptr = dictptr.cast(PyObjectPtrPtr) return PyObjectPtr.from_pyobject_ptr(dictptr.dereference()) @@ -1014,7 +1022,7 @@ def __str__(self): field_ob_size = self.field('ob_size') field_ob_sval = self.field('ob_sval') - char_ptr = field_ob_sval.address.cast(_type_unsigned_char_ptr) + char_ptr = field_ob_sval.address.cast(_type_unsigned_char_ptr()) # When gdb is linked with a Python 3 interpreter, this is really # a latin-1 mojibake decoding of the original string... return ''.join([chr(char_ptr[i]) for i in safe_range(field_ob_size)]) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 20 12:24:46 2016 From: python-checkins at python.org (victor.stinner) Date: Wed, 20 Apr 2016 16:24:46 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2Nzk5?= =?utf-8?q?=3A_Fix_typo_in_Misc/NEWS?= Message-ID: <20160420162408.107494.96661.A73577C7@psf.io> https://hg.python.org/cpython/rev/952c89a10be6 changeset: 101083:952c89a10be6 branch: 3.5 parent: 101080:e1c6f8895fd8 user: Victor Stinner date: Wed Apr 20 18:23:49 2016 +0200 summary: Issue #26799: Fix typo in Misc/NEWS files: Misc/NEWS | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -467,8 +467,8 @@ Tools/Demos ----------- -- Issue #26799: Fix python-gdb.py: don't get once C types when the Python code - is loaded, but get C types on demande. The C types can change if +- Issue #26799: Fix python-gdb.py: don't get C types once when the Python code + is loaded, but get C types on demand. The C types can change if python-gdb.py is loaded before the Python executable. Patch written by Thomas Ilsche. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 20 12:27:21 2016 From: python-checkins at python.org (victor.stinner) Date: Wed, 20 Apr 2016 16:27:21 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy41?= Message-ID: <20160420162720.12745.97171.184409D5@psf.io> https://hg.python.org/cpython/rev/a94156400269 changeset: 101086:a94156400269 parent: 101084:b6d7645e4b0c parent: 101085:a246047734b3 user: Victor Stinner date: Wed Apr 20 18:26:40 2016 +0200 summary: Merge 3.5 files: Tools/gdb/libpython.py | 16 +++++----------- 1 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -59,7 +59,6 @@ # Those need to be refreshed as types (pointer sizes) may change when # gdb loads different executables - def _type_char_ptr(): return gdb.lookup_type('char').pointer() # char* @@ -68,10 +67,6 @@ return gdb.lookup_type('unsigned char').pointer() # unsigned char* -def _type_void_ptr(): - return gdb.lookup_type('void').pointer() # void* - - def _type_unsigned_short_ptr(): return gdb.lookup_type('unsigned short').pointer() @@ -79,16 +74,15 @@ def _type_unsigned_int_ptr(): return gdb.lookup_type('unsigned int').pointer() + +def _sizeof_void_p(): + return gdb.lookup_type('void').pointer().sizeof + + # value computed later, see PyUnicodeObjectPtr.proxy() _is_pep393 = None - -def _sizeof_void_p(): - return _type_void_ptr().sizeof - - Py_TPFLAGS_HEAPTYPE = (1 << 9) - Py_TPFLAGS_LONG_SUBCLASS = (1 << 24) Py_TPFLAGS_LIST_SUBCLASS = (1 << 25) Py_TPFLAGS_TUPLE_SUBCLASS = (1 << 26) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 20 12:27:21 2016 From: python-checkins at python.org (victor.stinner) Date: Wed, 20 Apr 2016 16:27:21 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_gdb/libpython?= =?utf-8?b?LnB5OiBpbmxpbmUgX3R5cGVfdm9pZF9wdHIoKQ==?= Message-ID: <20160420162720.18809.58090.2D0E78B4@psf.io> https://hg.python.org/cpython/rev/a246047734b3 changeset: 101085:a246047734b3 branch: 3.5 parent: 101083:952c89a10be6 user: Victor Stinner date: Wed Apr 20 18:26:12 2016 +0200 summary: gdb/libpython.py: inline _type_void_ptr() The function was only called in _sizeof_void_p() files: Tools/gdb/libpython.py | 16 +++++----------- 1 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -59,7 +59,6 @@ # Those need to be refreshed as types (pointer sizes) may change when # gdb loads different executables - def _type_char_ptr(): return gdb.lookup_type('char').pointer() # char* @@ -68,10 +67,6 @@ return gdb.lookup_type('unsigned char').pointer() # unsigned char* -def _type_void_ptr(): - return gdb.lookup_type('void').pointer() # void* - - def _type_unsigned_short_ptr(): return gdb.lookup_type('unsigned short').pointer() @@ -79,16 +74,15 @@ def _type_unsigned_int_ptr(): return gdb.lookup_type('unsigned int').pointer() + +def _sizeof_void_p(): + return gdb.lookup_type('void').pointer().sizeof + + # value computed later, see PyUnicodeObjectPtr.proxy() _is_pep393 = None - -def _sizeof_void_p(): - return _type_void_ptr().sizeof - - Py_TPFLAGS_HEAPTYPE = (1 << 9) - Py_TPFLAGS_LONG_SUBCLASS = (1 << 24) Py_TPFLAGS_LIST_SUBCLASS = (1 << 25) Py_TPFLAGS_TUPLE_SUBCLASS = (1 << 26) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 20 18:38:03 2016 From: python-checkins at python.org (victor.stinner) Date: Wed, 20 Apr 2016 22:38:03 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP_509=3A_fix_typo_reported_?= =?utf-8?q?by_Jim_J=2E_Jewett?= Message-ID: <20160420223803.26083.23288.36F0E16A@psf.io> https://hg.python.org/peps/rev/23da8bc780bf changeset: 6289:23da8bc780bf user: Victor Stinner date: Thu Apr 21 00:37:56 2016 +0200 summary: PEP 509: fix typo reported by Jim J. Jewett files: pep-0509.txt | 23 ++++++++++++----------- 1 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pep-0509.txt b/pep-0509.txt --- a/pep-0509.txt +++ b/pep-0509.txt @@ -38,9 +38,9 @@ PEP proposes to add a private version to dictionaries to implement fast guards on namespaces. -Dictionary lookups can be skipped if the version does not change which +Dictionary lookups can be skipped if the version does not change, which is the common case for most namespaces. The version is globally unique, -so checking the version is also enough to check if the namespace +so checking the version is also enough to verify that the namespace dictionary was not replaced with a new dictionary. When the dictionary version does not change, the performance of a guard @@ -49,13 +49,14 @@ Example of optimization: copy the value of a global variable to function constants. This optimization requires a guard on the global variable to -check if it was modified. If the global variable is not modified, the -function uses the cached copy. If the global variable is modified, the -function uses a regular lookup, and maybe also deoptimize the function -(to remove the overhead of the guard check for next function calls). +check if it was modified after it was copied. If the global variable is +not modified, the function uses the cached copy. If the global variable +is modified, the function uses a regular lookup, and maybe also +deoptimizes the function (to remove the overhead of the guard check for +next function calls). See the `PEP 510 -- Specialized functions with guards -`_ for the concrete usage of +`_ for concrete usage of guards to specialize functions and for a more general rationale on Python static optimizers. @@ -63,7 +64,7 @@ Guard example ============= -Pseudo-code of an fast guard to check if a dictionary entry was modified +Pseudo-code of a fast guard to check if a dictionary entry was modified (created, updated or deleted) using an hypothetical ``dict_get_version(dict)`` function:: @@ -211,7 +212,7 @@ 103 ``dict.__setitem__(key, value)`` and ``dict.update(...)`` always -increases the version, even if the new value is identical or is equal to +increase the version, even if the new value is identical or is equal to the current value (even if ``(dict[key] is value) or (dict[key] == value)``). @@ -259,7 +260,7 @@ The implementation uses the C type ``PY_UINT64_T`` to store the version: a 64 bits unsigned integer. The C code uses ``version++``. On integer -overflow, the version is wrapped to ``0`` (and then continue to be +overflow, the version is wrapped to ``0`` (and then continues to be incremented) according to the C standard. After an integer overflow, a guard can succeed whereas the watched @@ -337,7 +338,7 @@ created or modified, the entry version is set to the dictionary version which is incremented at any change (create, modify, delete). -Pseudo-code of an fast guard to check if a dictionary key was modified +Pseudo-code of a fast guard to check if a dictionary key was modified using hypothetical ``dict_get_version(dict)`` and ``dict_get_entry_version(dict)`` functions:: -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Wed Apr 20 19:42:57 2016 From: python-checkins at python.org (victor.stinner) Date: Wed, 20 Apr 2016 23:42:57 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP_509=3A_don=27t_require_to?= =?utf-8?q?_always_increase_the_version?= Message-ID: <20160420234257.28303.14425.FB617CA8@psf.io> https://hg.python.org/peps/rev/16393fc7e31a changeset: 6290:16393fc7e31a user: Victor Stinner date: Thu Apr 21 01:15:25 2016 +0200 summary: PEP 509: don't require to always increase the version Don't require to increase the dict version if the dictionary content does not change. Leave this choice to the Python implementation. files: pep-0509.txt | 64 ++++++++++++++++++++++++++++----------- 1 files changed, 45 insertions(+), 19 deletions(-) diff --git a/pep-0509.txt b/pep-0509.txt --- a/pep-0509.txt +++ b/pep-0509.txt @@ -180,21 +180,52 @@ Add a ``ma_version_tag`` field to the ``PyDictObject`` structure with the C type ``PY_UINT64_T``, 64-bit unsigned integer. Add also a global -dictionary version. Each time a dictionary is created, the global -version is incremented and the dictionary version is initialized to the -global version. The global version is also incremented and copied to the -dictionary version at each dictionary change: +dictionary version. -* ``clear()`` if the dict is non-empty -* ``pop(key)`` if the key exists -* ``popitem()`` if the dict is non-empty -* ``setdefault(key, value)`` if the key does not exist -* ``__delitem__(key)`` if the key exists -* ``__setitem__(key, value)`` always increases the version -* ``update(...)`` if called with arguments +Each time a dictionary is created, the global version is incremented and +the dictionary version is initialized to the global version. + +Each time the dictionary content is modified, the global version must be +incremented and copied to the dictionary version. Dictionary methods +which can modify its content: + +* ``clear()`` +* ``pop(key)`` +* ``popitem()`` +* ``setdefault(key, value)`` +* ``__delitem__(key)`` +* ``__setitem__(key, value)`` +* ``update(...)`` + +The choice of increasing or not the version when a dictionary method +does not change its content is left to the Python implementation. A +Python implementation can decide to not increase the version to avoid +dictionary lookups in guards. Examples of cases when dictionary methods +don't modify its content: + +* ``clear()`` if the dict is already empty +* ``pop(key)`` if the key does not exist +* ``popitem()`` if the dict is empty +* ``setdefault(key, value)`` if the key already exists +* ``__delitem__(key)`` if the key does not exist +* ``__setitem__(key, value)`` if the new value is identical to the + current value +* ``update()`` if called without argument or if new values are identical + to current values + +Setting a key to a new value equals to the old value is also considered +as an operation modifying the dictionary content. + +Two different empty dictionaries must have a different version to be +able to identify a dictionary just by its version. It allows to verify +in a guard that a namespace was not replaced without storing a strong +reference to the dictionary. Using a borrowed reference does not work: +if the old dictionary is destroyed, it is possible that a new dictionary +is allocated at the same memory address. By the way, dictionaries don't +support weak references. The version increase must be atomic. In CPython, the Global Interpreter -Lock (GIL) already protects ``dict`` methods to make them atomic. +Lock (GIL) already protects ``dict`` methods to make changes atomic. Example using an hypothetical ``dict_get_version(dict)`` function:: @@ -211,15 +242,10 @@ >>> dict_get_version(d) 103 -``dict.__setitem__(key, value)`` and ``dict.update(...)`` always -increase the version, even if the new value is identical or is equal to -the current value (even if ``(dict[key] is value) or (dict[key] == -value)``). - The field is called ``ma_version_tag``, rather than ``ma_version``, to suggest to compare it using ``version_tag == old_version_tag``, rather -than ``version <= old_version`` which is wrong most of the time after an -integer overflow. +than ``version <= old_version`` which becomes wrong after an integer +overflow. Backwards Compatibility -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Thu Apr 21 03:23:13 2016 From: python-checkins at python.org (senthil.kumaran) Date: Thu, 21 Apr 2016 07:23:13 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_=5Bminor=5D_Doc_fix_in_old?= =?utf-8?q?_python_doc=2E?= Message-ID: <20160421072313.27770.21054.789C5A37@psf.io> https://hg.python.org/cpython/rev/496e094f4734 changeset: 101087:496e094f4734 user: Senthil Kumaran date: Thu Apr 21 00:23:08 2016 -0700 summary: [minor] Doc fix in old python doc. files: Doc/whatsnew/2.1.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/whatsnew/2.1.rst b/Doc/whatsnew/2.1.rst --- a/Doc/whatsnew/2.1.rst +++ b/Doc/whatsnew/2.1.rst @@ -367,7 +367,7 @@ This version works for simple things such as integers, but it has a side effect; the ``_cache`` dictionary holds a reference to the return values, so they'll -never be deallocated until the Python process exits and cleans up This isn't +never be deallocated until the Python process exits and cleans up. This isn't very noticeable for integers, but if :func:`f` returns an object, or a data structure that takes up a lot of memory, this can be a problem. -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Thu Apr 21 04:54:39 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 21 Apr 2016 08:54:39 +0000 Subject: [Python-checkins] Daily reference leaks (a94156400269): sum=7 Message-ID: <20160421085438.12739.85357.B8F2333A@psf.io> results for a94156400269 on branch "default" -------------------------------------------- test_asyncio leaked [3, 0, 0] memory blocks, sum=3 test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogyYP_aV', '--timeout', '7200'] From lp_benchmark_robot at intel.com Thu Apr 21 14:05:50 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Thu, 21 Apr 2016 19:05:50 +0100 Subject: [Python-checkins] NEUTRAL Benchmark Results for Python Default 2016-04-21 Message-ID: Results for project Python default, build date 2016-04-21 02:01:43 +0000 commit: a94156400269 previous commit: e745fe5c722c revision date: 2016-04-20 16:26:40 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.28% 0.15% 9.75% 14.25% :-| pybench 6.15% 0.10% 0.38% 6.66% :-( regex_v8 2.68% 0.24% -3.62% 1.74% :-( nbody 0.11% 0.19% -2.13% 10.31% :-| json_dump_v2 0.24% -0.15% -1.93% 11.56% :-| normal_startup 0.67% 0.24% 0.05% 5.01% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/neutral-benchmark-results-for-python-default-2016-04-21/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Thu Apr 21 14:06:21 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Thu, 21 Apr 2016 19:06:21 +0100 Subject: [Python-checkins] NEUTRAL Benchmark Results for Python 2.7 2016-04-21 Message-ID: <0fec41b9-a871-44d0-8936-20d8e05e914f@irsmsx102.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-21 02:46:33 +0000 commit: e4561aad29e6 previous commit: ac236f1e8fd4 revision date: 2016-04-20 16:23:13 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.17% 0.06% 6.17% 5.05% :-) pybench 0.14% -0.03% 5.86% 4.89% :-( regex_v8 0.78% 0.12% -2.18% 10.51% :-) nbody 0.13% 0.12% 7.04% 4.05% :-| json_dump_v2 0.54% -0.30% 1.80% 9.65% :-( normal_startup 1.79% -0.08% -5.43% 1.78% :-) ssbench 0.16% -0.19% 2.35% 1.47% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/neutral-benchmark-results-for-python-2-7-2016-04-21/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From solipsis at pitrou.net Fri Apr 22 04:53:33 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 22 Apr 2016 08:53:33 +0000 Subject: [Python-checkins] Daily reference leaks (496e094f4734): sum=4 Message-ID: <20160422085331.78695.37305.69C8B03B@psf.io> results for 496e094f4734 on branch "default" -------------------------------------------- test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogcltDlX', '--timeout', '7200'] From lp_benchmark_robot at intel.com Fri Apr 22 07:31:26 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Fri, 22 Apr 2016 12:31:26 +0100 Subject: [Python-checkins] BAD Benchmark Results for Python Default 2016-04-22 Message-ID: <25d33031-f875-462b-89ff-7eef5f5d3f77@irsmsx102.ger.corp.intel.com> Results for project Python default, build date 2016-04-22 02:02:17 +0000 commit: 496e094f4734 previous commit: a94156400269 revision date: 2016-04-21 07:23:08 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.32% -1.19% 8.68% 16.16% :-| pybench 6.23% -0.03% 0.35% 5.90% :-( regex_v8 2.66% -0.13% -3.76% 3.54% :-( nbody 0.10% -0.05% -2.18% 8.99% :-( json_dump_v2 0.24% -0.49% -2.43% 10.38% :-| normal_startup 0.82% -0.31% -0.26% 5.64% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/bad-benchmark-results-for-python-default-2016-04-22/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Fri Apr 22 07:33:57 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Fri, 22 Apr 2016 12:33:57 +0100 Subject: [Python-checkins] NEUTRAL Benchmark Results for Python 2.7 2016-04-22 Message-ID: No new revisions. Here are the previous results: Results for project Python 2.7, build date 2016-04-22 02:46:36 +0000 commit: e4561aad29e6 previous commit: ac236f1e8fd4 revision date: 2016-04-20 16:23:13 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.17% 0.06% 6.17% 5.05% :-) pybench 0.14% -0.03% 5.86% 4.89% :-( regex_v8 0.78% 0.12% -2.18% 10.51% :-) nbody 0.13% 0.12% 7.04% 4.05% :-| json_dump_v2 0.54% -0.30% 1.80% 9.65% :-( normal_startup 1.79% -0.08% -5.43% 1.78% :-) ssbench 0.16% -0.19% 2.35% 1.47% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/neutral-benchmark-results-for-python-2-7-2016-04-22/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Fri Apr 22 10:39:34 2016 From: python-checkins at python.org (victor.stinner) Date: Fri, 22 Apr 2016 14:39:34 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_PyMem=5FMalloc=28=29_now_u?= =?utf-8?q?ses_the_fast_pymalloc_allocator?= Message-ID: <20160422143842.115307.27349.B6C5737F@psf.io> https://hg.python.org/cpython/rev/68b2a43d8653 changeset: 101088:68b2a43d8653 user: Victor Stinner date: Fri Apr 22 16:26:23 2016 +0200 summary: PyMem_Malloc() now uses the fast pymalloc allocator Issue #26249: PyMem_Malloc() allocator family now uses the pymalloc allocator rather than system malloc(). Applications calling PyMem_Malloc() without holding the GIL can now crash: use PYTHONMALLOC=debug environment variable to validate the usage of memory allocators in your application. files: Doc/c-api/memory.rst | 60 +++++++++++++++++++----------- Doc/using/cmdline.rst | 11 ++--- Doc/whatsnew/3.6.rst | 6 +++ Misc/NEWS | 7 +++ Objects/obmalloc.c | 6 +- 5 files changed, 58 insertions(+), 32 deletions(-) diff --git a/Doc/c-api/memory.rst b/Doc/c-api/memory.rst --- a/Doc/c-api/memory.rst +++ b/Doc/c-api/memory.rst @@ -165,15 +165,17 @@ behavior when requesting zero bytes, are available for allocating and releasing memory from the Python heap. -The default memory block allocator uses the following functions: -:c:func:`malloc`, :c:func:`calloc`, :c:func:`realloc` and :c:func:`free`; call -``malloc(1)`` (or ``calloc(1, 1)``) when requesting zero bytes. +By default, these functions use :ref:`pymalloc memory allocator `. .. warning:: The :term:`GIL ` must be held when using these functions. +.. versionchanged:: 3.6 + + The default allocator is now pymalloc instead of system :c:func:`malloc`. + .. c:function:: void* PyMem_Malloc(size_t n) Allocates *n* bytes and returns a pointer of type :c:type:`void\*` to the @@ -295,15 +297,32 @@ Enum used to identify an allocator domain. Domains: - * :c:data:`PYMEM_DOMAIN_RAW`: functions :c:func:`PyMem_RawMalloc`, - :c:func:`PyMem_RawRealloc`, :c:func:`PyMem_RawCalloc` and - :c:func:`PyMem_RawFree` - * :c:data:`PYMEM_DOMAIN_MEM`: functions :c:func:`PyMem_Malloc`, - :c:func:`PyMem_Realloc`, :c:func:`PyMem_Calloc` and :c:func:`PyMem_Free` - * :c:data:`PYMEM_DOMAIN_OBJ`: functions :c:func:`PyObject_Malloc`, - :c:func:`PyObject_Realloc`, :c:func:`PyObject_Calloc` and - :c:func:`PyObject_Free` + .. c:var:: PYMEM_DOMAIN_RAW + Functions: + + * :c:func:`PyMem_RawMalloc` + * :c:func:`PyMem_RawRealloc` + * :c:func:`PyMem_RawCalloc` + * :c:func:`PyMem_RawFree` + + .. c:var:: PYMEM_DOMAIN_MEM + + Functions: + + * :c:func:`PyMem_Malloc`, + * :c:func:`PyMem_Realloc` + * :c:func:`PyMem_Calloc` + * :c:func:`PyMem_Free` + + .. c:var:: PYMEM_DOMAIN_OBJ + + Functions: + + * :c:func:`PyObject_Malloc` + * :c:func:`PyObject_Realloc` + * :c:func:`PyObject_Calloc` + * :c:func:`PyObject_Free` .. c:function:: void PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator) @@ -328,18 +347,12 @@ .. c:function:: void PyMem_SetupDebugHooks(void) - Setup hooks to detect bugs in the following Python memory allocator - functions: - - - :c:func:`PyMem_RawMalloc`, :c:func:`PyMem_RawRealloc`, - :c:func:`PyMem_RawCalloc`, :c:func:`PyMem_RawFree` - - :c:func:`PyMem_Malloc`, :c:func:`PyMem_Realloc`, :c:func:`PyMem_Calloc`, - :c:func:`PyMem_Free` - - :c:func:`PyObject_Malloc`, :c:func:`PyObject_Realloc`, - :c:func:`PyObject_Calloc`, :c:func:`PyObject_Free` + Setup hooks to detect bugs in the Python memory allocator functions. Newly allocated memory is filled with the byte ``0xCB``, freed memory is - filled with the byte ``0xDB``. Additional checks: + filled with the byte ``0xDB``. + + Runtime checks: - Detect API violations, ex: :c:func:`PyObject_Free` called on a buffer allocated by :c:func:`PyMem_Malloc` @@ -377,8 +390,9 @@ with a fixed size of 256 KB. It falls back to :c:func:`PyMem_RawMalloc` and :c:func:`PyMem_RawRealloc` for allocations larger than 512 bytes. -*pymalloc* is the default allocator of the :c:data:`PYMEM_DOMAIN_OBJ` domain -(ex: :c:func:`PyObject_Malloc`). +*pymalloc* is the default allocator of the :c:data:`PYMEM_DOMAIN_MEM` (ex: +:c:func:`PyObject_Malloc`) and :c:data:`PYMEM_DOMAIN_OBJ` (ex: +:c:func:`PyObject_Malloc`) domains. The arena allocator uses the following functions: diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -628,12 +628,11 @@ Set the family of memory allocators used by Python: * ``malloc``: use the :c:func:`malloc` function of the C library - for all Python memory allocators (ex: :c:func:`PyMem_RawMalloc`, - :c:func:`PyMem_Malloc` and :c:func:`PyObject_Malloc`). - * ``pymalloc``: :c:func:`PyObject_Malloc`, :c:func:`PyObject_Calloc` and - :c:func:`PyObject_Realloc` use the :ref:`pymalloc allocator `. - Other Python memory allocators (ex: :c:func:`PyMem_RawMalloc` and - :c:func:`PyMem_Malloc`) use :c:func:`malloc`. + for all domains (:c:data:`PYMEM_DOMAIN_RAW`, :c:data:`PYMEM_DOMAIN_MEM`, + :c:data:`PYMEM_DOMAIN_OBJ`). + * ``pymalloc``: use the :ref:`pymalloc allocator ` for + :c:data:`PYMEM_DOMAIN_MEM` and :c:data:`PYMEM_DOMAIN_OBJ` domains and use + the :c:func:`malloc` function for the :c:data:`PYMEM_DOMAIN_RAW` domain. Install debug hooks: diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -531,5 +531,11 @@ Changes in the C API -------------------- +* :c:func:`PyMem_Malloc` allocator family now uses the :ref:`pymalloc allocator + ` rather than system :c:func:`malloc`. Applications calling + :c:func:`PyMem_Malloc` without holding the GIL can now crash. Set the + :envvar:`PYTHONMALLOC` environment variable to ``debug`` to validate the + usage of memory allocators in your application. See :issue:`26249`. + * :c:func:`Py_Exit` (and the main interpreter) now override the exit status with 120 if flushing buffered data failed. See :issue:`5319`. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,13 @@ Core and Builtins ----------------- +- Issue #26249: Memory functions of the :c:func:`PyMem_Malloc` domain + (:c:data:`PYMEM_DOMAIN_MEM`) now use the :ref:`pymalloc allocator ` + rather than system :c:func:`malloc`. Applications calling + :c:func:`PyMem_Malloc` without holding the GIL can now crash: use + ``PYTHONMALLOC=debug`` environment variable to validate the usage of memory + allocators in your application. + - Issue #26802: Optimize function calls only using unpacking like ``func(*tuple)`` (no other positional argument, no keyword): avoid copying the tuple. Patch written by Joe Jevnik. diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -198,9 +198,9 @@ static PyMemAllocatorEx _PyMem = { #ifdef Py_DEBUG - &_PyMem_Debug.mem, PYDBG_FUNCS + &_PyMem_Debug.obj, PYDBG_FUNCS #else - NULL, PYMEM_FUNCS + NULL, PYOBJ_FUNCS #endif }; @@ -256,7 +256,7 @@ PyMemAllocatorEx obj_alloc = {NULL, PYOBJ_FUNCS}; PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &mem_alloc); - PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &mem_alloc); + PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &obj_alloc); PyMem_SetAllocator(PYMEM_DOMAIN_OBJ, &obj_alloc); if (strcmp(opt, "pymalloc_debug") == 0) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 22 13:11:28 2016 From: python-checkins at python.org (victor.stinner) Date: Fri, 22 Apr 2016 17:11:28 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326249=3A_Try_test?= =?utf-8?q?=5Fcapi_on_Windows?= Message-ID: <20160422171120.53068.39429.9D43681D@psf.io> https://hg.python.org/cpython/rev/104ed24ebbd0 changeset: 101089:104ed24ebbd0 user: Victor Stinner date: Fri Apr 22 18:52:22 2016 +0200 summary: Issue #26249: Try test_capi on Windows files: Objects/obmalloc.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -166,7 +166,7 @@ #else # define PYOBJ_FUNCS PYRAW_FUNCS #endif -#define PYMEM_FUNCS PYRAW_FUNCS +#define PYMEM_FUNCS PYOBJ_FUNCS typedef struct { /* We tag each block with an API ID in order to tag API violations */ @@ -198,9 +198,9 @@ static PyMemAllocatorEx _PyMem = { #ifdef Py_DEBUG - &_PyMem_Debug.obj, PYDBG_FUNCS + &_PyMem_Debug.mem, PYDBG_FUNCS #else - NULL, PYOBJ_FUNCS + NULL, PYMEM_FUNCS #endif }; @@ -252,11 +252,12 @@ else if (strcmp(opt, "pymalloc") == 0 || strcmp(opt, "pymalloc_debug") == 0) { - PyMemAllocatorEx mem_alloc = {NULL, PYRAW_FUNCS}; + PyMemAllocatorEx raw_alloc = {NULL, PYRAW_FUNCS}; + PyMemAllocatorEx mem_alloc = {NULL, PYMEM_FUNCS}; PyMemAllocatorEx obj_alloc = {NULL, PYOBJ_FUNCS}; - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &mem_alloc); - PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &obj_alloc); + PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &raw_alloc); + PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &mem_alloc); PyMem_SetAllocator(PYMEM_DOMAIN_OBJ, &obj_alloc); if (strcmp(opt, "pymalloc_debug") == 0) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 22 14:45:58 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 22 Apr 2016 18:45:58 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Clarify_why_pathlib_doesn=27t?= =?utf-8?q?_inherit_from_str?= Message-ID: <20160422184557.8354.55020.A0C8DBED@psf.io> https://hg.python.org/peps/rev/9298dc5eeecc changeset: 6291:9298dc5eeecc user: Brett Cannon date: Fri Apr 22 11:45:53 2016 -0700 summary: Clarify why pathlib doesn't inherit from str files: pep-0428.txt | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pep-0428.txt b/pep-0428.txt --- a/pep-0428.txt +++ b/pep-0428.txt @@ -156,8 +156,16 @@ if you want a path to act as a sequence, you have to lookup a dedicated attribute (the ``parts`` attribute). -Not behaving like one of the basic builtin types also minimizes the potential -for confusion if a path is combined by accident with genuine builtin types. +The key reasoning behind not inheriting from ``str`` is to prevent confusing +any object that has a string representation -- which is all Python objects -- +with a path object. This avoids situations when people must interface with an +API that mandates a string representation for a file system path, tempting you +to use ``str(path)`` to extract the string representation of the path. This +would be a problem if ``path = None; open(str(path), 'w')``. A `blog post`_ by +a Python core developer goes into more detail on the reasons behind this +specific design decision. + +.. _blog post: http://www.snarky.ca/why-pathlib-path-doesn-t-inherit-from-str Immutability -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Fri Apr 22 19:47:37 2016 From: python-checkins at python.org (brett.cannon) Date: Fri, 22 Apr 2016 23:47:37 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_The_CLA_bot_is_done_for_the_G?= =?utf-8?q?itHub_migration?= Message-ID: <20160422234737.18809.90261.8F0B0277@psf.io> https://hg.python.org/peps/rev/f0b6dcca1908 changeset: 6292:f0b6dcca1908 user: Brett Cannon date: Fri Apr 22 16:47:32 2016 -0700 summary: The CLA bot is done for the GitHub migration files: pep-0512.txt | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pep-0512.txt b/pep-0512.txt --- a/pep-0512.txt +++ b/pep-0512.txt @@ -537,8 +537,6 @@ * In progress - - `A bot to enforce CLA signing`_: - https://github.com/python/the-knights-who-say-ni (Brett Cannon) - `Define commands to move a Mercurial repository to Git`_: https://github.com/orsenthil/cpython-hg-to-git (Senthil Kumaran) @@ -546,6 +544,8 @@ - `Adding GitHub username support to bugs.python.org`_ (Maciej Szulik and Ezio Melotti) + - `A bot to enforce CLA signing`_: + https://github.com/python/the-knights-who-say-ni (Brett Cannon) Repositories whose build steps need updating: -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Fri Apr 22 21:51:31 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 23 Apr 2016 01:51:31 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzIyMzU5?= =?utf-8?q?=3A_Disable_running_cross-compiled_=5Ffreeze=5Fimportlib_and_pg?= =?utf-8?q?en?= Message-ID: <20160423015131.15830.27982.E324D06C@psf.io> https://hg.python.org/cpython/rev/66e40df31fac changeset: 101090:66e40df31fac branch: 3.5 parent: 101085:a246047734b3 user: Martin Panter date: Sat Apr 23 00:58:44 2016 +0000 summary: Issue #22359: Disable running cross-compiled _freeze_importlib and pgen Patch by Xavier de Gaye. files: Makefile.pre.in | 27 ++++++++++++++++++++------- Misc/NEWS | 5 +++++ configure | 1 + configure.ac | 1 + 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -221,6 +221,7 @@ PYTHON= python$(EXE) BUILDPYTHON= python$(BUILDEXE) +cross_compiling=@cross_compiling@ PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@ _PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@ BUILD_GNU_TYPE= @build@ @@ -718,12 +719,16 @@ $(LINKCC) $(PY_LDFLAGS) -o $@ Programs/_freeze_importlib.o $(LIBRARY_OBJS_OMIT_FROZEN) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) Python/importlib_external.h: $(srcdir)/Lib/importlib/_bootstrap_external.py Programs/_freeze_importlib - ./Programs/_freeze_importlib \ - $(srcdir)/Lib/importlib/_bootstrap_external.py Python/importlib_external.h + if test "$(cross_compiling)" != "yes"; then \ + ./Programs/_freeze_importlib \ + $(srcdir)/Lib/importlib/_bootstrap_external.py Python/importlib_external.h; \ + fi Python/importlib.h: $(srcdir)/Lib/importlib/_bootstrap.py Programs/_freeze_importlib - ./Programs/_freeze_importlib \ - $(srcdir)/Lib/importlib/_bootstrap.py Python/importlib.h + if test "$(cross_compiling)" != "yes"; then \ + ./Programs/_freeze_importlib \ + $(srcdir)/Lib/importlib/_bootstrap.py Python/importlib.h; \ + fi ############################################################################ @@ -784,10 +789,18 @@ $(IO_OBJS): $(IO_H) $(GRAMMAR_H): $(GRAMMAR_INPUT) $(PGEN) - @$(MKDIR_P) Include - $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C) + @$(MKDIR_P) Include + if test "$(cross_compiling)" != "yes"; then \ + $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C); \ + else \ + cp $(srcdir)/Include/graminit.h $(GRAMMAR_H); \ + fi $(GRAMMAR_C): $(GRAMMAR_H) - touch $(GRAMMAR_C) + if test "$(cross_compiling)" != "yes"; then \ + touch $(GRAMMAR_C); \ + else \ + cp $(srcdir)/Python/graminit.c $(GRAMMAR_C); \ + fi $(PGEN): $(PGENOBJS) $(CC) $(OPT) $(PY_LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -404,6 +404,11 @@ Build ----- +- Issue #22359: Disable the rules for running _freeze_importlib and pgen when + cross-compiling. The output of these programs is normally saved with the + source code anyway, and is still regenerated when doing a native build. + Patch by Xavier de Gaye. + - Issue #21668: Link audioop, _datetime, _ctypes_test modules to libm, except on Mac OS X. Patch written by Xavier de Gaye. diff --git a/configure b/configure --- a/configure +++ b/configure @@ -751,6 +751,7 @@ build_vendor build_cpu build +cross_compiling HAS_HG HGBRANCH HGTAG diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -49,6 +49,7 @@ AC_CONFIG_SRCDIR([Include/object.h]) AC_CONFIG_HEADER(pyconfig.h) +AC_SUBST(cross_compiling) AC_CANONICAL_HOST AC_SUBST(build) AC_SUBST(host) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 22 21:51:32 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 23 Apr 2016 01:51:32 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzIyMzU5?= =?utf-8?q?=3A_Avoid_recursive_=24=28MAKE=29=3B_disable_running_cross-comp?= =?utf-8?q?iled_pgen?= Message-ID: <20160423015132.26199.15882.B71BF46D@psf.io> https://hg.python.org/cpython/rev/0f7a299c6d50 changeset: 101092:0f7a299c6d50 branch: 2.7 parent: 101082:e4561aad29e6 user: Martin Panter date: Sat Apr 23 00:58:44 2016 +0000 summary: Issue #22359: Avoid recursive $(MAKE); disable running cross-compiled pgen Patches by Jonas Wagner and Xavier de Gaye. files: Makefile.pre.in | 21 ++++++++++++++------- Misc/NEWS | 5 +++++ configure | 1 + configure.ac | 1 + 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -200,6 +200,7 @@ PYTHON= python$(EXE) BUILDPYTHON= python$(BUILDEXE) +cross_compiling=@cross_compiling@ PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@ _PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@ HOST_GNU_TYPE= @host@ @@ -677,13 +678,19 @@ Modules/pwdmodule.o: $(srcdir)/Modules/pwdmodule.c $(srcdir)/Modules/posixmodule.h -$(GRAMMAR_H): $(GRAMMAR_INPUT) $(PGENSRCS) - @$(MKDIR_P) Include - $(MAKE) $(PGEN) - $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C) -$(GRAMMAR_C): $(GRAMMAR_H) $(GRAMMAR_INPUT) $(PGENSRCS) - $(MAKE) $(GRAMMAR_H) - touch $(GRAMMAR_C) +$(GRAMMAR_H): $(GRAMMAR_INPUT) $(PGEN) + @$(MKDIR_P) Include + if test "$(cross_compiling)" != "yes"; then \ + $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C); \ + else \ + cp $(srcdir)/Include/graminit.h $(GRAMMAR_H); \ + fi +$(GRAMMAR_C): $(GRAMMAR_H) + if test "$(cross_compiling)" != "yes"; then \ + touch $(GRAMMAR_C); \ + else \ + cp $(srcdir)/Python/graminit.c $(GRAMMAR_C); \ + fi $(PGEN): $(PGENOBJS) $(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -225,6 +225,11 @@ Build ----- +- Issue #22359: Avoid incorrect recursive $(MAKE), and disable the rules for + running pgen when cross-compiling. The pgen output is normally saved with + the source code anyway, and is still regenerated when doing a native build. + Patch by Jonas Wagner and Xavier de Gaye. + - Issue #19450: Update Windows builds to use SQLite 3.8.11.0. - Issue #17603: Avoid error about nonexistant fileblocks.o file by using a diff --git a/configure b/configure --- a/configure +++ b/configure @@ -743,6 +743,7 @@ build_vendor build_cpu build +cross_compiling target_alias host_alias build_alias diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -12,6 +12,7 @@ AC_CONFIG_SRCDIR([Include/object.h]) AC_CONFIG_HEADER(pyconfig.h) +AC_SUBST(cross_compiling) AC_CANONICAL_HOST AC_SUBST(build) AC_SUBST(host) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 22 21:51:42 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 23 Apr 2016 01:51:42 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2322359=3A_Merge_cross-compilation_fix_from_3=2E5?= Message-ID: <20160423015131.103093.72955.0E3865E2@psf.io> https://hg.python.org/cpython/rev/c36b9ef8ff39 changeset: 101091:c36b9ef8ff39 parent: 101089:104ed24ebbd0 parent: 101090:66e40df31fac user: Martin Panter date: Sat Apr 23 01:18:54 2016 +0000 summary: Issue #22359: Merge cross-compilation fix from 3.5 files: Makefile.pre.in | 27 ++++++++++++++++++++------- Misc/NEWS | 5 +++++ configure | 1 + configure.ac | 1 + 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -221,6 +221,7 @@ PYTHON= python$(EXE) BUILDPYTHON= python$(BUILDEXE) +cross_compiling=@cross_compiling@ PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@ _PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@ BUILD_GNU_TYPE= @build@ @@ -718,12 +719,16 @@ $(LINKCC) $(PY_LDFLAGS) -o $@ Programs/_freeze_importlib.o $(LIBRARY_OBJS_OMIT_FROZEN) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) Python/importlib_external.h: $(srcdir)/Lib/importlib/_bootstrap_external.py Programs/_freeze_importlib - ./Programs/_freeze_importlib \ - $(srcdir)/Lib/importlib/_bootstrap_external.py Python/importlib_external.h + if test "$(cross_compiling)" != "yes"; then \ + ./Programs/_freeze_importlib \ + $(srcdir)/Lib/importlib/_bootstrap_external.py Python/importlib_external.h; \ + fi Python/importlib.h: $(srcdir)/Lib/importlib/_bootstrap.py Programs/_freeze_importlib - ./Programs/_freeze_importlib \ - $(srcdir)/Lib/importlib/_bootstrap.py Python/importlib.h + if test "$(cross_compiling)" != "yes"; then \ + ./Programs/_freeze_importlib \ + $(srcdir)/Lib/importlib/_bootstrap.py Python/importlib.h; \ + fi ############################################################################ @@ -784,10 +789,18 @@ $(IO_OBJS): $(IO_H) $(GRAMMAR_H): $(GRAMMAR_INPUT) $(PGEN) - @$(MKDIR_P) Include - $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C) + @$(MKDIR_P) Include + if test "$(cross_compiling)" != "yes"; then \ + $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C); \ + else \ + cp $(srcdir)/Include/graminit.h $(GRAMMAR_H); \ + fi $(GRAMMAR_C): $(GRAMMAR_H) - touch $(GRAMMAR_C) + if test "$(cross_compiling)" != "yes"; then \ + touch $(GRAMMAR_C); \ + else \ + cp $(srcdir)/Python/graminit.c $(GRAMMAR_C); \ + fi $(PGEN): $(PGENOBJS) $(CC) $(OPT) $(PY_LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -1005,6 +1005,11 @@ Build ----- +- Issue #22359: Disable the rules for running _freeze_importlib and pgen when + cross-compiling. The output of these programs is normally saved with the + source code anyway, and is still regenerated when doing a native build. + Patch by Xavier de Gaye. + - Issue #21668: Link audioop, _datetime, _ctypes_test modules to libm, except on Mac OS X. Patch written by Chi Hsuan Yen. diff --git a/configure b/configure --- a/configure +++ b/configure @@ -751,6 +751,7 @@ build_vendor build_cpu build +cross_compiling HAS_HG HGBRANCH HGTAG diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -49,6 +49,7 @@ AC_CONFIG_SRCDIR([Include/object.h]) AC_CONFIG_HEADER(pyconfig.h) +AC_SUBST(cross_compiling) AC_CANONICAL_HOST AC_SUBST(build) AC_SUBST(host) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 22 23:35:46 2016 From: python-checkins at python.org (senthil.kumaran) Date: Sat, 23 Apr 2016 03:35:46 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Issue23806_-_D?= =?utf-8?q?ocument_the_no=5Fproxy_environment_variable_in_Python_3_docs=2E?= Message-ID: <20160423033546.395.77130.D87D5518@psf.io> https://hg.python.org/cpython/rev/5424a559ddea changeset: 101093:5424a559ddea branch: 3.5 parent: 101090:66e40df31fac user: Senthil Kumaran date: Fri Apr 22 20:34:42 2016 -0700 summary: Issue23806 - Document the no_proxy environment variable in Python 3 docs. files: Doc/library/urllib.request.rst | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -269,6 +269,11 @@ To disable autodetected proxy pass an empty dictionary. + The :envvar:`no_proxy` environment variable can be used to specify hosts + which shouldn't be reached via proxy; if set, it should be a comma-separated + list of hostname suffixes, optionally with ``:port`` appended, for example + ``cern.ch,ncsa.uiuc.edu,some.host:8080``. + .. class:: HTTPPasswordMgr() -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 22 23:35:47 2016 From: python-checkins at python.org (senthil.kumaran) Date: Sat, 23 Apr 2016 03:35:47 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy41?= Message-ID: <20160423033546.103093.10078.F106139A@psf.io> https://hg.python.org/cpython/rev/103fb8be940b changeset: 101094:103fb8be940b parent: 101091:c36b9ef8ff39 parent: 101093:5424a559ddea user: Senthil Kumaran date: Fri Apr 22 20:35:40 2016 -0700 summary: merge 3.5 Document no_proxy environment variable in python 3.x #issue23806 files: Doc/library/urllib.request.rst | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -269,6 +269,11 @@ To disable autodetected proxy pass an empty dictionary. + The :envvar:`no_proxy` environment variable can be used to specify hosts + which shouldn't be reached via proxy; if set, it should be a comma-separated + list of hostname suffixes, optionally with ``:port`` appended, for example + ``cern.ch,ncsa.uiuc.edu,some.host:8080``. + .. class:: HTTPPasswordMgr() -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 02:24:49 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 23 Apr 2016 06:24:49 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326733=3A_Disassembling_a_class_now_disassembles?= =?utf-8?q?_class_and_static_methods=2E?= Message-ID: <20160423062449.21456.43441.80D96C1A@psf.io> https://hg.python.org/cpython/rev/f96fec10cf25 changeset: 101096:f96fec10cf25 parent: 101094:103fb8be940b parent: 101095:d14ea3964590 user: Serhiy Storchaka date: Sat Apr 23 09:24:29 2016 +0300 summary: Issue #26733: Disassembling a class now disassembles class and static methods. Patch by Xiang Zhang. files: Doc/library/dis.rst | 10 +++--- Lib/dis.py | 3 +- Lib/test/test_dis.py | 52 ++++++++++++++++++++++++++++++- Misc/NEWS | 3 + 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -139,11 +139,11 @@ Disassemble the *x* object. *x* can denote either a module, a class, a method, a function, a generator, a code object, a string of source code or a byte sequence of raw bytecode. For a module, it disassembles all functions. - For a class, it disassembles all methods. For a code object or sequence of - raw bytecode, it prints one line per bytecode instruction. Strings are first - compiled to code objects with the :func:`compile` built-in function before being - disassembled. If no object is provided, this function disassembles the last - traceback. + For a class, it disassembles all methods (including class and static methods). + For a code object or sequence of raw bytecode, it prints one line per bytecode + instruction. Strings are first compiled to code objects with the :func:`compile` + built-in function before being disassembled. If no object is provided, this + function disassembles the last traceback. The disassembly is written as text to the supplied *file* argument if provided and to ``sys.stdout`` otherwise. diff --git a/Lib/dis.py b/Lib/dis.py --- a/Lib/dis.py +++ b/Lib/dis.py @@ -13,7 +13,8 @@ "get_instructions", "Instruction", "Bytecode"] + _opcodes_all del _opcodes_all -_have_code = (types.MethodType, types.FunctionType, types.CodeType, type) +_have_code = (types.MethodType, types.FunctionType, types.CodeType, + classmethod, staticmethod, type) def _try_compile(source, name): """Attempts to compile the given source, first as an expression and diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -30,6 +30,14 @@ def __init__(self, x): self.x = x == 1 + @staticmethod + def sm(x): + x = x == 1 + + @classmethod + def cm(cls, x): + cls.x = x == 1 + dis_c_instance_method = """\ %3d 0 LOAD_FAST 1 (x) 3 LOAD_CONST 1 (1) @@ -50,6 +58,37 @@ 18 RETURN_VALUE """ +dis_c_class_method = """\ +%3d 0 LOAD_FAST 1 (x) + 3 LOAD_CONST 1 (1) + 6 COMPARE_OP 2 (==) + 9 LOAD_FAST 0 (cls) + 12 STORE_ATTR 0 (x) + 15 LOAD_CONST 0 (None) + 18 RETURN_VALUE +""" % (_C.cm.__code__.co_firstlineno + 2,) + +dis_c_static_method = """\ +%3d 0 LOAD_FAST 0 (x) + 3 LOAD_CONST 1 (1) + 6 COMPARE_OP 2 (==) + 9 STORE_FAST 0 (x) + 12 LOAD_CONST 0 (None) + 15 RETURN_VALUE +""" % (_C.sm.__code__.co_firstlineno + 2,) + +# Class disassembling info has an extra newline at end. +dis_c = """\ +Disassembly of %s: +%s +Disassembly of %s: +%s +Disassembly of %s: +%s +""" % (_C.__init__.__name__, dis_c_instance_method, + _C.cm.__name__, dis_c_class_method, + _C.sm.__name__, dis_c_static_method) + def _f(a): print(a) return 1 @@ -311,13 +350,22 @@ def test_disassemble_bytes(self): self.do_disassembly_test(_f.__code__.co_code, dis_f_co_code) - def test_disassemble_method(self): + def test_disassemble_class(self): + self.do_disassembly_test(_C, dis_c) + + def test_disassemble_instance_method(self): self.do_disassembly_test(_C(1).__init__, dis_c_instance_method) - def test_disassemble_method_bytes(self): + def test_disassemble_instance_method_bytes(self): method_bytecode = _C(1).__init__.__code__.co_code self.do_disassembly_test(method_bytecode, dis_c_instance_method_bytes) + def test_disassemble_static_method(self): + self.do_disassembly_test(_C.sm, dis_c_static_method) + + def test_disassemble_class_method(self): + self.do_disassembly_test(_C.cm, dis_c_class_method) + def test_disassemble_generator(self): gen_func_disas = self.get_disassembly(_g) # Disassemble generator function gen_disas = self.get_disassembly(_g(1)) # Disassemble generator itself diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -256,6 +256,9 @@ Library ------- +- Issue #26733: Disassembling a class now disassembles class and static methods. + Patch by Xiang Zhang. + - Issue #26801: Fix error handling in :func:`shutil.get_terminal_size`, catch :exc:`AttributeError` instead of :exc:`NameError`. Patch written by Emanuel Barry. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 02:24:54 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 23 Apr 2016 06:24:54 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NzMz?= =?utf-8?q?=3A_Disassembling_a_class_now_disassembles_class_and_static_met?= =?utf-8?q?hods=2E?= Message-ID: <20160423062449.27120.34550.A08E52FB@psf.io> https://hg.python.org/cpython/rev/d14ea3964590 changeset: 101095:d14ea3964590 branch: 3.5 parent: 101093:5424a559ddea user: Serhiy Storchaka date: Sat Apr 23 09:23:52 2016 +0300 summary: Issue #26733: Disassembling a class now disassembles class and static methods. Patch by Xiang Zhang. files: Doc/library/dis.rst | 10 +++--- Lib/dis.py | 3 +- Lib/test/test_dis.py | 52 ++++++++++++++++++++++++++++++- Misc/NEWS | 3 + 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -139,11 +139,11 @@ Disassemble the *x* object. *x* can denote either a module, a class, a method, a function, a generator, a code object, a string of source code or a byte sequence of raw bytecode. For a module, it disassembles all functions. - For a class, it disassembles all methods. For a code object or sequence of - raw bytecode, it prints one line per bytecode instruction. Strings are first - compiled to code objects with the :func:`compile` built-in function before being - disassembled. If no object is provided, this function disassembles the last - traceback. + For a class, it disassembles all methods (including class and static methods). + For a code object or sequence of raw bytecode, it prints one line per bytecode + instruction. Strings are first compiled to code objects with the :func:`compile` + built-in function before being disassembled. If no object is provided, this + function disassembles the last traceback. The disassembly is written as text to the supplied *file* argument if provided and to ``sys.stdout`` otherwise. diff --git a/Lib/dis.py b/Lib/dis.py --- a/Lib/dis.py +++ b/Lib/dis.py @@ -13,7 +13,8 @@ "get_instructions", "Instruction", "Bytecode"] + _opcodes_all del _opcodes_all -_have_code = (types.MethodType, types.FunctionType, types.CodeType, type) +_have_code = (types.MethodType, types.FunctionType, types.CodeType, + classmethod, staticmethod, type) def _try_compile(source, name): """Attempts to compile the given source, first as an expression and diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -30,6 +30,14 @@ def __init__(self, x): self.x = x == 1 + @staticmethod + def sm(x): + x = x == 1 + + @classmethod + def cm(cls, x): + cls.x = x == 1 + dis_c_instance_method = """\ %3d 0 LOAD_FAST 1 (x) 3 LOAD_CONST 1 (1) @@ -50,6 +58,37 @@ 18 RETURN_VALUE """ +dis_c_class_method = """\ +%3d 0 LOAD_FAST 1 (x) + 3 LOAD_CONST 1 (1) + 6 COMPARE_OP 2 (==) + 9 LOAD_FAST 0 (cls) + 12 STORE_ATTR 0 (x) + 15 LOAD_CONST 0 (None) + 18 RETURN_VALUE +""" % (_C.cm.__code__.co_firstlineno + 2,) + +dis_c_static_method = """\ +%3d 0 LOAD_FAST 0 (x) + 3 LOAD_CONST 1 (1) + 6 COMPARE_OP 2 (==) + 9 STORE_FAST 0 (x) + 12 LOAD_CONST 0 (None) + 15 RETURN_VALUE +""" % (_C.sm.__code__.co_firstlineno + 2,) + +# Class disassembling info has an extra newline at end. +dis_c = """\ +Disassembly of %s: +%s +Disassembly of %s: +%s +Disassembly of %s: +%s +""" % (_C.__init__.__name__, dis_c_instance_method, + _C.cm.__name__, dis_c_class_method, + _C.sm.__name__, dis_c_static_method) + def _f(a): print(a) return 1 @@ -311,13 +350,22 @@ def test_disassemble_bytes(self): self.do_disassembly_test(_f.__code__.co_code, dis_f_co_code) - def test_disassemble_method(self): + def test_disassemble_class(self): + self.do_disassembly_test(_C, dis_c) + + def test_disassemble_instance_method(self): self.do_disassembly_test(_C(1).__init__, dis_c_instance_method) - def test_disassemble_method_bytes(self): + def test_disassemble_instance_method_bytes(self): method_bytecode = _C(1).__init__.__code__.co_code self.do_disassembly_test(method_bytecode, dis_c_instance_method_bytes) + def test_disassemble_static_method(self): + self.do_disassembly_test(_C.sm, dis_c_static_method) + + def test_disassemble_class_method(self): + self.do_disassembly_test(_C.cm, dis_c_class_method) + def test_disassemble_generator(self): gen_func_disas = self.get_disassembly(_g) # Disassemble generator function gen_disas = self.get_disassembly(_g(1)) # Disassemble generator itself diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,9 @@ Library ------- +- Issue #26733: Disassembling a class now disassembles class and static methods. + Patch by Xiang Zhang. + - Issue #26801: Fix error handling in :func:`shutil.get_terminal_size`, catch :exc:`AttributeError` instead of :exc:`NameError`. Patch written by Emanuel Barry. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 02:43:29 2016 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 23 Apr 2016 06:43:29 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_fix_python_3_m?= =?utf-8?q?od_init_function_declaration_=28closes_=2326827=29?= Message-ID: <20160423064329.4122.8266.B433D542@psf.io> https://hg.python.org/cpython/rev/188af2b4945a changeset: 101097:188af2b4945a branch: 3.5 parent: 101095:d14ea3964590 user: Benjamin Peterson date: Fri Apr 22 23:43:10 2016 -0700 summary: fix python 3 mod init function declaration (closes #26827) files: Doc/howto/cporting.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/howto/cporting.rst b/Doc/howto/cporting.rst --- a/Doc/howto/cporting.rst +++ b/Doc/howto/cporting.rst @@ -161,7 +161,7 @@ #define INITERROR return NULL - PyObject * + PyMODINIT_FUNC PyInit_myextension(void) #else -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 02:43:34 2016 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 23 Apr 2016 06:43:34 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy41ICgjMjY4Mjcp?= Message-ID: <20160423064334.21448.15.D78572D2@psf.io> https://hg.python.org/cpython/rev/df0e900b8860 changeset: 101098:df0e900b8860 parent: 101096:f96fec10cf25 parent: 101097:188af2b4945a user: Benjamin Peterson date: Fri Apr 22 23:43:24 2016 -0700 summary: merge 3.5 (#26827) files: Doc/howto/cporting.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/howto/cporting.rst b/Doc/howto/cporting.rst --- a/Doc/howto/cporting.rst +++ b/Doc/howto/cporting.rst @@ -161,7 +161,7 @@ #define INITERROR return NULL - PyObject * + PyMODINIT_FUNC PyInit_myextension(void) #else -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 02:49:19 2016 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 23 Apr 2016 06:49:19 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_fix_python_3_m?= =?utf-8?q?od_init_function_declaration_=28closes_=2326827=29?= Message-ID: <20160423064919.5060.80263.9D0BD23B@psf.io> https://hg.python.org/cpython/rev/8d6bd32a56a8 changeset: 101099:8d6bd32a56a8 branch: 2.7 parent: 101092:0f7a299c6d50 user: Benjamin Peterson date: Fri Apr 22 23:43:10 2016 -0700 summary: fix python 3 mod init function declaration (closes #26827) files: Doc/howto/cporting.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/howto/cporting.rst b/Doc/howto/cporting.rst --- a/Doc/howto/cporting.rst +++ b/Doc/howto/cporting.rst @@ -161,7 +161,7 @@ #define INITERROR return NULL - PyObject * + PyMODINIT_FUNC PyInit_myextension(void) #else -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 03:54:05 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 23 Apr 2016 07:54:05 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326822=3A_itemgetter=2C_attrgetter_and_methodcal?= =?utf-8?q?ler_objects_no_longer?= Message-ID: <20160423075405.21472.17606.6E747D94@psf.io> https://hg.python.org/cpython/rev/5faccb403ad8 changeset: 101102:5faccb403ad8 parent: 101098:df0e900b8860 parent: 101100:16461a0016bf user: Serhiy Storchaka date: Sat Apr 23 10:53:43 2016 +0300 summary: Issue #26822: itemgetter, attrgetter and methodcaller objects no longer silently ignore keyword arguments. files: Lib/test/test_operator.py | 9 +++++++++ Misc/NEWS | 3 +++ Modules/_operator.c | 6 ++++++ 3 files changed, 18 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -318,6 +318,9 @@ a.name = 'arthur' f = operator.attrgetter('name') self.assertEqual(f(a), 'arthur') + self.assertRaises(TypeError, f) + self.assertRaises(TypeError, f, a, 'dent') + self.assertRaises(TypeError, f, a, surname='dent') f = operator.attrgetter('rank') self.assertRaises(AttributeError, f, a) self.assertRaises(TypeError, operator.attrgetter, 2) @@ -365,6 +368,9 @@ a = 'ABCDE' f = operator.itemgetter(2) self.assertEqual(f(a), 'C') + self.assertRaises(TypeError, f) + self.assertRaises(TypeError, f, a, 3) + self.assertRaises(TypeError, f, a, size=3) f = operator.itemgetter(10) self.assertRaises(IndexError, f, a) @@ -411,6 +417,9 @@ self.assertRaises(IndexError, f, a) f = operator.methodcaller('foo', 1, 2) self.assertEqual(f(a), 3) + self.assertRaises(TypeError, f) + self.assertRaises(TypeError, f, a, 3) + self.assertRaises(TypeError, f, a, spam=3) f = operator.methodcaller('bar') self.assertEqual(f(a), 42) self.assertRaises(TypeError, f, a, a) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -256,6 +256,9 @@ Library ------- +- Issue #26822: itemgetter, attrgetter and methodcaller objects no longer + silently ignore keyword arguments. + - Issue #26733: Disassembling a class now disassembles class and static methods. Patch by Xiang Zhang. diff --git a/Modules/_operator.c b/Modules/_operator.c --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -460,6 +460,8 @@ PyObject *obj, *result; Py_ssize_t i, nitems=ig->nitems; + if (!_PyArg_NoKeywords("itemgetter", kw)) + return NULL; if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj)) return NULL; if (nitems == 1) @@ -747,6 +749,8 @@ PyObject *obj, *result; Py_ssize_t i, nattrs=ag->nattrs; + if (!_PyArg_NoKeywords("attrgetter", kw)) + return NULL; if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj)) return NULL; if (ag->nattrs == 1) /* ag->attr is always a tuple */ @@ -988,6 +992,8 @@ { PyObject *method, *obj, *result; + if (!_PyArg_NoKeywords("methodcaller", kw)) + return NULL; if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj)) return NULL; method = PyObject_GetAttr(obj, mc->name); -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 03:54:06 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 23 Apr 2016 07:54:06 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2ODIy?= =?utf-8?q?=3A_itemgetter=2C_attrgetter_and_methodcaller_objects_no_longer?= Message-ID: <20160423075404.111110.93041.792869F3@psf.io> https://hg.python.org/cpython/rev/16461a0016bf changeset: 101100:16461a0016bf branch: 3.5 parent: 101097:188af2b4945a user: Serhiy Storchaka date: Sat Apr 23 10:51:39 2016 +0300 summary: Issue #26822: itemgetter, attrgetter and methodcaller objects no longer silently ignore keyword arguments. files: Lib/test/test_operator.py | 9 +++++++++ Misc/NEWS | 3 +++ Modules/_operator.c | 6 ++++++ 3 files changed, 18 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -318,6 +318,9 @@ a.name = 'arthur' f = operator.attrgetter('name') self.assertEqual(f(a), 'arthur') + self.assertRaises(TypeError, f) + self.assertRaises(TypeError, f, a, 'dent') + self.assertRaises(TypeError, f, a, surname='dent') f = operator.attrgetter('rank') self.assertRaises(AttributeError, f, a) self.assertRaises(TypeError, operator.attrgetter, 2) @@ -365,6 +368,9 @@ a = 'ABCDE' f = operator.itemgetter(2) self.assertEqual(f(a), 'C') + self.assertRaises(TypeError, f) + self.assertRaises(TypeError, f, a, 3) + self.assertRaises(TypeError, f, a, size=3) f = operator.itemgetter(10) self.assertRaises(IndexError, f, a) @@ -411,6 +417,9 @@ self.assertRaises(IndexError, f, a) f = operator.methodcaller('foo', 1, 2) self.assertEqual(f(a), 3) + self.assertRaises(TypeError, f) + self.assertRaises(TypeError, f, a, 3) + self.assertRaises(TypeError, f, a, spam=3) f = operator.methodcaller('bar') self.assertEqual(f(a), 42) self.assertRaises(TypeError, f, a, a) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,9 @@ Library ------- +- Issue #26822: itemgetter, attrgetter and methodcaller objects no longer + silently ignore keyword arguments. + - Issue #26733: Disassembling a class now disassembles class and static methods. Patch by Xiang Zhang. diff --git a/Modules/_operator.c b/Modules/_operator.c --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -460,6 +460,8 @@ PyObject *obj, *result; Py_ssize_t i, nitems=ig->nitems; + if (!_PyArg_NoKeywords("itemgetter", kw)) + return NULL; if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj)) return NULL; if (nitems == 1) @@ -747,6 +749,8 @@ PyObject *obj, *result; Py_ssize_t i, nattrs=ag->nattrs; + if (!_PyArg_NoKeywords("attrgetter", kw)) + return NULL; if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj)) return NULL; if (ag->nattrs == 1) /* ag->attr is always a tuple */ @@ -988,6 +992,8 @@ { PyObject *method, *obj, *result; + if (!_PyArg_NoKeywords("methodcaller", kw)) + return NULL; if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj)) return NULL; method = PyObject_GetAttr(obj, mc->name); -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 03:54:06 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 23 Apr 2016 07:54:06 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2ODIy?= =?utf-8?q?=3A_itemgetter=2C_attrgetter_and_methodcaller_objects_no_longer?= Message-ID: <20160423075405.6232.53768.64EB9BF8@psf.io> https://hg.python.org/cpython/rev/9b565815079a changeset: 101101:9b565815079a branch: 2.7 parent: 101099:8d6bd32a56a8 user: Serhiy Storchaka date: Sat Apr 23 10:53:28 2016 +0300 summary: Issue #26822: itemgetter, attrgetter and methodcaller objects no longer silently ignore keyword arguments. files: Lib/test/test_operator.py | 9 +++++++++ Misc/NEWS | 3 +++ Modules/operator.c | 6 ++++++ 3 files changed, 18 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -371,6 +371,9 @@ a.name = 'arthur' f = operator.attrgetter('name') self.assertEqual(f(a), 'arthur') + self.assertRaises(TypeError, f) + self.assertRaises(TypeError, f, a, 'dent') + self.assertRaises(TypeError, f, a, surname='dent') f = operator.attrgetter('rank') self.assertRaises(AttributeError, f, a) f = operator.attrgetter(2) @@ -414,6 +417,9 @@ a = 'ABCDE' f = operator.itemgetter(2) self.assertEqual(f(a), 'C') + self.assertRaises(TypeError, f) + self.assertRaises(TypeError, f, a, 3) + self.assertRaises(TypeError, f, a, size=3) f = operator.itemgetter(10) self.assertRaises(IndexError, f, a) @@ -456,6 +462,9 @@ self.assertRaises(IndexError, f, a) f = operator.methodcaller('foo', 1, 2) self.assertEqual(f(a), 3) + self.assertRaises(TypeError, f) + self.assertRaises(TypeError, f, a, 3) + self.assertRaises(TypeError, f, a, spam=3) f = operator.methodcaller('bar') self.assertEqual(f(a), 42) self.assertRaises(TypeError, f, a, a) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,9 @@ Library ------- +- Issue #26822: itemgetter, attrgetter and methodcaller objects no longer + silently ignore keyword arguments. + - Issue #26657: Fix directory traversal vulnerability with SimpleHTTPServer on Windows. This fixes a regression that was introduced in 2.7.7. Based on patch by Philipp Hagemeister. diff --git a/Modules/operator.c b/Modules/operator.c --- a/Modules/operator.c +++ b/Modules/operator.c @@ -511,6 +511,8 @@ PyObject *obj, *result; Py_ssize_t i, nitems=ig->nitems; + if (!_PyArg_NoKeywords("itemgetter", kw)) + return NULL; if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj)) return NULL; if (nitems == 1) @@ -691,6 +693,8 @@ PyObject *obj, *result; Py_ssize_t i, nattrs=ag->nattrs; + if (!_PyArg_NoKeywords("attrgetter", kw)) + return NULL; if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj)) return NULL; if (ag->nattrs == 1) @@ -838,6 +842,8 @@ { PyObject *method, *obj, *result; + if (!_PyArg_NoKeywords("methodcaller", kw)) + return NULL; if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj)) return NULL; method = PyObject_GetAttr(obj, mc->name); -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Sat Apr 23 06:11:00 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 23 Apr 2016 10:11:00 +0000 Subject: [Python-checkins] Daily reference leaks (103fb8be940b): sum=29 Message-ID: <20160423101100.4120.49113.45C4B379@psf.io> results for 103fb8be940b on branch "default" -------------------------------------------- test_asyncio leaked [0, 0, 3] memory blocks, sum=3 test_collections leaked [0, 0, 4] memory blocks, sum=4 test_format leaked [6, 6, 6] memory blocks, sum=18 test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogwXW_jo', '--timeout', '7200'] From ethan at stoneleaf.us Fri Apr 22 14:54:32 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 22 Apr 2016 11:54:32 -0700 Subject: [Python-checkins] peps: Clarify why pathlib doesn't inherit from str In-Reply-To: <20160422184557.8354.55020.A0C8DBED@psf.io> References: <20160422184557.8354.55020.A0C8DBED@psf.io> Message-ID: <571A7368.4030102@stoneleaf.us> On 04/22/2016 11:45 AM, brett.cannon wrote: > +The key reasoning behind not inheriting from ``str`` is to prevent confusing > +any object that has a string representation -- which is all Python objects -- > +with a path object. That doesn't make sense. isinstance(Path('/home/ethan/.profile'), str) is orthogonal to str({a:1, b:2}). Preventing confusion with any object is why were discussing a new protocol. -- ~Ethan~ From python-checkins at python.org Sat Apr 23 12:15:11 2016 From: python-checkins at python.org (brett.cannon) Date: Sat, 23 Apr 2016 16:15:11 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Tweak_the_reasoning_for_pathl?= =?utf-8?q?ib_not_sublcassing_str=2E?= Message-ID: <20160423160431.96014.57727.114EAB9B@psf.io> https://hg.python.org/peps/rev/b79086c6626f changeset: 6293:b79086c6626f user: Brett Cannon date: Sat Apr 23 09:04:27 2016 -0700 summary: Tweak the reasoning for pathlib not sublcassing str. files: pep-0428.txt | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pep-0428.txt b/pep-0428.txt --- a/pep-0428.txt +++ b/pep-0428.txt @@ -156,14 +156,13 @@ if you want a path to act as a sequence, you have to lookup a dedicated attribute (the ``parts`` attribute). -The key reasoning behind not inheriting from ``str`` is to prevent confusing -any object that has a string representation -- which is all Python objects -- -with a path object. This avoids situations when people must interface with an -API that mandates a string representation for a file system path, tempting you -to use ``str(path)`` to extract the string representation of the path. This -would be a problem if ``path = None; open(str(path), 'w')``. A `blog post`_ by -a Python core developer goes into more detail on the reasons behind this -specific design decision. +The key reasoning behind not inheriting from ``str`` is to prevent accidentally +performing operations with a string representing a path and a string that +doesn't, e.g. ``path + an_accident``. Since operations with a string will not +necessarily lead to a valid or expected file system path, "explicit is better +than implicit" by avoiding accidental operations with strings by not +subclassing it. A `blog post`_ by a Python core developer goes into more detail +on the reasons behind this specific design decision. .. _blog post: http://www.snarky.ca/why-pathlib-path-doesn-t-inherit-from-str -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Sat Apr 23 18:51:19 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 23 Apr 2016 22:51:19 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzIwMTEy?= =?utf-8?q?=3A_Improve_BaseHTTPRequestHandler=2Eerror=5Fmessage=5Fformat_d?= =?utf-8?q?ocumentation?= Message-ID: <20160423225118.21456.91509.1A2497EC@psf.io> https://hg.python.org/cpython/rev/a912ca4f507b changeset: 101103:a912ca4f507b branch: 3.5 parent: 101100:16461a0016bf user: Berker Peksag date: Sun Apr 24 01:51:02 2016 +0300 summary: Issue #20112: Improve BaseHTTPRequestHandler.error_message_format documentation * Explain how 'error_message_format' is used by 'send_error' method * Mention that 'responses' is used by 'send_response_only' and 'send_error' methods * Replace 'class variables' with 'attributes' Initial patch by Anastasia Filatova. files: Doc/library/http.server.rst | 29 +++++++++--------------- 1 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Doc/library/http.server.rst b/Doc/library/http.server.rst --- a/Doc/library/http.server.rst +++ b/Doc/library/http.server.rst @@ -97,7 +97,6 @@ :mod:`http.client` is used to parse the headers and it requires that the HTTP request provide a valid :rfc:`2822` style header. - .. attribute:: rfile Contains an input stream, positioned at the start of the optional input @@ -109,7 +108,7 @@ client. Proper adherence to the HTTP protocol must be used when writing to this stream. - :class:`BaseHTTPRequestHandler` has the following class variables: + :class:`BaseHTTPRequestHandler` has the following attributes: .. attribute:: server_version @@ -125,13 +124,10 @@ .. attribute:: error_message_format - Specifies a format string for building an error response to the client. It - uses parenthesized, keyed format specifiers, so the format operand must be - a dictionary. The *code* key should be an integer, specifying the numeric - HTTP error code value. *message* should be a string containing a - (detailed) error message of what occurred, and *explain* should be an - explanation of the error code number. Default *message* and *explain* - values can found in the :attr:`responses` class variable. + Specifies a format string that should be used by :meth:`send_error` method + for building an error response to the client. The string is filled by + default with variables from :attr:`responses` based on the status code + that passed to :meth:`send_error`. .. attribute:: error_content_type @@ -154,11 +150,11 @@ .. attribute:: responses - This variable contains a mapping of error code integers to two-element tuples + This attribute contains a mapping of error code integers to two-element tuples containing a short and long message. For example, ``{code: (shortmessage, longmessage)}``. The *shortmessage* is usually used as the *message* key in an - error response, and *longmessage* as the *explain* key (see the - :attr:`error_message_format` class variable). + error response, and *longmessage* as the *explain* key. It is used by + :meth:`send_response_only` and :meth:`send_error` methods. A :class:`BaseHTTPRequestHandler` instance has the following methods: @@ -191,9 +187,9 @@ specifies the HTTP error code, with *message* as an optional, short, human readable description of the error. The *explain* argument can be used to provide more detailed information about the error; it will be formatted - using the :attr:`error_message_format` class variable and emitted, after + using the :attr:`error_message_format` attribute and emitted, after a complete set of headers, as the response body. The :attr:`responses` - class variable holds the default values for *message* and *explain* that + attribute holds the default values for *message* and *explain* that will be used if no value is provided; for unknown codes the default value for both is the string ``???``. @@ -201,7 +197,6 @@ The error response includes a Content-Length header. Added the *explain* argument. - .. method:: send_response(code, message=None) Adds a response header to the headers buffer and logs the accepted @@ -217,7 +212,6 @@ Headers are stored to an internal buffer and :meth:`end_headers` needs to be called explicitly. - .. method:: send_header(keyword, value) Adds the HTTP header to an internal buffer which will be written to the @@ -229,7 +223,6 @@ .. versionchanged:: 3.2 Headers are stored in an internal buffer. - .. method:: send_response_only(code, message=None) Sends the response header only, used for the purposes when ``100 @@ -279,7 +272,7 @@ .. method:: version_string() Returns the server software's version string. This is a combination of the - :attr:`server_version` and :attr:`sys_version` class variables. + :attr:`server_version` and :attr:`sys_version` attributes. .. method:: date_time_string(timestamp=None) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 18:51:19 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 23 Apr 2016 22:51:19 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2320112=3A_Improve_BaseHTTPRequestHandler=2Eerror?= =?utf-8?q?=5Fmessage=5Fformat_documentation?= Message-ID: <20160423225119.16868.24841.20AAB14B@psf.io> https://hg.python.org/cpython/rev/baed33df1aed changeset: 101104:baed33df1aed parent: 101102:5faccb403ad8 parent: 101103:a912ca4f507b user: Berker Peksag date: Sun Apr 24 01:51:31 2016 +0300 summary: Issue #20112: Improve BaseHTTPRequestHandler.error_message_format documentation * Explain how 'error_message_format' is used by 'send_error' method * Mention that 'responses' is used by 'send_response_only' and 'send_error' methods * Replace 'class variables' with 'attributes' Initial patch by Anastasia Filatova. files: Doc/library/http.server.rst | 29 +++++++++--------------- 1 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Doc/library/http.server.rst b/Doc/library/http.server.rst --- a/Doc/library/http.server.rst +++ b/Doc/library/http.server.rst @@ -97,7 +97,6 @@ :mod:`http.client` is used to parse the headers and it requires that the HTTP request provide a valid :rfc:`2822` style header. - .. attribute:: rfile Contains an input stream, positioned at the start of the optional input @@ -109,7 +108,7 @@ client. Proper adherence to the HTTP protocol must be used when writing to this stream. - :class:`BaseHTTPRequestHandler` has the following class variables: + :class:`BaseHTTPRequestHandler` has the following attributes: .. attribute:: server_version @@ -125,13 +124,10 @@ .. attribute:: error_message_format - Specifies a format string for building an error response to the client. It - uses parenthesized, keyed format specifiers, so the format operand must be - a dictionary. The *code* key should be an integer, specifying the numeric - HTTP error code value. *message* should be a string containing a - (detailed) error message of what occurred, and *explain* should be an - explanation of the error code number. Default *message* and *explain* - values can found in the :attr:`responses` class variable. + Specifies a format string that should be used by :meth:`send_error` method + for building an error response to the client. The string is filled by + default with variables from :attr:`responses` based on the status code + that passed to :meth:`send_error`. .. attribute:: error_content_type @@ -154,11 +150,11 @@ .. attribute:: responses - This variable contains a mapping of error code integers to two-element tuples + This attribute contains a mapping of error code integers to two-element tuples containing a short and long message. For example, ``{code: (shortmessage, longmessage)}``. The *shortmessage* is usually used as the *message* key in an - error response, and *longmessage* as the *explain* key (see the - :attr:`error_message_format` class variable). + error response, and *longmessage* as the *explain* key. It is used by + :meth:`send_response_only` and :meth:`send_error` methods. A :class:`BaseHTTPRequestHandler` instance has the following methods: @@ -191,9 +187,9 @@ specifies the HTTP error code, with *message* as an optional, short, human readable description of the error. The *explain* argument can be used to provide more detailed information about the error; it will be formatted - using the :attr:`error_message_format` class variable and emitted, after + using the :attr:`error_message_format` attribute and emitted, after a complete set of headers, as the response body. The :attr:`responses` - class variable holds the default values for *message* and *explain* that + attribute holds the default values for *message* and *explain* that will be used if no value is provided; for unknown codes the default value for both is the string ``???``. @@ -201,7 +197,6 @@ The error response includes a Content-Length header. Added the *explain* argument. - .. method:: send_response(code, message=None) Adds a response header to the headers buffer and logs the accepted @@ -217,7 +212,6 @@ Headers are stored to an internal buffer and :meth:`end_headers` needs to be called explicitly. - .. method:: send_header(keyword, value) Adds the HTTP header to an internal buffer which will be written to the @@ -229,7 +223,6 @@ .. versionchanged:: 3.2 Headers are stored in an internal buffer. - .. method:: send_response_only(code, message=None) Sends the response header only, used for the purposes when ``100 @@ -279,7 +272,7 @@ .. method:: version_string() Returns the server software's version string. This is a combination of the - :attr:`server_version` and :attr:`sys_version` class variables. + :attr:`server_version` and :attr:`sys_version` attributes. .. method:: date_time_string(timestamp=None) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 18:54:52 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 23 Apr 2016 22:54:52 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326089=3A_Remove_d?= =?utf-8?q?uplicate_field_=27license=27_from_DistributionMetadata?= Message-ID: <20160423225452.31833.54363.385AD2DD@psf.io> https://hg.python.org/cpython/rev/21e522177ca0 changeset: 101105:21e522177ca0 user: Berker Peksag date: Sun Apr 24 01:55:09 2016 +0300 summary: Issue #26089: Remove duplicate field 'license' from DistributionMetadata It was renamed to 'license' in 178d19cff163. Patch by Augustin Laville. files: Lib/distutils/dist.py | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py --- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -1018,8 +1018,7 @@ "maintainer", "maintainer_email", "url", "license", "description", "long_description", "keywords", "platforms", "fullname", "contact", - "contact_email", "license", "classifiers", - "download_url", + "contact_email", "classifiers", "download_url", # PEP 314 "provides", "requires", "obsoletes", ) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 19:59:26 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 23 Apr 2016 23:59:26 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzIxMzgy?= =?utf-8?q?=3A_Clarify_signal=2Esignal=28=29_documentation_on_Windows?= Message-ID: <20160423235926.15826.88971.B0CD9C2B@psf.io> https://hg.python.org/cpython/rev/1fcf68e6f4c7 changeset: 101106:1fcf68e6f4c7 branch: 3.5 parent: 101103:a912ca4f507b user: Berker Peksag date: Sun Apr 24 02:59:16 2016 +0300 summary: Issue #21382: Clarify signal.signal() documentation on Windows All signal.SIG* constants may not be defined on Windows so a call like signal.signal(signal.SIGPIPE, lambda signum, frame: sys.exit(1)) will raise an AttributeError. files: Doc/library/signal.rst | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Doc/library/signal.rst b/Doc/library/signal.rst --- a/Doc/library/signal.rst +++ b/Doc/library/signal.rst @@ -351,6 +351,9 @@ On Windows, :func:`signal` can only be called with :const:`SIGABRT`, :const:`SIGFPE`, :const:`SIGILL`, :const:`SIGINT`, :const:`SIGSEGV`, or :const:`SIGTERM`. A :exc:`ValueError` will be raised in any other case. + Note that not all systems define the same set of signal names; an + :exc:`AttributeError` will be raised if a signal name is not defined as + ``SIG*`` module level constant. .. function:: sigpending() -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 19:59:26 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 23 Apr 2016 23:59:26 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2321382=3A_Clarify_signal=2Esignal=28=29_document?= =?utf-8?q?ation_on_Windows?= Message-ID: <20160423235926.21466.79898.C30A2597@psf.io> https://hg.python.org/cpython/rev/3e27b21e3a7d changeset: 101107:3e27b21e3a7d parent: 101105:21e522177ca0 parent: 101106:1fcf68e6f4c7 user: Berker Peksag date: Sun Apr 24 02:59:43 2016 +0300 summary: Issue #21382: Clarify signal.signal() documentation on Windows All signal.SIG* constants may not be defined on Windows so a call like signal.signal(signal.SIGPIPE, lambda signum, frame: sys.exit(1)) will raise an AttributeError. files: Doc/library/signal.rst | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Doc/library/signal.rst b/Doc/library/signal.rst --- a/Doc/library/signal.rst +++ b/Doc/library/signal.rst @@ -351,6 +351,9 @@ On Windows, :func:`signal` can only be called with :const:`SIGABRT`, :const:`SIGFPE`, :const:`SIGILL`, :const:`SIGINT`, :const:`SIGSEGV`, or :const:`SIGTERM`. A :exc:`ValueError` will be raised in any other case. + Note that not all systems define the same set of signal names; an + :exc:`AttributeError` will be raised if a signal name is not defined as + ``SIG*`` module level constant. .. function:: sigpending() -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 20:06:46 2016 From: python-checkins at python.org (berker.peksag) Date: Sun, 24 Apr 2016 00:06:46 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2318353=3A_Remove_PyUnicode=5FWRITE=5FCHAR_macro_?= =?utf-8?q?link_from_c-api/unicode=2Erst?= Message-ID: <20160424000646.21474.5162.260225D3@psf.io> https://hg.python.org/cpython/rev/8c53fdc011a3 changeset: 101109:8c53fdc011a3 parent: 101107:3e27b21e3a7d parent: 101108:29e555e5956b user: Berker Peksag date: Sun Apr 24 03:07:03 2016 +0300 summary: Issue #18353: Remove PyUnicode_WRITE_CHAR macro link from c-api/unicode.rst Patch by Corey Brune. files: Doc/c-api/unicode.rst | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -613,8 +613,7 @@ This function checks that *unicode* is a Unicode object, that the index is not out of bounds, and that the object can be modified safely (i.e. that it - its reference count is one), in contrast to the macro version - :c:func:`PyUnicode_WRITE_CHAR`. + its reference count is one). .. versionadded:: 3.3 -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 20:06:46 2016 From: python-checkins at python.org (berker.peksag) Date: Sun, 24 Apr 2016 00:06:46 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzE4MzUz?= =?utf-8?q?=3A_Remove_PyUnicode=5FWRITE=5FCHAR_macro_link_from_c-api/unico?= =?utf-8?q?de=2Erst?= Message-ID: <20160424000646.21470.69950.47251921@psf.io> https://hg.python.org/cpython/rev/29e555e5956b changeset: 101108:29e555e5956b branch: 3.5 parent: 101106:1fcf68e6f4c7 user: Berker Peksag date: Sun Apr 24 03:06:44 2016 +0300 summary: Issue #18353: Remove PyUnicode_WRITE_CHAR macro link from c-api/unicode.rst Patch by Corey Brune. files: Doc/c-api/unicode.rst | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -613,8 +613,7 @@ This function checks that *unicode* is a Unicode object, that the index is not out of bounds, and that the object can be modified safely (i.e. that it - its reference count is one), in contrast to the macro version - :c:func:`PyUnicode_WRITE_CHAR`. + its reference count is one). .. versionadded:: 3.3 -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 20:13:48 2016 From: python-checkins at python.org (berker.peksag) Date: Sun, 24 Apr 2016 00:13:48 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzE4NTcy?= =?utf-8?q?=3A_Remove_redundant_note_about_surrogates_in_string_escape_doc?= Message-ID: <20160424001347.111110.87747.72B12B93@psf.io> https://hg.python.org/cpython/rev/79e7808c3941 changeset: 101110:79e7808c3941 branch: 3.5 parent: 101108:29e555e5956b user: Berker Peksag date: Sun Apr 24 03:13:40 2016 +0300 summary: Issue #18572: Remove redundant note about surrogates in string escape doc files: Doc/reference/lexical_analysis.rst | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -538,8 +538,7 @@ Support for name aliases [#]_ has been added. (5) - Individual code units which form parts of a surrogate pair can be encoded using - this escape sequence. Exactly four hex digits are required. + Exactly four hex digits are required. (6) Any Unicode character can be encoded this way. Exactly eight hex digits -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 20:13:48 2016 From: python-checkins at python.org (berker.peksag) Date: Sun, 24 Apr 2016 00:13:48 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2318572=3A_Remove_redundant_note_about_surrogates?= =?utf-8?q?_in_string_escape_doc?= Message-ID: <20160424001347.6232.10111.C942A63D@psf.io> https://hg.python.org/cpython/rev/ee815d3535f5 changeset: 101111:ee815d3535f5 parent: 101109:8c53fdc011a3 parent: 101110:79e7808c3941 user: Berker Peksag date: Sun Apr 24 03:14:01 2016 +0300 summary: Issue #18572: Remove redundant note about surrogates in string escape doc files: Doc/reference/lexical_analysis.rst | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -544,8 +544,7 @@ Support for name aliases [#]_ has been added. (5) - Individual code units which form parts of a surrogate pair can be encoded using - this escape sequence. Exactly four hex digits are required. + Exactly four hex digits are required. (6) Any Unicode character can be encoded this way. Exactly eight hex digits -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 20:21:15 2016 From: python-checkins at python.org (berker.peksag) Date: Sun, 24 Apr 2016 00:21:15 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzE5NzMx?= =?utf-8?q?=3A_Update_copyright_year_in_docs=2Ep=2Eo_footer?= Message-ID: <20160424002115.15967.28752.D198D6F2@psf.io> https://hg.python.org/cpython/rev/7cb3364952d5 changeset: 101112:7cb3364952d5 branch: 3.5 parent: 101110:79e7808c3941 user: Berker Peksag date: Sun Apr 24 03:21:13 2016 +0300 summary: Issue #19731: Update copyright year in docs.p.o footer See https://mail.python.org/pipermail/python-legal-sig/2013-November/000059.html for details. Patch by Antoine Pitrou. files: Doc/conf.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/conf.py b/Doc/conf.py --- a/Doc/conf.py +++ b/Doc/conf.py @@ -17,7 +17,7 @@ # General substitutions. project = 'Python' -copyright = '1990-%s, Python Software Foundation' % time.strftime('%Y') +copyright = '2001-%s, Python Software Foundation' % time.strftime('%Y') # We look for the Include/patchlevel.h file in the current Python source tree # and replace the values accordingly. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 20:21:16 2016 From: python-checkins at python.org (berker.peksag) Date: Sun, 24 Apr 2016 00:21:16 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2319731=3A_Update_copyright_year_in_docs=2Ep=2Eo_?= =?utf-8?q?footer?= Message-ID: <20160424002115.117418.25169.73014C18@psf.io> https://hg.python.org/cpython/rev/fa0a941728a8 changeset: 101113:fa0a941728a8 parent: 101111:ee815d3535f5 parent: 101112:7cb3364952d5 user: Berker Peksag date: Sun Apr 24 03:21:32 2016 +0300 summary: Issue #19731: Update copyright year in docs.p.o footer See https://mail.python.org/pipermail/python-legal-sig/2013-November/000059.html for details. Patch by Antoine Pitrou. files: Doc/conf.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/conf.py b/Doc/conf.py --- a/Doc/conf.py +++ b/Doc/conf.py @@ -17,7 +17,7 @@ # General substitutions. project = 'Python' -copyright = '1990-%s, Python Software Foundation' % time.strftime('%Y') +copyright = '2001-%s, Python Software Foundation' % time.strftime('%Y') # We look for the Include/patchlevel.h file in the current Python source tree # and replace the values accordingly. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 20:32:33 2016 From: python-checkins at python.org (berker.peksag) Date: Sun, 24 Apr 2016 00:32:33 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326041=3A_Remove_=22will_be_removed_in_Python_3?= =?utf-8?q?=2E7=22_from_description_messages?= Message-ID: <20160424003233.21468.99751.37CC1E81@psf.io> https://hg.python.org/cpython/rev/5d9f961edc30 changeset: 101115:5d9f961edc30 parent: 101113:fa0a941728a8 parent: 101114:8f7b317124d6 user: Berker Peksag date: Sun Apr 24 03:32:50 2016 +0300 summary: Issue #26041: Remove "will be removed in Python 3.7" from description messages We will keep platform.dist() and platform.linux_distribution() to make porting from Python 2 easier. Patch by Kumaripaba Miyurusara Athukorala. files: Doc/whatsnew/3.5.rst | 5 ++--- Lib/platform.py | 6 ++---- Lib/test/test_platform.py | 6 ++---- Misc/NEWS | 4 ++++ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst --- a/Doc/whatsnew/3.5.rst +++ b/Doc/whatsnew/3.5.rst @@ -2271,9 +2271,8 @@ (Contributed by Serhiy Storchaka in :issue:`23671`.) The :func:`platform.dist` and :func:`platform.linux_distribution` functions -are now deprecated and will be removed in Python 3.7. Linux distributions use -too many different ways of describing themselves, so the functionality is -left to a package. +are now deprecated. Linux distributions use too many different ways of +describing themselves, so the functionality is left to a package. (Contributed by Vajrasky Kok and Berker Peksag in :issue:`1322`.) The previously undocumented ``from_function`` and ``from_builtin`` methods of diff --git a/Lib/platform.py b/Lib/platform.py --- a/Lib/platform.py +++ b/Lib/platform.py @@ -303,8 +303,7 @@ full_distribution_name=1): import warnings warnings.warn("dist() and linux_distribution() functions are deprecated " - "in Python 3.5 and will be removed in Python 3.7", - PendingDeprecationWarning, stacklevel=2) + "in Python 3.5", PendingDeprecationWarning, stacklevel=2) return _linux_distribution(distname, version, id, supported_dists, full_distribution_name) @@ -378,8 +377,7 @@ """ import warnings warnings.warn("dist() and linux_distribution() functions are deprecated " - "in Python 3.5 and will be removed in Python 3.7", - PendingDeprecationWarning, stacklevel=2) + "in Python 3.5", PendingDeprecationWarning, stacklevel=2) return _linux_distribution(distname, version, id, supported_dists=supported_dists, full_distribution_name=0) diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -333,16 +333,14 @@ platform.dist() self.assertEqual(str(cm.warning), 'dist() and linux_distribution() functions are ' - 'deprecated in Python 3.5 and will be removed in ' - 'Python 3.7') + 'deprecated in Python 3.5') def test_linux_distribution_deprecation(self): with self.assertWarns(PendingDeprecationWarning) as cm: platform.linux_distribution() self.assertEqual(str(cm.warning), 'dist() and linux_distribution() functions are ' - 'deprecated in Python 3.5 and will be removed in ' - 'Python 3.7') + 'deprecated in Python 3.5') if __name__ == '__main__': unittest.main() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -256,6 +256,10 @@ Library ------- +- Issue #26041: Remove "will be removed in Python 3.7" from deprecation + messages of platform.dist() and platform.linux_distribution(). + Patch by Kumaripaba Miyurusara Athukorala. + - Issue #26822: itemgetter, attrgetter and methodcaller objects no longer silently ignore keyword arguments. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 23 20:32:33 2016 From: python-checkins at python.org (berker.peksag) Date: Sun, 24 Apr 2016 00:32:33 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2MDQx?= =?utf-8?q?=3A_Remove_=22will_be_removed_in_Python_3=2E7=22_from_descripti?= =?utf-8?q?on_messages?= Message-ID: <20160424003233.63430.81836.ED0E1AB4@psf.io> https://hg.python.org/cpython/rev/8f7b317124d6 changeset: 101114:8f7b317124d6 branch: 3.5 parent: 101112:7cb3364952d5 user: Berker Peksag date: Sun Apr 24 03:32:24 2016 +0300 summary: Issue #26041: Remove "will be removed in Python 3.7" from description messages We will keep platform.dist() and platform.linux_distribution() to make porting from Python 2 easier. Patch by Kumaripaba Miyurusara Athukorala. files: Doc/whatsnew/3.5.rst | 5 ++--- Lib/platform.py | 6 ++---- Lib/test/test_platform.py | 6 ++---- Misc/NEWS | 4 ++++ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst --- a/Doc/whatsnew/3.5.rst +++ b/Doc/whatsnew/3.5.rst @@ -2271,9 +2271,8 @@ (Contributed by Serhiy Storchaka in :issue:`23671`.) The :func:`platform.dist` and :func:`platform.linux_distribution` functions -are now deprecated and will be removed in Python 3.7. Linux distributions use -too many different ways of describing themselves, so the functionality is -left to a package. +are now deprecated. Linux distributions use too many different ways of +describing themselves, so the functionality is left to a package. (Contributed by Vajrasky Kok and Berker Peksag in :issue:`1322`.) The previously undocumented ``from_function`` and ``from_builtin`` methods of diff --git a/Lib/platform.py b/Lib/platform.py --- a/Lib/platform.py +++ b/Lib/platform.py @@ -303,8 +303,7 @@ full_distribution_name=1): import warnings warnings.warn("dist() and linux_distribution() functions are deprecated " - "in Python 3.5 and will be removed in Python 3.7", - PendingDeprecationWarning, stacklevel=2) + "in Python 3.5", PendingDeprecationWarning, stacklevel=2) return _linux_distribution(distname, version, id, supported_dists, full_distribution_name) @@ -378,8 +377,7 @@ """ import warnings warnings.warn("dist() and linux_distribution() functions are deprecated " - "in Python 3.5 and will be removed in Python 3.7", - PendingDeprecationWarning, stacklevel=2) + "in Python 3.5", PendingDeprecationWarning, stacklevel=2) return _linux_distribution(distname, version, id, supported_dists=supported_dists, full_distribution_name=0) diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -333,16 +333,14 @@ platform.dist() self.assertEqual(str(cm.warning), 'dist() and linux_distribution() functions are ' - 'deprecated in Python 3.5 and will be removed in ' - 'Python 3.7') + 'deprecated in Python 3.5') def test_linux_distribution_deprecation(self): with self.assertWarns(PendingDeprecationWarning) as cm: platform.linux_distribution() self.assertEqual(str(cm.warning), 'dist() and linux_distribution() functions are ' - 'deprecated in Python 3.5 and will be removed in ' - 'Python 3.7') + 'deprecated in Python 3.5') if __name__ == '__main__': unittest.main() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,10 @@ Library ------- +- Issue #26041: Remove "will be removed in Python 3.7" from deprecation + messages of platform.dist() and platform.linux_distribution(). + Patch by Kumaripaba Miyurusara Athukorala. + - Issue #26822: itemgetter, attrgetter and methodcaller objects no longer silently ignore keyword arguments. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 00:16:32 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 24 Apr 2016 04:16:32 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzIzODA2?= =?utf-8?q?=3A_Update_susp-ignored=2Ecsv?= Message-ID: <20160424041632.26173.67759.0879C0B7@psf.io> https://hg.python.org/cpython/rev/5ad93528c39c changeset: 101116:5ad93528c39c branch: 3.5 parent: 101114:8f7b317124d6 user: Martin Panter date: Sun Apr 24 04:06:15 2016 +0000 summary: Issue #23806: Update susp-ignored.csv files: Doc/tools/susp-ignored.csv | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/Doc/tools/susp-ignored.csv b/Doc/tools/susp-ignored.csv --- a/Doc/tools/susp-ignored.csv +++ b/Doc/tools/susp-ignored.csv @@ -198,6 +198,7 @@ library/unittest,,:foo,'ERROR:foo.bar:second message']) library/unittest,,:second,'ERROR:foo.bar:second message']) library/urllib.request,,:close,Connection:close +library/urllib.request,,:port,:port library/urllib.request,,:lang,"xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en"">\n\n\n" library/urllib.request,,:password,"""joe:password at python.org""" library/uuid,,:uuid,urn:uuid:12345678-1234-5678-1234-567812345678 -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 00:16:32 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 24 Apr 2016 04:16:32 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2323806=3A_Merge_susp-ignored=2Ecsv_from_3=2E5?= Message-ID: <20160424041632.4138.68966.A16D19D5@psf.io> https://hg.python.org/cpython/rev/cb38785acc8d changeset: 101117:cb38785acc8d parent: 101115:5d9f961edc30 parent: 101116:5ad93528c39c user: Martin Panter date: Sun Apr 24 04:07:58 2016 +0000 summary: Issue #23806: Merge susp-ignored.csv from 3.5 files: Doc/tools/susp-ignored.csv | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/Doc/tools/susp-ignored.csv b/Doc/tools/susp-ignored.csv --- a/Doc/tools/susp-ignored.csv +++ b/Doc/tools/susp-ignored.csv @@ -198,6 +198,7 @@ library/unittest,,:foo,'ERROR:foo.bar:second message']) library/unittest,,:second,'ERROR:foo.bar:second message']) library/urllib.request,,:close,Connection:close +library/urllib.request,,:port,:port library/urllib.request,,:lang,"xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en"">\n\n\n" library/urllib.request,,:password,"""joe:password at python.org""" library/uuid,,:uuid,urn:uuid:12345678-1234-5678-1234-567812345678 -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 00:22:53 2016 From: python-checkins at python.org (nick.coghlan) Date: Sun, 24 Apr 2016 04:22:53 +0000 Subject: [Python-checkins] =?utf-8?q?devguide=3A_Allow_for_simpler_motivat?= =?utf-8?q?ions_entries?= Message-ID: <20160424042253.21472.34586.730805E3@psf.io> https://hg.python.org/devguide/rev/9a9f32fcb794 changeset: 797:9a9f32fcb794 user: Nick Coghlan date: Sun Apr 24 14:22:41 2016 +1000 summary: Allow for simpler motivations entries Coming up with a short personal bio can require a non-trivial amount of effort, so this update makes that aspect of the motivations & affiliations page explicitly optional - if folks just want to document relevant professional affiliations without adding any other info, that's still helpful data. I also eliminated the remaining reference to the page being an experiment. There are still experimental aspects, but those relate to seeing how people use the information, and exploring ways to help ensure contributors with relevant professional affiliations are comfortable sharing those, rather than relating to the existence of the page itself. files: motivations.rst | 52 ++++++++++++++++++++---------------- 1 files changed, 29 insertions(+), 23 deletions(-) diff --git a/motivations.rst b/motivations.rst --- a/motivations.rst +++ b/motivations.rst @@ -11,9 +11,8 @@ This page allows core developers that choose to do so to provide more information to the rest of the Python community regarding their personal -motivations for participating in the core review process, as well as any -personal and professional affiliations which they consider particularly -relevant. +situation (such as their general location and professional affiliations), as +well as any personal motivations that they consider particularly relevant. Core developers that wish to provide this additional information add a new entry to the :ref:`published-motivations` section below. Guidelines relating @@ -21,7 +20,7 @@ Core developers that are available for training, consulting or contract work, or are seeking crowdfunding support for their community contributions, may also -choose to disclose that information here (including linking out to commercial +choose to provide that information here (including linking out to commercial sites with the relevant details). Goals of this page @@ -43,15 +42,15 @@ contributors. This page aims to provide at least some of that missing data by encouraging -core developers to disclose commercial affiliations in the following two cases -(even if not currently paid for time spent participating in the core +core developers to highlight professional affiliations in the following two +cases (even if not currently paid for time spent participating in the core development process): * developers working for vendors that distribute a commercially supported Python runtime * developers working for Sponsor Members of the Python Software Foundation -These are cases where disclosure of commercial interests helps to improve the +These are cases where documenting our affiliations helps to improve the overall transparency of the core development process, as well as making it easier for staff at these organisations to locate colleagues that can help them to participate in and contribute effectively to supporting the core @@ -89,10 +88,10 @@ * Specific technical areas of interest for core developers should be captured in the :ref:`Experts Index `. -* This specific listing is limited to CPython core developers, but if this - experiment proves successful, it may make sense to create a more expansive - listing on the Python wiki that also covers issue triagers, and folks seeking - to become core developers. +* This specific listing is limited to CPython core developers (since it's + focused on the specific constraint that is core developer time), but it + would be possible to create a more expansive listing on the Python wiki that + also covers issue triagers, and folks seeking to become core developers. * Changes to the software and documentation maintained by core developers, together with related design discussions, all take place in public venues, and @@ -111,28 +110,35 @@ ----------------- The following core developers have chosen to provide additional details -regarding their reasons for participating in the CPython core development -process: +regarding their professional affiliations and (optionally) other reasons for +participating in the CPython core development process: .. Entry guidelines: We use the "topic" directive rather than normal section headings in order to avoid creating entries in the main table of contents. - Topic headings should be in the form of "Name (Country)" to help give some - indication as to the geographic dispersal of core developers. + Topic headings should be in the form of "Name (Country)" or + "Name (Continent)" to help give some indication as to the geographic + distribution of core developers. NOTE: The rest of these guidelines are highly provisional - we can evolve - them as people add entries, and we decide on the style we like. I (Nick) - made a best guess based on what I wanted to include, but it's hard to - really tell how it looks with only one entry. + them as people add entries, and we decide on the style we like. The + current iteration is based on feedback that the first version (which + *required* coming up with a personal bio) was a bit excessive. - Entries should be written as short third person biographies, rather than - being written in first person. + Minimal entries just include relevant professional affiliations, as follows: - Entries should be maintained in alphabetical order by last name, or by first - name (relative to other last names) if "last name" isn't a meaningful term - for your name. + .. topic:: () + + * () + + Longer entries should be written as short third person biographies, rather + than being written in first person (See existing entries for examples). + + Entries should be maintained in alphabetical order by last name, or by + name-as-written (relative to other last names) if "last name" isn't a + meaningful term for your name. Include a "Personal site" bullet point with a link if you'd like to highlight a personal blog or other site. -- Repository URL: https://hg.python.org/devguide From python-checkins at python.org Sun Apr 24 00:31:27 2016 From: python-checkins at python.org (berker.peksag) Date: Sun, 24 Apr 2016 04:31:27 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2323277=3A_Remove_u?= =?utf-8?q?nused_sys_and_os_imports?= Message-ID: <20160424043127.96198.84681.12C6D3CF@psf.io> https://hg.python.org/cpython/rev/6958bbf7f0ec changeset: 101118:6958bbf7f0ec user: Berker Peksag date: Sun Apr 24 07:31:42 2016 +0300 summary: Issue #23277: Remove unused sys and os imports Patch by Jon Dufresne. files: Lib/ctypes/test/test_objects.py | 2 +- Lib/ctypes/test/test_parameters.py | 2 +- Lib/ctypes/test/test_returnfuncptrs.py | 1 - Lib/ctypes/test/test_sizes.py | 1 - Lib/test/audiotests.py | 2 +- Lib/test/make_ssl_certs.py | 1 - Lib/test/test_aifc.py | 1 - Lib/test/test_binhex.py | 1 - Lib/test/test_csv.py | 1 - Lib/test/test_dbm.py | 1 - Lib/test/test_dbm_ndbm.py | 1 - Lib/test/test_devpoll.py | 1 - Lib/test/test_eintr.py | 1 - Lib/test/test_email/__init__.py | 1 - Lib/test/test_heapq.py | 1 - Lib/test/test_importlib/extension/test_case_sensitivity.py | 1 - Lib/test/test_importlib/extension/test_path_hook.py | 1 - Lib/test/test_importlib/frozen/test_loader.py | 2 -- Lib/test/test_importlib/import_/test_relative_imports.py | 1 - Lib/test/test_importlib/source/test_case_sensitivity.py | 1 - Lib/test/test_json/__init__.py | 1 - Lib/test/test_kqueue.py | 1 - Lib/test/test_msilib.py | 1 - Lib/test/test_multibytecodec.py | 2 +- Lib/test/test_nis.py | 1 - Lib/test/test_normalization.py | 1 - Lib/test/test_parser.py | 1 - Lib/test/test_pep3151.py | 1 - Lib/test/test_posixpath.py | 1 - Lib/test/test_pulldom.py | 1 - Lib/test/test_quopri.py | 2 +- Lib/test/test_sort.py | 1 - Lib/test/test_strptime.py | 1 - Lib/test/test_tools/test_md5sum.py | 1 - Lib/test/test_tools/test_pdeps.py | 1 - Lib/test/test_ttk_guionly.py | 1 - Lib/test/test_ttk_textonly.py | 1 - Lib/test/test_unpack_ex.py | 1 - Lib/test/test_urllibnet.py | 1 - Lib/test/test_weakset.py | 2 -- Lib/test/test_xml_etree_c.py | 2 +- Lib/test/test_xmlrpc_net.py | 1 - Lib/test/test_zipfile.py | 1 - Lib/tkinter/test/runtktests.py | 1 - Lib/unittest/test/testmock/support.py | 2 -- 45 files changed, 6 insertions(+), 48 deletions(-) diff --git a/Lib/ctypes/test/test_objects.py b/Lib/ctypes/test/test_objects.py --- a/Lib/ctypes/test/test_objects.py +++ b/Lib/ctypes/test/test_objects.py @@ -54,7 +54,7 @@ ''' -import unittest, doctest, sys +import unittest, doctest import ctypes.test.test_objects diff --git a/Lib/ctypes/test/test_parameters.py b/Lib/ctypes/test/test_parameters.py --- a/Lib/ctypes/test/test_parameters.py +++ b/Lib/ctypes/test/test_parameters.py @@ -1,4 +1,4 @@ -import unittest, sys +import unittest from ctypes.test import need_symbol class SimpleTypesTestCase(unittest.TestCase): diff --git a/Lib/ctypes/test/test_returnfuncptrs.py b/Lib/ctypes/test/test_returnfuncptrs.py --- a/Lib/ctypes/test/test_returnfuncptrs.py +++ b/Lib/ctypes/test/test_returnfuncptrs.py @@ -1,6 +1,5 @@ import unittest from ctypes import * -import os import _ctypes_test diff --git a/Lib/ctypes/test/test_sizes.py b/Lib/ctypes/test/test_sizes.py --- a/Lib/ctypes/test/test_sizes.py +++ b/Lib/ctypes/test/test_sizes.py @@ -2,7 +2,6 @@ from ctypes import * -import sys import unittest diff --git a/Lib/test/audiotests.py b/Lib/test/audiotests.py --- a/Lib/test/audiotests.py +++ b/Lib/test/audiotests.py @@ -3,7 +3,7 @@ import array import io import pickle -import sys + class UnseekableIO(io.FileIO): def tell(self): diff --git a/Lib/test/make_ssl_certs.py b/Lib/test/make_ssl_certs.py --- a/Lib/test/make_ssl_certs.py +++ b/Lib/test/make_ssl_certs.py @@ -3,7 +3,6 @@ import os import shutil -import sys import tempfile from subprocess import * diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -2,7 +2,6 @@ import unittest from test import audiotests from audioop import byteswap -import os import io import sys import struct diff --git a/Lib/test/test_binhex.py b/Lib/test/test_binhex.py --- a/Lib/test/test_binhex.py +++ b/Lib/test/test_binhex.py @@ -4,7 +4,6 @@ Based on an original test by Roger E. Masse. """ import binhex -import os import unittest from test import support diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -4,7 +4,6 @@ import copy import io import sys -import os import unittest from io import StringIO from tempfile import TemporaryFile diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py --- a/Lib/test/test_dbm.py +++ b/Lib/test/test_dbm.py @@ -1,6 +1,5 @@ """Test script for the dbm.open function based on testdumbdbm.py""" -import os import unittest import glob import test.support diff --git a/Lib/test/test_dbm_ndbm.py b/Lib/test/test_dbm_ndbm.py --- a/Lib/test/test_dbm_ndbm.py +++ b/Lib/test/test_dbm_ndbm.py @@ -1,7 +1,6 @@ from test import support support.import_module("dbm.ndbm") #skip if not supported import unittest -import os import random import dbm.ndbm from dbm.ndbm import error diff --git a/Lib/test/test_devpoll.py b/Lib/test/test_devpoll.py --- a/Lib/test/test_devpoll.py +++ b/Lib/test/test_devpoll.py @@ -5,7 +5,6 @@ import os import random import select -import sys import unittest from test.support import TESTFN, run_unittest, cpython_only diff --git a/Lib/test/test_eintr.py b/Lib/test/test_eintr.py --- a/Lib/test/test_eintr.py +++ b/Lib/test/test_eintr.py @@ -1,7 +1,6 @@ import os import signal import subprocess -import sys import unittest from test import support diff --git a/Lib/test/test_email/__init__.py b/Lib/test/test_email/__init__.py --- a/Lib/test/test_email/__init__.py +++ b/Lib/test/test_email/__init__.py @@ -1,5 +1,4 @@ import os -import sys import unittest import collections import email diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py --- a/Lib/test/test_heapq.py +++ b/Lib/test/test_heapq.py @@ -1,6 +1,5 @@ """Unittests for heapq.""" -import sys import random import unittest diff --git a/Lib/test/test_importlib/extension/test_case_sensitivity.py b/Lib/test/test_importlib/extension/test_case_sensitivity.py --- a/Lib/test/test_importlib/extension/test_case_sensitivity.py +++ b/Lib/test/test_importlib/extension/test_case_sensitivity.py @@ -1,5 +1,4 @@ from importlib import _bootstrap_external -import sys from test import support import unittest diff --git a/Lib/test/test_importlib/extension/test_path_hook.py b/Lib/test/test_importlib/extension/test_path_hook.py --- a/Lib/test/test_importlib/extension/test_path_hook.py +++ b/Lib/test/test_importlib/extension/test_path_hook.py @@ -3,7 +3,6 @@ machinery = util.import_importlib('importlib.machinery') import collections -import sys import unittest diff --git a/Lib/test/test_importlib/frozen/test_loader.py b/Lib/test/test_importlib/frozen/test_loader.py --- a/Lib/test/test_importlib/frozen/test_loader.py +++ b/Lib/test/test_importlib/frozen/test_loader.py @@ -3,8 +3,6 @@ machinery = util.import_importlib('importlib.machinery') - -import sys from test.support import captured_stdout import types import unittest diff --git a/Lib/test/test_importlib/import_/test_relative_imports.py b/Lib/test/test_importlib/import_/test_relative_imports.py --- a/Lib/test/test_importlib/import_/test_relative_imports.py +++ b/Lib/test/test_importlib/import_/test_relative_imports.py @@ -1,6 +1,5 @@ """Test relative imports (PEP 328).""" from .. import util -import sys import unittest import warnings diff --git a/Lib/test/test_importlib/source/test_case_sensitivity.py b/Lib/test/test_importlib/source/test_case_sensitivity.py --- a/Lib/test/test_importlib/source/test_case_sensitivity.py +++ b/Lib/test/test_importlib/source/test_case_sensitivity.py @@ -5,7 +5,6 @@ machinery = util.import_importlib('importlib.machinery') import os -import sys from test import support as test_support import unittest diff --git a/Lib/test/test_json/__init__.py b/Lib/test/test_json/__init__.py --- a/Lib/test/test_json/__init__.py +++ b/Lib/test/test_json/__init__.py @@ -1,5 +1,4 @@ import os -import sys import json import doctest import unittest diff --git a/Lib/test/test_kqueue.py b/Lib/test/test_kqueue.py --- a/Lib/test/test_kqueue.py +++ b/Lib/test/test_kqueue.py @@ -5,7 +5,6 @@ import os import select import socket -import sys import time import unittest diff --git a/Lib/test/test_msilib.py b/Lib/test/test_msilib.py --- a/Lib/test/test_msilib.py +++ b/Lib/test/test_msilib.py @@ -1,6 +1,5 @@ """ Test suite for the code in msilib """ import unittest -import os from test.support import import_module msilib = import_module('msilib') diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -5,7 +5,7 @@ from test import support from test.support import TESTFN -import unittest, io, codecs, sys, os +import unittest, io, codecs, sys import _multibytecodec ALL_CJKENCODINGS = [ diff --git a/Lib/test/test_nis.py b/Lib/test/test_nis.py --- a/Lib/test/test_nis.py +++ b/Lib/test/test_nis.py @@ -1,6 +1,5 @@ from test import support import unittest -import sys # Skip test if nis module does not exist. nis = support.import_module('nis') diff --git a/Lib/test/test_normalization.py b/Lib/test/test_normalization.py --- a/Lib/test/test_normalization.py +++ b/Lib/test/test_normalization.py @@ -3,7 +3,6 @@ from http.client import HTTPException import sys -import os from unicodedata import normalize, unidata_version TESTDATAFILE = "NormalizationTest.txt" diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -1,6 +1,5 @@ import parser import unittest -import sys import operator import struct from test import support diff --git a/Lib/test/test_pep3151.py b/Lib/test/test_pep3151.py --- a/Lib/test/test_pep3151.py +++ b/Lib/test/test_pep3151.py @@ -2,7 +2,6 @@ import os import select import socket -import sys import unittest import errno from errno import EEXIST diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -1,7 +1,6 @@ import itertools import os import posixpath -import sys import unittest import warnings from posixpath import realpath, abspath, dirname, basename diff --git a/Lib/test/test_pulldom.py b/Lib/test/test_pulldom.py --- a/Lib/test/test_pulldom.py +++ b/Lib/test/test_pulldom.py @@ -1,6 +1,5 @@ import io import unittest -import sys import xml.sax from xml.sax.xmlreader import AttributesImpl diff --git a/Lib/test/test_quopri.py b/Lib/test/test_quopri.py --- a/Lib/test/test_quopri.py +++ b/Lib/test/test_quopri.py @@ -1,6 +1,6 @@ import unittest -import sys, os, io, subprocess +import sys, io, subprocess import quopri diff --git a/Lib/test/test_sort.py b/Lib/test/test_sort.py --- a/Lib/test/test_sort.py +++ b/Lib/test/test_sort.py @@ -1,6 +1,5 @@ from test import support import random -import sys import unittest from functools import cmp_to_key diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py --- a/Lib/test/test_strptime.py +++ b/Lib/test/test_strptime.py @@ -5,7 +5,6 @@ import locale import re import os -import sys from test import support from datetime import date as datetime_date diff --git a/Lib/test/test_tools/test_md5sum.py b/Lib/test/test_tools/test_md5sum.py --- a/Lib/test/test_tools/test_md5sum.py +++ b/Lib/test/test_tools/test_md5sum.py @@ -1,7 +1,6 @@ """Tests for the md5sum script in the Tools directory.""" import os -import sys import unittest from test import support from test.support.script_helper import assert_python_ok, assert_python_failure diff --git a/Lib/test/test_tools/test_pdeps.py b/Lib/test/test_tools/test_pdeps.py --- a/Lib/test/test_tools/test_pdeps.py +++ b/Lib/test/test_tools/test_pdeps.py @@ -1,7 +1,6 @@ """Tests for the pdeps script in the Tools directory.""" import os -import sys import unittest import tempfile from test import support diff --git a/Lib/test/test_ttk_guionly.py b/Lib/test/test_ttk_guionly.py --- a/Lib/test/test_ttk_guionly.py +++ b/Lib/test/test_ttk_guionly.py @@ -1,4 +1,3 @@ -import os import unittest from test import support diff --git a/Lib/test/test_ttk_textonly.py b/Lib/test/test_ttk_textonly.py --- a/Lib/test/test_ttk_textonly.py +++ b/Lib/test/test_ttk_textonly.py @@ -1,4 +1,3 @@ -import os from test import support # Skip this test if _tkinter does not exist. diff --git a/Lib/test/test_unpack_ex.py b/Lib/test/test_unpack_ex.py --- a/Lib/test/test_unpack_ex.py +++ b/Lib/test/test_unpack_ex.py @@ -352,7 +352,6 @@ __test__ = {'doctests' : doctests} def test_main(verbose=False): - import sys from test import support from test import test_unpack_ex support.run_doctest(test_unpack_ex, verbose) diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -4,7 +4,6 @@ import contextlib import socket import urllib.request -import sys import os import email.message import time diff --git a/Lib/test/test_weakset.py b/Lib/test/test_weakset.py --- a/Lib/test/test_weakset.py +++ b/Lib/test/test_weakset.py @@ -3,9 +3,7 @@ import operator import copy import string -import os from random import randrange, shuffle -import sys import warnings import collections from collections import UserString as ustr diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -1,5 +1,5 @@ # xml.etree test for cElementTree -import sys, struct +import struct from test import support from test.support import import_fresh_module import types diff --git a/Lib/test/test_xmlrpc_net.py b/Lib/test/test_xmlrpc_net.py --- a/Lib/test/test_xmlrpc_net.py +++ b/Lib/test/test_xmlrpc_net.py @@ -1,7 +1,6 @@ import collections.abc import errno import socket -import sys import unittest from test import support diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -1,7 +1,6 @@ import contextlib import io import os -import sys import importlib.util import posixpath import time diff --git a/Lib/tkinter/test/runtktests.py b/Lib/tkinter/test/runtktests.py --- a/Lib/tkinter/test/runtktests.py +++ b/Lib/tkinter/test/runtktests.py @@ -7,7 +7,6 @@ """ import os -import sys import unittest import importlib import test.support diff --git a/Lib/unittest/test/testmock/support.py b/Lib/unittest/test/testmock/support.py --- a/Lib/unittest/test/testmock/support.py +++ b/Lib/unittest/test/testmock/support.py @@ -1,5 +1,3 @@ -import sys - def is_instance(obj, klass): """Version of is_instance that doesn't access __class__""" return issubclass(type(obj), klass) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 00:55:43 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 24 Apr 2016 04:55:43 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI0OTEx?= =?utf-8?q?=3A_All_socket_objects_are_context_managers=3B_update_examples?= Message-ID: <20160424045542.4138.83494.66F23E7F@psf.io> https://hg.python.org/cpython/rev/d5f7980dd654 changeset: 101119:d5f7980dd654 branch: 3.5 parent: 101116:5ad93528c39c user: Martin Panter date: Sun Apr 24 04:24:36 2016 +0000 summary: Issue #24911: All socket objects are context managers; update examples files: Doc/library/socket.rst | 54 ++++++++++++------------ Doc/library/socketserver.rst | 13 +---- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -445,9 +445,6 @@ .. versionchanged:: 3.2 *source_address* was added. - .. versionchanged:: 3.2 - support for the :keyword:`with` statement was added. - .. function:: fromfd(fd, family, type, proto=0) @@ -831,6 +828,10 @@ :meth:`~socket.makefile`, these correspond to Unix system calls applicable to sockets. +.. versionchanged:: 3.2 + Support for the :term:`context manager` protocol was added. Exiting the + context manager is equivalent to calling :meth:`~socket.close`. + .. method:: socket.accept() @@ -1457,16 +1458,16 @@ HOST = '' # Symbolic name meaning all available interfaces PORT = 50007 # Arbitrary non-privileged port - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.bind((HOST, PORT)) - s.listen(1) - conn, addr = s.accept() - print('Connected by', addr) - while True: - data = conn.recv(1024) - if not data: break - conn.sendall(data) - conn.close() + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.bind((HOST, PORT)) + s.listen(1) + conn, addr = s.accept() + with conn: + print('Connected by', addr) + while True: + data = conn.recv(1024) + if not data: break + conn.sendall(data) :: @@ -1475,11 +1476,10 @@ HOST = 'daring.cwi.nl' # The remote host PORT = 50007 # The same port as used by the server - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((HOST, PORT)) - s.sendall(b'Hello, world') - data = s.recv(1024) - s.close() + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.connect((HOST, PORT)) + s.sendall(b'Hello, world') + data = s.recv(1024) print('Received', repr(data)) The next two examples are identical to the above two, but support both IPv4 and @@ -1516,12 +1516,12 @@ print('could not open socket') sys.exit(1) conn, addr = s.accept() - print('Connected by', addr) - while True: - data = conn.recv(1024) - if not data: break - conn.send(data) - conn.close() + with conn: + print('Connected by', addr) + while True: + data = conn.recv(1024) + if not data: break + conn.send(data) :: @@ -1549,9 +1549,9 @@ if s is None: print('could not open socket') sys.exit(1) - s.sendall(b'Hello, world') - data = s.recv(1024) - s.close() + with s: + s.sendall(b'Hello, world') + data = s.recv(1024) print('Received', repr(data)) diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst --- a/Doc/library/socketserver.rst +++ b/Doc/library/socketserver.rst @@ -465,17 +465,13 @@ data = " ".join(sys.argv[1:]) # Create a socket (SOCK_STREAM means a TCP socket) - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - - try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: # Connect to server and send data sock.connect((HOST, PORT)) sock.sendall(bytes(data + "\n", "utf-8")) # Receive data from the server and shut down received = str(sock.recv(1024), "utf-8") - finally: - sock.close() print("Sent: {}".format(data)) print("Received: {}".format(received)) @@ -574,14 +570,11 @@ pass def client(ip, port, message): - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.connect((ip, port)) - try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: + sock.connect((ip, port)) sock.sendall(bytes(message, 'ascii')) response = str(sock.recv(1024), 'ascii') print("Received: {}".format(response)) - finally: - sock.close() if __name__ == "__main__": # Port 0 means to select an arbitrary unused port -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 00:55:46 2016 From: python-checkins at python.org (martin.panter) Date: Sun, 24 Apr 2016 04:55:46 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2324911=3A_Merge_socket_context_manager_doc_from_?= =?utf-8?b?My41?= Message-ID: <20160424045543.110685.78175.6148081A@psf.io> https://hg.python.org/cpython/rev/711201953505 changeset: 101120:711201953505 parent: 101118:6958bbf7f0ec parent: 101119:d5f7980dd654 user: Martin Panter date: Sun Apr 24 04:55:00 2016 +0000 summary: Issue #24911: Merge socket context manager doc from 3.5 files: Doc/library/socket.rst | 54 ++++++++++++------------ Doc/library/socketserver.rst | 13 +---- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -445,9 +445,6 @@ .. versionchanged:: 3.2 *source_address* was added. - .. versionchanged:: 3.2 - support for the :keyword:`with` statement was added. - .. function:: fromfd(fd, family, type, proto=0) @@ -831,6 +828,10 @@ :meth:`~socket.makefile`, these correspond to Unix system calls applicable to sockets. +.. versionchanged:: 3.2 + Support for the :term:`context manager` protocol was added. Exiting the + context manager is equivalent to calling :meth:`~socket.close`. + .. method:: socket.accept() @@ -1461,16 +1462,16 @@ HOST = '' # Symbolic name meaning all available interfaces PORT = 50007 # Arbitrary non-privileged port - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.bind((HOST, PORT)) - s.listen(1) - conn, addr = s.accept() - print('Connected by', addr) - while True: - data = conn.recv(1024) - if not data: break - conn.sendall(data) - conn.close() + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.bind((HOST, PORT)) + s.listen(1) + conn, addr = s.accept() + with conn: + print('Connected by', addr) + while True: + data = conn.recv(1024) + if not data: break + conn.sendall(data) :: @@ -1479,11 +1480,10 @@ HOST = 'daring.cwi.nl' # The remote host PORT = 50007 # The same port as used by the server - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((HOST, PORT)) - s.sendall(b'Hello, world') - data = s.recv(1024) - s.close() + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.connect((HOST, PORT)) + s.sendall(b'Hello, world') + data = s.recv(1024) print('Received', repr(data)) The next two examples are identical to the above two, but support both IPv4 and @@ -1520,12 +1520,12 @@ print('could not open socket') sys.exit(1) conn, addr = s.accept() - print('Connected by', addr) - while True: - data = conn.recv(1024) - if not data: break - conn.send(data) - conn.close() + with conn: + print('Connected by', addr) + while True: + data = conn.recv(1024) + if not data: break + conn.send(data) :: @@ -1553,9 +1553,9 @@ if s is None: print('could not open socket') sys.exit(1) - s.sendall(b'Hello, world') - data = s.recv(1024) - s.close() + with s: + s.sendall(b'Hello, world') + data = s.recv(1024) print('Received', repr(data)) diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst --- a/Doc/library/socketserver.rst +++ b/Doc/library/socketserver.rst @@ -474,17 +474,13 @@ data = " ".join(sys.argv[1:]) # Create a socket (SOCK_STREAM means a TCP socket) - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - - try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: # Connect to server and send data sock.connect((HOST, PORT)) sock.sendall(bytes(data + "\n", "utf-8")) # Receive data from the server and shut down received = str(sock.recv(1024), "utf-8") - finally: - sock.close() print("Sent: {}".format(data)) print("Received: {}".format(received)) @@ -583,14 +579,11 @@ pass def client(ip, port, message): - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.connect((ip, port)) - try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: + sock.connect((ip, port)) sock.sendall(bytes(message, 'ascii')) response = str(sock.recv(1024), 'ascii') print("Received: {}".format(response)) - finally: - sock.close() if __name__ == "__main__": # Port 0 means to select an arbitrary unused port -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 02:59:40 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 24 Apr 2016 06:59:40 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2ODAx?= =?utf-8?q?=3A_shutil=2Eget=5Fterminal=5Fsize=28=29_now_handles_the_case_o?= =?utf-8?q?f_stdout_is?= Message-ID: <20160424065939.53265.36739.6F7CC26B@psf.io> https://hg.python.org/cpython/rev/df8652452d25 changeset: 101121:df8652452d25 branch: 3.5 parent: 101119:d5f7980dd654 user: Serhiy Storchaka date: Sun Apr 24 09:58:43 2016 +0300 summary: Issue #26801: shutil.get_terminal_size() now handles the case of stdout is reopened on Windows. Added tests for fallbacks. files: Lib/shutil.py | 4 +++- Lib/test/test_shutil.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletions(-) diff --git a/Lib/shutil.py b/Lib/shutil.py --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -1069,7 +1069,9 @@ if columns <= 0 or lines <= 0: try: size = os.get_terminal_size(sys.__stdout__.fileno()) - except (AttributeError, OSError): + except (AttributeError, ValueError, OSError): + # stdout is None, closed, detached, or not a terminal, or + # os.get_terminal_size() is unsupported size = os.terminal_size(fallback) if columns <= 0: columns = size.columns diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1828,14 +1828,24 @@ with support.EnvironmentVarGuard() as env: env['COLUMNS'] = '777' + del env['LINES'] size = shutil.get_terminal_size() self.assertEqual(size.columns, 777) with support.EnvironmentVarGuard() as env: + del env['COLUMNS'] env['LINES'] = '888' size = shutil.get_terminal_size() self.assertEqual(size.lines, 888) + def test_bad_environ(self): + with support.EnvironmentVarGuard() as env: + env['COLUMNS'] = 'xxx' + env['LINES'] = 'yyy' + size = shutil.get_terminal_size() + self.assertGreaterEqual(size.columns, 0) + self.assertGreaterEqual(size.lines, 0) + @unittest.skipUnless(os.isatty(sys.__stdout__.fileno()), "not on tty") @unittest.skipUnless(hasattr(os, 'get_terminal_size'), 'need os.get_terminal_size()') @@ -1859,6 +1869,25 @@ self.assertEqual(expected, actual) + def test_fallback(self): + with support.EnvironmentVarGuard() as env: + del env['LINES'] + del env['COLUMNS'] + + # sys.__stdout__ has no fileno() + with support.swap_attr(sys, '__stdout__', None): + size = shutil.get_terminal_size(fallback=(10, 20)) + self.assertEqual(size.columns, 10) + self.assertEqual(size.lines, 20) + + # sys.__stdout__ is not a terminal on Unix + # or fileno() not in (0, 1, 2) on Windows + with open(os.devnull, 'w') as f, \ + support.swap_attr(sys, '__stdout__', f): + size = shutil.get_terminal_size(fallback=(30, 40)) + self.assertEqual(size.columns, 30) + self.assertEqual(size.lines, 40) + class PublicAPITests(unittest.TestCase): """Ensures that the correct values are exposed in the public API.""" -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 02:59:40 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 24 Apr 2016 06:59:40 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogSXNzdWUgIzI2ODAxOiBzaHV0aWwuZ2V0X3Rlcm1pbmFsX3NpemUoKSBu?= =?utf-8?q?ow_handles_the_case_of_stdout_is?= Message-ID: <20160424065939.31058.42266.8792497B@psf.io> https://hg.python.org/cpython/rev/d6e6dcef674f changeset: 101122:d6e6dcef674f parent: 101120:711201953505 parent: 101121:df8652452d25 user: Serhiy Storchaka date: Sun Apr 24 09:59:17 2016 +0300 summary: Issue #26801: shutil.get_terminal_size() now handles the case of stdout is reopened on Windows. Added tests for fallbacks. files: Lib/shutil.py | 4 +++- Lib/test/test_shutil.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletions(-) diff --git a/Lib/shutil.py b/Lib/shutil.py --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -1072,7 +1072,9 @@ if columns <= 0 or lines <= 0: try: size = os.get_terminal_size(sys.__stdout__.fileno()) - except (AttributeError, OSError): + except (AttributeError, ValueError, OSError): + # stdout is None, closed, detached, or not a terminal, or + # os.get_terminal_size() is unsupported size = os.terminal_size(fallback) if columns <= 0: columns = size.columns diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1828,14 +1828,24 @@ with support.EnvironmentVarGuard() as env: env['COLUMNS'] = '777' + del env['LINES'] size = shutil.get_terminal_size() self.assertEqual(size.columns, 777) with support.EnvironmentVarGuard() as env: + del env['COLUMNS'] env['LINES'] = '888' size = shutil.get_terminal_size() self.assertEqual(size.lines, 888) + def test_bad_environ(self): + with support.EnvironmentVarGuard() as env: + env['COLUMNS'] = 'xxx' + env['LINES'] = 'yyy' + size = shutil.get_terminal_size() + self.assertGreaterEqual(size.columns, 0) + self.assertGreaterEqual(size.lines, 0) + @unittest.skipUnless(os.isatty(sys.__stdout__.fileno()), "not on tty") @unittest.skipUnless(hasattr(os, 'get_terminal_size'), 'need os.get_terminal_size()') @@ -1859,6 +1869,25 @@ self.assertEqual(expected, actual) + def test_fallback(self): + with support.EnvironmentVarGuard() as env: + del env['LINES'] + del env['COLUMNS'] + + # sys.__stdout__ has no fileno() + with support.swap_attr(sys, '__stdout__', None): + size = shutil.get_terminal_size(fallback=(10, 20)) + self.assertEqual(size.columns, 10) + self.assertEqual(size.lines, 20) + + # sys.__stdout__ is not a terminal on Unix + # or fileno() not in (0, 1, 2) on Windows + with open(os.devnull, 'w') as f, \ + support.swap_attr(sys, '__stdout__', f): + size = shutil.get_terminal_size(fallback=(30, 40)) + self.assertEqual(size.columns, 30) + self.assertEqual(size.lines, 40) + class PublicAPITests(unittest.TestCase): """Ensures that the correct values are exposed in the public API.""" -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 03:30:19 2016 From: python-checkins at python.org (victor.stinner) Date: Sun, 24 Apr 2016 07:30:19 +0000 Subject: [Python-checkins] =?utf-8?q?devguide=3A_motivations=3A_add_myself?= Message-ID: <20160424073002.112732.38013.8949960C@psf.io> https://hg.python.org/devguide/rev/217cad96131e changeset: 798:217cad96131e user: Victor Stinner date: Sun Apr 24 09:29:57 2016 +0200 summary: motivations: add myself files: motivations.rst | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/motivations.rst b/motivations.rst --- a/motivations.rst +++ b/motivations.rst @@ -216,3 +216,12 @@ QNX, and work on CPython ICC support funded by Intel). He would like to spend more of his (and his company's) time on open source work, and so is actively seeking additional such contract opportunities. + +.. topic:: Victor Stinner (France) + + * `Personal website `_ + * Red Hat (Senior Software Engineer) + + Victor is hacking the development version of CPython to make Python better + than ever. + -- Repository URL: https://hg.python.org/devguide From python-checkins at python.org Sun Apr 24 06:54:48 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 24 Apr 2016 10:54:48 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2323277=3A_Remove_m?= =?utf-8?q?ore_unused_sys_and_os_imports=2E?= Message-ID: <20160424105448.21448.84556.195FBF6E@psf.io> https://hg.python.org/cpython/rev/9d7f2615f7b3 changeset: 101123:9d7f2615f7b3 user: Serhiy Storchaka date: Sun Apr 24 13:25:01 2016 +0300 summary: Issue #23277: Remove more unused sys and os imports. files: Lib/distutils/tests/test_clean.py | 1 - Lib/distutils/tests/test_config.py | 1 - Lib/distutils/tests/test_install_data.py | 1 - Lib/distutils/tests/test_install_headers.py | 1 - Lib/distutils/tests/test_unixccompiler.py | 1 - Lib/lib2to3/tests/test_parser.py | 1 - Lib/lib2to3/tests/test_pytree.py | 1 - Lib/lib2to3/tests/test_util.py | 3 --- Lib/test/seq_tests.py | 1 - Lib/test/test_importlib/source/test_source_encoding.py | 1 - Lib/test/test_itertools.py | 1 - Lib/test/test_set.py | 1 - Lib/test/test_xmlrpc.py | 1 - 13 files changed, 0 insertions(+), 15 deletions(-) diff --git a/Lib/distutils/tests/test_clean.py b/Lib/distutils/tests/test_clean.py --- a/Lib/distutils/tests/test_clean.py +++ b/Lib/distutils/tests/test_clean.py @@ -1,5 +1,4 @@ """Tests for distutils.command.clean.""" -import sys import os import unittest import getpass diff --git a/Lib/distutils/tests/test_config.py b/Lib/distutils/tests/test_config.py --- a/Lib/distutils/tests/test_config.py +++ b/Lib/distutils/tests/test_config.py @@ -1,5 +1,4 @@ """Tests for distutils.pypirc.pypirc.""" -import sys import os import unittest import tempfile diff --git a/Lib/distutils/tests/test_install_data.py b/Lib/distutils/tests/test_install_data.py --- a/Lib/distutils/tests/test_install_data.py +++ b/Lib/distutils/tests/test_install_data.py @@ -1,5 +1,4 @@ """Tests for distutils.command.install_data.""" -import sys import os import unittest import getpass diff --git a/Lib/distutils/tests/test_install_headers.py b/Lib/distutils/tests/test_install_headers.py --- a/Lib/distutils/tests/test_install_headers.py +++ b/Lib/distutils/tests/test_install_headers.py @@ -1,5 +1,4 @@ """Tests for distutils.command.install_headers.""" -import sys import os import unittest import getpass diff --git a/Lib/distutils/tests/test_unixccompiler.py b/Lib/distutils/tests/test_unixccompiler.py --- a/Lib/distutils/tests/test_unixccompiler.py +++ b/Lib/distutils/tests/test_unixccompiler.py @@ -1,5 +1,4 @@ """Tests for distutils.unixccompiler.""" -import os import sys import unittest from test.support import EnvironmentVarGuard, run_unittest diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py --- a/Lib/lib2to3/tests/test_parser.py +++ b/Lib/lib2to3/tests/test_parser.py @@ -15,7 +15,6 @@ # Python imports import os -import sys import unittest import warnings import subprocess diff --git a/Lib/lib2to3/tests/test_pytree.py b/Lib/lib2to3/tests/test_pytree.py --- a/Lib/lib2to3/tests/test_pytree.py +++ b/Lib/lib2to3/tests/test_pytree.py @@ -11,7 +11,6 @@ from __future__ import with_statement -import sys import warnings # Testing imports diff --git a/Lib/lib2to3/tests/test_util.py b/Lib/lib2to3/tests/test_util.py --- a/Lib/lib2to3/tests/test_util.py +++ b/Lib/lib2to3/tests/test_util.py @@ -3,9 +3,6 @@ # Testing imports from . import support -# Python imports -import os.path - # Local imports from lib2to3.pytree import Node, Leaf from lib2to3 import fixer_util diff --git a/Lib/test/seq_tests.py b/Lib/test/seq_tests.py --- a/Lib/test/seq_tests.py +++ b/Lib/test/seq_tests.py @@ -318,7 +318,6 @@ self.assertEqual(id(s), id(s*1)) def test_bigrepeat(self): - import sys if sys.maxsize <= 2147483647: x = self.type2test([0]) x *= 2**16 diff --git a/Lib/test/test_importlib/source/test_source_encoding.py b/Lib/test/test_importlib/source/test_source_encoding.py --- a/Lib/test/test_importlib/source/test_source_encoding.py +++ b/Lib/test/test_importlib/source/test_source_encoding.py @@ -5,7 +5,6 @@ import codecs import importlib.util import re -import sys import types # Because sys.path gets essentially blanked, need to have unicodedata already # imported for the parser to use. diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -4,7 +4,6 @@ import weakref from decimal import Decimal from fractions import Fraction -import sys import operator import random import copy diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -6,7 +6,6 @@ import copy import pickle from random import randrange, shuffle -import sys import warnings import collections import collections.abc diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -9,7 +9,6 @@ import http.client import http, http.server import socket -import os import re import io import contextlib -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 06:55:00 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 24 Apr 2016 10:55:00 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2323277=3A_Remove_u?= =?utf-8?q?nused_support=2Erun=5Funittest_import=2E?= Message-ID: <20160424105448.1066.21552.39BEFF51@psf.io> https://hg.python.org/cpython/rev/abf3f0dcf2fd changeset: 101124:abf3f0dcf2fd user: Serhiy Storchaka date: Sun Apr 24 13:45:58 2016 +0300 summary: Issue #23277: Remove unused support.run_unittest import. files: Lib/test/test_codecmaps_cn.py | 1 - Lib/test/test_codecmaps_hk.py | 1 - Lib/test/test_codecmaps_kr.py | 1 - Lib/test/test_codecmaps_tw.py | 1 - Lib/test/test_dictcomps.py | 2 -- Lib/test/test_email/test_asian_codecs.py | 1 - Lib/test/test_file.py | 2 +- Lib/test/test_fileinput.py | 2 +- Lib/test/test_htmlparser.py | 1 - Lib/test/test_importlib/test_namespace_pkgs.py | 1 - Lib/test/test_iterlen.py | 1 - Lib/test/test_macpath.py | 2 +- Lib/test/test_sched.py | 1 - Lib/test/test_tools/test_pdeps.py | 1 - Lib/test/test_userstring.py | 2 +- 15 files changed, 4 insertions(+), 16 deletions(-) diff --git a/Lib/test/test_codecmaps_cn.py b/Lib/test/test_codecmaps_cn.py --- a/Lib/test/test_codecmaps_cn.py +++ b/Lib/test/test_codecmaps_cn.py @@ -3,7 +3,6 @@ # Codec mapping tests for PRC encodings # -from test import support from test import multibytecodec_support import unittest diff --git a/Lib/test/test_codecmaps_hk.py b/Lib/test/test_codecmaps_hk.py --- a/Lib/test/test_codecmaps_hk.py +++ b/Lib/test/test_codecmaps_hk.py @@ -3,7 +3,6 @@ # Codec mapping tests for HongKong encodings # -from test import support from test import multibytecodec_support import unittest diff --git a/Lib/test/test_codecmaps_kr.py b/Lib/test/test_codecmaps_kr.py --- a/Lib/test/test_codecmaps_kr.py +++ b/Lib/test/test_codecmaps_kr.py @@ -3,7 +3,6 @@ # Codec mapping tests for ROK encodings # -from test import support from test import multibytecodec_support import unittest diff --git a/Lib/test/test_codecmaps_tw.py b/Lib/test/test_codecmaps_tw.py --- a/Lib/test/test_codecmaps_tw.py +++ b/Lib/test/test_codecmaps_tw.py @@ -3,7 +3,6 @@ # Codec mapping tests for ROC encodings # -from test import support from test import multibytecodec_support import unittest diff --git a/Lib/test/test_dictcomps.py b/Lib/test/test_dictcomps.py --- a/Lib/test/test_dictcomps.py +++ b/Lib/test/test_dictcomps.py @@ -1,7 +1,5 @@ import unittest -from test import support - # For scope testing. g = "Global variable" diff --git a/Lib/test/test_email/test_asian_codecs.py b/Lib/test/test_email/test_asian_codecs.py --- a/Lib/test/test_email/test_asian_codecs.py +++ b/Lib/test/test_email/test_asian_codecs.py @@ -3,7 +3,6 @@ # email package unit tests for (optional) Asian codecs import unittest -from test.support import run_unittest from test.test_email.test_email import TestEmailBase from email.charset import Charset diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -7,7 +7,7 @@ import io import _pyio as pyio -from test.support import TESTFN, run_unittest +from test.support import TESTFN from collections import UserList class AutoFileTests: diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py --- a/Lib/test/test_fileinput.py +++ b/Lib/test/test_fileinput.py @@ -22,7 +22,7 @@ from io import BytesIO, StringIO from fileinput import FileInput, hook_encoded -from test.support import verbose, TESTFN, run_unittest, check_warnings +from test.support import verbose, TESTFN, check_warnings from test.support import unlink as safe_unlink from test import support from unittest import mock diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py --- a/Lib/test/test_htmlparser.py +++ b/Lib/test/test_htmlparser.py @@ -3,7 +3,6 @@ import html.parser import pprint import unittest -from test import support class EventCollector(html.parser.HTMLParser): diff --git a/Lib/test/test_importlib/test_namespace_pkgs.py b/Lib/test/test_importlib/test_namespace_pkgs.py --- a/Lib/test/test_importlib/test_namespace_pkgs.py +++ b/Lib/test/test_importlib/test_namespace_pkgs.py @@ -7,7 +7,6 @@ import unittest from test.test_importlib import util -from test.support import run_unittest # needed tests: # diff --git a/Lib/test/test_iterlen.py b/Lib/test/test_iterlen.py --- a/Lib/test/test_iterlen.py +++ b/Lib/test/test_iterlen.py @@ -42,7 +42,6 @@ """ import unittest -from test import support from itertools import repeat from collections import deque from operator import length_hint diff --git a/Lib/test/test_macpath.py b/Lib/test/test_macpath.py --- a/Lib/test/test_macpath.py +++ b/Lib/test/test_macpath.py @@ -1,5 +1,5 @@ import macpath -from test import support, test_genericpath +from test import test_genericpath import unittest diff --git a/Lib/test/test_sched.py b/Lib/test/test_sched.py --- a/Lib/test/test_sched.py +++ b/Lib/test/test_sched.py @@ -2,7 +2,6 @@ import sched import time import unittest -from test import support try: import threading except ImportError: diff --git a/Lib/test/test_tools/test_pdeps.py b/Lib/test/test_tools/test_pdeps.py --- a/Lib/test/test_tools/test_pdeps.py +++ b/Lib/test/test_tools/test_pdeps.py @@ -3,7 +3,6 @@ import os import unittest import tempfile -from test import support from test.test_tools import scriptsdir, skip_if_missing, import_tool diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py --- a/Lib/test/test_userstring.py +++ b/Lib/test/test_userstring.py @@ -3,7 +3,7 @@ import string import unittest -from test import support, string_tests +from test import string_tests from collections import UserString -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 14:41:25 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 24 Apr 2016 18:41:25 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2323277=3A_Remove_u?= =?utf-8?q?nused_imports_in_tests=2E?= Message-ID: <20160424184125.7711.46556.A075BCDC@psf.io> https://hg.python.org/cpython/rev/fa44d1bc9b68 changeset: 101125:fa44d1bc9b68 user: Serhiy Storchaka date: Sun Apr 24 21:41:02 2016 +0300 summary: Issue #23277: Remove unused imports in tests. files: Lib/ctypes/test/test_parameters.py | 6 +++--- Lib/distutils/tests/test_bdist_rpm.py | 4 ---- Lib/distutils/tests/test_build_ext.py | 1 - Lib/distutils/tests/test_clean.py | 1 - Lib/distutils/tests/test_config.py | 1 - Lib/distutils/tests/test_cygwinccompiler.py | 3 +-- Lib/distutils/tests/test_dep_util.py | 1 - Lib/distutils/tests/test_file_util.py | 1 - Lib/distutils/tests/test_install_data.py | 1 - Lib/distutils/tests/test_install_headers.py | 1 - Lib/distutils/tests/test_spawn.py | 5 ++--- Lib/lib2to3/tests/test_all_fixers.py | 1 - Lib/lib2to3/tests/test_fixers.py | 3 +-- Lib/lib2to3/tests/test_parser.py | 2 +- Lib/lib2to3/tests/test_pytree.py | 2 -- Lib/lib2to3/tests/test_refactor.py | 4 ---- Lib/test/audiotests.py | 1 - Lib/test/test__locale.py | 1 - Lib/test/test__osx_support.py | 1 - Lib/test/test_array.py | 2 -- Lib/test/test_asynchat.py | 1 - Lib/test/test_bigmem.py | 1 - Lib/test/test_binop.py | 2 +- Lib/test/test_buffer.py | 1 - Lib/test/test_codeccallbacks.py | 1 - Lib/test/test_codecs.py | 1 - Lib/test/test_cprofile.py | 2 +- Lib/test/test_csv.py | 3 --- Lib/test/test_dbm_gnu.py | 2 +- Lib/test/test_dbm_ndbm.py | 1 - Lib/test/test_devpoll.py | 2 +- Lib/test/test_doctest.py | 4 +--- Lib/test/test_dynamic.py | 1 - Lib/test/test_email/test_email.py | 1 - Lib/test/test_email/test_headerregistry.py | 1 - Lib/test/test_float.py | 1 - Lib/test/test_gdb.py | 1 - Lib/test/test_gettext.py | 1 - Lib/test/test_idle.py | 1 - Lib/test/test_importlib/extension/test_path_hook.py | 1 - Lib/test/test_importlib/import_/test_packages.py | 1 - Lib/test/test_importlib/test_locks.py | 1 - Lib/test/test_importlib/test_namespace_pkgs.py | 3 --- Lib/test/test_mailbox.py | 5 ----- Lib/test/test_mailcap.py | 1 - Lib/test/test_math.py | 1 - Lib/test/test_multiprocessing_main_handling.py | 3 +-- Lib/test/test_pdb.py | 1 - Lib/test/test_pep352.py | 1 - Lib/test/test_pickletools.py | 1 - Lib/test/test_plistlib.py | 1 - Lib/test/test_poplib.py | 1 - Lib/test/test_posix.py | 1 - Lib/test/test_posixpath.py | 1 - Lib/test/test_regrtest.py | 2 -- Lib/test/test_robotparser.py | 2 -- Lib/test/test_socket.py | 1 - Lib/test/test_socketserver.py | 2 -- Lib/test/test_subprocess.py | 3 --- Lib/test/test_sunau.py | 1 - Lib/test/test_telnetlib.py | 1 - Lib/test/test_threading.py | 2 +- Lib/test/test_tools/test_gprof2html.py | 3 +-- Lib/test/test_tools/test_md5sum.py | 2 +- Lib/test/test_tools/test_pdeps.py | 2 +- Lib/test/test_urllib2.py | 2 +- Lib/test/test_userstring.py | 1 - Lib/test/test_uu.py | 1 - Lib/test/test_venv.py | 1 - Lib/test/test_wave.py | 1 - Lib/test/test_weakset.py | 7 +------ Lib/test/test_xml_etree_c.py | 2 +- Lib/test/test_xmlrpc.py | 1 - Lib/test/test_xmlrpc_net.py | 2 -- Lib/test/test_zipimport_support.py | 1 - Lib/tkinter/test/runtktests.py | 1 - Lib/tkinter/test/test_ttk/test_functions.py | 1 - Lib/unittest/test/testmock/testmagicmethods.py | 1 - Lib/unittest/test/testmock/testpatch.py | 4 ++-- 79 files changed, 23 insertions(+), 117 deletions(-) diff --git a/Lib/ctypes/test/test_parameters.py b/Lib/ctypes/test/test_parameters.py --- a/Lib/ctypes/test/test_parameters.py +++ b/Lib/ctypes/test/test_parameters.py @@ -49,7 +49,7 @@ # XXX Replace by c_char_p tests def test_cstrings(self): - from ctypes import c_char_p, byref + from ctypes import c_char_p # c_char_p.from_param on a Python String packs the string # into a cparam object @@ -68,7 +68,7 @@ @need_symbol('c_wchar_p') def test_cw_strings(self): - from ctypes import byref, c_wchar_p + from ctypes import c_wchar_p c_wchar_p.from_param("123") @@ -98,7 +98,7 @@ def test_byref_pointer(self): # The from_param class method of POINTER(typ) classes accepts what is # returned by byref(obj), it type(obj) == typ - from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref + from ctypes import c_short, c_uint, c_int, c_long, POINTER, byref LPINT = POINTER(c_int) LPINT.from_param(byref(c_int(42))) diff --git a/Lib/distutils/tests/test_bdist_rpm.py b/Lib/distutils/tests/test_bdist_rpm.py --- a/Lib/distutils/tests/test_bdist_rpm.py +++ b/Lib/distutils/tests/test_bdist_rpm.py @@ -3,16 +3,12 @@ import unittest import sys import os -import tempfile -import shutil from test.support import run_unittest from distutils.core import Distribution from distutils.command.bdist_rpm import bdist_rpm from distutils.tests import support from distutils.spawn import find_executable -from distutils import spawn -from distutils.errors import DistutilsExecError SETUP_PY = """\ from distutils.core import setup diff --git a/Lib/distutils/tests/test_build_ext.py b/Lib/distutils/tests/test_build_ext.py --- a/Lib/distutils/tests/test_build_ext.py +++ b/Lib/distutils/tests/test_build_ext.py @@ -166,7 +166,6 @@ cmd = self.build_ext(dist) cmd.finalize_options() - from distutils import sysconfig py_include = sysconfig.get_python_inc() self.assertIn(py_include, cmd.include_dirs) diff --git a/Lib/distutils/tests/test_clean.py b/Lib/distutils/tests/test_clean.py --- a/Lib/distutils/tests/test_clean.py +++ b/Lib/distutils/tests/test_clean.py @@ -1,7 +1,6 @@ """Tests for distutils.command.clean.""" import os import unittest -import getpass from distutils.command.clean import clean from distutils.tests import support diff --git a/Lib/distutils/tests/test_config.py b/Lib/distutils/tests/test_config.py --- a/Lib/distutils/tests/test_config.py +++ b/Lib/distutils/tests/test_config.py @@ -1,7 +1,6 @@ """Tests for distutils.pypirc.pypirc.""" import os import unittest -import tempfile from distutils.core import PyPIRCCommand from distutils.core import Distribution diff --git a/Lib/distutils/tests/test_cygwinccompiler.py b/Lib/distutils/tests/test_cygwinccompiler.py --- a/Lib/distutils/tests/test_cygwinccompiler.py +++ b/Lib/distutils/tests/test_cygwinccompiler.py @@ -3,11 +3,10 @@ import sys import os from io import BytesIO -import subprocess from test.support import run_unittest from distutils import cygwinccompiler -from distutils.cygwinccompiler import (CygwinCCompiler, check_config_h, +from distutils.cygwinccompiler import (check_config_h, CONFIG_H_OK, CONFIG_H_NOTOK, CONFIG_H_UNCERTAIN, get_versions, get_msvcr) diff --git a/Lib/distutils/tests/test_dep_util.py b/Lib/distutils/tests/test_dep_util.py --- a/Lib/distutils/tests/test_dep_util.py +++ b/Lib/distutils/tests/test_dep_util.py @@ -1,7 +1,6 @@ """Tests for distutils.dep_util.""" import unittest import os -import time from distutils.dep_util import newer, newer_pairwise, newer_group from distutils.errors import DistutilsFileError diff --git a/Lib/distutils/tests/test_file_util.py b/Lib/distutils/tests/test_file_util.py --- a/Lib/distutils/tests/test_file_util.py +++ b/Lib/distutils/tests/test_file_util.py @@ -1,7 +1,6 @@ """Tests for distutils.file_util.""" import unittest import os -import shutil import errno from unittest.mock import patch diff --git a/Lib/distutils/tests/test_install_data.py b/Lib/distutils/tests/test_install_data.py --- a/Lib/distutils/tests/test_install_data.py +++ b/Lib/distutils/tests/test_install_data.py @@ -1,7 +1,6 @@ """Tests for distutils.command.install_data.""" import os import unittest -import getpass from distutils.command.install_data import install_data from distutils.tests import support diff --git a/Lib/distutils/tests/test_install_headers.py b/Lib/distutils/tests/test_install_headers.py --- a/Lib/distutils/tests/test_install_headers.py +++ b/Lib/distutils/tests/test_install_headers.py @@ -1,7 +1,6 @@ """Tests for distutils.command.install_headers.""" import os import unittest -import getpass from distutils.command.install_headers import install_headers from distutils.tests import support diff --git a/Lib/distutils/tests/test_spawn.py b/Lib/distutils/tests/test_spawn.py --- a/Lib/distutils/tests/test_spawn.py +++ b/Lib/distutils/tests/test_spawn.py @@ -1,11 +1,10 @@ """Tests for distutils.spawn.""" import unittest import os -import time -from test.support import captured_stdout, run_unittest +from test.support import run_unittest from distutils.spawn import _nt_quote_args -from distutils.spawn import spawn, find_executable +from distutils.spawn import spawn from distutils.errors import DistutilsExecError from distutils.tests import support diff --git a/Lib/lib2to3/tests/test_all_fixers.py b/Lib/lib2to3/tests/test_all_fixers.py --- a/Lib/lib2to3/tests/test_all_fixers.py +++ b/Lib/lib2to3/tests/test_all_fixers.py @@ -10,7 +10,6 @@ import test.support # Local imports -from lib2to3 import refactor from . import support diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py --- a/Lib/lib2to3/tests/test_fixers.py +++ b/Lib/lib2to3/tests/test_fixers.py @@ -2,12 +2,11 @@ # Python imports import os -import unittest from itertools import chain from operator import itemgetter # Local imports -from lib2to3 import pygram, pytree, refactor, fixer_util +from lib2to3 import pygram, fixer_util from lib2to3.tests import support diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py --- a/Lib/lib2to3/tests/test_parser.py +++ b/Lib/lib2to3/tests/test_parser.py @@ -10,7 +10,7 @@ # Testing imports from . import support -from .support import driver, test_dir +from .support import driver from test.support import verbose # Python imports diff --git a/Lib/lib2to3/tests/test_pytree.py b/Lib/lib2to3/tests/test_pytree.py --- a/Lib/lib2to3/tests/test_pytree.py +++ b/Lib/lib2to3/tests/test_pytree.py @@ -11,8 +11,6 @@ from __future__ import with_statement -import warnings - # Testing imports from . import support diff --git a/Lib/lib2to3/tests/test_refactor.py b/Lib/lib2to3/tests/test_refactor.py --- a/Lib/lib2to3/tests/test_refactor.py +++ b/Lib/lib2to3/tests/test_refactor.py @@ -7,18 +7,14 @@ import sys import os import codecs -import operator import io import tempfile import shutil import unittest -import warnings from lib2to3 import refactor, pygram, fixer_base from lib2to3.pgen2 import token -from . import support - TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data") FIXER_DIR = os.path.join(TEST_DATA_DIR, "fixers") diff --git a/Lib/test/audiotests.py b/Lib/test/audiotests.py --- a/Lib/test/audiotests.py +++ b/Lib/test/audiotests.py @@ -1,5 +1,4 @@ from test.support import findfile, TESTFN, unlink -import unittest import array import io import pickle diff --git a/Lib/test/test__locale.py b/Lib/test/test__locale.py --- a/Lib/test/test__locale.py +++ b/Lib/test/test__locale.py @@ -4,7 +4,6 @@ except ImportError: nl_langinfo = None -import codecs import locale import sys import unittest diff --git a/Lib/test/test__osx_support.py b/Lib/test/test__osx_support.py --- a/Lib/test/test__osx_support.py +++ b/Lib/test/test__osx_support.py @@ -4,7 +4,6 @@ import os import platform -import shutil import stat import sys import unittest diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -7,8 +7,6 @@ import weakref import pickle import operator -import io -import math import struct import sys import warnings diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py --- a/Lib/test/test_asynchat.py +++ b/Lib/test/test_asynchat.py @@ -12,7 +12,6 @@ import sys import time import unittest -import warnings import unittest.mock try: import threading diff --git a/Lib/test/test_bigmem.py b/Lib/test/test_bigmem.py --- a/Lib/test/test_bigmem.py +++ b/Lib/test/test_bigmem.py @@ -14,7 +14,6 @@ import unittest import operator import sys -import functools # These tests all use one of the bigmemtest decorators to indicate how much # memory they use and how much memory they need to be even meaningful. The diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py --- a/Lib/test/test_binop.py +++ b/Lib/test/test_binop.py @@ -2,7 +2,7 @@ import unittest from test import support -from operator import eq, ne, lt, gt, le, ge +from operator import eq, le from abc import ABCMeta def gcd(a, b): diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -16,7 +16,6 @@ from test import support from itertools import permutations, product from random import randrange, sample, choice -from sysconfig import get_config_var import warnings import sys, array, io from decimal import Decimal diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py --- a/Lib/test/test_codeccallbacks.py +++ b/Lib/test/test_codeccallbacks.py @@ -4,7 +4,6 @@ import test.support import unicodedata import unittest -import warnings class PosReturn: # this can be used for configurable callbacks diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -4,7 +4,6 @@ import locale import sys import unittest -import warnings import encodings from test import support diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py --- a/Lib/test/test_cprofile.py +++ b/Lib/test/test_cprofile.py @@ -6,7 +6,7 @@ # rip off all interesting stuff from test_profile import cProfile from test.test_profile import ProfileTest, regenerate_expected_output -from test.profilee import testfunc + class CProfileTest(ProfileTest): profilerclass = cProfile.Profile diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -2,7 +2,6 @@ # csv package unit tests import copy -import io import sys import unittest from io import StringIO @@ -1078,7 +1077,6 @@ "Fran?ois Pinard"] def test_unicode_read(self): - import io with TemporaryFile("w+", newline='', encoding="utf-8") as fileobj: fileobj.write(",".join(self.names) + "\r\n") fileobj.seek(0) @@ -1087,7 +1085,6 @@ def test_unicode_write(self): - import io with TemporaryFile("w+", newline='', encoding="utf-8") as fileobj: writer = csv.writer(fileobj) writer.writerow(self.names) diff --git a/Lib/test/test_dbm_gnu.py b/Lib/test/test_dbm_gnu.py --- a/Lib/test/test_dbm_gnu.py +++ b/Lib/test/test_dbm_gnu.py @@ -2,7 +2,7 @@ gdbm = support.import_module("dbm.gnu") #skip if not supported import unittest import os -from test.support import verbose, TESTFN, unlink +from test.support import TESTFN, unlink filename = TESTFN diff --git a/Lib/test/test_dbm_ndbm.py b/Lib/test/test_dbm_ndbm.py --- a/Lib/test/test_dbm_ndbm.py +++ b/Lib/test/test_dbm_ndbm.py @@ -1,7 +1,6 @@ from test import support support.import_module("dbm.ndbm") #skip if not supported import unittest -import random import dbm.ndbm from dbm.ndbm import error diff --git a/Lib/test/test_devpoll.py b/Lib/test/test_devpoll.py --- a/Lib/test/test_devpoll.py +++ b/Lib/test/test_devpoll.py @@ -6,7 +6,7 @@ import random import select import unittest -from test.support import TESTFN, run_unittest, cpython_only +from test.support import run_unittest, cpython_only if not hasattr(select, 'devpoll') : raise unittest.SkipTest('test works only on Solaris OS family') diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -1876,7 +1876,6 @@ To demonstrate this, we'll create a fake standard input that captures our debugger input: - >>> import tempfile >>> real_stdin = sys.stdin >>> sys.stdin = _FakeInput([ ... 'print(x)', # print data defined by the example @@ -1917,7 +1916,7 @@ ... finally: ... sys.stdin = real_stdin --Return-- - > (3)calls_set_trace()->None + > (3)calls_set_trace()->None -> import pdb; pdb.set_trace() (Pdb) print(y) 2 @@ -2804,7 +2803,6 @@ ... _ = f.write(" 'abc def'\n") ... _ = f.write("\n") ... _ = f.write(' \"\"\"\n') - ... import shutil ... rc1, out1, err1 = script_helper.assert_python_failure( ... '-m', 'doctest', fn, fn2, TERM='') ... rc2, out2, err2 = script_helper.assert_python_ok( diff --git a/Lib/test/test_dynamic.py b/Lib/test/test_dynamic.py --- a/Lib/test/test_dynamic.py +++ b/Lib/test/test_dynamic.py @@ -1,7 +1,6 @@ # Test the most dynamic corner cases of Python's runtime semantics. import builtins -import contextlib import unittest from test.support import swap_item, swap_attr diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -3421,7 +3421,6 @@ class TestFeedParsers(TestEmailBase): def parse(self, chunks): - from email.feedparser import FeedParser feedparser = FeedParser() for chunk in chunks: feedparser.feed(chunk) diff --git a/Lib/test/test_email/test_headerregistry.py b/Lib/test/test_email/test_headerregistry.py --- a/Lib/test/test_email/test_headerregistry.py +++ b/Lib/test/test_email/test_headerregistry.py @@ -1,7 +1,6 @@ import datetime import textwrap import unittest -import types from email import errors from email import policy from email.message import Message diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -1,6 +1,5 @@ import fractions -import math import operator import os import random diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -5,7 +5,6 @@ import os import re -import pprint import subprocess import sys import sysconfig diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -1,6 +1,5 @@ import os import base64 -import shutil import gettext import unittest diff --git a/Lib/test/test_idle.py b/Lib/test/test_idle.py --- a/Lib/test/test_idle.py +++ b/Lib/test/test_idle.py @@ -1,5 +1,4 @@ import unittest -from test import support from test.support import import_module # Skip test if _thread or _tkinter wasn't built or idlelib was deleted. diff --git a/Lib/test/test_importlib/extension/test_path_hook.py b/Lib/test/test_importlib/extension/test_path_hook.py --- a/Lib/test/test_importlib/extension/test_path_hook.py +++ b/Lib/test/test_importlib/extension/test_path_hook.py @@ -2,7 +2,6 @@ machinery = util.import_importlib('importlib.machinery') -import collections import unittest diff --git a/Lib/test/test_importlib/import_/test_packages.py b/Lib/test/test_importlib/import_/test_packages.py --- a/Lib/test/test_importlib/import_/test_packages.py +++ b/Lib/test/test_importlib/import_/test_packages.py @@ -1,7 +1,6 @@ from .. import util import sys import unittest -import importlib from test import support diff --git a/Lib/test/test_importlib/test_locks.py b/Lib/test/test_importlib/test_locks.py --- a/Lib/test/test_importlib/test_locks.py +++ b/Lib/test/test_importlib/test_locks.py @@ -3,7 +3,6 @@ init = test_util.import_importlib('importlib') import sys -import time import unittest import weakref diff --git a/Lib/test/test_importlib/test_namespace_pkgs.py b/Lib/test/test_importlib/test_namespace_pkgs.py --- a/Lib/test/test_importlib/test_namespace_pkgs.py +++ b/Lib/test/test_importlib/test_namespace_pkgs.py @@ -1,9 +1,6 @@ import contextlib -import importlib.abc -import importlib.machinery import os import sys -import types import unittest from test.test_importlib import util diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -7,17 +7,12 @@ import email.message import re import io -import shutil import tempfile from test import support import unittest import textwrap import mailbox import glob -try: - import fcntl -except ImportError: - pass class TestBase: diff --git a/Lib/test/test_mailcap.py b/Lib/test/test_mailcap.py --- a/Lib/test/test_mailcap.py +++ b/Lib/test/test_mailcap.py @@ -1,6 +1,5 @@ import mailcap import os -import shutil import test.support import unittest diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -6,7 +6,6 @@ import unittest import math import os -import platform import sys import struct import sysconfig diff --git a/Lib/test/test_multiprocessing_main_handling.py b/Lib/test/test_multiprocessing_main_handling.py --- a/Lib/test/test_multiprocessing_main_handling.py +++ b/Lib/test/test_multiprocessing_main_handling.py @@ -6,7 +6,6 @@ import importlib import importlib.machinery -import zipimport import unittest import sys import os @@ -15,7 +14,7 @@ from test.support.script_helper import ( make_pkg, make_script, make_zip_pkg, make_zip_script, - assert_python_ok, assert_python_failure, spawn_python, kill_python) + assert_python_ok) # Look up which start methods are available to test import multiprocessing diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -558,7 +558,6 @@ def pdb_invoke(method, arg): """Run pdb.method(arg).""" - import pdb getattr(pdb.Pdb(nosigint=True), method)(arg) diff --git a/Lib/test/test_pep352.py b/Lib/test/test_pep352.py --- a/Lib/test/test_pep352.py +++ b/Lib/test/test_pep352.py @@ -1,6 +1,5 @@ import unittest import builtins -import warnings import os from platform import system as platform_system diff --git a/Lib/test/test_pickletools.py b/Lib/test/test_pickletools.py --- a/Lib/test/test_pickletools.py +++ b/Lib/test/test_pickletools.py @@ -1,4 +1,3 @@ -import struct import pickle import pickletools from test import support diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -7,7 +7,6 @@ import codecs import binascii import collections -import struct from test import support from io import BytesIO diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py --- a/Lib/test/test_poplib.py +++ b/Lib/test/test_poplib.py @@ -8,7 +8,6 @@ import asynchat import socket import os -import time import errno from unittest import TestCase, skipUnless diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -11,7 +11,6 @@ import os import platform import pwd -import shutil import stat import tempfile import unittest diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -1,4 +1,3 @@ -import itertools import os import posixpath import unittest diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py --- a/Lib/test/test_regrtest.py +++ b/Lib/test/test_regrtest.py @@ -4,10 +4,8 @@ Note: test_regrtest cannot be run twice in parallel. """ -import argparse import contextlib import faulthandler -import getopt import io import os.path import platform diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py --- a/Lib/test/test_robotparser.py +++ b/Lib/test/test_robotparser.py @@ -2,8 +2,6 @@ import unittest import urllib.robotparser from collections import namedtuple -from urllib.error import URLError, HTTPError -from urllib.request import urlopen from test import support from http.server import BaseHTTPRequestHandler, HTTPServer try: diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -13,7 +13,6 @@ import sys import os import array -import platform import contextlib from weakref import proxy import signal diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -7,8 +7,6 @@ import select import signal import socket -import select -import errno import tempfile import unittest import socketserver diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -5,15 +5,12 @@ import sys import signal import io -import locale import os import errno import tempfile import time -import re import selectors import sysconfig -import warnings import select import shutil import gc diff --git a/Lib/test/test_sunau.py b/Lib/test/test_sunau.py --- a/Lib/test/test_sunau.py +++ b/Lib/test/test_sunau.py @@ -1,4 +1,3 @@ -from test.support import TESTFN import unittest from test import audiotests from audioop import byteswap diff --git a/Lib/test/test_telnetlib.py b/Lib/test/test_telnetlib.py --- a/Lib/test/test_telnetlib.py +++ b/Lib/test/test_telnetlib.py @@ -1,7 +1,6 @@ import socket import selectors import telnetlib -import time import contextlib from test import support diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -3,7 +3,7 @@ """ import test.support -from test.support import verbose, strip_python_stderr, import_module, cpython_only +from test.support import verbose, import_module, cpython_only from test.support.script_helper import assert_python_ok, assert_python_failure import random diff --git a/Lib/test/test_tools/test_gprof2html.py b/Lib/test/test_tools/test_gprof2html.py --- a/Lib/test/test_tools/test_gprof2html.py +++ b/Lib/test/test_tools/test_gprof2html.py @@ -2,12 +2,11 @@ import os import sys -import importlib import unittest from unittest import mock import tempfile -from test.test_tools import scriptsdir, skip_if_missing, import_tool +from test.test_tools import skip_if_missing, import_tool skip_if_missing() diff --git a/Lib/test/test_tools/test_md5sum.py b/Lib/test/test_tools/test_md5sum.py --- a/Lib/test/test_tools/test_md5sum.py +++ b/Lib/test/test_tools/test_md5sum.py @@ -5,7 +5,7 @@ from test import support from test.support.script_helper import assert_python_ok, assert_python_failure -from test.test_tools import scriptsdir, import_tool, skip_if_missing +from test.test_tools import scriptsdir, skip_if_missing skip_if_missing() diff --git a/Lib/test/test_tools/test_pdeps.py b/Lib/test/test_tools/test_pdeps.py --- a/Lib/test/test_tools/test_pdeps.py +++ b/Lib/test/test_tools/test_pdeps.py @@ -4,7 +4,7 @@ import unittest import tempfile -from test.test_tools import scriptsdir, skip_if_missing, import_tool +from test.test_tools import skip_if_missing, import_tool skip_if_missing() diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -462,7 +462,7 @@ self.requests = [] def http_open(self, req): - import email, http.client, copy + import email, copy self.requests.append(copy.deepcopy(req)) if self._count == 0: self._count = self._count + 1 diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py --- a/Lib/test/test_userstring.py +++ b/Lib/test/test_userstring.py @@ -1,7 +1,6 @@ # UserString is a wrapper around the native builtin string type. # UserString instances should behave similar to builtin string objects. -import string import unittest from test import string_tests diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py --- a/Lib/test/test_uu.py +++ b/Lib/test/test_uu.py @@ -8,7 +8,6 @@ import sys, os import uu -from io import BytesIO import io plaintext = b"The smooth-scaled python crept over the sleeping dog\n" diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -15,7 +15,6 @@ import tempfile from test.support import (captured_stdout, captured_stderr, can_symlink, EnvironmentVarGuard, rmtree) -import textwrap import unittest import venv diff --git a/Lib/test/test_wave.py b/Lib/test/test_wave.py --- a/Lib/test/test_wave.py +++ b/Lib/test/test_wave.py @@ -1,4 +1,3 @@ -from test.support import TESTFN import unittest from test import audiotests from test import support diff --git a/Lib/test/test_weakset.py b/Lib/test/test_weakset.py --- a/Lib/test/test_weakset.py +++ b/Lib/test/test_weakset.py @@ -1,11 +1,6 @@ import unittest -from weakref import proxy, ref, WeakSet -import operator -import copy +from weakref import WeakSet import string -from random import randrange, shuffle -import warnings -import collections from collections import UserString as ustr import gc import contextlib diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -108,7 +108,7 @@ struct.calcsize('8P')) def test_main(): - from test import test_xml_etree, test_xml_etree_c + from test import test_xml_etree # Run the tests specific to the C implementation support.run_unittest( diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -1132,7 +1132,6 @@ """A variation on support.captured_stdout() which gives a text stream having a `buffer` attribute. """ - import io orig_stdout = sys.stdout sys.stdout = io.TextIOWrapper(io.BytesIO(), encoding=encoding) try: diff --git a/Lib/test/test_xmlrpc_net.py b/Lib/test/test_xmlrpc_net.py --- a/Lib/test/test_xmlrpc_net.py +++ b/Lib/test/test_xmlrpc_net.py @@ -1,6 +1,4 @@ import collections.abc -import errno -import socket import unittest from test import support diff --git a/Lib/test/test_zipimport_support.py b/Lib/test/test_zipimport_support.py --- a/Lib/test/test_zipimport_support.py +++ b/Lib/test/test_zipimport_support.py @@ -12,7 +12,6 @@ import doctest import inspect import linecache -import pdb import unittest from test.support.script_helper import (spawn_python, kill_python, assert_python_ok, make_script, make_zip_script) diff --git a/Lib/tkinter/test/runtktests.py b/Lib/tkinter/test/runtktests.py --- a/Lib/tkinter/test/runtktests.py +++ b/Lib/tkinter/test/runtktests.py @@ -7,7 +7,6 @@ """ import os -import unittest import importlib import test.support diff --git a/Lib/tkinter/test/test_ttk/test_functions.py b/Lib/tkinter/test/test_ttk/test_functions.py --- a/Lib/tkinter/test/test_ttk/test_functions.py +++ b/Lib/tkinter/test/test_ttk/test_functions.py @@ -1,6 +1,5 @@ # -*- encoding: utf-8 -*- import unittest -import tkinter from tkinter import ttk class MockTkApp: diff --git a/Lib/unittest/test/testmock/testmagicmethods.py b/Lib/unittest/test/testmock/testmagicmethods.py --- a/Lib/unittest/test/testmock/testmagicmethods.py +++ b/Lib/unittest/test/testmock/testmagicmethods.py @@ -1,5 +1,4 @@ import unittest -import inspect import sys from unittest.mock import Mock, MagicMock, _magics diff --git a/Lib/unittest/test/testmock/testpatch.py b/Lib/unittest/test/testmock/testpatch.py --- a/Lib/unittest/test/testmock/testpatch.py +++ b/Lib/unittest/test/testmock/testpatch.py @@ -10,9 +10,9 @@ from unittest.test.testmock.support import SomeClass, is_instance from unittest.mock import ( - NonCallableMock, CallableMixin, patch, sentinel, + NonCallableMock, CallableMixin, sentinel, MagicMock, Mock, NonCallableMagicMock, patch, _patch, - DEFAULT, call, _get_target, _patch + DEFAULT, call, _get_target ) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 16:33:32 2016 From: python-checkins at python.org (victor.stinner) Date: Sun, 24 Apr 2016 20:33:32 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326249=3A_Mention_?= =?utf-8?q?PyMem=5FMalloc=28=29_change_in_What=27s_New_in_Python_3=2E6_in_?= =?utf-8?q?the?= Message-ID: <20160424203332.30496.10134.0256D990@psf.io> https://hg.python.org/cpython/rev/7acad5d8f80e changeset: 101126:7acad5d8f80e user: Victor Stinner date: Sun Apr 24 22:33:26 2016 +0200 summary: Issue #26249: Mention PyMem_Malloc() change in What's New in Python 3.6 in the Optimizations section. files: Doc/whatsnew/3.6.rst | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -388,6 +388,13 @@ * Optimize ``bytes.replace(b'', b'.')`` and ``bytearray.replace(b'', b'.')``: up to 80% faster. (Contributed by Josh Snider in :issue:`26574`). +* Allocator functions of the :c:func:`PyMem_Malloc` domain + (:c:data:`PYMEM_DOMAIN_MEM`) now use the :ref:`pymalloc memory allocator + ` instead of :c:func:`malloc` function of the C library. The + pymalloc allocator is optimized for objects smaller or equal to 512 bytes + with a short lifetime, and use :c:func:`malloc` for larger memory blocks. + (Contributed by Victor Stinner in :issue:`26249`). + Build and C API Changes ======================= -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 17:12:54 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 24 Apr 2016 21:12:54 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_Remove_duplica?= =?utf-8?q?ted_tests=2E?= Message-ID: <20160424211254.15804.55224.771F1EC8@psf.io> https://hg.python.org/cpython/rev/dd223c585fb6 changeset: 101128:dd223c585fb6 branch: 3.5 parent: 101121:df8652452d25 user: Serhiy Storchaka date: Sun Apr 24 23:50:18 2016 +0300 summary: Remove duplicated tests. There were duplicated methods with the same name and body. files: Lib/test/test_pyexpat.py | 6 ------ Tools/clinic/clinic_test.py | 10 ---------- 2 files changed, 0 insertions(+), 16 deletions(-) diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py --- a/Lib/test/test_pyexpat.py +++ b/Lib/test/test_pyexpat.py @@ -42,12 +42,6 @@ self.parser.specified_attributes = x self.assertIs(self.parser.specified_attributes, bool(x)) - def test_specified_attributes(self): - self.assertIs(self.parser.specified_attributes, False) - for x in 0, 1, 2, 0: - self.parser.specified_attributes = x - self.assertIs(self.parser.specified_attributes, bool(x)) - def test_invalid_attributes(self): with self.assertRaises(AttributeError): self.parser.returns_unicode = 1 diff --git a/Tools/clinic/clinic_test.py b/Tools/clinic/clinic_test.py --- a/Tools/clinic/clinic_test.py +++ b/Tools/clinic/clinic_test.py @@ -3,7 +3,6 @@ # Licensed to the PSF under a contributor agreement. # -import builtins import clinic from clinic import DSLParser import collections @@ -747,15 +746,6 @@ Nested docstring here, goeth. """.strip(), function.docstring) - def test_parser_regression_special_character_in_parameter_column_of_docstring_first_line(self): - function = self.parse_function(""" -module os -os.stat - path: str -This/used to break Clinic! -""") - self.assertEqual("stat($module, /, path)\n--\n\nThis/used to break Clinic!", function.docstring) - def test_directive(self): c = FakeClinic() parser = DSLParser(c) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 17:12:54 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 24 Apr 2016 21:12:54 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy41?= Message-ID: <20160424211254.5836.56539.82186E7D@psf.io> https://hg.python.org/cpython/rev/323f226136f4 changeset: 101129:323f226136f4 parent: 101127:9348e88c89c8 parent: 101128:dd223c585fb6 user: Serhiy Storchaka date: Sun Apr 24 23:53:16 2016 +0300 summary: Merge 3.5 files: Lib/test/test_pyexpat.py | 6 ------ Tools/clinic/clinic_test.py | 10 ---------- 2 files changed, 0 insertions(+), 16 deletions(-) diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py --- a/Lib/test/test_pyexpat.py +++ b/Lib/test/test_pyexpat.py @@ -42,12 +42,6 @@ self.parser.specified_attributes = x self.assertIs(self.parser.specified_attributes, bool(x)) - def test_specified_attributes(self): - self.assertIs(self.parser.specified_attributes, False) - for x in 0, 1, 2, 0: - self.parser.specified_attributes = x - self.assertIs(self.parser.specified_attributes, bool(x)) - def test_invalid_attributes(self): with self.assertRaises(AttributeError): self.parser.returns_unicode = 1 diff --git a/Tools/clinic/clinic_test.py b/Tools/clinic/clinic_test.py --- a/Tools/clinic/clinic_test.py +++ b/Tools/clinic/clinic_test.py @@ -3,7 +3,6 @@ # Licensed to the PSF under a contributor agreement. # -import builtins import clinic from clinic import DSLParser import collections @@ -747,15 +746,6 @@ Nested docstring here, goeth. """.strip(), function.docstring) - def test_parser_regression_special_character_in_parameter_column_of_docstring_first_line(self): - function = self.parse_function(""" -module os -os.stat - path: str -This/used to break Clinic! -""") - self.assertEqual("stat($module, /, path)\n--\n\nThis/used to break Clinic!", function.docstring) - def test_directive(self): c = FakeClinic() parser = DSLParser(c) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 17:12:54 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 24 Apr 2016 21:12:54 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Remove_unused_support=2Eru?= =?utf-8?q?n=5Funittest_imports=2E?= Message-ID: <20160424211254.15834.25730.AC336F54@psf.io> https://hg.python.org/cpython/rev/9348e88c89c8 changeset: 101127:9348e88c89c8 user: Serhiy Storchaka date: Sun Apr 24 23:42:49 2016 +0300 summary: Remove unused support.run_unittest imports. It is not needed since tests use unittest.main(). files: Lib/test/test_charmapcodec.py | 2 +- Lib/test/test_codecencodings_cn.py | 1 - Lib/test/test_codecencodings_hk.py | 1 - Lib/test/test_codecencodings_iso2022.py | 1 - Lib/test/test_codecencodings_jp.py | 1 - Lib/test/test_codecencodings_kr.py | 1 - Lib/test/test_codecencodings_tw.py | 1 - Lib/test/test_codecmaps_jp.py | 1 - Lib/test/test_epoll.py | 1 - Lib/test/test_hmac.py | 1 - Lib/test/test_list.py | 2 +- Lib/test/test_pow.py | 2 +- Lib/test/test_range.py | 2 +- Lib/test/test_userdict.py | 2 +- Lib/test/test_userlist.py | 2 +- 15 files changed, 6 insertions(+), 15 deletions(-) diff --git a/Lib/test/test_charmapcodec.py b/Lib/test/test_charmapcodec.py --- a/Lib/test/test_charmapcodec.py +++ b/Lib/test/test_charmapcodec.py @@ -9,7 +9,7 @@ """#" -import test.support, unittest +import unittest import codecs diff --git a/Lib/test/test_codecencodings_cn.py b/Lib/test/test_codecencodings_cn.py --- a/Lib/test/test_codecencodings_cn.py +++ b/Lib/test/test_codecencodings_cn.py @@ -3,7 +3,6 @@ # Codec encoding tests for PRC encodings. # -from test import support from test import multibytecodec_support import unittest diff --git a/Lib/test/test_codecencodings_hk.py b/Lib/test/test_codecencodings_hk.py --- a/Lib/test/test_codecencodings_hk.py +++ b/Lib/test/test_codecencodings_hk.py @@ -3,7 +3,6 @@ # Codec encoding tests for HongKong encodings. # -from test import support from test import multibytecodec_support import unittest diff --git a/Lib/test/test_codecencodings_iso2022.py b/Lib/test/test_codecencodings_iso2022.py --- a/Lib/test/test_codecencodings_iso2022.py +++ b/Lib/test/test_codecencodings_iso2022.py @@ -1,6 +1,5 @@ # Codec encoding tests for ISO 2022 encodings. -from test import support from test import multibytecodec_support import unittest diff --git a/Lib/test/test_codecencodings_jp.py b/Lib/test/test_codecencodings_jp.py --- a/Lib/test/test_codecencodings_jp.py +++ b/Lib/test/test_codecencodings_jp.py @@ -3,7 +3,6 @@ # Codec encoding tests for Japanese encodings. # -from test import support from test import multibytecodec_support import unittest diff --git a/Lib/test/test_codecencodings_kr.py b/Lib/test/test_codecencodings_kr.py --- a/Lib/test/test_codecencodings_kr.py +++ b/Lib/test/test_codecencodings_kr.py @@ -3,7 +3,6 @@ # Codec encoding tests for ROK encodings. # -from test import support from test import multibytecodec_support import unittest diff --git a/Lib/test/test_codecencodings_tw.py b/Lib/test/test_codecencodings_tw.py --- a/Lib/test/test_codecencodings_tw.py +++ b/Lib/test/test_codecencodings_tw.py @@ -3,7 +3,6 @@ # Codec encoding tests for ROC encodings. # -from test import support from test import multibytecodec_support import unittest diff --git a/Lib/test/test_codecmaps_jp.py b/Lib/test/test_codecmaps_jp.py --- a/Lib/test/test_codecmaps_jp.py +++ b/Lib/test/test_codecmaps_jp.py @@ -3,7 +3,6 @@ # Codec mapping tests for Japanese encodings # -from test import support from test import multibytecodec_support import unittest diff --git a/Lib/test/test_epoll.py b/Lib/test/test_epoll.py --- a/Lib/test/test_epoll.py +++ b/Lib/test/test_epoll.py @@ -28,7 +28,6 @@ import time import unittest -from test import support if not hasattr(select, "epoll"): raise unittest.SkipTest("test works only on Linux 2.6") diff --git a/Lib/test/test_hmac.py b/Lib/test/test_hmac.py --- a/Lib/test/test_hmac.py +++ b/Lib/test/test_hmac.py @@ -3,7 +3,6 @@ import hashlib import unittest import warnings -from test import support def ignore_warning(func): diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -1,5 +1,5 @@ import sys -from test import support, list_tests +from test import list_tests import pickle import unittest diff --git a/Lib/test/test_pow.py b/Lib/test/test_pow.py --- a/Lib/test/test_pow.py +++ b/Lib/test/test_pow.py @@ -1,4 +1,4 @@ -import test.support, unittest +import unittest class PowTest(unittest.TestCase): diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py --- a/Lib/test/test_range.py +++ b/Lib/test/test_range.py @@ -1,6 +1,6 @@ # Python test set -- built-in functions -import test.support, unittest +import unittest import sys import pickle import itertools diff --git a/Lib/test/test_userdict.py b/Lib/test/test_userdict.py --- a/Lib/test/test_userdict.py +++ b/Lib/test/test_userdict.py @@ -1,6 +1,6 @@ # Check every path through every method of UserDict -from test import support, mapping_tests +from test import mapping_tests import unittest import collections diff --git a/Lib/test/test_userlist.py b/Lib/test/test_userlist.py --- a/Lib/test/test_userlist.py +++ b/Lib/test/test_userlist.py @@ -1,7 +1,7 @@ # Check every path through every method of UserList from collections import UserList -from test import support, list_tests +from test import list_tests import unittest class UserListTest(list_tests.CommonTest): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 17:12:54 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 24 Apr 2016 21:12:54 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Remove_more_unused_imports?= =?utf-8?q?_in_tests=2E?= Message-ID: <20160424211254.21451.73392.A2376169@psf.io> https://hg.python.org/cpython/rev/54ff12c2e0e9 changeset: 101130:54ff12c2e0e9 user: Serhiy Storchaka date: Mon Apr 25 00:05:30 2016 +0300 summary: Remove more unused imports in tests. files: Lib/ctypes/test/test_bitfields.py | 1 - Lib/ctypes/test/test_pep3118.py | 2 +- Lib/lib2to3/tests/support.py | 2 -- Lib/test/eintrdata/eintr_tester.py | 1 - Lib/test/test_eintr.py | 1 - Lib/test/test_imp.py | 1 - Lib/test/test_json/test_fail.py | 1 - Lib/test/test_subprocess.py | 1 - Lib/test/test_symbol.py | 1 - Lib/test/test_threading.py | 1 - Lib/test/test_tools/__init__.py | 1 - 11 files changed, 1 insertions(+), 12 deletions(-) diff --git a/Lib/ctypes/test/test_bitfields.py b/Lib/ctypes/test/test_bitfields.py --- a/Lib/ctypes/test/test_bitfields.py +++ b/Lib/ctypes/test/test_bitfields.py @@ -3,7 +3,6 @@ import unittest import os -import ctypes import _ctypes_test class BITS(Structure): diff --git a/Lib/ctypes/test/test_pep3118.py b/Lib/ctypes/test/test_pep3118.py --- a/Lib/ctypes/test/test_pep3118.py +++ b/Lib/ctypes/test/test_pep3118.py @@ -1,6 +1,6 @@ import unittest from ctypes import * -import re, struct, sys +import re, sys if sys.byteorder == "little": THIS_ENDIAN = "<" diff --git a/Lib/lib2to3/tests/support.py b/Lib/lib2to3/tests/support.py --- a/Lib/lib2to3/tests/support.py +++ b/Lib/lib2to3/tests/support.py @@ -3,10 +3,8 @@ # Python imports import unittest -import sys import os import os.path -import re from textwrap import dedent # Local imports diff --git a/Lib/test/eintrdata/eintr_tester.py b/Lib/test/eintrdata/eintr_tester.py --- a/Lib/test/eintrdata/eintr_tester.py +++ b/Lib/test/eintrdata/eintr_tester.py @@ -10,7 +10,6 @@ import contextlib import faulthandler -import io import os import select import signal diff --git a/Lib/test/test_eintr.py b/Lib/test/test_eintr.py --- a/Lib/test/test_eintr.py +++ b/Lib/test/test_eintr.py @@ -1,6 +1,5 @@ import os import signal -import subprocess import unittest from test import support diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -6,7 +6,6 @@ import importlib.util import os import os.path -import shutil import sys from test import support import unittest diff --git a/Lib/test/test_json/test_fail.py b/Lib/test/test_json/test_fail.py --- a/Lib/test/test_json/test_fail.py +++ b/Lib/test/test_json/test_fail.py @@ -1,5 +1,4 @@ from test.test_json import PyTest, CTest -import re # 2007-10-05 JSONDOCS = [ diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1,5 +1,4 @@ import unittest -from test.support import script_helper from test import support import subprocess import sys diff --git a/Lib/test/test_symbol.py b/Lib/test/test_symbol.py --- a/Lib/test/test_symbol.py +++ b/Lib/test/test_symbol.py @@ -1,6 +1,5 @@ import unittest from test import support -import filecmp import os import sys import subprocess diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -7,7 +7,6 @@ from test.support.script_helper import assert_python_ok, assert_python_failure import random -import re import sys _thread = import_module('_thread') threading = import_module('threading') diff --git a/Lib/test/test_tools/__init__.py b/Lib/test/test_tools/__init__.py --- a/Lib/test/test_tools/__init__.py +++ b/Lib/test/test_tools/__init__.py @@ -3,7 +3,6 @@ import unittest import importlib from test import support -from fnmatch import fnmatch basepath = os.path.dirname( # os.path.dirname( # Lib -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 17:12:57 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 24 Apr 2016 21:12:57 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Removed_unused_imports=2E?= Message-ID: <20160424211254.115248.87093.EC568157@psf.io> https://hg.python.org/cpython/rev/0dd6ac8ea523 changeset: 101131:0dd6ac8ea523 user: Serhiy Storchaka date: Mon Apr 25 00:12:32 2016 +0300 summary: Removed unused imports. files: Lib/distutils/command/config.py | 2 +- Lib/distutils/command/register.py | 2 +- Lib/distutils/command/sdist.py | 1 - Lib/distutils/extension.py | 1 - Lib/distutils/text_file.py | 2 +- Lib/ftplib.py | 2 -- Lib/idlelib/help.py | 4 ++-- Lib/idlelib/macosxSupport.py | 1 - Lib/lib2to3/fixer_util.py | 2 -- Lib/lib2to3/fixes/fix_dict.py | 3 +-- Lib/lib2to3/fixes/fix_exec.py | 1 - Lib/lib2to3/fixes/fix_filter.py | 1 - Lib/lib2to3/fixes/fix_has_key.py | 1 - Lib/lib2to3/fixes/fix_metaclass.py | 2 +- Lib/lib2to3/fixes/fix_nonzero.py | 2 +- Lib/lib2to3/fixes/fix_print.py | 2 +- Lib/lib2to3/fixes/fix_types.py | 1 - Lib/lib2to3/fixes/fix_urllib.py | 1 - Lib/lib2to3/refactor.py | 1 - Lib/pyclbr.py | 3 +-- Lib/re.py | 1 - Lib/turtledemo/__main__.py | 1 - Lib/turtledemo/bytedesign.py | 1 - Lib/turtledemo/planet_and_moon.py | 1 - Lib/uuid.py | 1 - Tools/scripts/diff.py | 2 +- 26 files changed, 11 insertions(+), 31 deletions(-) diff --git a/Lib/distutils/command/config.py b/Lib/distutils/command/config.py --- a/Lib/distutils/command/config.py +++ b/Lib/distutils/command/config.py @@ -9,7 +9,7 @@ this header file lives". """ -import sys, os, re +import os, re from distutils.core import Command from distutils.errors import DistutilsExecError diff --git a/Lib/distutils/command/register.py b/Lib/distutils/command/register.py --- a/Lib/distutils/command/register.py +++ b/Lib/distutils/command/register.py @@ -5,7 +5,7 @@ # created 2002/10/21, Richard Jones -import os, string, getpass +import getpass import io import urllib.parse, urllib.request from warnings import warn diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py --- a/Lib/distutils/command/sdist.py +++ b/Lib/distutils/command/sdist.py @@ -3,7 +3,6 @@ Implements the Distutils 'sdist' command (create a source distribution).""" import os -import string import sys from types import * from glob import glob diff --git a/Lib/distutils/extension.py b/Lib/distutils/extension.py --- a/Lib/distutils/extension.py +++ b/Lib/distutils/extension.py @@ -4,7 +4,6 @@ modules in setup scripts.""" import os -import sys import warnings # This class is really only used by the "build_ext" command, so it might diff --git a/Lib/distutils/text_file.py b/Lib/distutils/text_file.py --- a/Lib/distutils/text_file.py +++ b/Lib/distutils/text_file.py @@ -4,7 +4,7 @@ that (optionally) takes care of stripping comments, ignoring blank lines, and joining lines with backslashes.""" -import sys, os, io +import sys, io class TextFile: diff --git a/Lib/ftplib.py b/Lib/ftplib.py --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -36,10 +36,8 @@ # Modified by Giampaolo Rodola' to add TLS support. # -import os import sys import socket -import warnings from socket import _GLOBAL_DEFAULT_TIMEOUT __all__ = ["FTP", "error_reply", "error_temp", "error_perm", "error_proto", diff --git a/Lib/idlelib/help.py b/Lib/idlelib/help.py --- a/Lib/idlelib/help.py +++ b/Lib/idlelib/help.py @@ -25,8 +25,8 @@ show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog. """ from html.parser import HTMLParser -from os.path import abspath, dirname, isdir, isfile, join -from tkinter import Tk, Toplevel, Frame, Text, Scrollbar, Menu, Menubutton +from os.path import abspath, dirname, isfile, join +from tkinter import Toplevel, Frame, Text, Scrollbar, Menu, Menubutton from tkinter import font as tkfont from idlelib.configHandler import idleConf diff --git a/Lib/idlelib/macosxSupport.py b/Lib/idlelib/macosxSupport.py --- a/Lib/idlelib/macosxSupport.py +++ b/Lib/idlelib/macosxSupport.py @@ -3,7 +3,6 @@ """ import sys import tkinter -from os import path import warnings def runningAsOSXApp(): diff --git a/Lib/lib2to3/fixer_util.py b/Lib/lib2to3/fixer_util.py --- a/Lib/lib2to3/fixer_util.py +++ b/Lib/lib2to3/fixer_util.py @@ -1,8 +1,6 @@ """Utility functions, node construction macros, etc.""" # Author: Collin Winter -from itertools import islice - # Local imports from .pgen2 import token from .pytree import Leaf, Node diff --git a/Lib/lib2to3/fixes/fix_dict.py b/Lib/lib2to3/fixes/fix_dict.py --- a/Lib/lib2to3/fixes/fix_dict.py +++ b/Lib/lib2to3/fixes/fix_dict.py @@ -30,9 +30,8 @@ # Local imports from .. import pytree from .. import patcomp -from ..pgen2 import token from .. import fixer_base -from ..fixer_util import Name, Call, LParen, RParen, ArgList, Dot +from ..fixer_util import Name, Call, Dot from .. import fixer_util diff --git a/Lib/lib2to3/fixes/fix_exec.py b/Lib/lib2to3/fixes/fix_exec.py --- a/Lib/lib2to3/fixes/fix_exec.py +++ b/Lib/lib2to3/fixes/fix_exec.py @@ -10,7 +10,6 @@ """ # Local imports -from .. import pytree from .. import fixer_base from ..fixer_util import Comma, Name, Call diff --git a/Lib/lib2to3/fixes/fix_filter.py b/Lib/lib2to3/fixes/fix_filter.py --- a/Lib/lib2to3/fixes/fix_filter.py +++ b/Lib/lib2to3/fixes/fix_filter.py @@ -14,7 +14,6 @@ """ # Local imports -from ..pgen2 import token from .. import fixer_base from ..fixer_util import Name, Call, ListComp, in_special_context diff --git a/Lib/lib2to3/fixes/fix_has_key.py b/Lib/lib2to3/fixes/fix_has_key.py --- a/Lib/lib2to3/fixes/fix_has_key.py +++ b/Lib/lib2to3/fixes/fix_has_key.py @@ -31,7 +31,6 @@ # Local imports from .. import pytree -from ..pgen2 import token from .. import fixer_base from ..fixer_util import Name, parenthesize diff --git a/Lib/lib2to3/fixes/fix_metaclass.py b/Lib/lib2to3/fixes/fix_metaclass.py --- a/Lib/lib2to3/fixes/fix_metaclass.py +++ b/Lib/lib2to3/fixes/fix_metaclass.py @@ -20,7 +20,7 @@ # Local imports from .. import fixer_base from ..pygram import token -from ..fixer_util import Name, syms, Node, Leaf +from ..fixer_util import syms, Node, Leaf def has_metaclass(parent): diff --git a/Lib/lib2to3/fixes/fix_nonzero.py b/Lib/lib2to3/fixes/fix_nonzero.py --- a/Lib/lib2to3/fixes/fix_nonzero.py +++ b/Lib/lib2to3/fixes/fix_nonzero.py @@ -3,7 +3,7 @@ # Local imports from .. import fixer_base -from ..fixer_util import Name, syms +from ..fixer_util import Name class FixNonzero(fixer_base.BaseFix): BM_compatible = True diff --git a/Lib/lib2to3/fixes/fix_print.py b/Lib/lib2to3/fixes/fix_print.py --- a/Lib/lib2to3/fixes/fix_print.py +++ b/Lib/lib2to3/fixes/fix_print.py @@ -18,7 +18,7 @@ from .. import pytree from ..pgen2 import token from .. import fixer_base -from ..fixer_util import Name, Call, Comma, String, is_tuple +from ..fixer_util import Name, Call, Comma, String parend_expr = patcomp.compile_pattern( diff --git a/Lib/lib2to3/fixes/fix_types.py b/Lib/lib2to3/fixes/fix_types.py --- a/Lib/lib2to3/fixes/fix_types.py +++ b/Lib/lib2to3/fixes/fix_types.py @@ -20,7 +20,6 @@ """ # Local imports -from ..pgen2 import token from .. import fixer_base from ..fixer_util import Name diff --git a/Lib/lib2to3/fixes/fix_urllib.py b/Lib/lib2to3/fixes/fix_urllib.py --- a/Lib/lib2to3/fixes/fix_urllib.py +++ b/Lib/lib2to3/fixes/fix_urllib.py @@ -6,7 +6,6 @@ # Local imports from lib2to3.fixes.fix_imports import alternates, FixImports -from lib2to3 import fixer_base from lib2to3.fixer_util import (Name, Comma, FromImport, Newline, find_indentation, Node, syms) diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py --- a/Lib/lib2to3/refactor.py +++ b/Lib/lib2to3/refactor.py @@ -26,7 +26,6 @@ from .pgen2 import driver, tokenize, token from .fixer_util import find_root from . import pytree, pygram -from . import btm_utils as bu from . import btm_matcher as bm diff --git a/Lib/pyclbr.py b/Lib/pyclbr.py --- a/Lib/pyclbr.py +++ b/Lib/pyclbr.py @@ -40,12 +40,10 @@ """ import io -import os import sys import importlib.util import tokenize from token import NAME, DEDENT, OP -from operator import itemgetter __all__ = ["readmodule", "readmodule_ex", "Class", "Function"] @@ -328,6 +326,7 @@ def _main(): # Main program for testing. import os + from operator import itemgetter mod = sys.argv[1] if os.path.exists(mod): path = [os.path.dirname(mod)] diff --git a/Lib/re.py b/Lib/re.py --- a/Lib/re.py +++ b/Lib/re.py @@ -119,7 +119,6 @@ """ -import sys import sre_compile import sre_parse try: diff --git a/Lib/turtledemo/__main__.py b/Lib/turtledemo/__main__.py --- a/Lib/turtledemo/__main__.py +++ b/Lib/turtledemo/__main__.py @@ -95,7 +95,6 @@ from turtledemo import __doc__ as about_turtledemo import turtle -import time demo_dir = os.path.dirname(os.path.abspath(__file__)) darwin = sys.platform == 'darwin' diff --git a/Lib/turtledemo/bytedesign.py b/Lib/turtledemo/bytedesign.py --- a/Lib/turtledemo/bytedesign.py +++ b/Lib/turtledemo/bytedesign.py @@ -22,7 +22,6 @@ mode as fast as possible. """ -import math from turtle import Turtle, mainloop from time import clock diff --git a/Lib/turtledemo/planet_and_moon.py b/Lib/turtledemo/planet_and_moon.py --- a/Lib/turtledemo/planet_and_moon.py +++ b/Lib/turtledemo/planet_and_moon.py @@ -18,7 +18,6 @@ """ from turtle import Shape, Turtle, mainloop, Vec2D as Vec -from time import sleep G = 8 diff --git a/Lib/uuid.py b/Lib/uuid.py --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -487,7 +487,6 @@ # Assume that the uuid_generate functions are broken from 10.5 onward, # the test can be adjusted when a later version is fixed. if sys.platform == 'darwin': - import os if int(os.uname().release.split('.')[0]) >= 9: _uuid_generate_time = None diff --git a/Tools/scripts/diff.py b/Tools/scripts/diff.py --- a/Tools/scripts/diff.py +++ b/Tools/scripts/diff.py @@ -8,7 +8,7 @@ """ -import sys, os, time, difflib, argparse +import sys, os, difflib, argparse from datetime import datetime, timezone def file_mtime(path): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sun Apr 24 20:55:13 2016 From: python-checkins at python.org (guido.van.rossum) Date: Mon, 25 Apr 2016 00:55:13 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Rip_out_the_promotion_from_by?= =?utf-8?q?tearray/memoryview_to_bytes=2E_See?= Message-ID: <20160425005513.26189.36109.9AEEC061@psf.io> https://hg.python.org/peps/rev/3fb0f9a0b195 changeset: 6294:3fb0f9a0b195 user: Guido van Rossum date: Sun Apr 24 17:55:04 2016 -0700 summary: Rip out the promotion from bytearray/memoryview to bytes. See http://bugs.python.org/issue26800. files: pep-0484.txt | 20 -------------------- 1 files changed, 0 insertions(+), 20 deletions(-) diff --git a/pep-0484.txt b/pep-0484.txt --- a/pep-0484.txt +++ b/pep-0484.txt @@ -722,26 +722,6 @@ exceedingly rare. -The bytes types ---------------- - -There are three different builtin classes used for arrays of bytes -(not counting the classes available in the ``array`` module): -``bytes``, ``bytearray`` and ``memoryview``. Of these, ``bytes`` and -``bytearray`` have many behaviors in common (though not all -- -``bytearray`` is mutable). - -While there is an ABC ``ByteString`` defined in ``collections.abc`` -and a corresponding type in ``typing``, functions accepting bytes (of -some form) are so common that it would be cumbersome to have to write -``typing.ByteString`` everywhere. So, as a shortcut similar to that -for the builtin numeric classes, when an argument is annotated as -having type ``bytes``, arguments of type ``bytearray`` or -``memoryview`` are acceptable. (Again, there are situations where -this isn't sound, but we believe those are exceedingly rare in -practice.) - - Forward references ------------------ -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Mon Apr 25 02:00:13 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 25 Apr 2016 06:00:13 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2ODM3?= =?utf-8?q?=3A_assertSequenceEqual=28=29_now_correctly_outputs_non-stringi?= =?utf-8?q?fied?= Message-ID: <20160425060013.112223.91002.94C179C3@psf.io> https://hg.python.org/cpython/rev/d0d541c2afb7 changeset: 101134:d0d541c2afb7 branch: 2.7 parent: 101101:9b565815079a user: Serhiy Storchaka date: Mon Apr 25 08:59:35 2016 +0300 summary: Issue #26837: assertSequenceEqual() now correctly outputs non-stringified differing items. This affects assertListEqual() and assertTupleEqual(). files: Lib/unittest/case.py | 6 +++--- Misc/NEWS | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -689,7 +689,7 @@ if item1 != item2: differing += ('\nFirst differing element %d:\n%s\n%s\n' % - (i, item1, item2)) + (i, safe_repr(item1), safe_repr(item2))) break else: if (len1 == len2 and seq_type is None and @@ -702,7 +702,7 @@ 'elements.\n' % (seq_type_name, len1 - len2)) try: differing += ('First extra element %d:\n%s\n' % - (len2, seq1[len2])) + (len2, safe_repr(seq1[len2]))) except (TypeError, IndexError, NotImplementedError): differing += ('Unable to index element %d ' 'of first %s\n' % (len2, seq_type_name)) @@ -711,7 +711,7 @@ 'elements.\n' % (seq_type_name, len2 - len1)) try: differing += ('First extra element %d:\n%s\n' % - (len1, seq2[len1])) + (len1, safe_repr(seq2[len1]))) except (TypeError, IndexError, NotImplementedError): differing += ('Unable to index element %d ' 'of second %s\n' % (len1, seq_type_name)) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,9 @@ Library ------- +- Issue #26837: assertSequenceEqual() now correctly outputs non-stringified + differing items. This affects assertListEqual() and assertTupleEqual(). + - Issue #26822: itemgetter, attrgetter and methodcaller objects no longer silently ignore keyword arguments. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 02:00:13 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 25 Apr 2016 06:00:13 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy41?= Message-ID: <20160425060012.126633.29192.1DFA62ED@psf.io> https://hg.python.org/cpython/rev/049463a379cc changeset: 101133:049463a379cc parent: 101131:0dd6ac8ea523 parent: 101132:ae5cc8ab664a user: Serhiy Storchaka date: Mon Apr 25 08:58:59 2016 +0300 summary: Merge 3.5 files: Lib/unittest/case.py | 6 +- Lib/unittest/test/test_case.py | 76 ++++++++++++++++++++++ Misc/NEWS | 4 + 3 files changed, 83 insertions(+), 3 deletions(-) diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -964,7 +964,7 @@ if item1 != item2: differing += ('\nFirst differing element %d:\n%s\n%s\n' % - (i, item1, item2)) + ((i,) + _common_shorten_repr(item1, item2))) break else: if (len1 == len2 and seq_type is None and @@ -977,7 +977,7 @@ 'elements.\n' % (seq_type_name, len1 - len2)) try: differing += ('First extra element %d:\n%s\n' % - (len2, seq1[len2])) + (len2, safe_repr(seq1[len2]))) except (TypeError, IndexError, NotImplementedError): differing += ('Unable to index element %d ' 'of first %s\n' % (len2, seq_type_name)) @@ -986,7 +986,7 @@ 'elements.\n' % (seq_type_name, len2 - len1)) try: differing += ('First extra element %d:\n%s\n' % - (len1, seq2[len1])) + (len1, safe_repr(seq2[len1]))) except (TypeError, IndexError, NotImplementedError): differing += ('Unable to index element %d ' 'of second %s\n' % (len1, seq_type_name)) diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -1121,6 +1121,82 @@ error = str(e).split('\n', 1)[1] self.assertEqual(sample_text_error, error) + def testEqualityBytesWarning(self): + if sys.flags.bytes_warning: + def bytes_warning(): + return self.assertWarnsRegex(BytesWarning, + 'Comparison between bytes and string') + else: + def bytes_warning(): + return contextlib.ExitStack() + + with bytes_warning(), self.assertRaises(self.failureException): + self.assertEqual('a', b'a') + with bytes_warning(): + self.assertNotEqual('a', b'a') + + a = [0, 'a'] + b = [0, b'a'] + with bytes_warning(), self.assertRaises(self.failureException): + self.assertListEqual(a, b) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertTupleEqual(tuple(a), tuple(b)) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertSequenceEqual(a, tuple(b)) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertSequenceEqual(tuple(a), b) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertSequenceEqual('a', b'a') + with bytes_warning(), self.assertRaises(self.failureException): + self.assertSetEqual(set(a), set(b)) + + with self.assertRaises(self.failureException): + self.assertListEqual(a, tuple(b)) + with self.assertRaises(self.failureException): + self.assertTupleEqual(tuple(a), b) + + a = [0, b'a'] + b = [0] + with self.assertRaises(self.failureException): + self.assertListEqual(a, b) + with self.assertRaises(self.failureException): + self.assertTupleEqual(tuple(a), tuple(b)) + with self.assertRaises(self.failureException): + self.assertSequenceEqual(a, tuple(b)) + with self.assertRaises(self.failureException): + self.assertSequenceEqual(tuple(a), b) + with self.assertRaises(self.failureException): + self.assertSetEqual(set(a), set(b)) + + a = [0] + b = [0, b'a'] + with self.assertRaises(self.failureException): + self.assertListEqual(a, b) + with self.assertRaises(self.failureException): + self.assertTupleEqual(tuple(a), tuple(b)) + with self.assertRaises(self.failureException): + self.assertSequenceEqual(a, tuple(b)) + with self.assertRaises(self.failureException): + self.assertSequenceEqual(tuple(a), b) + with self.assertRaises(self.failureException): + self.assertSetEqual(set(a), set(b)) + + with bytes_warning(), self.assertRaises(self.failureException): + self.assertDictEqual({'a': 0}, {b'a': 0}) + with self.assertRaises(self.failureException): + self.assertDictEqual({}, {b'a': 0}) + with self.assertRaises(self.failureException): + self.assertDictEqual({b'a': 0}, {}) + + with self.assertRaises(self.failureException): + self.assertCountEqual([b'a', b'a'], [b'a', b'a', b'a']) + with bytes_warning(): + self.assertCountEqual(['a', b'a'], ['a', b'a']) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertCountEqual(['a', 'a'], [b'a', b'a']) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertCountEqual(['a', 'a', []], [b'a', b'a', []]) + def testAssertIsNone(self): self.assertIsNone(None) self.assertRaises(self.failureException, self.assertIsNone, False) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -256,6 +256,10 @@ Library ------- +- Issue #26837: assertSequenceEqual() now correctly outputs non-stringified + differing items (like bytes in the -b mode). This affects assertListEqual() + and assertTupleEqual(). + - Issue #26041: Remove "will be removed in Python 3.7" from deprecation messages of platform.dist() and platform.linux_distribution(). Patch by Kumaripaba Miyurusara Athukorala. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 02:00:13 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 25 Apr 2016 06:00:13 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2ODM3?= =?utf-8?q?=3A_assertSequenceEqual=28=29_now_correctly_outputs_non-stringi?= =?utf-8?q?fied?= Message-ID: <20160425060011.21623.6964.BB0E77CE@psf.io> https://hg.python.org/cpython/rev/ae5cc8ab664a changeset: 101132:ae5cc8ab664a branch: 3.5 parent: 101128:dd223c585fb6 user: Serhiy Storchaka date: Mon Apr 25 08:58:25 2016 +0300 summary: Issue #26837: assertSequenceEqual() now correctly outputs non-stringified differing items (like bytes in the -b mode). This affects assertListEqual() and assertTupleEqual(). files: Lib/unittest/case.py | 6 +- Lib/unittest/test/test_case.py | 76 ++++++++++++++++++++++ Misc/NEWS | 4 + 3 files changed, 83 insertions(+), 3 deletions(-) diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -964,7 +964,7 @@ if item1 != item2: differing += ('\nFirst differing element %d:\n%s\n%s\n' % - (i, item1, item2)) + ((i,) + _common_shorten_repr(item1, item2))) break else: if (len1 == len2 and seq_type is None and @@ -977,7 +977,7 @@ 'elements.\n' % (seq_type_name, len1 - len2)) try: differing += ('First extra element %d:\n%s\n' % - (len2, seq1[len2])) + (len2, safe_repr(seq1[len2]))) except (TypeError, IndexError, NotImplementedError): differing += ('Unable to index element %d ' 'of first %s\n' % (len2, seq_type_name)) @@ -986,7 +986,7 @@ 'elements.\n' % (seq_type_name, len2 - len1)) try: differing += ('First extra element %d:\n%s\n' % - (len1, seq2[len1])) + (len1, safe_repr(seq2[len1]))) except (TypeError, IndexError, NotImplementedError): differing += ('Unable to index element %d ' 'of second %s\n' % (len1, seq_type_name)) diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -1121,6 +1121,82 @@ error = str(e).split('\n', 1)[1] self.assertEqual(sample_text_error, error) + def testEqualityBytesWarning(self): + if sys.flags.bytes_warning: + def bytes_warning(): + return self.assertWarnsRegex(BytesWarning, + 'Comparison between bytes and string') + else: + def bytes_warning(): + return contextlib.ExitStack() + + with bytes_warning(), self.assertRaises(self.failureException): + self.assertEqual('a', b'a') + with bytes_warning(): + self.assertNotEqual('a', b'a') + + a = [0, 'a'] + b = [0, b'a'] + with bytes_warning(), self.assertRaises(self.failureException): + self.assertListEqual(a, b) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertTupleEqual(tuple(a), tuple(b)) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertSequenceEqual(a, tuple(b)) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertSequenceEqual(tuple(a), b) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertSequenceEqual('a', b'a') + with bytes_warning(), self.assertRaises(self.failureException): + self.assertSetEqual(set(a), set(b)) + + with self.assertRaises(self.failureException): + self.assertListEqual(a, tuple(b)) + with self.assertRaises(self.failureException): + self.assertTupleEqual(tuple(a), b) + + a = [0, b'a'] + b = [0] + with self.assertRaises(self.failureException): + self.assertListEqual(a, b) + with self.assertRaises(self.failureException): + self.assertTupleEqual(tuple(a), tuple(b)) + with self.assertRaises(self.failureException): + self.assertSequenceEqual(a, tuple(b)) + with self.assertRaises(self.failureException): + self.assertSequenceEqual(tuple(a), b) + with self.assertRaises(self.failureException): + self.assertSetEqual(set(a), set(b)) + + a = [0] + b = [0, b'a'] + with self.assertRaises(self.failureException): + self.assertListEqual(a, b) + with self.assertRaises(self.failureException): + self.assertTupleEqual(tuple(a), tuple(b)) + with self.assertRaises(self.failureException): + self.assertSequenceEqual(a, tuple(b)) + with self.assertRaises(self.failureException): + self.assertSequenceEqual(tuple(a), b) + with self.assertRaises(self.failureException): + self.assertSetEqual(set(a), set(b)) + + with bytes_warning(), self.assertRaises(self.failureException): + self.assertDictEqual({'a': 0}, {b'a': 0}) + with self.assertRaises(self.failureException): + self.assertDictEqual({}, {b'a': 0}) + with self.assertRaises(self.failureException): + self.assertDictEqual({b'a': 0}, {}) + + with self.assertRaises(self.failureException): + self.assertCountEqual([b'a', b'a'], [b'a', b'a', b'a']) + with bytes_warning(): + self.assertCountEqual(['a', b'a'], ['a', b'a']) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertCountEqual(['a', 'a'], [b'a', b'a']) + with bytes_warning(), self.assertRaises(self.failureException): + self.assertCountEqual(['a', 'a', []], [b'a', b'a', []]) + def testAssertIsNone(self): self.assertIsNone(None) self.assertRaises(self.failureException, self.assertIsNone, False) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,10 @@ Library ------- +- Issue #26837: assertSequenceEqual() now correctly outputs non-stringified + differing items (like bytes in the -b mode). This affects assertListEqual() + and assertTupleEqual(). + - Issue #26041: Remove "will be removed in Python 3.7" from deprecation messages of platform.dist() and platform.linux_distribution(). Patch by Kumaripaba Miyurusara Athukorala. -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Mon Apr 25 05:46:17 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 25 Apr 2016 09:46:17 +0000 Subject: [Python-checkins] Daily reference leaks (0dd6ac8ea523): sum=27 Message-ID: <20160425094617.15816.7084.7600AE7C@psf.io> results for 0dd6ac8ea523 on branch "default" -------------------------------------------- test_asyncio leaked [3, 0, 0] memory blocks, sum=3 test_collections leaked [0, 0, 4] memory blocks, sum=4 test_format leaked [6, 6, 6] memory blocks, sum=18 test_functools leaked [0, 3, 1] memory blocks, sum=4 test_multiprocessing_spawn leaked [0, 0, -2] memory blocks, sum=-2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogYwtPp5', '--timeout', '7200'] From python-checkins at python.org Mon Apr 25 07:02:08 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 25 Apr 2016 11:02:08 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Remove_outdated_TkVersion_?= =?utf-8?q?checks=2E?= Message-ID: <20160425110208.15832.37032.8449F185@psf.io> https://hg.python.org/cpython/rev/7d3fba5f8070 changeset: 101135:7d3fba5f8070 parent: 101133:049463a379cc user: Serhiy Storchaka date: Mon Apr 25 13:49:11 2016 +0300 summary: Remove outdated TkVersion checks. Minimal supported Tcl/Tk version is 8.4, and this is checked in _tkinter.c. files: Lib/tkinter/__init__.py | 3 --- Lib/tkinter/commondialog.py | 5 ----- Lib/tkinter/dialog.py | 5 +---- Lib/tkinter/tix.py | 4 ---- 4 files changed, 1 insertions(+), 16 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1887,9 +1887,6 @@ if tcl_version != _tkinter.TCL_VERSION: raise RuntimeError("tcl.h version (%s) doesn't match libtcl.a version (%s)" \ % (_tkinter.TCL_VERSION, tcl_version)) - if TkVersion < 4.0: - raise RuntimeError("Tk 4.0 or higher is required; found Tk %s" - % str(TkVersion)) # Create and register the tkerror and exit commands # We need to inline parts of _register here, _ register # would register differently-named commands. diff --git a/Lib/tkinter/commondialog.py b/Lib/tkinter/commondialog.py --- a/Lib/tkinter/commondialog.py +++ b/Lib/tkinter/commondialog.py @@ -15,11 +15,6 @@ command = None def __init__(self, master=None, **options): - - # FIXME: should this be placed on the module level instead? - if TkVersion < 4.2: - raise TclError("this module requires Tk 4.2 or newer") - self.master = master self.options = options if not master and options.get('parent'): diff --git a/Lib/tkinter/dialog.py b/Lib/tkinter/dialog.py --- a/Lib/tkinter/dialog.py +++ b/Lib/tkinter/dialog.py @@ -3,10 +3,7 @@ from tkinter import * from tkinter import _cnfmerge -if TkVersion <= 3.6: - DIALOG_ICON = 'warning' -else: - DIALOG_ICON = 'questhead' +DIALOG_ICON = 'questhead' class Dialog(Widget): diff --git a/Lib/tkinter/tix.py b/Lib/tkinter/tix.py --- a/Lib/tkinter/tix.py +++ b/Lib/tkinter/tix.py @@ -29,10 +29,6 @@ from tkinter import * from tkinter import _cnfmerge, _default_root -# WARNING - TkVersion is a limited precision floating point number -if TkVersion < 3.999: - raise ImportError("This version of Tix.py requires Tk 4.0 or higher") - import _tkinter # If this fails your Python may not be configured for Tk # Some more constants (for consistency with Tkinter) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 07:32:20 2016 From: python-checkins at python.org (berker.peksag) Date: Mon, 25 Apr 2016 11:32:20 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2323662=3A_Document_default_value_of_RFC_2109_att?= =?utf-8?q?ributes?= Message-ID: <20160425113217.13758.12340.568F3105@psf.io> https://hg.python.org/cpython/rev/b3ad9c002bb8 changeset: 101137:b3ad9c002bb8 parent: 101135:7d3fba5f8070 parent: 101136:1fdaa71d47f5 user: Berker Peksag date: Mon Apr 25 14:32:41 2016 +0300 summary: Issue #23662: Document default value of RFC 2109 attributes files: Doc/library/http.cookies.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/http.cookies.rst b/Doc/library/http.cookies.rst --- a/Doc/library/http.cookies.rst +++ b/Doc/library/http.cookies.rst @@ -141,7 +141,7 @@ in HTTP requests, and is not accessible through JavaScript. This is intended to mitigate some forms of cross-site scripting. - The keys are case-insensitive. + The keys are case-insensitive and their default value is ``''``. .. versionchanged:: 3.5 :meth:`~Morsel.__eq__` now takes :attr:`~Morsel.key` and :attr:`~Morsel.value` -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 07:32:21 2016 From: python-checkins at python.org (berker.peksag) Date: Mon, 25 Apr 2016 11:32:21 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzIzNjYy?= =?utf-8?q?=3A_Document_default_value_of_RFC_2109_attributes?= Message-ID: <20160425113216.112397.10030.ECB36646@psf.io> https://hg.python.org/cpython/rev/1fdaa71d47f5 changeset: 101136:1fdaa71d47f5 branch: 3.5 parent: 101132:ae5cc8ab664a user: Berker Peksag date: Mon Apr 25 14:32:19 2016 +0300 summary: Issue #23662: Document default value of RFC 2109 attributes files: Doc/library/http.cookies.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/http.cookies.rst b/Doc/library/http.cookies.rst --- a/Doc/library/http.cookies.rst +++ b/Doc/library/http.cookies.rst @@ -141,7 +141,7 @@ in HTTP requests, and is not accessible through JavaScript. This is intended to mitigate some forms of cross-site scripting. - The keys are case-insensitive. + The keys are case-insensitive and their default value is ``''``. .. versionchanged:: 3.5 :meth:`~Morsel.__eq__` now takes :attr:`~Morsel.key` and :attr:`~Morsel.value` -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 10:28:45 2016 From: python-checkins at python.org (zach.ware) Date: Mon, 25 Apr 2016 14:28:45 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Merge_with_3=2E5?= Message-ID: <20160425142810.41855.73567.68BACDC8@psf.io> https://hg.python.org/cpython/rev/e014be53e7b9 changeset: 101139:e014be53e7b9 parent: 101137:b3ad9c002bb8 parent: 101138:2c1651fbfbba user: Zachary Ware date: Mon Apr 25 09:27:49 2016 -0500 summary: Merge with 3.5 files: Doc/library/os.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1624,8 +1624,8 @@ Create a directory named *path* with numeric mode *mode*. On some systems, *mode* is ignored. Where it is used, the current umask - value is first masked out. If the directory already exists, :exc:`OSError` - is raised. + value is first masked out. If the directory already exists, + :exc:`FileExistsError` is raised. This function can also support :ref:`paths relative to directory descriptors `. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 10:28:46 2016 From: python-checkins at python.org (zach.ware) Date: Mon, 25 Apr 2016 14:28:46 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E5=29=3A_FileExistsErro?= =?utf-8?q?r_is_raised_by_mkdir_when_dir_exists?= Message-ID: <20160425142810.108284.94528.14838DCD@psf.io> https://hg.python.org/cpython/rev/2c1651fbfbba changeset: 101138:2c1651fbfbba branch: 3.5 parent: 101136:1fdaa71d47f5 user: Zachary Ware date: Mon Apr 25 09:27:27 2016 -0500 summary: FileExistsError is raised by mkdir when dir exists Reported by Saul Spatz on docs@ files: Doc/library/os.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1624,8 +1624,8 @@ Create a directory named *path* with numeric mode *mode*. On some systems, *mode* is ignored. Where it is used, the current umask - value is first masked out. If the directory already exists, :exc:`OSError` - is raised. + value is first masked out. If the directory already exists, + :exc:`FileExistsError` is raised. This function can also support :ref:`paths relative to directory descriptors `. -- Repository URL: https://hg.python.org/cpython From lp_benchmark_robot at intel.com Mon Apr 25 10:54:37 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Mon, 25 Apr 2016 15:54:37 +0100 Subject: [Python-checkins] GOOD Benchmark Results for Python Default 2016-04-25 Message-ID: <945e650f-911b-409c-8c98-eb81fc6926b4@irsmsx104.ger.corp.intel.com> Results for project Python default, build date 2016-04-25 07:08:22 +0000 commit: 049463a379cc previous commit: 496e094f4734 revision date: 2016-04-25 05:58:59 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.31% 1.26% 9.83% 16.07% :-| pybench 0.12% 0.51% 0.86% 6.68% :-( regex_v8 2.70% 1.65% -2.05% 0.99% :-( nbody 0.11% -0.11% -2.30% 10.55% :-) json_dump_v2 0.27% 2.77% 0.41% 11.38% :-| normal_startup 0.74% 1.23% 0.98% 5.74% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/good-benchmark-results-for-python-default-2016-04-25/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Mon Apr 25 10:55:22 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Mon, 25 Apr 2016 15:55:22 +0100 Subject: [Python-checkins] NEUTRAL Benchmark Results for Python 2.7 2016-04-25 Message-ID: <18a2737f-6e5e-44cc-9fe0-b63e75bbc06f@irsmsx104.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-25 07:55:30 +0000 commit: d0d541c2afb7 previous commit: 9b565815079a revision date: 2016-04-25 05:59:35 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.14% 0.40% 6.13% 6.62% :-) pybench 0.13% 0.07% 5.95% 5.15% :-( regex_v8 0.71% 0.13% -2.11% 11.14% :-) nbody 0.14% 0.02% 7.04% 5.75% :-| json_dump_v2 0.66% -0.88% 1.57% 11.30% :-( normal_startup 1.57% -0.18% -4.97% 1.68% :-) ssbench 0.29% 0.54% 2.97% 1.30% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/neutral-benchmark-results-for-python-2-7-2016-04-25/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Mon Apr 25 11:34:52 2016 From: python-checkins at python.org (senthil.kumaran) Date: Mon, 25 Apr 2016 15:34:52 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2ODA0?= =?utf-8?q?=3A_urllib=2Erequest_will_prefer_lower=5Fcase_proxy_environment?= =?utf-8?q?_variables?= Message-ID: <20160425153450.4122.46000.A3EC2F51@psf.io> https://hg.python.org/cpython/rev/49b975122022 changeset: 101140:49b975122022 branch: 3.5 parent: 101138:2c1651fbfbba user: Senthil Kumaran date: Mon Apr 25 08:16:23 2016 -0700 summary: Issue #26804: urllib.request will prefer lower_case proxy environment variables over UPPER_CASE or Mixed_Case ones. Patch contributed by Hans-Peter Jansen. Reviewed by Martin Panter and Senthil Kumaran. files: Doc/library/urllib.request.rst | 2 + Lib/test/test_urllib.py | 40 ++++++++++++++++++- Lib/urllib/request.py | 46 ++++++++++++++++----- Misc/ACKS | 1 + Misc/NEWS | 4 + 5 files changed, 81 insertions(+), 12 deletions(-) diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -166,6 +166,8 @@ in a case insensitive approach, for all operating systems first, and when it cannot find it, looks for proxy information from Mac OSX System Configuration for Mac OS X and Windows Systems Registry for Windows. + If both lowercase and uppercase environment variables exist (and disagree), + lowercase is preferred. The following classes are provided: diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -226,8 +226,46 @@ # getproxies_environment use lowered case truncated (no '_proxy') keys self.assertEqual('localhost', proxies['no']) # List of no_proxies with space. - self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com') + self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com:1234') self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com')) + self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com:8888')) + self.assertTrue(urllib.request.proxy_bypass_environment('newdomain.com:1234')) + + +class ProxyTests_withOrderedEnv(unittest.TestCase): + + def setUp(self): + # We need to test conditions, where variable order _is_ significant + self._saved_env = os.environ + # Monkey patch os.environ, start with empty fake environment + os.environ = collections.OrderedDict() + + def tearDown(self): + os.environ = self._saved_env + + def test_getproxies_environment_prefer_lowercase(self): + # Test lowercase preference with removal + os.environ['no_proxy'] = '' + os.environ['No_Proxy'] = 'localhost' + self.assertFalse(urllib.request.proxy_bypass_environment('localhost')) + self.assertFalse(urllib.request.proxy_bypass_environment('arbitrary')) + os.environ['http_proxy'] = '' + os.environ['HTTP_PROXY'] = 'http://somewhere:3128' + proxies = urllib.request.getproxies_environment() + self.assertEqual({}, proxies) + # Test lowercase preference of proxy bypass and correct matching including ports + os.environ['no_proxy'] = 'localhost, noproxy.com, my.proxy:1234' + os.environ['No_Proxy'] = 'xyz.com' + self.assertTrue(urllib.request.proxy_bypass_environment('localhost')) + self.assertTrue(urllib.request.proxy_bypass_environment('noproxy.com:5678')) + self.assertTrue(urllib.request.proxy_bypass_environment('my.proxy:1234')) + self.assertFalse(urllib.request.proxy_bypass_environment('my.proxy')) + self.assertFalse(urllib.request.proxy_bypass_environment('arbitrary')) + # Test lowercase preference with replacement + os.environ['http_proxy'] = 'http://somewhere:3128' + os.environ['Http_Proxy'] = 'http://somewhereelse:3128' + proxies = urllib.request.getproxies_environment() + self.assertEqual('http://somewhere:3128', proxies['http']) class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin, FakeFTPMixin): """Test urlopen() opening a fake http connection.""" diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -2395,19 +2395,35 @@ """ proxies = {} + # in order to prefer lowercase variables, process environment in + # two passes: first matches any, second pass matches lowercase only for name, value in os.environ.items(): name = name.lower() if value and name[-6:] == '_proxy': proxies[name[:-6]] = value + for name, value in os.environ.items(): + if name[-6:] == '_proxy': + name = name.lower() + if value: + proxies[name[:-6]] = value + else: + proxies.pop(name[:-6], None) return proxies -def proxy_bypass_environment(host): +def proxy_bypass_environment(host, proxies=None): """Test if proxies should not be used for a particular host. - Checks the environment for a variable named no_proxy, which should - be a list of DNS suffixes separated by commas, or '*' for all hosts. + Checks the proxy dict for the value of no_proxy, which should + be a list of comma separated DNS suffixes, or '*' for all hosts. + """ - no_proxy = os.environ.get('no_proxy', '') or os.environ.get('NO_PROXY', '') + if proxies is None: + proxies = getproxies_environment() + # don't bypass, if no_proxy isn't specified + try: + no_proxy = proxies['no'] + except KeyError: + return 0 # '*' is special case for always bypass if no_proxy == '*': return 1 @@ -2502,8 +2518,15 @@ def proxy_bypass(host): - if getproxies_environment(): - return proxy_bypass_environment(host) + """Return True, if host should be bypassed. + + Checks proxy settings gathered from the environment, if specified, + or from the MacOSX framework SystemConfiguration. + + """ + proxies = getproxies_environment() + if proxies: + return proxy_bypass_environment(host, proxies) else: return proxy_bypass_macosx_sysconf(host) @@ -2617,14 +2640,15 @@ return 0 def proxy_bypass(host): - """Return a dictionary of scheme -> proxy server URL mappings. - - Returns settings gathered from the environment, if specified, + """Return True, if host should be bypassed. + + Checks proxy settings gathered from the environment, if specified, or the registry. """ - if getproxies_environment(): - return proxy_bypass_environment(host) + proxies = getproxies_environment() + if proxies: + return proxy_bypass_environment(host, proxies) else: return proxy_bypass_registry(host) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -670,6 +670,7 @@ Bertrand Janin Geert Jansen Jack Jansen +Hans-Peter Jansen Bill Janssen Thomas Jarosch Juhana Jauhiainen diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,10 @@ Library ------- +- Issue #26804: urllib.request will prefer lower_case proxy environment + variables over UPPER_CASE or Mixed_Case ones. Patch contributed by Hans-Peter + Jansen. + - Issue #26837: assertSequenceEqual() now correctly outputs non-stringified differing items (like bytes in the -b mode). This affects assertListEqual() and assertTupleEqual(). -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 11:34:52 2016 From: python-checkins at python.org (senthil.kumaran) Date: Mon, 25 Apr 2016 15:34:52 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy41?= Message-ID: <20160425153450.15832.15131.38A401B4@psf.io> https://hg.python.org/cpython/rev/316593f5bf73 changeset: 101141:316593f5bf73 parent: 101139:e014be53e7b9 parent: 101140:49b975122022 user: Senthil Kumaran date: Mon Apr 25 08:18:07 2016 -0700 summary: merge 3.5 Issue #26804: urllib.request will prefer lower_case proxy environment variables over UPPER_CASE or Mixed_Case ones. Patch contributed by Hans-Peter Jansen. Reviewed by Martin Panter and Senthil Kumaran. files: Doc/library/urllib.request.rst | 2 + Lib/test/test_urllib.py | 40 ++++++++++++++++++- Lib/urllib/request.py | 46 ++++++++++++++++----- Misc/ACKS | 1 + Misc/NEWS | 4 + 5 files changed, 81 insertions(+), 12 deletions(-) diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -166,6 +166,8 @@ in a case insensitive approach, for all operating systems first, and when it cannot find it, looks for proxy information from Mac OSX System Configuration for Mac OS X and Windows Systems Registry for Windows. + If both lowercase and uppercase environment variables exist (and disagree), + lowercase is preferred. The following classes are provided: diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -226,8 +226,46 @@ # getproxies_environment use lowered case truncated (no '_proxy') keys self.assertEqual('localhost', proxies['no']) # List of no_proxies with space. - self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com') + self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com:1234') self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com')) + self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com:8888')) + self.assertTrue(urllib.request.proxy_bypass_environment('newdomain.com:1234')) + + +class ProxyTests_withOrderedEnv(unittest.TestCase): + + def setUp(self): + # We need to test conditions, where variable order _is_ significant + self._saved_env = os.environ + # Monkey patch os.environ, start with empty fake environment + os.environ = collections.OrderedDict() + + def tearDown(self): + os.environ = self._saved_env + + def test_getproxies_environment_prefer_lowercase(self): + # Test lowercase preference with removal + os.environ['no_proxy'] = '' + os.environ['No_Proxy'] = 'localhost' + self.assertFalse(urllib.request.proxy_bypass_environment('localhost')) + self.assertFalse(urllib.request.proxy_bypass_environment('arbitrary')) + os.environ['http_proxy'] = '' + os.environ['HTTP_PROXY'] = 'http://somewhere:3128' + proxies = urllib.request.getproxies_environment() + self.assertEqual({}, proxies) + # Test lowercase preference of proxy bypass and correct matching including ports + os.environ['no_proxy'] = 'localhost, noproxy.com, my.proxy:1234' + os.environ['No_Proxy'] = 'xyz.com' + self.assertTrue(urllib.request.proxy_bypass_environment('localhost')) + self.assertTrue(urllib.request.proxy_bypass_environment('noproxy.com:5678')) + self.assertTrue(urllib.request.proxy_bypass_environment('my.proxy:1234')) + self.assertFalse(urllib.request.proxy_bypass_environment('my.proxy')) + self.assertFalse(urllib.request.proxy_bypass_environment('arbitrary')) + # Test lowercase preference with replacement + os.environ['http_proxy'] = 'http://somewhere:3128' + os.environ['Http_Proxy'] = 'http://somewhereelse:3128' + proxies = urllib.request.getproxies_environment() + self.assertEqual('http://somewhere:3128', proxies['http']) class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin, FakeFTPMixin): """Test urlopen() opening a fake http connection.""" diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -2455,19 +2455,35 @@ """ proxies = {} + # in order to prefer lowercase variables, process environment in + # two passes: first matches any, second pass matches lowercase only for name, value in os.environ.items(): name = name.lower() if value and name[-6:] == '_proxy': proxies[name[:-6]] = value + for name, value in os.environ.items(): + if name[-6:] == '_proxy': + name = name.lower() + if value: + proxies[name[:-6]] = value + else: + proxies.pop(name[:-6], None) return proxies -def proxy_bypass_environment(host): +def proxy_bypass_environment(host, proxies=None): """Test if proxies should not be used for a particular host. - Checks the environment for a variable named no_proxy, which should - be a list of DNS suffixes separated by commas, or '*' for all hosts. + Checks the proxy dict for the value of no_proxy, which should + be a list of comma separated DNS suffixes, or '*' for all hosts. + """ - no_proxy = os.environ.get('no_proxy', '') or os.environ.get('NO_PROXY', '') + if proxies is None: + proxies = getproxies_environment() + # don't bypass, if no_proxy isn't specified + try: + no_proxy = proxies['no'] + except KeyError: + return 0 # '*' is special case for always bypass if no_proxy == '*': return 1 @@ -2562,8 +2578,15 @@ def proxy_bypass(host): - if getproxies_environment(): - return proxy_bypass_environment(host) + """Return True, if host should be bypassed. + + Checks proxy settings gathered from the environment, if specified, + or from the MacOSX framework SystemConfiguration. + + """ + proxies = getproxies_environment() + if proxies: + return proxy_bypass_environment(host, proxies) else: return proxy_bypass_macosx_sysconf(host) @@ -2677,14 +2700,15 @@ return 0 def proxy_bypass(host): - """Return a dictionary of scheme -> proxy server URL mappings. - - Returns settings gathered from the environment, if specified, + """Return True, if host should be bypassed. + + Checks proxy settings gathered from the environment, if specified, or the registry. """ - if getproxies_environment(): - return proxy_bypass_environment(host) + proxies = getproxies_environment() + if proxies: + return proxy_bypass_environment(host, proxies) else: return proxy_bypass_registry(host) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -673,6 +673,7 @@ Bertrand Janin Geert Jansen Jack Jansen +Hans-Peter Jansen Bill Janssen Thomas Jarosch Juhana Jauhiainen diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -256,6 +256,10 @@ Library ------- +- Issue #26804: urllib.request will prefer lower_case proxy environment + variables over UPPER_CASE or Mixed_Case ones. Patch contributed by Hans-Peter + Jansen. + - Issue #26837: assertSequenceEqual() now correctly outputs non-stringified differing items (like bytes in the -b mode). This affects assertListEqual() and assertTupleEqual(). -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 12:18:00 2016 From: python-checkins at python.org (senthil.kumaran) Date: Mon, 25 Apr 2016 16:18:00 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_backport_fix_f?= =?utf-8?q?or_Issue_=2326804=2E?= Message-ID: <20160425161759.32231.18513.01AEDC61@psf.io> https://hg.python.org/cpython/rev/c502deb19cb0 changeset: 101142:c502deb19cb0 branch: 2.7 parent: 101134:d0d541c2afb7 user: Senthil Kumaran date: Mon Apr 25 09:17:54 2016 -0700 summary: backport fix for Issue #26804. urllib.request will prefer lower_case proxy environment variables over UPPER_CASE or Mixed_Case ones. files: Doc/library/urllib.rst | 2 + Lib/test/test_urllib.py | 43 +++++++++++++++++++++++- Lib/urllib.py | 51 +++++++++++++++++++++------- Misc/NEWS | 3 + 4 files changed, 84 insertions(+), 15 deletions(-) diff --git a/Doc/library/urllib.rst b/Doc/library/urllib.rst --- a/Doc/library/urllib.rst +++ b/Doc/library/urllib.rst @@ -292,6 +292,8 @@ in case insensitive way, for all operating systems first, and when it cannot find it, looks for proxy information from Mac OSX System Configuration for Mac OS X and Windows Systems Registry for Windows. + If both lowercase and uppercase environment variables exist (and disagree), + lowercase is preferred. .. note:: urllib also exposes certain utility functions like splittype, splithost and diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -1,5 +1,6 @@ """Regresssion tests for urllib""" +import collections import urllib import httplib import unittest @@ -158,8 +159,46 @@ # getproxies_environment use lowered case truncated (no '_proxy') keys self.assertEqual('localhost', proxies['no']) # List of no_proxies with space. - self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com') + self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com:1234') self.assertTrue(urllib.proxy_bypass_environment('anotherdomain.com')) + self.assertTrue(urllib.proxy_bypass_environment('anotherdomain.com:8888')) + self.assertTrue(urllib.proxy_bypass_environment('newdomain.com:1234')) + + +class ProxyTests_withOrderedEnv(unittest.TestCase): + + def setUp(self): + # We need to test conditions, where variable order _is_ significant + self._saved_env = os.environ + # Monkey patch os.environ, start with empty fake environment + os.environ = collections.OrderedDict() + + def tearDown(self): + os.environ = self._saved_env + + def test_getproxies_environment_prefer_lowercase(self): + # Test lowercase preference with removal + os.environ['no_proxy'] = '' + os.environ['No_Proxy'] = 'localhost' + self.assertFalse(urllib.proxy_bypass_environment('localhost')) + self.assertFalse(urllib.proxy_bypass_environment('arbitrary')) + os.environ['http_proxy'] = '' + os.environ['HTTP_PROXY'] = 'http://somewhere:3128' + proxies = urllib.getproxies_environment() + self.assertEqual({}, proxies) + # Test lowercase preference of proxy bypass and correct matching including ports + os.environ['no_proxy'] = 'localhost, noproxy.com, my.proxy:1234' + os.environ['No_Proxy'] = 'xyz.com' + self.assertTrue(urllib.proxy_bypass_environment('localhost')) + self.assertTrue(urllib.proxy_bypass_environment('noproxy.com:5678')) + self.assertTrue(urllib.proxy_bypass_environment('my.proxy:1234')) + self.assertFalse(urllib.proxy_bypass_environment('my.proxy')) + self.assertFalse(urllib.proxy_bypass_environment('arbitrary')) + # Test lowercase preference with replacement + os.environ['http_proxy'] = 'http://somewhere:3128' + os.environ['Http_Proxy'] = 'http://somewhereelse:3128' + proxies = urllib.getproxies_environment() + self.assertEqual('http://somewhere:3128', proxies['http']) class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin): @@ -1030,6 +1069,8 @@ Pathname_Tests, Utility_Tests, URLopener_Tests, + ProxyTests, + ProxyTests_withOrderedEnv, #FTPWrapperTests, ) diff --git a/Lib/urllib.py b/Lib/urllib.py --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -1379,25 +1379,42 @@ """Return a dictionary of scheme -> proxy server URL mappings. Scan the environment for variables named _proxy; - this seems to be the standard convention. If you need a - different way, you can pass a proxies dictionary to the + this seems to be the standard convention. In order to prefer lowercase + variables, we process the environment in two passes, first matches any + and second matches only lower case proxies. + + If you need a different way, you can pass a proxies dictionary to the [Fancy]URLopener constructor. - """ proxies = {} for name, value in os.environ.items(): name = name.lower() if value and name[-6:] == '_proxy': proxies[name[:-6]] = value + + for name, value in os.environ.items(): + if name[-6:] == '_proxy': + name = name.lower() + if value: + proxies[name[:-6]] = value + else: + proxies.pop(name[:-6], None) + return proxies -def proxy_bypass_environment(host): +def proxy_bypass_environment(host, proxies=None): """Test if proxies should not be used for a particular host. - Checks the environment for a variable named no_proxy, which should - be a list of DNS suffixes separated by commas, or '*' for all hosts. + Checks the proxies dict for the value of no_proxy, which should be a + list of comma separated DNS suffixes, or '*' for all hosts. """ - no_proxy = os.environ.get('no_proxy', '') or os.environ.get('NO_PROXY', '') + if proxies is None: + proxies = getproxies_environment() + # don't bypass, if no_proxy isn't specified + try: + no_proxy = proxies['no'] + except KeyError: + return 0 # '*' is special case for always bypass if no_proxy == '*': return 1 @@ -1483,8 +1500,14 @@ return _get_proxies() def proxy_bypass(host): - if getproxies_environment(): - return proxy_bypass_environment(host) + """Return True, if a host should be bypassed. + + Checks proxy settings gathered from the environment, if specified, or + from the MacOSX framework SystemConfiguration. + """ + proxies = getproxies_environment() + if proxies: + return proxy_bypass_environment(host, proxies) else: return proxy_bypass_macosx_sysconf(host) @@ -1600,14 +1623,14 @@ return 0 def proxy_bypass(host): - """Return a dictionary of scheme -> proxy server URL mappings. + """Return True, if the host should be bypassed. - Returns settings gathered from the environment, if specified, + Checks proxy settings gathered from the environment, if specified, or the registry. - """ - if getproxies_environment(): - return proxy_bypass_environment(host) + proxies = getproxies_environment() + if proxies: + return proxy_bypass_environment(host, proxies) else: return proxy_bypass_registry(host) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,9 @@ Library ------- +- Issue #26804: urllib will prefer lower_case proxy environment variables over + UPPER_CASE or Mixed_Case ones. Patch contributed by Hans-Peter Jansen. + - Issue #26837: assertSequenceEqual() now correctly outputs non-stringified differing items. This affects assertListEqual() and assertTupleEqual(). -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 15:39:36 2016 From: python-checkins at python.org (stefan.krah) Date: Mon, 25 Apr 2016 19:39:36 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2317905=3A_Do_not_g?= =?utf-8?q?uard_locale_include_with_HAVE=5FLANGINFO=5FH=2E?= Message-ID: <20160425193908.109607.42301.6D59B075@psf.io> https://hg.python.org/cpython/rev/cc501d439239 changeset: 101143:cc501d439239 parent: 101141:316593f5bf73 user: Stefan Krah date: Mon Apr 25 21:38:53 2016 +0200 summary: Issue #17905: Do not guard locale include with HAVE_LANGINFO_H. files: Python/sysmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -20,6 +20,7 @@ #include "pythread.h" #include "osdefs.h" +#include #ifdef MS_WINDOWS #define WIN32_LEAN_AND_MEAN @@ -33,7 +34,6 @@ #endif #ifdef HAVE_LANGINFO_H -#include #include #endif -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 16:49:32 2016 From: python-checkins at python.org (stefan.krah) Date: Mon, 25 Apr 2016 20:49:32 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326846=3A_Workarou?= =?utf-8?q?nd_for_non-standard_stdlib=2Eh_on_Android=2E?= Message-ID: <20160425204931.16114.44611.0B612BD0@psf.io> https://hg.python.org/cpython/rev/fae01d14dd4e changeset: 101144:fae01d14dd4e user: Stefan Krah date: Mon Apr 25 22:48:42 2016 +0200 summary: Issue #26846: Workaround for non-standard stdlib.h on Android. files: Modules/_decimal/libmpdec/basearith.c | 1 - Modules/_decimal/libmpdec/io.c | 1 - Modules/_decimal/libmpdec/memory.c | 2 +- Modules/_decimal/libmpdec/mpalloc.h | 4 ++-- Modules/_decimal/libmpdec/mpdecimal.c | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Modules/_decimal/libmpdec/basearith.c b/Modules/_decimal/libmpdec/basearith.c --- a/Modules/_decimal/libmpdec/basearith.c +++ b/Modules/_decimal/libmpdec/basearith.c @@ -32,7 +32,6 @@ #include #include #include "constants.h" -#include "memory.h" #include "typearith.h" #include "basearith.h" diff --git a/Modules/_decimal/libmpdec/io.c b/Modules/_decimal/libmpdec/io.c --- a/Modules/_decimal/libmpdec/io.c +++ b/Modules/_decimal/libmpdec/io.c @@ -37,7 +37,6 @@ #include #include "bits.h" #include "constants.h" -#include "memory.h" #include "typearith.h" #include "io.h" diff --git a/Modules/_decimal/libmpdec/memory.c b/Modules/_decimal/libmpdec/memory.c --- a/Modules/_decimal/libmpdec/memory.c +++ b/Modules/_decimal/libmpdec/memory.c @@ -30,7 +30,7 @@ #include #include #include "typearith.h" -#include "memory.h" +#include "mpalloc.h" #if defined(_MSC_VER) diff --git a/Modules/_decimal/libmpdec/memory.h b/Modules/_decimal/libmpdec/mpalloc.h rename from Modules/_decimal/libmpdec/memory.h rename to Modules/_decimal/libmpdec/mpalloc.h --- a/Modules/_decimal/libmpdec/memory.h +++ b/Modules/_decimal/libmpdec/mpalloc.h @@ -26,8 +26,8 @@ */ -#ifndef MEMORY_H -#define MEMORY_H +#ifndef MPALLOC_H +#define MPALLOC_H #include "mpdecimal.h" diff --git a/Modules/_decimal/libmpdec/mpdecimal.c b/Modules/_decimal/libmpdec/mpdecimal.c --- a/Modules/_decimal/libmpdec/mpdecimal.c +++ b/Modules/_decimal/libmpdec/mpdecimal.c @@ -36,7 +36,7 @@ #include "bits.h" #include "convolute.h" #include "crt.h" -#include "memory.h" +#include "mpalloc.h" #include "typearith.h" #include "umodarith.h" -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 19:10:47 2016 From: python-checkins at python.org (stefan.krah) Date: Mon, 25 Apr 2016 23:10:47 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2320306=3A_The_pw?= =?utf-8?q?=5Fgecos_and_pw=5Fpasswd_fields_are_not_required_by_POSIX=2E?= Message-ID: <20160425231036.59192.12326.7584B56F@psf.io> https://hg.python.org/cpython/rev/0d74d4937ab9 changeset: 101145:0d74d4937ab9 user: Stefan Krah date: Tue Apr 26 01:09:18 2016 +0200 summary: Issue #20306: The pw_gecos and pw_passwd fields are not required by POSIX. If they aren't present, set them to an empty string. files: Modules/pwdmodule.c | 8 ++++++++ configure | 27 +++++++++++++++++++++++++++ configure.ac | 4 ++++ pyconfig.h.in | 6 ++++++ 4 files changed, 45 insertions(+), 0 deletions(-) diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c --- a/Modules/pwdmodule.c +++ b/Modules/pwdmodule.c @@ -75,10 +75,18 @@ #define SETS(i,val) sets(v, i, val) SETS(setIndex++, p->pw_name); +#if defined(HAVE_STRUCT_PASSWD_PW_PASSWD) SETS(setIndex++, p->pw_passwd); +#else + SETS(setIndex++, ""); +#endif PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromUid(p->pw_uid)); PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromGid(p->pw_gid)); +#if defined(HAVE_STRUCT_PASSWD_PW_GECOS) SETS(setIndex++, p->pw_gecos); +#else + SETS(setIndex++, ""); +#endif SETS(setIndex++, p->pw_dir); SETS(setIndex++, p->pw_shell); diff --git a/configure b/configure --- a/configure +++ b/configure @@ -12918,6 +12918,33 @@ fi +ac_fn_c_check_member "$LINENO" "struct passwd" "pw_gecos" "ac_cv_member_struct_passwd_pw_gecos" " + #include + #include + +" +if test "x$ac_cv_member_struct_passwd_pw_gecos" = xyes; then : + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_PASSWD_PW_GECOS 1 +_ACEOF + + +fi +ac_fn_c_check_member "$LINENO" "struct passwd" "pw_passwd" "ac_cv_member_struct_passwd_pw_passwd" " + #include + #include + +" +if test "x$ac_cv_member_struct_passwd_pw_passwd" = xyes; then : + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_PASSWD_PW_PASSWD 1 +_ACEOF + + +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for time.h that defines altzone" >&5 $as_echo_n "checking for time.h that defines altzone... " >&6; } diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -3762,6 +3762,10 @@ AC_CHECK_MEMBERS([struct stat.st_gen]) AC_CHECK_MEMBERS([struct stat.st_birthtime]) AC_CHECK_MEMBERS([struct stat.st_blocks]) +AC_CHECK_MEMBERS([struct passwd.pw_gecos, struct passwd.pw_passwd], [], [], [[ + #include + #include +]]) AC_MSG_CHECKING(for time.h that defines altzone) AC_CACHE_VAL(ac_cv_header_time_altzone,[ diff --git a/pyconfig.h.in b/pyconfig.h.in --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -916,6 +916,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STROPTS_H +/* Define to 1 if `pw_gecos' is a member of `struct passwd'. */ +#undef HAVE_STRUCT_PASSWD_PW_GECOS + +/* Define to 1 if `pw_passwd' is a member of `struct passwd'. */ +#undef HAVE_STRUCT_PASSWD_PW_PASSWD + /* Define to 1 if `st_birthtime' is a member of `struct stat'. */ #undef HAVE_STRUCT_STAT_ST_BIRTHTIME -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 19:57:18 2016 From: python-checkins at python.org (stefan.krah) Date: Mon, 25 Apr 2016 23:57:18 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2322747=3A_Workarou?= =?utf-8?q?nd_for_systems_without_langinfo=2Eh=2E?= Message-ID: <20160425235705.24233.47904.75846DEF@psf.io> https://hg.python.org/cpython/rev/ad6be34ce8c9 changeset: 101146:ad6be34ce8c9 user: Stefan Krah date: Tue Apr 26 01:56:50 2016 +0200 summary: Issue #22747: Workaround for systems without langinfo.h. files: Python/pylifecycle.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -223,6 +223,8 @@ return NULL; } return get_codec_name(codeset); +#elif defined(__ANDROID__) + return get_codec_name("UTF-8"); #else PyErr_SetNone(PyExc_NotImplementedError); return NULL; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Mon Apr 25 20:13:42 2016 From: python-checkins at python.org (ned.deily) Date: Tue, 26 Apr 2016 00:13:42 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Update_email_address?= Message-ID: <20160426001336.71171.41463.E0EE05F1@psf.io> https://hg.python.org/peps/rev/ff538b4d43f5 changeset: 6295:ff538b4d43f5 user: Ned Deily date: Mon Apr 25 20:13:27 2016 -0400 summary: Update email address files: pep-0494.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pep-0494.txt b/pep-0494.txt --- a/pep-0494.txt +++ b/pep-0494.txt @@ -2,7 +2,7 @@ Title: Python 3.6 Release Schedule Version: $Revision$ Last-Modified: $Date$ -Author: Ned Deily +Author: Ned Deily Status: Active Type: Informational Content-Type: text/x-rst -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Tue Apr 26 02:31:34 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Tue, 26 Apr 2016 06:31:34 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?b?KTogSXNzdWUgIzI2NjM0OiByZWN1cnNpdmVfcmVwcigpIG5vdyBzZXRzIF9f?= =?utf-8?q?qualname=5F=5F_of_wrapper=2E?= Message-ID: <20160426063134.13115.86384.BD6DA262@psf.io> https://hg.python.org/cpython/rev/fb70ea8b7b2d changeset: 101148:fb70ea8b7b2d parent: 101146:ad6be34ce8c9 parent: 101147:1f0369547b0e user: Serhiy Storchaka date: Tue Apr 26 09:31:11 2016 +0300 summary: Issue #26634: recursive_repr() now sets __qualname__ of wrapper. Patch by Xiang Zhang. files: Lib/reprlib.py | 1 + Lib/test/test_reprlib.py | 14 ++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 18 insertions(+), 0 deletions(-) diff --git a/Lib/reprlib.py b/Lib/reprlib.py --- a/Lib/reprlib.py +++ b/Lib/reprlib.py @@ -30,6 +30,7 @@ wrapper.__module__ = getattr(user_function, '__module__') wrapper.__doc__ = getattr(user_function, '__doc__') wrapper.__name__ = getattr(user_function, '__name__') + wrapper.__qualname__ = getattr(user_function, '__qualname__') wrapper.__annotations__ = getattr(user_function, '__annotations__', {}) return wrapper diff --git a/Lib/test/test_reprlib.py b/Lib/test/test_reprlib.py --- a/Lib/test/test_reprlib.py +++ b/Lib/test/test_reprlib.py @@ -374,6 +374,13 @@ def __repr__(self): return '<' + ', '.join(map(str, self.values)) + '>' +class MyContainer3: + def __repr__(self): + 'Test document content' + pass + wrapped = __repr__ + wrapper = recursive_repr()(wrapped) + class TestRecursiveRepr(unittest.TestCase): def test_recursive_repr(self): m = MyContainer(list('abcde')) @@ -387,5 +394,12 @@ m.append(m) self.assertEqual(repr(m), '') + def test_assigned_attributes(self): + from functools import WRAPPER_ASSIGNMENTS as assigned + wrapped = MyContainer3.wrapped + wrapper = MyContainer3.wrapper + for name in assigned: + self.assertIs(getattr(wrapper, name), getattr(wrapped, name)) + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -256,6 +256,9 @@ Library ------- +- Issue #26634: recursive_repr() now sets __qualname__ of wrapper. Patch by + Xiang Zhang. + - Issue #26804: urllib.request will prefer lower_case proxy environment variables over UPPER_CASE or Mixed_Case ones. Patch contributed by Hans-Peter Jansen. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 02:31:36 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Tue, 26 Apr 2016 06:31:36 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2NjM0?= =?utf-8?q?=3A_recursive=5Frepr=28=29_now_sets_=5F=5Fqualname=5F=5F_of_wra?= =?utf-8?q?pper=2E?= Message-ID: <20160426063134.71179.79646.68EA3120@psf.io> https://hg.python.org/cpython/rev/1f0369547b0e changeset: 101147:1f0369547b0e branch: 3.5 parent: 101140:49b975122022 user: Serhiy Storchaka date: Tue Apr 26 09:30:44 2016 +0300 summary: Issue #26634: recursive_repr() now sets __qualname__ of wrapper. Patch by Xiang Zhang. files: Lib/reprlib.py | 1 + Lib/test/test_reprlib.py | 14 ++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 18 insertions(+), 0 deletions(-) diff --git a/Lib/reprlib.py b/Lib/reprlib.py --- a/Lib/reprlib.py +++ b/Lib/reprlib.py @@ -30,6 +30,7 @@ wrapper.__module__ = getattr(user_function, '__module__') wrapper.__doc__ = getattr(user_function, '__doc__') wrapper.__name__ = getattr(user_function, '__name__') + wrapper.__qualname__ = getattr(user_function, '__qualname__') wrapper.__annotations__ = getattr(user_function, '__annotations__', {}) return wrapper diff --git a/Lib/test/test_reprlib.py b/Lib/test/test_reprlib.py --- a/Lib/test/test_reprlib.py +++ b/Lib/test/test_reprlib.py @@ -374,6 +374,13 @@ def __repr__(self): return '<' + ', '.join(map(str, self.values)) + '>' +class MyContainer3: + def __repr__(self): + 'Test document content' + pass + wrapped = __repr__ + wrapper = recursive_repr()(wrapped) + class TestRecursiveRepr(unittest.TestCase): def test_recursive_repr(self): m = MyContainer(list('abcde')) @@ -387,5 +394,12 @@ m.append(m) self.assertEqual(repr(m), '') + def test_assigned_attributes(self): + from functools import WRAPPER_ASSIGNMENTS as assigned + wrapped = MyContainer3.wrapped + wrapper = MyContainer3.wrapper + for name in assigned: + self.assertIs(getattr(wrapper, name), getattr(wrapped, name)) + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,9 @@ Library ------- +- Issue #26634: recursive_repr() now sets __qualname__ of wrapper. Patch by + Xiang Zhang. + - Issue #26804: urllib.request will prefer lower_case proxy environment variables over UPPER_CASE or Mixed_Case ones. Patch contributed by Hans-Peter Jansen. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 03:10:06 2016 From: python-checkins at python.org (raymond.hettinger) Date: Tue, 26 Apr 2016 07:10:06 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316394=3A__Note_th?= =?utf-8?q?e_tee=28=29_pure_python_equivalent_is_only_a_rough?= Message-ID: <20160426071005.21044.22330.7DBCDF38@psf.io> https://hg.python.org/cpython/rev/f09306f9fa6f changeset: 101149:f09306f9fa6f user: Raymond Hettinger date: Tue Apr 26 00:10:00 2016 -0700 summary: Issue #16394: Note the tee() pure python equivalent is only a rough approximation. files: Doc/library/itertools.rst | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -588,7 +588,10 @@ .. function:: tee(iterable, n=2) - Return *n* independent iterators from a single iterable. Equivalent to:: + Return *n* independent iterators from a single iterable. + + The following Python code helps explain what *tee* does (although the actual + implementation is more complex and uses only a single underlying FIFO queue):: def tee(iterable, n=2): it = iter(iterable) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 03:59:21 2016 From: python-checkins at python.org (raymond.hettinger) Date: Tue, 26 Apr 2016 07:59:21 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzIzOTg2?= =?utf-8?q?=3A__Note_that_the_in-operator_for_lists_and_tuples_check_ident?= =?utf-8?q?ity?= Message-ID: <20160426075921.13091.69581.D7790430@psf.io> https://hg.python.org/cpython/rev/aba647a34ed4 changeset: 101150:aba647a34ed4 branch: 2.7 parent: 101142:c502deb19cb0 user: Raymond Hettinger date: Tue Apr 26 00:59:16 2016 -0700 summary: Issue #23986: Note that the in-operator for lists and tuples check identity before equality. files: Doc/reference/expressions.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1153,7 +1153,7 @@ dictionaries (for keys) and sets support membership testing. For the list and tuple types, ``x in y`` is true if and only if there exists an -index *i* such that ``x == y[i]`` is true. +index *i* such that either ``x is y[i]`` or ``x == y[i]`` is true. For the Unicode and string types, ``x in y`` is true if and only if *x* is a substring of *y*. An equivalent test is ``y.find(x) != -1``. Note, *x* and *y* -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 04:09:44 2016 From: python-checkins at python.org (raymond.hettinger) Date: Tue, 26 Apr 2016 08:09:44 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI0NzE1?= =?utf-8?q?=3A_Improve_sort_stability_example?= Message-ID: <20160426080937.122294.12287.223D1516@psf.io> https://hg.python.org/cpython/rev/ba87f7f246e0 changeset: 101151:ba87f7f246e0 branch: 2.7 user: Raymond Hettinger date: Tue Apr 26 01:09:32 2016 -0700 summary: Issue #24715: Improve sort stability example files: Doc/howto/sorting.rst | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Doc/howto/sorting.rst b/Doc/howto/sorting.rst --- a/Doc/howto/sorting.rst +++ b/Doc/howto/sorting.rst @@ -274,7 +274,11 @@ twice: >>> data = [('red', 1), ('blue', 1), ('red', 2), ('blue', 2)] - >>> assert sorted(data, reverse=True) == list(reversed(sorted(reversed(data)))) + >>> standard_way = sorted(data, key=itemgetter(0), reverse=True) + >>> double_reversed = list(reversed(sorted(reversed(data), key=itemgetter(0)))) + >>> assert standard_way == double_reversed + >>> standard_way + [('red', 1), ('red', 2), ('blue', 1), ('blue', 2)] * To create a standard sort order for a class, just add the appropriate rich comparison methods: -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 04:11:34 2016 From: python-checkins at python.org (raymond.hettinger) Date: Tue, 26 Apr 2016 08:11:34 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_merge?= Message-ID: <20160426081134.30191.23361.C8B92D58@psf.io> https://hg.python.org/cpython/rev/ac165e566573 changeset: 101153:ac165e566573 parent: 101149:f09306f9fa6f parent: 101152:ae1e55102449 user: Raymond Hettinger date: Tue Apr 26 01:11:28 2016 -0700 summary: merge files: Doc/howto/sorting.rst | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Doc/howto/sorting.rst b/Doc/howto/sorting.rst --- a/Doc/howto/sorting.rst +++ b/Doc/howto/sorting.rst @@ -262,7 +262,11 @@ twice: >>> data = [('red', 1), ('blue', 1), ('red', 2), ('blue', 2)] - >>> assert sorted(data, reverse=True) == list(reversed(sorted(reversed(data)))) + >>> standard_way = sorted(data, key=itemgetter(0), reverse=True) + >>> double_reversed = list(reversed(sorted(reversed(data), key=itemgetter(0)))) + >>> assert standard_way == double_reversed + >>> standard_way + [('red', 1), ('red', 2), ('blue', 1), ('blue', 2)] * The sort routines are guaranteed to use :meth:`__lt__` when making comparisons between two objects. So, it is easy to add a standard sort order to a class by -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 04:11:36 2016 From: python-checkins at python.org (raymond.hettinger) Date: Tue, 26 Apr 2016 08:11:36 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI0NzE1?= =?utf-8?q?=3A_Improve_sort_stability_example?= Message-ID: <20160426081134.7748.58431.53C1F178@psf.io> https://hg.python.org/cpython/rev/ae1e55102449 changeset: 101152:ae1e55102449 branch: 3.5 parent: 101147:1f0369547b0e user: Raymond Hettinger date: Tue Apr 26 01:11:10 2016 -0700 summary: Issue #24715: Improve sort stability example files: Doc/howto/sorting.rst | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Doc/howto/sorting.rst b/Doc/howto/sorting.rst --- a/Doc/howto/sorting.rst +++ b/Doc/howto/sorting.rst @@ -262,7 +262,11 @@ twice: >>> data = [('red', 1), ('blue', 1), ('red', 2), ('blue', 2)] - >>> assert sorted(data, reverse=True) == list(reversed(sorted(reversed(data)))) + >>> standard_way = sorted(data, key=itemgetter(0), reverse=True) + >>> double_reversed = list(reversed(sorted(reversed(data), key=itemgetter(0)))) + >>> assert standard_way == double_reversed + >>> standard_way + [('red', 1), ('red', 2), ('blue', 1), ('blue', 2)] * The sort routines are guaranteed to use :meth:`__lt__` when making comparisons between two objects. So, it is easy to add a standard sort order to a class by -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 05:43:33 2016 From: python-checkins at python.org (stefan.krah) Date: Tue, 26 Apr 2016 09:43:33 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2320306=3A__Android?= =?utf-8?q?_is_the_only_system_that_returns_NULL_for_the_pw=5Fpasswd?= Message-ID: <20160426094333.21050.1115.2D98A250@psf.io> https://hg.python.org/cpython/rev/f0f519aca558 changeset: 101154:f0f519aca558 user: Stefan Krah date: Tue Apr 26 11:43:21 2016 +0200 summary: Issue #20306: Android is the only system that returns NULL for the pw_passwd field. Rather than cluttering the tests, translate the arguably more correct "None" to an empty string. files: Modules/pwdmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c --- a/Modules/pwdmodule.c +++ b/Modules/pwdmodule.c @@ -75,7 +75,7 @@ #define SETS(i,val) sets(v, i, val) SETS(setIndex++, p->pw_name); -#if defined(HAVE_STRUCT_PASSWD_PW_PASSWD) +#if defined(HAVE_STRUCT_PASSWD_PW_PASSWD) && !defined(__ANDROID__) SETS(setIndex++, p->pw_passwd); #else SETS(setIndex++, ""); -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 06:36:36 2016 From: python-checkins at python.org (victor.stinner) Date: Tue, 26 Apr 2016 10:36:36 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2325349=2C_=2326249?= =?utf-8?q?=3A_Fix_memleak_in_formatfloat=28=29?= Message-ID: <20160426103636.29338.66768.CC072D0A@psf.io> https://hg.python.org/cpython/rev/090502a0c69c changeset: 101155:090502a0c69c user: Victor Stinner date: Tue Apr 26 12:35:13 2016 +0200 summary: Issue #25349, #26249: Fix memleak in formatfloat() files: Objects/bytesobject.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -438,6 +438,7 @@ if (str == NULL) return NULL; Py_MEMCPY(str, p, len); + PyMem_Free(p); str += len; return str; } -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 07:48:48 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 26 Apr 2016 11:48:48 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzIwNTk4?= =?utf-8?q?=3A_Replace_trivial_split=28=29_calls_with_lists_in_argparse_do?= =?utf-8?q?cs?= Message-ID: <20160426114848.1669.632.4359F4DA@psf.io> https://hg.python.org/cpython/rev/44f888e47ab0 changeset: 101156:44f888e47ab0 branch: 2.7 parent: 101151:ba87f7f246e0 user: Martin Panter date: Tue Apr 26 11:33:46 2016 +0000 summary: Issue #20598: Replace trivial split() calls with lists in argparse docs files: Doc/library/argparse.rst | 46 ++++++++++++++-------------- 1 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -680,7 +680,7 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', action='store_const', const=42) - >>> parser.parse_args('--foo'.split()) + >>> parser.parse_args(['--foo']) Namespace(foo=42) * ``'store_true'`` and ``'store_false'`` - These are special cases of @@ -721,7 +721,7 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--verbose', '-v', action='count') - >>> parser.parse_args('-vvv'.split()) + >>> parser.parse_args(['-vvv']) Namespace(verbose=3) * ``'help'`` - This prints a complete help message for all the options in the @@ -796,11 +796,11 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', nargs='?', const='c', default='d') >>> parser.add_argument('bar', nargs='?', default='d') - >>> parser.parse_args('XX --foo YY'.split()) + >>> parser.parse_args(['XX', '--foo', 'YY']) Namespace(bar='XX', foo='YY') - >>> parser.parse_args('XX --foo'.split()) + >>> parser.parse_args(['XX', '--foo']) Namespace(bar='XX', foo='c') - >>> parser.parse_args(''.split()) + >>> parser.parse_args([]) Namespace(bar='d', foo='d') One of the more common uses of ``nargs='?'`` is to allow optional input and @@ -836,9 +836,9 @@ >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('foo', nargs='+') - >>> parser.parse_args('a b'.split()) + >>> parser.parse_args(['a', 'b']) Namespace(foo=['a', 'b']) - >>> parser.parse_args(''.split()) + >>> parser.parse_args([]) usage: PROG [-h] foo [foo ...] PROG: error: too few arguments @@ -893,9 +893,9 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', default=42) - >>> parser.parse_args('--foo 2'.split()) + >>> parser.parse_args(['--foo', '2']) Namespace(foo='2') - >>> parser.parse_args(''.split()) + >>> parser.parse_args([]) Namespace(foo=42) If the ``default`` value is a string, the parser parses the value as if it @@ -914,9 +914,9 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('foo', nargs='?', default=42) - >>> parser.parse_args('a'.split()) + >>> parser.parse_args(['a']) Namespace(foo='a') - >>> parser.parse_args(''.split()) + >>> parser.parse_args([]) Namespace(foo=42) @@ -973,9 +973,9 @@ ... >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('foo', type=perfect_square) - >>> parser.parse_args('9'.split()) + >>> parser.parse_args(['9']) Namespace(foo=9) - >>> parser.parse_args('7'.split()) + >>> parser.parse_args(['7']) usage: PROG [-h] foo PROG: error: argument foo: '7' is not a perfect square @@ -984,9 +984,9 @@ >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('foo', type=int, choices=xrange(5, 10)) - >>> parser.parse_args('7'.split()) + >>> parser.parse_args(['7']) Namespace(foo=7) - >>> parser.parse_args('11'.split()) + >>> parser.parse_args(['11']) usage: PROG [-h] {5,6,7,8,9} PROG: error: argument foo: invalid choice: 11 (choose from 5, 6, 7, 8, 9) @@ -1067,7 +1067,7 @@ ... help='foo the bars before frobbling') >>> parser.add_argument('bar', nargs='+', ... help='one of the bars to be frobbled') - >>> parser.parse_args('-h'.split()) + >>> parser.parse_args(['-h']) usage: frobble [-h] [--foo] bar [bar ...] positional arguments: @@ -1182,7 +1182,7 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('bar') - >>> parser.parse_args('XXX'.split()) + >>> parser.parse_args(['XXX']) Namespace(bar='XXX') For optional argument actions, the value of ``dest`` is normally inferred from @@ -1277,22 +1277,22 @@ >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('-x') >>> parser.add_argument('--foo') - >>> parser.parse_args('-x X'.split()) + >>> parser.parse_args(['-x', 'X']) Namespace(foo=None, x='X') - >>> parser.parse_args('--foo FOO'.split()) + >>> parser.parse_args(['--foo', 'FOO']) Namespace(foo='FOO', x=None) For long options (options with names longer than a single character), the option and value can also be passed as a single command-line argument, using ``=`` to separate them:: - >>> parser.parse_args('--foo=FOO'.split()) + >>> parser.parse_args(['--foo=FOO']) Namespace(foo='FOO', x=None) For short options (options only one character long), the option and its value can be concatenated:: - >>> parser.parse_args('-xX'.split()) + >>> parser.parse_args(['-xX']) Namespace(foo=None, x='X') Several short options can be joined together, using only a single ``-`` prefix, @@ -1302,7 +1302,7 @@ >>> parser.add_argument('-x', action='store_true') >>> parser.add_argument('-y', action='store_true') >>> parser.add_argument('-z') - >>> parser.parse_args('-xyzZ'.split()) + >>> parser.parse_args(['-xyzZ']) Namespace(x=True, y=True, z='Z') @@ -1423,7 +1423,7 @@ ... default=max, help='sum the integers (default: find the max)') >>> parser.parse_args(['1', '2', '3', '4']) Namespace(accumulate=, integers=[1, 2, 3, 4]) - >>> parser.parse_args('1 2 3 4 --sum'.split()) + >>> parser.parse_args(['1', '2', '3', '4', '--sum']) Namespace(accumulate=, integers=[1, 2, 3, 4]) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 07:48:49 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 26 Apr 2016 11:48:49 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2320598=3A_Merge_argparse_docs_from_3=2E5?= Message-ID: <20160426114849.12698.14020.6F64AC1E@psf.io> https://hg.python.org/cpython/rev/14cb17682831 changeset: 101158:14cb17682831 parent: 101155:090502a0c69c parent: 101157:49561532504c user: Martin Panter date: Tue Apr 26 11:47:10 2016 +0000 summary: Issue #20598: Merge argparse docs from 3.5 files: Doc/library/argparse.rst | 46 ++++++++++++++-------------- 1 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -725,7 +725,7 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', action='store_const', const=42) - >>> parser.parse_args('--foo'.split()) + >>> parser.parse_args(['--foo']) Namespace(foo=42) * ``'store_true'`` and ``'store_false'`` - These are special cases of @@ -766,7 +766,7 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--verbose', '-v', action='count') - >>> parser.parse_args('-vvv'.split()) + >>> parser.parse_args(['-vvv']) Namespace(verbose=3) * ``'help'`` - This prints a complete help message for all the options in the @@ -841,11 +841,11 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', nargs='?', const='c', default='d') >>> parser.add_argument('bar', nargs='?', default='d') - >>> parser.parse_args('XX --foo YY'.split()) + >>> parser.parse_args(['XX', '--foo', 'YY']) Namespace(bar='XX', foo='YY') - >>> parser.parse_args('XX --foo'.split()) + >>> parser.parse_args(['XX', '--foo']) Namespace(bar='XX', foo='c') - >>> parser.parse_args(''.split()) + >>> parser.parse_args([]) Namespace(bar='d', foo='d') One of the more common uses of ``nargs='?'`` is to allow optional input and @@ -881,9 +881,9 @@ >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('foo', nargs='+') - >>> parser.parse_args('a b'.split()) + >>> parser.parse_args(['a', 'b']) Namespace(foo=['a', 'b']) - >>> parser.parse_args(''.split()) + >>> parser.parse_args([]) usage: PROG [-h] foo [foo ...] PROG: error: too few arguments @@ -938,9 +938,9 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', default=42) - >>> parser.parse_args('--foo 2'.split()) + >>> parser.parse_args(['--foo', '2']) Namespace(foo='2') - >>> parser.parse_args(''.split()) + >>> parser.parse_args([]) Namespace(foo=42) If the ``default`` value is a string, the parser parses the value as if it @@ -959,9 +959,9 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('foo', nargs='?', default=42) - >>> parser.parse_args('a'.split()) + >>> parser.parse_args(['a']) Namespace(foo='a') - >>> parser.parse_args(''.split()) + >>> parser.parse_args([]) Namespace(foo=42) @@ -1018,9 +1018,9 @@ ... >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('foo', type=perfect_square) - >>> parser.parse_args('9'.split()) + >>> parser.parse_args(['9']) Namespace(foo=9) - >>> parser.parse_args('7'.split()) + >>> parser.parse_args(['7']) usage: PROG [-h] foo PROG: error: argument foo: '7' is not a perfect square @@ -1029,9 +1029,9 @@ >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('foo', type=int, choices=range(5, 10)) - >>> parser.parse_args('7'.split()) + >>> parser.parse_args(['7']) Namespace(foo=7) - >>> parser.parse_args('11'.split()) + >>> parser.parse_args(['11']) usage: PROG [-h] {5,6,7,8,9} PROG: error: argument foo: invalid choice: 11 (choose from 5, 6, 7, 8, 9) @@ -1112,7 +1112,7 @@ ... help='foo the bars before frobbling') >>> parser.add_argument('bar', nargs='+', ... help='one of the bars to be frobbled') - >>> parser.parse_args('-h'.split()) + >>> parser.parse_args(['-h']) usage: frobble [-h] [--foo] bar [bar ...] positional arguments: @@ -1230,7 +1230,7 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('bar') - >>> parser.parse_args('XXX'.split()) + >>> parser.parse_args(['XXX']) Namespace(bar='XXX') For optional argument actions, the value of ``dest`` is normally inferred from @@ -1327,22 +1327,22 @@ >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('-x') >>> parser.add_argument('--foo') - >>> parser.parse_args('-x X'.split()) + >>> parser.parse_args(['-x', 'X']) Namespace(foo=None, x='X') - >>> parser.parse_args('--foo FOO'.split()) + >>> parser.parse_args(['--foo', 'FOO']) Namespace(foo='FOO', x=None) For long options (options with names longer than a single character), the option and value can also be passed as a single command-line argument, using ``=`` to separate them:: - >>> parser.parse_args('--foo=FOO'.split()) + >>> parser.parse_args(['--foo=FOO']) Namespace(foo='FOO', x=None) For short options (options only one character long), the option and its value can be concatenated:: - >>> parser.parse_args('-xX'.split()) + >>> parser.parse_args(['-xX']) Namespace(foo=None, x='X') Several short options can be joined together, using only a single ``-`` prefix, @@ -1352,7 +1352,7 @@ >>> parser.add_argument('-x', action='store_true') >>> parser.add_argument('-y', action='store_true') >>> parser.add_argument('-z') - >>> parser.parse_args('-xyzZ'.split()) + >>> parser.parse_args(['-xyzZ']) Namespace(x=True, y=True, z='Z') @@ -1474,7 +1474,7 @@ ... default=max, help='sum the integers (default: find the max)') >>> parser.parse_args(['1', '2', '3', '4']) Namespace(accumulate=, integers=[1, 2, 3, 4]) - >>> parser.parse_args('1 2 3 4 --sum'.split()) + >>> parser.parse_args(['1', '2', '3', '4', '--sum']) Namespace(accumulate=, integers=[1, 2, 3, 4]) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 07:48:56 2016 From: python-checkins at python.org (martin.panter) Date: Tue, 26 Apr 2016 11:48:56 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzIwNTk4?= =?utf-8?q?=3A_Replace_trivial_split=28=29_calls_with_lists_in_argparse_do?= =?utf-8?q?cs?= Message-ID: <20160426114849.18201.88459.45C92881@psf.io> https://hg.python.org/cpython/rev/49561532504c changeset: 101157:49561532504c branch: 3.5 parent: 101152:ae1e55102449 user: Martin Panter date: Tue Apr 26 11:41:25 2016 +0000 summary: Issue #20598: Replace trivial split() calls with lists in argparse docs files: Doc/library/argparse.rst | 46 ++++++++++++++-------------- 1 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -725,7 +725,7 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', action='store_const', const=42) - >>> parser.parse_args('--foo'.split()) + >>> parser.parse_args(['--foo']) Namespace(foo=42) * ``'store_true'`` and ``'store_false'`` - These are special cases of @@ -766,7 +766,7 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--verbose', '-v', action='count') - >>> parser.parse_args('-vvv'.split()) + >>> parser.parse_args(['-vvv']) Namespace(verbose=3) * ``'help'`` - This prints a complete help message for all the options in the @@ -841,11 +841,11 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', nargs='?', const='c', default='d') >>> parser.add_argument('bar', nargs='?', default='d') - >>> parser.parse_args('XX --foo YY'.split()) + >>> parser.parse_args(['XX', '--foo', 'YY']) Namespace(bar='XX', foo='YY') - >>> parser.parse_args('XX --foo'.split()) + >>> parser.parse_args(['XX', '--foo']) Namespace(bar='XX', foo='c') - >>> parser.parse_args(''.split()) + >>> parser.parse_args([]) Namespace(bar='d', foo='d') One of the more common uses of ``nargs='?'`` is to allow optional input and @@ -881,9 +881,9 @@ >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('foo', nargs='+') - >>> parser.parse_args('a b'.split()) + >>> parser.parse_args(['a', 'b']) Namespace(foo=['a', 'b']) - >>> parser.parse_args(''.split()) + >>> parser.parse_args([]) usage: PROG [-h] foo [foo ...] PROG: error: too few arguments @@ -938,9 +938,9 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', default=42) - >>> parser.parse_args('--foo 2'.split()) + >>> parser.parse_args(['--foo', '2']) Namespace(foo='2') - >>> parser.parse_args(''.split()) + >>> parser.parse_args([]) Namespace(foo=42) If the ``default`` value is a string, the parser parses the value as if it @@ -959,9 +959,9 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('foo', nargs='?', default=42) - >>> parser.parse_args('a'.split()) + >>> parser.parse_args(['a']) Namespace(foo='a') - >>> parser.parse_args(''.split()) + >>> parser.parse_args([]) Namespace(foo=42) @@ -1018,9 +1018,9 @@ ... >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('foo', type=perfect_square) - >>> parser.parse_args('9'.split()) + >>> parser.parse_args(['9']) Namespace(foo=9) - >>> parser.parse_args('7'.split()) + >>> parser.parse_args(['7']) usage: PROG [-h] foo PROG: error: argument foo: '7' is not a perfect square @@ -1029,9 +1029,9 @@ >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('foo', type=int, choices=range(5, 10)) - >>> parser.parse_args('7'.split()) + >>> parser.parse_args(['7']) Namespace(foo=7) - >>> parser.parse_args('11'.split()) + >>> parser.parse_args(['11']) usage: PROG [-h] {5,6,7,8,9} PROG: error: argument foo: invalid choice: 11 (choose from 5, 6, 7, 8, 9) @@ -1112,7 +1112,7 @@ ... help='foo the bars before frobbling') >>> parser.add_argument('bar', nargs='+', ... help='one of the bars to be frobbled') - >>> parser.parse_args('-h'.split()) + >>> parser.parse_args(['-h']) usage: frobble [-h] [--foo] bar [bar ...] positional arguments: @@ -1230,7 +1230,7 @@ >>> parser = argparse.ArgumentParser() >>> parser.add_argument('bar') - >>> parser.parse_args('XXX'.split()) + >>> parser.parse_args(['XXX']) Namespace(bar='XXX') For optional argument actions, the value of ``dest`` is normally inferred from @@ -1327,22 +1327,22 @@ >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('-x') >>> parser.add_argument('--foo') - >>> parser.parse_args('-x X'.split()) + >>> parser.parse_args(['-x', 'X']) Namespace(foo=None, x='X') - >>> parser.parse_args('--foo FOO'.split()) + >>> parser.parse_args(['--foo', 'FOO']) Namespace(foo='FOO', x=None) For long options (options with names longer than a single character), the option and value can also be passed as a single command-line argument, using ``=`` to separate them:: - >>> parser.parse_args('--foo=FOO'.split()) + >>> parser.parse_args(['--foo=FOO']) Namespace(foo='FOO', x=None) For short options (options only one character long), the option and its value can be concatenated:: - >>> parser.parse_args('-xX'.split()) + >>> parser.parse_args(['-xX']) Namespace(foo=None, x='X') Several short options can be joined together, using only a single ``-`` prefix, @@ -1352,7 +1352,7 @@ >>> parser.add_argument('-x', action='store_true') >>> parser.add_argument('-y', action='store_true') >>> parser.add_argument('-z') - >>> parser.parse_args('-xyzZ'.split()) + >>> parser.parse_args(['-xyzZ']) Namespace(x=True, y=True, z='Z') @@ -1474,7 +1474,7 @@ ... default=max, help='sum the integers (default: find the max)') >>> parser.parse_args(['1', '2', '3', '4']) Namespace(accumulate=, integers=[1, 2, 3, 4]) - >>> parser.parse_args('1 2 3 4 --sum'.split()) + >>> parser.parse_args(['1', '2', '3', '4', '--sum']) Namespace(accumulate=, integers=[1, 2, 3, 4]) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 10:22:12 2016 From: python-checkins at python.org (stefan.krah) Date: Tue, 26 Apr 2016 14:22:12 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326857=3A_Workarou?= =?utf-8?q?nd_for_missing_symbol_=22gethostbyaddr=5Fr=22_on_Android=2E?= Message-ID: <20160426142040.35287.14186.1AC30E5F@psf.io> https://hg.python.org/cpython/rev/eb19ad1918cd changeset: 101159:eb19ad1918cd user: Stefan Krah date: Tue Apr 26 16:20:17 2016 +0200 summary: Issue #26857: Workaround for missing symbol "gethostbyaddr_r" on Android. files: Modules/socketmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -163,7 +163,7 @@ # include #endif -#ifndef WITH_THREAD +#if !defined(WITH_THREAD) || defined(__ANDROID__) # undef HAVE_GETHOSTBYNAME_R #endif -- Repository URL: https://hg.python.org/cpython From lp_benchmark_robot at intel.com Tue Apr 26 10:31:16 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Tue, 26 Apr 2016 15:31:16 +0100 Subject: [Python-checkins] BAD Benchmark Results for Python Default 2016-04-26 Message-ID: <9bdf6a5d-8691-4c60-8828-c79e9b2cfdca@irsmsx103.ger.corp.intel.com> Results for project Python default, build date 2016-04-26 02:02:59 +0000 commit: ad6be34ce8c9 previous commit: 049463a379cc revision date: 2016-04-25 23:56:50 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.31% 0.83% 10.57% 13.29% :-| pybench 0.08% -0.25% 0.61% 6.77% :-( regex_v8 2.42% -3.04% -5.15% 5.35% :-( nbody 0.11% -0.35% -2.66% 8.49% :-| json_dump_v2 0.24% -1.41% -0.99% 12.75% :-| normal_startup 0.79% -0.17% 0.60% 5.04% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/bad-benchmark-results-for-python-default-2016-04-26/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Tue Apr 26 10:35:21 2016 From: python-checkins at python.org (stefan.krah) Date: Tue, 26 Apr 2016 14:35:21 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326846=3A_Post_com?= =?utf-8?q?mit_cleanup=2E?= Message-ID: <20160426143518.12700.90367.6B7A354E@psf.io> https://hg.python.org/cpython/rev/287996ff241f changeset: 101160:287996ff241f user: Stefan Krah date: Tue Apr 26 16:34:41 2016 +0200 summary: Issue #26846: Post commit cleanup. files: Modules/_decimal/_decimal.c | 1 - setup.py | 2 +- 2 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -36,7 +36,6 @@ #include #include "docstrings.h" -#include "memory.h" #if !defined(MPD_VERSION_HEX) || MPD_VERSION_HEX < 0x02040100 diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -2060,7 +2060,7 @@ '_decimal/libmpdec/fnt.h', '_decimal/libmpdec/fourstep.h', '_decimal/libmpdec/io.h', - '_decimal/libmpdec/memory.h', + '_decimal/libmpdec/mpalloc.h', '_decimal/libmpdec/mpdecimal.h', '_decimal/libmpdec/numbertheory.h', '_decimal/libmpdec/sixstep.h', -- Repository URL: https://hg.python.org/cpython From lp_benchmark_robot at intel.com Tue Apr 26 10:31:50 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Tue, 26 Apr 2016 15:31:50 +0100 Subject: [Python-checkins] BAD Benchmark Results for Python 2.7 2016-04-26 Message-ID: Results for project Python 2.7, build date 2016-04-26 02:47:01 +0000 commit: c502deb19cb0 previous commit: d0d541c2afb7 revision date: 2016-04-25 16:17:54 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.12% -1.52% 4.70% 7.07% :-) pybench 0.14% -0.06% 5.89% 4.91% :-( regex_v8 0.96% -0.19% -2.30% 10.69% :-) nbody 0.15% -0.49% 6.58% 6.35% :-| json_dump_v2 0.58% 0.06% 1.64% 12.91% :-( normal_startup 1.67% -0.43% -5.42% 2.67% :-) ssbench 0.18% -0.56% 2.40% 1.03% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/bad-benchmark-results-for-python-2-7-2016-04-26/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Tue Apr 26 10:49:21 2016 From: python-checkins at python.org (stefan.krah) Date: Tue, 26 Apr 2016 14:49:21 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326854=3A_Android_?= =?utf-8?q?has_a_different_include_path_for_soundcard=2Eh=2E?= Message-ID: <20160426144905.89223.30813.1224CFE2@psf.io> https://hg.python.org/cpython/rev/d943e6f7c9f3 changeset: 101161:d943e6f7c9f3 user: Stefan Krah date: Tue Apr 26 16:48:48 2016 +0200 summary: Issue #26854: Android has a different include path for soundcard.h. files: Modules/ossaudiodev.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c --- a/Modules/ossaudiodev.c +++ b/Modules/ossaudiodev.c @@ -31,7 +31,11 @@ #endif #include +#ifdef __ANDROID__ +#include +#else #include +#endif #if defined(linux) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 11:04:47 2016 From: python-checkins at python.org (stefan.krah) Date: Tue, 26 Apr 2016 15:04:47 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326863=3A_HAVE=5FF?= =?utf-8?q?ACCESSAT_should_=28currently=29_not_be_defined_on_Android=2E?= Message-ID: <20160426150432.13920.86521.8AFB8685@psf.io> https://hg.python.org/cpython/rev/f4c6dab59cd8 changeset: 101162:f4c6dab59cd8 user: Stefan Krah date: Tue Apr 26 17:04:18 2016 +0200 summary: Issue #26863: HAVE_FACCESSAT should (currently) not be defined on Android. files: Modules/posixmodule.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -32,6 +32,12 @@ #include "winreparse.h" #endif +/* On android API level 21, 'AT_EACCESS' is not declared although + * HAVE_FACCESSAT is defined. */ +#ifdef __ANDROID__ +#undef HAVE_FACCESSAT +#endif + #ifdef __cplusplus extern "C" { #endif @@ -5933,7 +5939,7 @@ if (_Py_set_inheritable(master_fd, 0, NULL) < 0) goto posix_error; -#if !defined(__CYGWIN__) && !defined(HAVE_DEV_PTC) +#if !defined(__CYGWIN__) && !defined(__ANDROID__) && !defined(HAVE_DEV_PTC) ioctl(slave_fd, I_PUSH, "ptem"); /* push ptem */ ioctl(slave_fd, I_PUSH, "ldterm"); /* push ldterm */ #ifndef __hpux -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Tue Apr 26 18:42:20 2016 From: python-checkins at python.org (brett.cannon) Date: Tue, 26 Apr 2016 22:42:20 +0000 Subject: [Python-checkins] =?utf-8?q?devguide=3A_Add_Brett_to_the_dev_affi?= =?utf-8?q?liations_list?= Message-ID: <20160426224220.12156.20634.8BD30FD3@psf.io> https://hg.python.org/devguide/rev/85d959870ab8 changeset: 799:85d959870ab8 user: Brett Cannon date: Tue Apr 26 15:41:17 2016 -0700 summary: Add Brett to the dev affiliations list files: motivations.rst | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/motivations.rst b/motivations.rst --- a/motivations.rst +++ b/motivations.rst @@ -170,6 +170,14 @@ questions or suggestions relating to this page. +.. topic:: Brett Cannon (Canada) + + * Personal site: `snarky.ca `_ + * `Extended bio `__ + * Microsoft (Software Developer) + * Python Software Foundation (Fellow) + + .. topic:: Nick Coghlan (Australia) * Personal site: `Curious Efficiency `_ -- Repository URL: https://hg.python.org/devguide From python-checkins at python.org Wed Apr 27 01:57:57 2016 From: python-checkins at python.org (berker.peksag) Date: Wed, 27 Apr 2016 05:57:57 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2Njcy?= =?utf-8?q?=3A_Fix_regrtest_example_in_test=2Erst?= Message-ID: <20160427055755.89243.18885.9640C730@psf.io> https://hg.python.org/cpython/rev/2ef61a4747eb changeset: 101163:2ef61a4747eb branch: 2.7 parent: 101156:44f888e47ab0 user: Berker Peksag date: Wed Apr 27 08:58:32 2016 +0300 summary: Issue #26672: Fix regrtest example in test.rst Reported by Axel Luttgens. files: Doc/library/test.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/test.rst b/Doc/library/test.rst --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -171,7 +171,7 @@ Running :mod:`test.regrtest` directly allows what resources are available for tests to use to be set. You do this by using the ``-u`` command-line option. Specifying ``all`` as the value for the ``-u`` option enables all -possible resources: :program:`python -m test -uall`. +possible resources: :program:`python -m test.regrtest -uall`. If all but one resource is desired (a more common case), a comma-separated list of resources that are not desired may be listed after ``all``. The command :program:`python -m test.regrtest -uall,-audio,-largefile` -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Wed Apr 27 04:49:16 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 27 Apr 2016 08:49:16 +0000 Subject: [Python-checkins] Daily reference leaks (f4c6dab59cd8): sum=-2 Message-ID: <20160427084912.35309.66158.B4905E3F@psf.io> results for f4c6dab59cd8 on branch "default" -------------------------------------------- test_asyncio leaked [3, 0, 0] memory blocks, sum=3 test_collections leaked [-2, -4, 0] references, sum=-6 test_collections leaked [-1, 2, -4] memory blocks, sum=-3 test_functools leaked [0, 3, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogUYYoyQ', '--timeout', '7200'] From lp_benchmark_robot at intel.com Wed Apr 27 09:57:22 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Wed, 27 Apr 2016 14:57:22 +0100 Subject: [Python-checkins] GOOD Benchmark Results for Python Default 2016-04-27 Message-ID: <5ee281b8-35b5-4202-8ddf-e2ec406c6a3b@irsmsx103.ger.corp.intel.com> Results for project Python default, build date 2016-04-27 02:02:32 +0000 commit: f4c6dab59cd8 previous commit: ad6be34ce8c9 revision date: 2016-04-26 15:04:18 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.19% -0.55% 10.08% 15.82% :-| pybench 0.07% 0.25% 0.85% 5.40% :-( regex_v8 2.65% 1.64% -3.43% 3.37% :-( nbody 0.11% 0.58% -2.06% 6.72% :-| json_dump_v2 0.33% 0.61% -0.37% 13.40% :-| normal_startup 0.73% 0.10% 0.81% 5.53% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/good-benchmark-results-for-python-default-2016-04-27/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Wed Apr 27 09:58:17 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Wed, 27 Apr 2016 14:58:17 +0100 Subject: [Python-checkins] GOOD Benchmark Results for Python 2.7 2016-04-27 Message-ID: Results for project Python 2.7, build date 2016-04-27 02:46:35 +0000 commit: 44f888e47ab0 previous commit: c502deb19cb0 revision date: 2016-04-26 11:33:46 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.14% 2.15% 6.75% 0.45% :-) pybench 0.10% -0.16% 5.75% 4.43% :-( regex_v8 0.73% 0.16% -2.14% 10.33% :-) nbody 0.15% -0.18% 6.41% 6.55% :-) json_dump_v2 0.56% 0.91% 2.53% 10.86% :-( normal_startup 1.62% 0.60% -4.79% 1.88% :-) ssbench 0.14% 0.28% 2.68% 1.51% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/good-benchmark-results-for-python-2-7-2016-04-27/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Wed Apr 27 16:07:53 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 27 Apr 2016 20:07:53 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogZmlsZWlucHV0Lmhv?= =?utf-8?q?ok=5Fencoded=28=29_uses_builtin_open=28=29=2C_not_codecs=2Eopen?= =?utf-8?b?KCku?= Message-ID: <20160427200749.122139.57966.87E8264F@psf.io> https://hg.python.org/cpython/rev/f6818806ecc0 changeset: 101164:f6818806ecc0 branch: 3.5 parent: 101157:49561532504c user: Serhiy Storchaka date: Wed Apr 27 23:06:15 2016 +0300 summary: fileinput.hook_encoded() uses builtin open(), not codecs.open(). files: Doc/library/fileinput.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/fileinput.rst b/Doc/library/fileinput.rst --- a/Doc/library/fileinput.rst +++ b/Doc/library/fileinput.rst @@ -196,7 +196,7 @@ .. function:: hook_encoded(encoding) - Returns a hook which opens each file with :func:`codecs.open`, using the given + Returns a hook which opens each file with :func:`open`, using the given *encoding* to read the file. Usage example: ``fi = -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 27 16:07:55 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 27 Apr 2016 20:07:55 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogZmlsZWlucHV0Lmhv?= =?utf-8?b?b2tfZW5jb2RlZCgpIHVzZXMgaW8ub3BlbigpLCBub3QgY29kZWNzLm9wZW4o?= =?utf-8?b?KS4=?= Message-ID: <20160427200750.89223.73052.EF46553B@psf.io> https://hg.python.org/cpython/rev/224d83c81edd changeset: 101166:224d83c81edd branch: 2.7 parent: 101163:2ef61a4747eb user: Serhiy Storchaka date: Wed Apr 27 23:07:25 2016 +0300 summary: fileinput.hook_encoded() uses io.open(), not codecs.open(). files: Doc/library/fileinput.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/fileinput.rst b/Doc/library/fileinput.rst --- a/Doc/library/fileinput.rst +++ b/Doc/library/fileinput.rst @@ -181,7 +181,7 @@ .. function:: hook_encoded(encoding) - Returns a hook which opens each file with :func:`codecs.open`, using the given + Returns a hook which opens each file with :func:`io.open`, using the given *encoding* to read the file. Usage example: ``fi = -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 27 16:07:55 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 27 Apr 2016 20:07:55 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_fileinput=2Ehook=5Fencoded=28=29_uses_builtin_open=28=29?= =?utf-8?b?LCBub3QgY29kZWNzLm9wZW4oKS4=?= Message-ID: <20160427200750.102997.49573.6609DDC3@psf.io> https://hg.python.org/cpython/rev/cb5645b36713 changeset: 101165:cb5645b36713 parent: 101162:f4c6dab59cd8 parent: 101164:f6818806ecc0 user: Serhiy Storchaka date: Wed Apr 27 23:06:41 2016 +0300 summary: fileinput.hook_encoded() uses builtin open(), not codecs.open(). files: Doc/library/fileinput.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/fileinput.rst b/Doc/library/fileinput.rst --- a/Doc/library/fileinput.rst +++ b/Doc/library/fileinput.rst @@ -195,7 +195,7 @@ .. function:: hook_encoded(encoding) - Returns a hook which opens each file with :func:`codecs.open`, using the given + Returns a hook which opens each file with :func:`open`, using the given *encoding* to read the file. Usage example: ``fi = -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Wed Apr 27 16:14:20 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Wed, 27 Apr 2016 20:14:20 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2325788=3A_fileinpu?= =?utf-8?q?t=2Ehook=5Fencoded=28=29_now_supports_an_=22errors=22_argument?= Message-ID: <20160427201410.12148.35680.FF07ADCC@psf.io> https://hg.python.org/cpython/rev/8ab8f5259f09 changeset: 101167:8ab8f5259f09 parent: 101165:cb5645b36713 user: Serhiy Storchaka date: Wed Apr 27 23:13:46 2016 +0300 summary: Issue #25788: fileinput.hook_encoded() now supports an "errors" argument for passing to open. Original patch by Joseph Hackman. files: Doc/library/fileinput.rst | 10 +++++++--- Doc/whatsnew/3.6.rst | 7 +++++++ Lib/fileinput.py | 4 ++-- Lib/test/test_fileinput.py | 21 ++++++++++++++++++++- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Doc/library/fileinput.rst b/Doc/library/fileinput.rst --- a/Doc/library/fileinput.rst +++ b/Doc/library/fileinput.rst @@ -193,10 +193,14 @@ Usage example: ``fi = fileinput.FileInput(openhook=fileinput.hook_compressed)`` -.. function:: hook_encoded(encoding) +.. function:: hook_encoded(encoding, errors=None) Returns a hook which opens each file with :func:`open`, using the given - *encoding* to read the file. + *encoding* and *errors* to read the file. Usage example: ``fi = - fileinput.FileInput(openhook=fileinput.hook_encoded("iso-8859-1"))`` + fileinput.FileInput(openhook=fileinput.hook_encoded("utf-8", + "surrogateescape"))`` + + .. versionchanged:: 3.6 + Added the optional *errors* parameter. diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -358,6 +358,13 @@ (Contributed by Aviv Palivoda in :issue:`26243`.) +fileinput +--------- + +:func:`~fileinput.hook_encoded` now supports the *errors* argument. +(Contributed by Joseph Hackman in :issue:`25788`.) + + Optimizations ============= diff --git a/Lib/fileinput.py b/Lib/fileinput.py --- a/Lib/fileinput.py +++ b/Lib/fileinput.py @@ -400,9 +400,9 @@ return open(filename, mode) -def hook_encoded(encoding): +def hook_encoded(encoding, errors=None): def openhook(filename, mode): - return open(filename, mode, encoding=encoding) + return open(filename, mode, encoding=encoding, errors=errors) return openhook diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py --- a/Lib/test/test_fileinput.py +++ b/Lib/test/test_fileinput.py @@ -945,7 +945,8 @@ def test(self): encoding = object() - result = fileinput.hook_encoded(encoding) + errors = object() + result = fileinput.hook_encoded(encoding, errors=errors) fake_open = InvocationRecorder() original_open = builtins.open @@ -963,8 +964,26 @@ self.assertIs(args[0], filename) self.assertIs(args[1], mode) self.assertIs(kwargs.pop('encoding'), encoding) + self.assertIs(kwargs.pop('errors'), errors) self.assertFalse(kwargs) + def test_errors(self): + with open(TESTFN, 'wb') as f: + f.write(b'\x80abc') + self.addCleanup(safe_unlink, TESTFN) + + def check(errors, expected_lines): + with FileInput(files=TESTFN, mode='r', + openhook=hook_encoded('utf-8', errors=errors)) as fi: + lines = list(fi) + self.assertEqual(lines, expected_lines) + + check('ignore', ['abc']) + with self.assertRaises(UnicodeDecodeError): + check('strict', ['abc']) + check('replace', ['\ufffdabc']) + check('backslashreplace', ['\\x80abc']) + def test_modes(self): with open(TESTFN, 'wb') as f: # UTF-7 is a convenient, seldom used encoding diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -538,6 +538,7 @@ Lars Gust?bel Thomas G?ttler Jonas H. +Joseph Hackman Barry Haddow Philipp Hagemeister Paul ten Hagen diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -256,6 +256,9 @@ Library ------- +- Issue #25788: fileinput.hook_encoded() now supports an "errors" argument + for passing to open. Original patch by Joseph Hackman. + - Issue #26634: recursive_repr() now sets __qualname__ of wrapper. Patch by Xiang Zhang. -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Thu Apr 28 04:52:02 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 28 Apr 2016 08:52:02 +0000 Subject: [Python-checkins] Daily reference leaks (8ab8f5259f09): sum=0 Message-ID: <20160428085201.27046.10766.A25CB1E0@psf.io> results for 8ab8f5259f09 on branch "default" -------------------------------------------- test_collections leaked [-4, 0, 0] references, sum=-4 test_collections leaked [-6, 1, 4] memory blocks, sum=-1 test_functools leaked [0, 3, 1] memory blocks, sum=4 test_multiprocessing_forkserver leaked [-1, 2, 0] memory blocks, sum=1 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogWE5R5S', '--timeout', '7200'] From lp_benchmark_robot at intel.com Thu Apr 28 10:49:57 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Thu, 28 Apr 2016 15:49:57 +0100 Subject: [Python-checkins] BAD Benchmark Results for Python Default 2016-04-28 Message-ID: <2b23ab9d-6983-4991-b6a8-2e387c7bae67@irsmsx104.ger.corp.intel.com> Results for project Python default, build date 2016-04-28 02:01:51 +0000 commit: 8ab8f5259f09 previous commit: f4c6dab59cd8 revision date: 2016-04-27 20:13:46 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.24% -0.55% 9.59% 17.09% :-| pybench 0.07% -0.14% 0.72% 6.18% :-( regex_v8 2.66% 0.16% -3.26% 4.71% :-( nbody 0.12% 0.01% -2.05% 6.57% :-| json_dump_v2 0.33% -1.00% -1.38% 14.30% :-| normal_startup 0.80% 0.01% 0.66% 5.42% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/bad-benchmark-results-for-python-default-2016-04-28/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Thu Apr 28 10:50:31 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Thu, 28 Apr 2016 15:50:31 +0100 Subject: [Python-checkins] NEUTRAL Benchmark Results for Python 2.7 2016-04-28 Message-ID: <905e47ca-5e9b-4fd9-a0a6-274f16c6a477@irsmsx104.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-28 02:48:02 +0000 commit: 224d83c81edd previous commit: 44f888e47ab0 revision date: 2016-04-27 20:07:25 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.14% -0.30% 6.47% 4.71% :-) pybench 0.09% 0.17% 5.91% 5.52% :-( regex_v8 0.75% -0.03% -2.18% 10.86% :-) nbody 0.13% 0.71% 7.08% 2.46% :-) json_dump_v2 0.55% -0.12% 2.41% 11.45% :-( normal_startup 1.65% -0.35% -5.16% 2.44% :-) ssbench 0.23% 0.12% 2.81% 1.32% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/neutral-benchmark-results-for-python-2-7-2016-04-28/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Thu Apr 28 15:25:57 2016 From: python-checkins at python.org (zach.ware) Date: Thu, 28 Apr 2016 19:25:57 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2ODc0?= =?utf-8?q?=3A_Fix_divmod_docstring?= Message-ID: <20160428192556.28426.31435.651845D3@psf.io> https://hg.python.org/cpython/rev/ef193be5c3cd changeset: 101169:ef193be5c3cd branch: 3.5 parent: 101164:f6818806ecc0 user: Zachary Ware date: Thu Apr 28 14:24:55 2016 -0500 summary: Issue #26874: Fix divmod docstring files: Python/bltinmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -796,7 +796,7 @@ y: object / -Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x. +Return the tuple ((x-x%y)//y, x%y). Invariant: div*y + mod == x. [clinic start generated code]*/ static PyObject * -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 28 15:25:57 2016 From: python-checkins at python.org (zach.ware) Date: Thu, 28 Apr 2016 19:25:57 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Closes_=2326874=3A_Merge_with_3=2E5?= Message-ID: <20160428192557.13904.86705.654EE0D7@psf.io> https://hg.python.org/cpython/rev/28c89ebd6e5a changeset: 101170:28c89ebd6e5a parent: 101167:8ab8f5259f09 parent: 101169:ef193be5c3cd user: Zachary Ware date: Thu Apr 28 14:25:32 2016 -0500 summary: Closes #26874: Merge with 3.5 files: Python/bltinmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -796,7 +796,7 @@ y: object / -Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x. +Return the tuple ((x-x%y)//y, x%y). Invariant: div*y + mod == x. [clinic start generated code]*/ static PyObject * -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 28 15:25:57 2016 From: python-checkins at python.org (zach.ware) Date: Thu, 28 Apr 2016 19:25:57 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2ODc0?= =?utf-8?q?=3A_Make_divmod_docstring_and_full_doc_match?= Message-ID: <20160428192556.12702.11301.D33831A9@psf.io> https://hg.python.org/cpython/rev/fb49082a75d1 changeset: 101168:fb49082a75d1 branch: 2.7 parent: 101166:224d83c81edd user: Zachary Ware date: Thu Apr 28 14:23:48 2016 -0500 summary: Issue #26874: Make divmod docstring and full doc match files: Python/bltinmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -625,7 +625,7 @@ PyDoc_STRVAR(divmod_doc, "divmod(x, y) -> (quotient, remainder)\n\ \n\ -Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x."); +Return the tuple ((x-x%y)//y, x%y). Invariant: div*y + mod == x."); static PyObject * -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 28 15:40:37 2016 From: python-checkins at python.org (zach.ware) Date: Thu, 28 Apr 2016 19:40:37 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2ODc0?= =?utf-8?q?=3A_Simplify_the_divmod_docstring?= Message-ID: <20160428194037.13898.97298.28140B55@psf.io> https://hg.python.org/cpython/rev/3edf8aa1ed97 changeset: 101172:3edf8aa1ed97 branch: 3.5 parent: 101169:ef193be5c3cd user: Zachary Ware date: Thu Apr 28 14:39:50 2016 -0500 summary: Issue #26874: Simplify the divmod docstring files: Python/bltinmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -796,7 +796,7 @@ y: object / -Return the tuple ((x-x%y)//y, x%y). Invariant: div*y + mod == x. +Return the tuple (x//y, x%y). Invariant: div*y + mod == x. [clinic start generated code]*/ static PyObject * -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 28 15:40:40 2016 From: python-checkins at python.org (zach.ware) Date: Thu, 28 Apr 2016 19:40:40 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2ODc0?= =?utf-8?q?=3A_Simplify_the_divmod_docstring=2E?= Message-ID: <20160428194036.24609.26601.F88E20D3@psf.io> https://hg.python.org/cpython/rev/5a578ec4b3b3 changeset: 101171:5a578ec4b3b3 branch: 2.7 parent: 101168:fb49082a75d1 user: Zachary Ware date: Thu Apr 28 14:38:48 2016 -0500 summary: Issue #26874: Simplify the divmod docstring. Now it actually matches the prose docs. files: Python/bltinmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -625,7 +625,7 @@ PyDoc_STRVAR(divmod_doc, "divmod(x, y) -> (quotient, remainder)\n\ \n\ -Return the tuple ((x-x%y)//y, x%y). Invariant: div*y + mod == x."); +Return the tuple (x//y, x%y). Invariant: div*y + mod == x."); static PyObject * -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 28 15:41:09 2016 From: python-checkins at python.org (zach.ware) Date: Thu, 28 Apr 2016 19:41:09 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Closes_=2326874=3A_Merge_with_3=2E5?= Message-ID: <20160428194037.40042.99611.EC0100B6@psf.io> https://hg.python.org/cpython/rev/c6e285789963 changeset: 101173:c6e285789963 parent: 101170:28c89ebd6e5a parent: 101172:3edf8aa1ed97 user: Zachary Ware date: Thu Apr 28 14:40:08 2016 -0500 summary: Closes #26874: Merge with 3.5 files: Python/bltinmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -796,7 +796,7 @@ y: object / -Return the tuple ((x-x%y)//y, x%y). Invariant: div*y + mod == x. +Return the tuple (x//y, x%y). Invariant: div*y + mod == x. [clinic start generated code]*/ static PyObject * -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 28 15:47:58 2016 From: python-checkins at python.org (zach.ware) Date: Thu, 28 Apr 2016 19:47:58 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Closes_=2326875=3A_Merge_with_3=2E5?= Message-ID: <20160428194757.4017.9586.0B4E104D@psf.io> https://hg.python.org/cpython/rev/aaf2ad84ae1c changeset: 101175:aaf2ad84ae1c parent: 101173:c6e285789963 parent: 101174:5c8e1b98dc3f user: Zachary Ware date: Thu Apr 28 14:47:33 2016 -0500 summary: Closes #26875: Merge with 3.5 files: Doc/library/mmap.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/mmap.rst b/Doc/library/mmap.rst --- a/Doc/library/mmap.rst +++ b/Doc/library/mmap.rst @@ -127,7 +127,7 @@ import mmap with mmap.mmap(-1, 13) as mm: - mm.write("Hello world!") + mm.write(b"Hello world!") .. versionadded:: 3.2 Context manager support. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 28 15:48:19 2016 From: python-checkins at python.org (zach.ware) Date: Thu, 28 Apr 2016 19:48:19 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2ODc1?= =?utf-8?q?=3A_Fix_mmap_example?= Message-ID: <20160428194757.18203.17287.4C3EF656@psf.io> https://hg.python.org/cpython/rev/5c8e1b98dc3f changeset: 101174:5c8e1b98dc3f branch: 3.5 parent: 101172:3edf8aa1ed97 user: Zachary Ware date: Thu Apr 28 14:47:12 2016 -0500 summary: Issue #26875: Fix mmap example Patch by Xiang Zhang. files: Doc/library/mmap.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/mmap.rst b/Doc/library/mmap.rst --- a/Doc/library/mmap.rst +++ b/Doc/library/mmap.rst @@ -127,7 +127,7 @@ import mmap with mmap.mmap(-1, 13) as mm: - mm.write("Hello world!") + mm.write(b"Hello world!") .. versionadded:: 3.2 Context manager support. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Thu Apr 28 21:44:26 2016 From: python-checkins at python.org (larry.hastings) Date: Fri, 29 Apr 2016 01:44:26 +0000 Subject: [Python-checkins] =?utf-8?q?peps=3A_Update_3=2E5_release_schedule?= =?utf-8?q?_with_dates_for_3=2E5=2E2=2E?= Message-ID: <20160429014425.12713.97024.F26DBF67@psf.io> https://hg.python.org/peps/rev/79e82db88f37 changeset: 6296:79e82db88f37 user: Larry Hastings date: Thu Apr 28 18:44:22 2016 -0700 summary: Update 3.5 release schedule with dates for 3.5.2. files: pep-0478.txt | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pep-0478.txt b/pep-0478.txt --- a/pep-0478.txt +++ b/pep-0478.txt @@ -54,8 +54,8 @@ .. Planned future release dates: -- 3.5.2: Spring 2016 (contingent on some bug fixes) - +- 3.5.2 release candidate 1: Sunday, June 12, 2016 +- 3.5.2 final: Sunday, June 26, 2016 Features for 3.5 ================ -- Repository URL: https://hg.python.org/peps From python-checkins at python.org Fri Apr 29 02:13:00 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 29 Apr 2016 06:13:00 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326822=3A_Decreased_an_overhead_of_using_=5FPyAr?= =?utf-8?q?g=5FNoKeywords=28=29_in_calls_of?= Message-ID: <20160429061300.12150.40042.20C8D35B@psf.io> https://hg.python.org/cpython/rev/22caee20223e changeset: 101177:22caee20223e parent: 101175:aaf2ad84ae1c parent: 101176:54663cbd0de1 user: Serhiy Storchaka date: Fri Apr 29 09:12:25 2016 +0300 summary: Issue #26822: Decreased an overhead of using _PyArg_NoKeywords() in calls of itemgetter, attrgetter and methodcaller objects. files: Modules/_operator.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_operator.c b/Modules/_operator.c --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -460,7 +460,7 @@ PyObject *obj, *result; Py_ssize_t i, nitems=ig->nitems; - if (!_PyArg_NoKeywords("itemgetter", kw)) + if (kw != NULL && !_PyArg_NoKeywords("itemgetter", kw)) return NULL; if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj)) return NULL; @@ -749,7 +749,7 @@ PyObject *obj, *result; Py_ssize_t i, nattrs=ag->nattrs; - if (!_PyArg_NoKeywords("attrgetter", kw)) + if (kw != NULL && !_PyArg_NoKeywords("attrgetter", kw)) return NULL; if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj)) return NULL; @@ -992,7 +992,7 @@ { PyObject *method, *obj, *result; - if (!_PyArg_NoKeywords("methodcaller", kw)) + if (kw != NULL && !_PyArg_NoKeywords("methodcaller", kw)) return NULL; if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj)) return NULL; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 02:13:00 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 29 Apr 2016 06:13:00 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2ODIy?= =?utf-8?q?=3A_Decreased_an_overhead_of_using_=5FPyArg=5FNoKeywords=28=29_?= =?utf-8?q?in_calls_of?= Message-ID: <20160429061300.13904.12620.80C24712@psf.io> https://hg.python.org/cpython/rev/d738f268a013 changeset: 101178:d738f268a013 branch: 2.7 parent: 101171:5a578ec4b3b3 user: Serhiy Storchaka date: Fri Apr 29 09:12:38 2016 +0300 summary: Issue #26822: Decreased an overhead of using _PyArg_NoKeywords() in calls of itemgetter, attrgetter and methodcaller objects. files: Modules/operator.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/operator.c b/Modules/operator.c --- a/Modules/operator.c +++ b/Modules/operator.c @@ -511,7 +511,7 @@ PyObject *obj, *result; Py_ssize_t i, nitems=ig->nitems; - if (!_PyArg_NoKeywords("itemgetter", kw)) + if (kw != NULL && !_PyArg_NoKeywords("itemgetter", kw)) return NULL; if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj)) return NULL; @@ -693,7 +693,7 @@ PyObject *obj, *result; Py_ssize_t i, nattrs=ag->nattrs; - if (!_PyArg_NoKeywords("attrgetter", kw)) + if (kw != NULL && !_PyArg_NoKeywords("attrgetter", kw)) return NULL; if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj)) return NULL; @@ -842,7 +842,7 @@ { PyObject *method, *obj, *result; - if (!_PyArg_NoKeywords("methodcaller", kw)) + if (kw != NULL && !_PyArg_NoKeywords("methodcaller", kw)) return NULL; if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj)) return NULL; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 02:13:04 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 29 Apr 2016 06:13:04 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2ODIy?= =?utf-8?q?=3A_Decreased_an_overhead_of_using_=5FPyArg=5FNoKeywords=28=29_?= =?utf-8?q?in_calls_of?= Message-ID: <20160429061259.18221.19778.57C873CF@psf.io> https://hg.python.org/cpython/rev/54663cbd0de1 changeset: 101176:54663cbd0de1 branch: 3.5 parent: 101174:5c8e1b98dc3f user: Serhiy Storchaka date: Fri Apr 29 09:10:55 2016 +0300 summary: Issue #26822: Decreased an overhead of using _PyArg_NoKeywords() in calls of itemgetter, attrgetter and methodcaller objects. files: Modules/_operator.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_operator.c b/Modules/_operator.c --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -460,7 +460,7 @@ PyObject *obj, *result; Py_ssize_t i, nitems=ig->nitems; - if (!_PyArg_NoKeywords("itemgetter", kw)) + if (kw != NULL && !_PyArg_NoKeywords("itemgetter", kw)) return NULL; if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj)) return NULL; @@ -749,7 +749,7 @@ PyObject *obj, *result; Py_ssize_t i, nattrs=ag->nattrs; - if (!_PyArg_NoKeywords("attrgetter", kw)) + if (kw != NULL && !_PyArg_NoKeywords("attrgetter", kw)) return NULL; if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj)) return NULL; @@ -992,7 +992,7 @@ { PyObject *method, *obj, *result; - if (!_PyArg_NoKeywords("methodcaller", kw)) + if (kw != NULL && !_PyArg_NoKeywords("methodcaller", kw)) return NULL; if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj)) return NULL; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 04:32:16 2016 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 29 Apr 2016 08:32:16 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2326880=3A_Removed_?= =?utf-8?b?cmVkdW5kYW50IGNoZWNrcyBpbiBzZXQuX19pbml0X18u?= Message-ID: <20160429083216.1536.72870.6ED676E8@psf.io> https://hg.python.org/cpython/rev/ed6345cb08ab changeset: 101179:ed6345cb08ab parent: 101177:22caee20223e user: Serhiy Storchaka date: Fri Apr 29 11:31:52 2016 +0300 summary: Issue #26880: Removed redundant checks in set.__init__. files: Objects/setobject.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/Objects/setobject.c b/Objects/setobject.c --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1998,9 +1998,7 @@ { PyObject *iterable = NULL; - if (!PyAnySet_Check(self)) - return -1; - if (kwds != NULL && PySet_Check(self) && !_PyArg_NoKeywords("set()", kwds)) + if (kwds != NULL && !_PyArg_NoKeywords("set()", kwds)) return -1; if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable)) return -1; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 04:37:13 2016 From: python-checkins at python.org (raymond.hettinger) Date: Fri, 29 Apr 2016 08:37:13 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Removed_unused_initializat?= =?utf-8?q?ion_and_the_uninteresting_comment=2E?= Message-ID: <20160429083710.10751.14354.3EF43A21@psf.io> https://hg.python.org/cpython/rev/988d1c742609 changeset: 101180:988d1c742609 user: Raymond Hettinger date: Fri Apr 29 01:37:05 2016 -0700 summary: Removed unused initialization and the uninteresting comment. files: Objects/setobject.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Objects/setobject.c b/Objects/setobject.c --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1043,9 +1043,8 @@ static PyObject * make_new_set(PyTypeObject *type, PyObject *iterable) { - PySetObject *so = NULL; + PySetObject *so; - /* create PySetObject structure */ so = (PySetObject *)type->tp_alloc(type, 0); if (so == NULL) return NULL; -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Fri Apr 29 04:52:30 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 29 Apr 2016 08:52:30 +0000 Subject: [Python-checkins] Daily reference leaks (aaf2ad84ae1c): sum=8 Message-ID: <20160429085215.21689.69116.E2D3EFF3@psf.io> results for aaf2ad84ae1c on branch "default" -------------------------------------------- test_collections leaked [0, 0, 4] memory blocks, sum=4 test_functools leaked [0, 3, 1] memory blocks, sum=4 test_multiprocessing_forkserver leaked [0, 0, -2] memory blocks, sum=-2 test_multiprocessing_spawn leaked [2, -1, 1] memory blocks, sum=2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogXVIGtR', '--timeout', '7200'] From lp_benchmark_robot at intel.com Fri Apr 29 07:20:47 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Fri, 29 Apr 2016 12:20:47 +0100 Subject: [Python-checkins] GOOD Benchmark Results for Python Default 2016-04-29 Message-ID: <4c6240e5-643e-4416-9667-5ccf829dbb98@irsmsx105.ger.corp.intel.com> Results for project Python default, build date 2016-04-29 02:02:47 +0000 commit: aaf2ad84ae1c previous commit: 8ab8f5259f09 revision date: 2016-04-28 19:47:33 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v3.4.3, with hash b4cbecbc0781 from 2015-02-25 12:15:33+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.20% 0.25% 9.81% 17.30% :-| pybench 0.10% 0.16% 0.87% 6.05% :-( regex_v8 2.65% -0.03% -3.29% 3.38% :-( nbody 0.13% -0.13% -2.19% 9.61% :-| json_dump_v2 0.28% 1.32% -0.04% 13.59% :-| normal_startup 0.73% -0.16% 0.62% 5.66% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/good-benchmark-results-for-python-default-2016-04-29/ Note: Benchmark results are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From lp_benchmark_robot at intel.com Fri Apr 29 07:21:30 2016 From: lp_benchmark_robot at intel.com (lp_benchmark_robot at intel.com) Date: Fri, 29 Apr 2016 12:21:30 +0100 Subject: [Python-checkins] NEUTRAL Benchmark Results for Python 2.7 2016-04-29 Message-ID: <088472e6-57b3-4af9-a798-8d6ee086fe7a@irsmsx105.ger.corp.intel.com> Results for project Python 2.7, build date 2016-04-29 02:46:43 +0000 commit: 5a578ec4b3b3 previous commit: 224d83c81edd revision date: 2016-04-28 19:38:48 +0000 environment: Haswell-EP cpu: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB mem: 128 GB os: CentOS 7.1 kernel: Linux 3.10.0-229.4.2.el7.x86_64 Baseline results were generated using release v2.7.10, with hash 15c95b7d81dc from 2015-05-23 16:02:14+00:00 ---------------------------------------------------------------------------------- benchmark relative change since change since current rev run std_dev* last run baseline with PGO ---------------------------------------------------------------------------------- :-) django_v2 0.11% -0.01% 6.46% 5.04% :-) pybench 0.11% -0.02% 5.89% 5.27% :-( regex_v8 0.69% 0.17% -2.01% 10.85% :-) nbody 0.14% -0.04% 7.04% 4.82% :-) json_dump_v2 0.52% -0.19% 2.23% 10.11% :-( normal_startup 1.88% -0.23% -5.40% 2.43% :-) ssbench 0.22% -0.18% 2.62% 1.04% ---------------------------------------------------------------------------------- * Relative Standard Deviation (Standard Deviation/Average) If this is not displayed properly please visit our results page here: http://languagesperformance.intel.com/neutral-benchmark-results-for-python-2-7-2016-04-29/ Note: Benchmark results for ssbench are measured in requests/second while all other are measured in seconds. Subject Label Legend: Attributes are determined based on the performance evolution of the workloads compared to the previous measurement iteration. NEUTRAL: performance did not change by more than 1% for any workload GOOD: performance improved by more than 1% for at least one workload and there is no regression greater than 1% BAD: performance dropped by more than 1% for at least one workload and there is no improvement greater than 1% UGLY: performance improved by more than 1% for at least one workload and also dropped by more than 1% for at least one workload Our lab does a nightly source pull and build of the Python project and measures performance changes against the previous stable version and the previous nightly measurement. This is provided as a service to the community so that quality issues with current hardware can be identified quickly. Intel technologies' features and benefits depend on system configuration and may require enabled hardware, software or service activation. Performance varies depending on system configuration. From python-checkins at python.org Fri Apr 29 07:41:44 2016 From: python-checkins at python.org (berker.peksag) Date: Fri, 29 Apr 2016 11:41:44 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2MzIy?= =?utf-8?q?=3A_Document_typing=2ESet=2C_patch_by_Joseph_Moran?= Message-ID: <20160429114143.1512.25139.41A6E0AE@psf.io> https://hg.python.org/cpython/rev/6cd8cd14f648 changeset: 101181:6cd8cd14f648 branch: 3.5 parent: 101176:54663cbd0de1 user: Berker Peksag date: Fri Apr 29 14:41:16 2016 +0300 summary: Issue #26322: Document typing.Set, patch by Joseph Moran files: Doc/library/typing.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -431,9 +431,9 @@ def slice__to_4(vector: Sequence[T]) -> List[T]: return vector[0:4] -.. class:: AbstractSet(set, MutableSet[T]) +.. class:: Set(set, MutableSet[T]) - A generic version of :class:`collections.abc.Set`. + A generic version of :class:`builtins.set `. .. class:: MappingView(Sized, Iterable[T_co]) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 07:41:48 2016 From: python-checkins at python.org (berker.peksag) Date: Fri, 29 Apr 2016 11:41:48 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326322=3A_Document_typing=2ESet=2C_patch_by_Jose?= =?utf-8?q?ph_Moran?= Message-ID: <20160429114144.84506.15487.06B0E5B3@psf.io> https://hg.python.org/cpython/rev/d263dcfd9bb6 changeset: 101182:d263dcfd9bb6 parent: 101180:988d1c742609 parent: 101181:6cd8cd14f648 user: Berker Peksag date: Fri Apr 29 14:41:41 2016 +0300 summary: Issue #26322: Document typing.Set, patch by Joseph Moran files: Doc/library/typing.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -430,9 +430,9 @@ def slice__to_4(vector: Sequence[T]) -> List[T]: return vector[0:4] -.. class:: AbstractSet(set, MutableSet[T]) +.. class:: Set(set, MutableSet[T]) - A generic version of :class:`collections.abc.Set`. + A generic version of :class:`builtins.set `. .. class:: MappingView(Sized, Iterable[T_co]) -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 09:48:20 2016 From: python-checkins at python.org (berker.peksag) Date: Fri, 29 Apr 2016 13:48:20 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2324902=3A_Print_se?= =?utf-8?q?rver_URL_on_http=2Eserver_startup?= Message-ID: <20160429134813.39152.28982.6FA5E1D8@psf.io> https://hg.python.org/cpython/rev/3be61137280a changeset: 101183:3be61137280a user: Berker Peksag date: Fri Apr 29 16:48:11 2016 +0300 summary: Issue #24902: Print server URL on http.server startup Initial patch by Felix Kaiser. files: Lib/http/server.py | 3 ++- Misc/NEWS | 3 +++ 2 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Lib/http/server.py b/Lib/http/server.py --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -1177,7 +1177,8 @@ HandlerClass.protocol_version = protocol with ServerClass(server_address, HandlerClass) as httpd: sa = httpd.socket.getsockname() - print("Serving HTTP on", sa[0], "port", sa[1], "...") + serve_message = "Serving HTTP on {host} port {port} (http://{host}:{port}/) ..." + print(serve_message.format(host=sa[0], port=sa[1])) try: httpd.serve_forever() except KeyboardInterrupt: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -256,6 +256,9 @@ Library ------- +- Issue #24902: Print server URL on http.server startup. Initial patch by + Felix Kaiser. + - Issue #25788: fileinput.hook_encoded() now supports an "errors" argument for passing to open. Original patch by Joseph Hackman. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 09:54:14 2016 From: python-checkins at python.org (berker.peksag) Date: Fri, 29 Apr 2016 13:54:14 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_typos=2E_Reported_by_a?= =?utf-8?q?ndportnoy_on_GitHub=2E?= Message-ID: <20160429135412.100798.61612.8A6E9CF0@psf.io> https://hg.python.org/cpython/rev/39397748a5b0 changeset: 101184:39397748a5b0 user: Berker Peksag date: Fri Apr 29 16:54:10 2016 +0300 summary: Fix typos. Reported by andportnoy on GitHub. files: Modules/_randommodule.c | 2 +- Objects/typeobject.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -136,7 +136,7 @@ * optimize the division away at compile-time. 67108864 is 2**26. In * effect, a contains 27 random bits shifted left 26, and b fills in the * lower 26 bits of the 53-bit numerator. - * The orginal code credited Isaku Wada for this algorithm, 2002/01/09. + * The original code credited Isaku Wada for this algorithm, 2002/01/09. */ static PyObject * random_random(RandomObject *self) diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3944,7 +3944,7 @@ } /* If we found some slot attributes, pack them in a tuple along - the orginal attribute dictionary. */ + the original attribute dictionary. */ if (PyDict_Size(slots) > 0) { PyObject *state2; -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 10:26:01 2016 From: python-checkins at python.org (berker.peksag) Date: Fri, 29 Apr 2016 14:26:01 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI1NTUx?= =?utf-8?q?=3A_Test_condition_behavior_instead_of_its_internals?= Message-ID: <20160429142553.21687.14249.2A7DC79D@psf.io> https://hg.python.org/cpython/rev/110dfb244b27 changeset: 101185:110dfb244b27 branch: 3.5 parent: 101181:6cd8cd14f648 user: Berker Peksag date: Fri Apr 29 17:25:29 2016 +0300 summary: Issue #25551: Test condition behavior instead of its internals test_reset_internal_locks was looking at Event's _cond._lock. This makes it harder to change internals of the Condition object and makes the test fragile. The test was added by Nir Soffer in 6108d30dde21. Patch by Nir Soffer. files: Lib/test/lock_tests.py | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py --- a/Lib/test/lock_tests.py +++ b/Lib/test/lock_tests.py @@ -395,12 +395,13 @@ self.assertEqual(results, [True] * N) def test_reset_internal_locks(self): + # ensure that condition is still using a Lock after reset evt = self.eventtype() - old_lock = evt._cond._lock + with evt._cond: + self.assertFalse(evt._cond.acquire(False)) evt._reset_internal_locks() - new_lock = evt._cond._lock - self.assertIsNot(new_lock, old_lock) - self.assertIs(type(new_lock), type(old_lock)) + with evt._cond: + self.assertFalse(evt._cond.acquire(False)) class ConditionTests(BaseTestCase): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 10:26:03 2016 From: python-checkins at python.org (berker.peksag) Date: Fri, 29 Apr 2016 14:26:03 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2325551=3A_Test_condition_behavior_instead_of_its?= =?utf-8?q?_internals?= Message-ID: <20160429142553.12170.87025.849CE48D@psf.io> https://hg.python.org/cpython/rev/9694185cdd9f changeset: 101186:9694185cdd9f parent: 101184:39397748a5b0 parent: 101185:110dfb244b27 user: Berker Peksag date: Fri Apr 29 17:25:51 2016 +0300 summary: Issue #25551: Test condition behavior instead of its internals test_reset_internal_locks was looking at Event's _cond._lock. This makes it harder to change internals of the Condition object and makes the test fragile. The test was added by Nir Soffer in 6108d30dde21. Patch by Nir Soffer. files: Lib/test/lock_tests.py | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py --- a/Lib/test/lock_tests.py +++ b/Lib/test/lock_tests.py @@ -407,12 +407,13 @@ self.assertEqual(results, [True] * N) def test_reset_internal_locks(self): + # ensure that condition is still using a Lock after reset evt = self.eventtype() - old_lock = evt._cond._lock + with evt._cond: + self.assertFalse(evt._cond.acquire(False)) evt._reset_internal_locks() - new_lock = evt._cond._lock - self.assertIsNot(new_lock, old_lock) - self.assertIs(type(new_lock), type(old_lock)) + with evt._cond: + self.assertFalse(evt._cond.acquire(False)) class ConditionTests(BaseTestCase): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 15:00:25 2016 From: python-checkins at python.org (berker.peksag) Date: Fri, 29 Apr 2016 19:00:25 +0000 Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2313436=3A_Add_a_te?= =?utf-8?q?st_to_make_sure_that_ast=2EImportFrom=28level=3DNone=29_works?= Message-ID: <20160429165002.100782.58311.28F4039A@psf.io> https://hg.python.org/cpython/rev/59638baee25e changeset: 101187:59638baee25e user: Berker Peksag date: Fri Apr 29 19:50:02 2016 +0300 summary: Issue #13436: Add a test to make sure that ast.ImportFrom(level=None) works files: Lib/test/test_ast.py | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -548,6 +548,17 @@ compile(mod, 'test', 'exec') self.assertIn("invalid integer value: None", str(cm.exception)) + def test_level_as_none(self): + body = [ast.ImportFrom(module='time', + names=[ast.alias(name='sleep')], + level=None, + lineno=0, col_offset=0)] + mod = ast.Module(body) + code = compile(mod, 'test', 'exec') + ns = {} + exec(code, ns) + self.assertIn('sleep', ns) + class ASTValidatorTests(unittest.TestCase): -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 23:46:25 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 30 Apr 2016 03:46:25 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI2ODY0?= =?utf-8?q?=3A_Fix_case_insensitivity_and_suffix_comparison_with_no=5Fprox?= =?utf-8?q?y?= Message-ID: <20160430034625.14942.67340.1CC18022@psf.io> https://hg.python.org/cpython/rev/ca882ee68d46 changeset: 101188:ca882ee68d46 branch: 3.5 parent: 101185:110dfb244b27 user: Martin Panter date: Sat Apr 30 01:03:40 2016 +0000 summary: Issue #26864: Fix case insensitivity and suffix comparison with no_proxy Patch by Xiang Zhang. files: Lib/test/test_urllib.py | 13 +++++++++++++ Lib/urllib/request.py | 8 ++++++-- Misc/NEWS | 5 +++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -231,6 +231,19 @@ self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com:8888')) self.assertTrue(urllib.request.proxy_bypass_environment('newdomain.com:1234')) + def test_proxy_bypass_environment_host_match(self): + bypass = urllib.request.proxy_bypass_environment + self.env.set('NO_PROXY', + 'localhost, anotherdomain.com, newdomain.com:1234') + self.assertTrue(bypass('localhost')) + self.assertTrue(bypass('LocalHost')) # MixedCase + self.assertTrue(bypass('LOCALHOST')) # UPPERCASE + self.assertTrue(bypass('newdomain.com:1234')) + self.assertTrue(bypass('anotherdomain.com:8888')) + self.assertTrue(bypass('www.newdomain.com:1234')) + self.assertFalse(bypass('prelocalhost')) + self.assertFalse(bypass('newdomain.com')) # no port + self.assertFalse(bypass('newdomain.com:1235')) # wrong port class ProxyTests_withOrderedEnv(unittest.TestCase): diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -2432,8 +2432,12 @@ # check if the host ends with any of the DNS suffixes no_proxy_list = [proxy.strip() for proxy in no_proxy.split(',')] for name in no_proxy_list: - if name and (hostonly.endswith(name) or host.endswith(name)): - return 1 + if name: + name = re.escape(name) + pattern = r'(.+\.)?%s$' % name + if (re.match(pattern, hostonly, re.I) + or re.match(pattern, host, re.I)): + return 1 # otherwise, don't bypass return 0 diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,11 @@ Library ------- +- Issue #26864: In urllib.request, change the proxy bypass host checking + against no_proxy to be case-insensitive, and to not match unrelated host + names that happen to have a bypassed hostname as a suffix. Patch by Xiang + Zhang. + - Issue #26634: recursive_repr() now sets __qualname__ of wrapper. Patch by Xiang Zhang. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 23:46:30 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 30 Apr 2016 03:46:30 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2326864=3A_Merge_no=5Fproxy_fixes_from_3=2E5?= Message-ID: <20160430034630.1512.44223.FEEC0001@psf.io> https://hg.python.org/cpython/rev/1ceb91974dc4 changeset: 101189:1ceb91974dc4 parent: 101187:59638baee25e parent: 101188:ca882ee68d46 user: Martin Panter date: Sat Apr 30 01:30:57 2016 +0000 summary: Issue #26864: Merge no_proxy fixes from 3.5 files: Lib/test/test_urllib.py | 13 +++++++++++++ Lib/urllib/request.py | 8 ++++++-- Misc/NEWS | 5 +++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -231,6 +231,19 @@ self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com:8888')) self.assertTrue(urllib.request.proxy_bypass_environment('newdomain.com:1234')) + def test_proxy_bypass_environment_host_match(self): + bypass = urllib.request.proxy_bypass_environment + self.env.set('NO_PROXY', + 'localhost, anotherdomain.com, newdomain.com:1234') + self.assertTrue(bypass('localhost')) + self.assertTrue(bypass('LocalHost')) # MixedCase + self.assertTrue(bypass('LOCALHOST')) # UPPERCASE + self.assertTrue(bypass('newdomain.com:1234')) + self.assertTrue(bypass('anotherdomain.com:8888')) + self.assertTrue(bypass('www.newdomain.com:1234')) + self.assertFalse(bypass('prelocalhost')) + self.assertFalse(bypass('newdomain.com')) # no port + self.assertFalse(bypass('newdomain.com:1235')) # wrong port class ProxyTests_withOrderedEnv(unittest.TestCase): diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -2492,8 +2492,12 @@ # check if the host ends with any of the DNS suffixes no_proxy_list = [proxy.strip() for proxy in no_proxy.split(',')] for name in no_proxy_list: - if name and (hostonly.endswith(name) or host.endswith(name)): - return 1 + if name: + name = re.escape(name) + pattern = r'(.+\.)?%s$' % name + if (re.match(pattern, hostonly, re.I) + or re.match(pattern, host, re.I)): + return 1 # otherwise, don't bypass return 0 diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -256,6 +256,11 @@ Library ------- +- Issue #26864: In urllib.request, change the proxy bypass host checking + against no_proxy to be case-insensitive, and to not match unrelated host + names that happen to have a bypassed hostname as a suffix. Patch by Xiang + Zhang. + - Issue #24902: Print server URL on http.server startup. Initial patch by Felix Kaiser. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Fri Apr 29 23:46:30 2016 From: python-checkins at python.org (martin.panter) Date: Sat, 30 Apr 2016 03:46:30 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI2ODY0?= =?utf-8?q?=3A_Fix_case_insensitivity_and_suffix_comparison_with_no=5Fprox?= =?utf-8?q?y?= Message-ID: <20160430034630.18006.91365.4EF95CD8@psf.io> https://hg.python.org/cpython/rev/a1aad42f1195 changeset: 101190:a1aad42f1195 branch: 2.7 parent: 101178:d738f268a013 user: Martin Panter date: Sat Apr 30 01:03:40 2016 +0000 summary: Issue #26864: Fix case insensitivity and suffix comparison with no_proxy Patch by Xiang Zhang. files: Lib/test/test_urllib.py | 13 +++++++++++++ Lib/urllib.py | 8 ++++++-- Misc/NEWS | 4 ++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -164,6 +164,19 @@ self.assertTrue(urllib.proxy_bypass_environment('anotherdomain.com:8888')) self.assertTrue(urllib.proxy_bypass_environment('newdomain.com:1234')) + def test_proxy_bypass_environment_host_match(self): + bypass = urllib.proxy_bypass_environment + self.env.set('NO_PROXY', + 'localhost, anotherdomain.com, newdomain.com:1234') + self.assertTrue(bypass('localhost')) + self.assertTrue(bypass('LocalHost')) # MixedCase + self.assertTrue(bypass('LOCALHOST')) # UPPERCASE + self.assertTrue(bypass('newdomain.com:1234')) + self.assertTrue(bypass('anotherdomain.com:8888')) + self.assertTrue(bypass('www.newdomain.com:1234')) + self.assertFalse(bypass('prelocalhost')) + self.assertFalse(bypass('newdomain.com')) # no port + self.assertFalse(bypass('newdomain.com:1235')) # wrong port class ProxyTests_withOrderedEnv(unittest.TestCase): diff --git a/Lib/urllib.py b/Lib/urllib.py --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -1423,8 +1423,12 @@ # check if the host ends with any of the DNS suffixes no_proxy_list = [proxy.strip() for proxy in no_proxy.split(',')] for name in no_proxy_list: - if name and (hostonly.endswith(name) or host.endswith(name)): - return 1 + if name: + name = re.escape(name) + pattern = r'(.+\.)?%s$' % name + if (re.match(pattern, hostonly, re.I) + or re.match(pattern, host, re.I)): + return 1 # otherwise, don't bypass return 0 diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,10 @@ Library ------- +- Issue #26864: In urllib, change the proxy bypass host checking against + no_proxy to be case-insensitive, and to not match unrelated host names that + happen to have a bypassed hostname as a suffix. Patch by Xiang Zhang. + - Issue #26804: urllib will prefer lower_case proxy environment variables over UPPER_CASE or Mixed_Case ones. Patch contributed by Hans-Peter Jansen. -- Repository URL: https://hg.python.org/cpython From solipsis at pitrou.net Sat Apr 30 04:52:22 2016 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 30 Apr 2016 08:52:22 +0000 Subject: [Python-checkins] Daily reference leaks (1ceb91974dc4): sum=6 Message-ID: <20160430085219.21689.24351.DB8C9594@psf.io> results for 1ceb91974dc4 on branch "default" -------------------------------------------- test_collections leaked [-4, 0, 4] memory blocks, sum=0 test_functools leaked [0, 3, 1] memory blocks, sum=4 test_typing leaked [2, 0, 0] references, sum=2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflog8mRFcT', '--timeout', '7200'] From python-checkins at python.org Sat Apr 30 11:36:43 2016 From: python-checkins at python.org (berker.peksag) Date: Sat, 30 Apr 2016 15:36:43 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzIxNzQ2?= =?utf-8?q?=3A_Remove_BaseResult_reference_from_urlparse_documentation?= Message-ID: <20160430153637.100784.18124.3615630E@psf.io> https://hg.python.org/cpython/rev/6d49a7330c99 changeset: 101191:6d49a7330c99 branch: 2.7 user: Berker Peksag date: Sat Apr 30 18:36:31 2016 +0300 summary: Issue #21746: Remove BaseResult reference from urlparse documentation BaseResult no longer exists and it has been replaced by namedtuple. Patch by Matthew Gilson. files: Doc/library/urlparse.rst | 14 ++------------ 1 files changed, 2 insertions(+), 12 deletions(-) diff --git a/Doc/library/urlparse.rst b/Doc/library/urlparse.rst --- a/Doc/library/urlparse.rst +++ b/Doc/library/urlparse.rst @@ -337,22 +337,12 @@ The following classes provide the implementations of the parse results: -.. class:: BaseResult - - Base class for the concrete result classes. This provides most of the attribute - definitions. It does not provide a :meth:`geturl` method. It is derived from - :class:`tuple`, but does not override the :meth:`__init__` or :meth:`__new__` - methods. - - .. class:: ParseResult(scheme, netloc, path, params, query, fragment) - Concrete class for :func:`urlparse` results. The :meth:`__new__` method is - overridden to support checking that the right number of arguments are passed. + Concrete class for :func:`urlparse` results. .. class:: SplitResult(scheme, netloc, path, query, fragment) - Concrete class for :func:`urlsplit` results. The :meth:`__new__` method is - overridden to support checking that the right number of arguments are passed. + Concrete class for :func:`urlsplit` results. -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 30 23:29:13 2016 From: python-checkins at python.org (meador.inge) Date: Sun, 01 May 2016 03:29:13 +0000 Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E5_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2324114=3A_Fix_an_uninitialized_variable_in_=60ct?= =?utf-8?b?eXBlcy51dGlsYC4=?= Message-ID: <20160501032913.19898.84468.EFE57747@psf.io> https://hg.python.org/cpython/rev/5b5fbce1db9c changeset: 101194:5b5fbce1db9c parent: 101189:1ceb91974dc4 parent: 101193:db5baad7ad69 user: Meador Inge date: Sat Apr 30 22:17:22 2016 -0500 summary: Issue #24114: Fix an uninitialized variable in `ctypes.util`. The bug only occurs on SunOS when the ctypes implementation searches for the `crle` program. Patch by Xiang Zhang. Tested on SunOS by Kees Bos. files: Lib/ctypes/util.py | 1 + Misc/NEWS | 6 ++++++ 2 files changed, 7 insertions(+), 0 deletions(-) diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -184,6 +184,7 @@ else: cmd = 'env LC_ALL=C /usr/bin/crle 2>/dev/null' + paths = None with contextlib.closing(os.popen(cmd)) as f: for line in f.readlines(): line = line.strip() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -256,6 +256,12 @@ Library ------- +- Issue #24114: Fix an uninitialized variable in `ctypes.util`. + + The bug only occurs on SunOS when the ctypes implementation searches + for the `crle` program. Patch by Xiang Zhang. Tested on SunOS by + Kees Bos. + - Issue #26864: In urllib.request, change the proxy bypass host checking against no_proxy to be case-insensitive, and to not match unrelated host names that happen to have a bypassed hostname as a suffix. Patch by Xiang -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 30 23:29:13 2016 From: python-checkins at python.org (meador.inge) Date: Sun, 01 May 2016 03:29:13 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy41KTogSXNzdWUgIzI0MTE0?= =?utf-8?q?=3A_Fix_an_uninitialized_variable_in_=60ctypes=2Eutil=60=2E?= Message-ID: <20160501032913.12119.1682.10C4FE93@psf.io> https://hg.python.org/cpython/rev/db5baad7ad69 changeset: 101193:db5baad7ad69 branch: 3.5 parent: 101188:ca882ee68d46 user: Meador Inge date: Sat Apr 30 21:56:59 2016 -0500 summary: Issue #24114: Fix an uninitialized variable in `ctypes.util`. The bug only occurs on SunOS when the ctypes implementation searches for the `crle` program. Patch by Xiang Zhang. Tested on SunOS by Kees Bos. files: Lib/ctypes/util.py | 1 + Misc/NEWS | 6 ++++++ 2 files changed, 7 insertions(+), 0 deletions(-) diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -184,6 +184,7 @@ else: cmd = 'env LC_ALL=C /usr/bin/crle 2>/dev/null' + paths = None with contextlib.closing(os.popen(cmd)) as f: for line in f.readlines(): line = line.strip() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,12 @@ Library ------- +- Issue #24114: Fix an uninitialized variable in `ctypes.util`. + + The bug only occurs on SunOS when the ctypes implementation searches + for the `crle` program. Patch by Xiang Zhang. Tested on SunOS by + Kees Bos. + - Issue #26864: In urllib.request, change the proxy bypass host checking against no_proxy to be case-insensitive, and to not match unrelated host names that happen to have a bypassed hostname as a suffix. Patch by Xiang -- Repository URL: https://hg.python.org/cpython From python-checkins at python.org Sat Apr 30 23:29:13 2016 From: python-checkins at python.org (meador.inge) Date: Sun, 01 May 2016 03:29:13 +0000 Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzI0MTE0?= =?utf-8?q?=3A_Fix_an_uninitialized_variable_in_=60ctypes=2Eutil=60=2E?= Message-ID: <20160501032913.21669.55871.9D836C62@psf.io> https://hg.python.org/cpython/rev/57bf7a40925f changeset: 101192:57bf7a40925f branch: 2.7 user: Meador Inge date: Sat Apr 30 21:56:59 2016 -0500 summary: Issue #24114: Fix an uninitialized variable in `ctypes.util`. The bug only occurs on SunOS when the ctypes implementation searches for the `crle` program. Patch by Xiang Zhang. Tested on SunOS by Kees Bos. files: Lib/ctypes/util.py | 1 + Misc/NEWS | 6 ++++++ 2 files changed, 7 insertions(+), 0 deletions(-) diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -191,6 +191,7 @@ else: cmd = 'env LC_ALL=C /usr/bin/crle 2>/dev/null' + paths = None for line in os.popen(cmd).readlines(): line = line.strip() if line.startswith('Default Library Path (ELF):'): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,12 @@ Library ------- +- Issue #24114: Fix an uninitialized variable in `ctypes.util`. + + The bug only occurs on SunOS when the ctypes implementation searches + for the `crle` program. Patch by Xiang Zhang. Tested on SunOS by + Kees Bos. + - Issue #26864: In urllib, change the proxy bypass host checking against no_proxy to be case-insensitive, and to not match unrelated host names that happen to have a bypassed hostname as a suffix. Patch by Xiang Zhang. -- Repository URL: https://hg.python.org/cpython