Python-checkins
Threads by month
- ----- 2026 -----
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
November 2016
- 4 participants
- 606 discussions
https://hg.python.org/cpython/rev/983a8887a895
changeset: 104960:983a8887a895
parent: 104958:d0e4440a68b3
parent: 104959:31543f7cbdf4
user: Eric V. Smith <eric(a)trueblade.com>
date: Mon Nov 07 17:57:48 2016 -0500
summary:
Merge from 3.6.
files:
Lib/test/test_fstring.py | 7 +++++++
Python/ast.c | 9 +++++----
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -92,6 +92,13 @@
exec(c)
self.assertEqual(x[0], 'foo3')
+ def test_compile_time_concat_errors(self):
+ self.assertAllRaise(SyntaxError,
+ 'cannot mix bytes and nonbytes literals',
+ [r"""f'' b''""",
+ r"""b'' f''""",
+ ])
+
def test_literal(self):
self.assertEqual(f'', '')
self.assertEqual(f'a', 'a')
diff --git a/Python/ast.c b/Python/ast.c
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -5147,7 +5147,8 @@
/* Check that we're not mixing bytes with unicode. */
if (i != 0 && bytesmode != this_bytesmode) {
ast_error(c, n, "cannot mix bytes and nonbytes literals");
- Py_DECREF(s);
+ /* s is NULL if the current string part is an f-string. */
+ Py_XDECREF(s);
goto error;
}
bytesmode = this_bytesmode;
@@ -5161,11 +5162,12 @@
if (result < 0)
goto error;
} else {
+ /* A string or byte string. */
+ assert(s != NULL && fstr == NULL);
+
assert(bytesmode ? PyBytes_CheckExact(s) :
PyUnicode_CheckExact(s));
- /* A string or byte string. */
- assert(s != NULL && fstr == NULL);
if (bytesmode) {
/* For bytes, concat as we go. */
if (i == 0) {
@@ -5177,7 +5179,6 @@
goto error;
}
} else {
- assert(s != NULL && fstr == NULL);
/* This is a regular string. Concatenate it. */
if (FstringParser_ConcatAndDel(&state, s) < 0)
goto error;
--
Repository URL: https://hg.python.org/cpython
1
0
cpython (3.6): Issue #28572: Add 10% to coverage of IDLE's test_configdialog.
by terry.reedy Nov. 7, 2016
by terry.reedy Nov. 7, 2016
Nov. 7, 2016
https://hg.python.org/cpython/rev/d6440718eb30
changeset: 104957:d6440718eb30
branch: 3.6
parent: 104955:5cf13fd36af1
user: Terry Jan Reedy <tjreedy(a)udel.edu>
date: Mon Nov 07 17:15:01 2016 -0500
summary:
Issue #28572: Add 10% to coverage of IDLE's test_configdialog.
Update and augment description of the configuration system.
files:
Lib/idlelib/config-main.def | 68 ++--
Lib/idlelib/config.py | 23 +-
Lib/idlelib/configdialog.py | 32 +-
Lib/idlelib/idle_test/test_configdialog.py | 129 ++++++++-
4 files changed, 179 insertions(+), 73 deletions(-)
diff --git a/Lib/idlelib/config-main.def b/Lib/idlelib/config-main.def
--- a/Lib/idlelib/config-main.def
+++ b/Lib/idlelib/config-main.def
@@ -4,44 +4,50 @@
# When IDLE starts, it will look in
# the following two sets of files, in order:
#
-# default configuration
-# ---------------------
-# config-main.def the default general config file
-# config-extensions.def the default extension config file
-# config-highlight.def the default highlighting config file
-# config-keys.def the default keybinding config file
+# default configuration files in idlelib
+# --------------------------------------
+# config-main.def default general config file
+# config-extensions.def default extension config file
+# config-highlight.def default highlighting config file
+# config-keys.def default keybinding config file
#
-# user configuration
-# -------------------
-# ~/.idlerc/config-main.cfg the user general config file
-# ~/.idlerc/config-extensions.cfg the user extension config file
-# ~/.idlerc/config-highlight.cfg the user highlighting config file
-# ~/.idlerc/config-keys.cfg the user keybinding config file
+# user configuration files in ~/.idlerc
+# -------------------------------------
+# config-main.cfg user general config file
+# config-extensions.cfg user extension config file
+# config-highlight.cfg user highlighting config file
+# config-keys.cfg user keybinding config file
#
-# On Windows2000 and Windows XP the .idlerc directory is at
-# Documents and Settings\<username>\.idlerc
-#
-# On Windows98 it is at c:\.idlerc
+# On Windows, the default location of the home directory ('~' above)
+# depends on the version. For Windows 10, it is C:\Users\<username>.
#
# Any options the user saves through the config dialog will be saved to
-# the relevant user config file. Reverting any general setting to the
-# default causes that entry to be wiped from the user file and re-read
-# from the default file. User highlighting themes or keybinding sets are
-# retained unless specifically deleted within the config dialog. Choosing
-# one of the default themes or keysets just applies the relevant settings
-# from the default file.
+# the relevant user config file. Reverting any general or extension
+# setting to the default causes that entry to be wiped from the user
+# file and re-read from the default file. This rule applies to each
+# item, except that the three editor font items are saved as a group.
#
-# Additional help sources are listed in the [HelpFiles] section and must be
-# viewable by a web browser (or the Windows Help viewer in the case of .chm
-# files). These sources will be listed on the Help menu. The pattern is
+# User highlighting themes and keybinding sets must have (section) names
+# distinct from the default names. All items are added and saved as a
+# group. They are retained unless specifically deleted within the config
+# dialog. Choosing one of the default themes or keysets just applies the
+# relevant settings from the default file.
+#
+# Additional help sources are listed in the [HelpFiles] section below
+# and should be viewable by a web browser (or the Windows Help viewer in
+# the case of .chm files). These sources will be listed on the Help
+# menu. The pattern, and two examples, are
+#
# <sequence_number = menu item;/path/to/help/source>
-# You can't use a semi-colon in a menu item or path. The path will be platform
-# specific because of path separators, drive specs etc.
+# 1 = IDLE;C:/Programs/Python36/Lib/idlelib/help.html
+# 2 = Pillow;https://pillow.readthedocs.io/en/latest/
#
-# It is best to use the Configuration GUI to set up additional help sources!
-# Example:
-#1 = My Extra Help Source;/usr/share/doc/foo/index.html
-#2 = Another Help Source;/path/to/another.pdf
+# You can't use a semi-colon in a menu item or path. The path will be
+# platform specific because of path separators, drive specs etc.
+#
+# The default files should not be edited except to add new sections to
+# config-extensions.def for added extensions . The user files should be
+# modified through the Settings dialog.
[General]
editor-on-startup= 0
diff --git a/Lib/idlelib/config.py b/Lib/idlelib/config.py
--- a/Lib/idlelib/config.py
+++ b/Lib/idlelib/config.py
@@ -1,13 +1,20 @@
-"""Provides access to stored IDLE configuration information.
+"""idlelib.config -- Manage IDLE configuration information.
-Refer to the comments at the beginning of config-main.def for a description of
-the available configuration files and the design implemented to update user
-configuration information. In particular, user configuration choices which
-duplicate the defaults will be removed from the user's configuration files,
-and if a file becomes empty, it will be deleted.
+The comments at the beginning of config-main.def describe the
+configuration files and the design implemented to update user
+configuration information. In particular, user configuration choices
+which duplicate the defaults will be removed from the user's
+configuration files, and if a user file becomes empty, it will be
+deleted.
-The contents of the user files may be altered using the Options/Configure IDLE
-menu to access the configuration GUI (configdialog.py), or manually.
+The configuration database maps options to values. Comceptually, the
+database keys are tuples (config-type, section, item). As implemented,
+there are separate dicts for default and user values. Each has
+config-type keys 'main', 'extensions', 'highlight', and 'keys'. The
+value for each key is a ConfigParser instance that maps section and item
+to values. For 'main' and 'extenstons', user values override
+default values. For 'highlight' and 'keys', user sections augment the
+default sections (and must, therefore, have distinct names).
Throughout this module there is an emphasis on returning useable defaults
when a problem occurs in returning a requested configuration value back to
diff --git a/Lib/idlelib/configdialog.py b/Lib/idlelib/configdialog.py
--- a/Lib/idlelib/configdialog.py
+++ b/Lib/idlelib/configdialog.py
@@ -392,28 +392,28 @@
text=' Additional Help Sources ')
#frameRun
labelRunChoiceTitle = Label(frameRun, text='At Startup')
- radioStartupEdit = Radiobutton(
+ self.radioStartupEdit = Radiobutton(
frameRun, variable=self.startupEdit, value=1,
- command=self.SetKeysType, text="Open Edit Window")
- radioStartupShell = Radiobutton(
+ text="Open Edit Window")
+ self.radioStartupShell = Radiobutton(
frameRun, variable=self.startupEdit, value=0,
- command=self.SetKeysType, text='Open Shell Window')
+ text='Open Shell Window')
#frameSave
labelRunSaveTitle = Label(frameSave, text='At Start of Run (F5) ')
- radioSaveAsk = Radiobutton(
+ self.radioSaveAsk = Radiobutton(
frameSave, variable=self.autoSave, value=0,
- command=self.SetKeysType, text="Prompt to Save")
- radioSaveAuto = Radiobutton(
+ text="Prompt to Save")
+ self.radioSaveAuto = Radiobutton(
frameSave, variable=self.autoSave, value=1,
- command=self.SetKeysType, text='No Prompt')
+ text='No Prompt')
#frameWinSize
labelWinSizeTitle = Label(
frameWinSize, text='Initial Window Size (in characters)')
labelWinWidthTitle = Label(frameWinSize, text='Width')
- entryWinWidth = Entry(
+ self.entryWinWidth = Entry(
frameWinSize, textvariable=self.winWidth, width=3)
labelWinHeightTitle = Label(frameWinSize, text='Height')
- entryWinHeight = Entry(
+ self.entryWinHeight = Entry(
frameWinSize, textvariable=self.winHeight, width=3)
#frameHelp
frameHelpList = Frame(frameHelp)
@@ -443,17 +443,17 @@
frameHelp.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
#frameRun
labelRunChoiceTitle.pack(side=LEFT, anchor=W, padx=5, pady=5)
- radioStartupShell.pack(side=RIGHT, anchor=W, padx=5, pady=5)
- radioStartupEdit.pack(side=RIGHT, anchor=W, padx=5, pady=5)
+ self.radioStartupShell.pack(side=RIGHT, anchor=W, padx=5, pady=5)
+ self.radioStartupEdit.pack(side=RIGHT, anchor=W, padx=5, pady=5)
#frameSave
labelRunSaveTitle.pack(side=LEFT, anchor=W, padx=5, pady=5)
- radioSaveAuto.pack(side=RIGHT, anchor=W, padx=5, pady=5)
- radioSaveAsk.pack(side=RIGHT, anchor=W, padx=5, pady=5)
+ self.radioSaveAuto.pack(side=RIGHT, anchor=W, padx=5, pady=5)
+ self.radioSaveAsk.pack(side=RIGHT, anchor=W, padx=5, pady=5)
#frameWinSize
labelWinSizeTitle.pack(side=LEFT, anchor=W, padx=5, pady=5)
- entryWinHeight.pack(side=RIGHT, anchor=E, padx=10, pady=5)
+ self.entryWinHeight.pack(side=RIGHT, anchor=E, padx=10, pady=5)
labelWinHeightTitle.pack(side=RIGHT, anchor=E, pady=5)
- entryWinWidth.pack(side=RIGHT, anchor=E, padx=10, pady=5)
+ self.entryWinWidth.pack(side=RIGHT, anchor=E, padx=10, pady=5)
labelWinWidthTitle.pack(side=RIGHT, anchor=E, pady=5)
#frameHelp
frameHelpListButtons.pack(side=RIGHT, padx=5, pady=5, fill=Y)
diff --git a/Lib/idlelib/idle_test/test_configdialog.py b/Lib/idlelib/idle_test/test_configdialog.py
--- a/Lib/idlelib/idle_test/test_configdialog.py
+++ b/Lib/idlelib/idle_test/test_configdialog.py
@@ -1,30 +1,123 @@
-'''Test idlelib.configdialog.
+"""Test idlelib.configdialog.
-Coverage: 46% just by creating dialog.
-The other half is code for working with user customizations.
-'''
-from idlelib.configdialog import ConfigDialog # always test import
+Half the class creates dialog, half works with user customizations.
+Coverage: 46% just by creating dialog, 56% with current tests.
+"""
+from idlelib.configdialog import ConfigDialog, idleConf # test import
from test.support import requires
requires('gui')
from tkinter import Tk
import unittest
+import idlelib.config as config
-class ConfigDialogTest(unittest.TestCase):
+# Tests should not depend on fortuitous user configurations.
+# They must not affect actual user .cfg files.
+# Use solution from test_config: empty parsers with no filename.
+usercfg = idleConf.userCfg
+testcfg = {
+ 'main': config.IdleUserConfParser(''),
+ 'highlight': config.IdleUserConfParser(''),
+ 'keys': config.IdleUserConfParser(''),
+ 'extensions': config.IdleUserConfParser(''),
+}
- @classmethod
- def setUpClass(cls):
- cls.root = Tk()
- cls.root.withdraw()
+# ConfigDialog.changedItems is a 3-level hierarchical dictionary of
+# pending changes that mirrors the multilevel user config dict.
+# For testing, record args in a list for comparison with expected.
+changes = []
+class TestDialog(ConfigDialog):
+ def AddChangedItem(self, *args):
+ changes.append(args)
- @classmethod
- def tearDownClass(cls):
- cls.root.update_idletasks()
- cls.root.destroy()
- del cls.root
+def setUpModule():
+ global root, configure
+ idleConf.userCfg = testcfg
+ root = Tk()
+ root.withdraw()
+ configure = TestDialog(root, 'Test', _utest=True)
- def test_configdialog(self):
- d = ConfigDialog(self.root, 'Test', _utest=True)
- d.remove_var_callbacks()
+
+def tearDownModule():
+ global root, configure
+ idleConf.userCfg = testcfg
+ configure.remove_var_callbacks()
+ del configure
+ root.update_idletasks()
+ root.destroy()
+ del root
+
+
+class FontTabTest(unittest.TestCase):
+
+
+ def setUp(self):
+ changes.clear()
+
+ def test_font(self):
+ configure.fontName.set('Test Font')
+ expected = [
+ ('main', 'EditorWindow', 'font', 'Test Font'),
+ ('main', 'EditorWindow', 'font-size', '10'),
+ ('main', 'EditorWindow', 'font-bold', False)]
+ self.assertEqual(changes, expected)
+ changes.clear()
+ configure.fontSize.set(12)
+ expected = [
+ ('main', 'EditorWindow', 'font', 'Test Font'),
+ ('main', 'EditorWindow', 'font-size', '12'),
+ ('main', 'EditorWindow', 'font-bold', False)]
+ self.assertEqual(changes, expected)
+ changes.clear()
+ configure.fontBold.set(True)
+ expected = [
+ ('main', 'EditorWindow', 'font', 'Test Font'),
+ ('main', 'EditorWindow', 'font-size', '12'),
+ ('main', 'EditorWindow', 'font-bold', True)]
+ self.assertEqual(changes, expected)
+
+ #def test_sample(self): pass # TODO
+
+ def test_tabspace(self):
+ configure.spaceNum.set(6)
+ self.assertEqual(changes, [('main', 'Indent', 'num-spaces', 6)])
+
+
+class HighlightTest(unittest.TestCase):
+
+ def setUp(self):
+ changes.clear()
+
+ #def test_colorchoose(self): pass # TODO
+
+
+class KeysTest(unittest.TestCase):
+
+ def setUp(self):
+ changes.clear()
+
+
+class GeneralTest(unittest.TestCase):
+
+ def setUp(self):
+ changes.clear()
+
+ def test_startup(self):
+ configure.radioStartupEdit.invoke()
+ self.assertEqual(changes,
+ [('main', 'General', 'editor-on-startup', 1)])
+
+ def test_autosave(self):
+ configure.radioSaveAuto.invoke()
+ self.assertEqual(changes, [('main', 'General', 'autosave', 1)])
+
+ def test_editor_size(self):
+ configure.entryWinHeight.insert(0, '1')
+ self.assertEqual(changes, [('main', 'EditorWindow', 'height', '140')])
+ changes.clear()
+ configure.entryWinWidth.insert(0, '1')
+ self.assertEqual(changes, [('main', 'EditorWindow', 'width', '180')])
+
+ #def test_help_sources(self): pass # TODO
if __name__ == '__main__':
--
Repository URL: https://hg.python.org/cpython
1
0
https://hg.python.org/cpython/rev/d0e4440a68b3
changeset: 104958:d0e4440a68b3
parent: 104956:38c806f0943b
parent: 104957:d6440718eb30
user: Terry Jan Reedy <tjreedy(a)udel.edu>
date: Mon Nov 07 17:15:16 2016 -0500
summary:
Merge with 3.6
files:
Lib/idlelib/config-main.def | 68 ++--
Lib/idlelib/config.py | 23 +-
Lib/idlelib/configdialog.py | 32 +-
Lib/idlelib/idle_test/test_configdialog.py | 129 ++++++++-
4 files changed, 179 insertions(+), 73 deletions(-)
diff --git a/Lib/idlelib/config-main.def b/Lib/idlelib/config-main.def
--- a/Lib/idlelib/config-main.def
+++ b/Lib/idlelib/config-main.def
@@ -4,44 +4,50 @@
# When IDLE starts, it will look in
# the following two sets of files, in order:
#
-# default configuration
-# ---------------------
-# config-main.def the default general config file
-# config-extensions.def the default extension config file
-# config-highlight.def the default highlighting config file
-# config-keys.def the default keybinding config file
+# default configuration files in idlelib
+# --------------------------------------
+# config-main.def default general config file
+# config-extensions.def default extension config file
+# config-highlight.def default highlighting config file
+# config-keys.def default keybinding config file
#
-# user configuration
-# -------------------
-# ~/.idlerc/config-main.cfg the user general config file
-# ~/.idlerc/config-extensions.cfg the user extension config file
-# ~/.idlerc/config-highlight.cfg the user highlighting config file
-# ~/.idlerc/config-keys.cfg the user keybinding config file
+# user configuration files in ~/.idlerc
+# -------------------------------------
+# config-main.cfg user general config file
+# config-extensions.cfg user extension config file
+# config-highlight.cfg user highlighting config file
+# config-keys.cfg user keybinding config file
#
-# On Windows2000 and Windows XP the .idlerc directory is at
-# Documents and Settings\<username>\.idlerc
-#
-# On Windows98 it is at c:\.idlerc
+# On Windows, the default location of the home directory ('~' above)
+# depends on the version. For Windows 10, it is C:\Users\<username>.
#
# Any options the user saves through the config dialog will be saved to
-# the relevant user config file. Reverting any general setting to the
-# default causes that entry to be wiped from the user file and re-read
-# from the default file. User highlighting themes or keybinding sets are
-# retained unless specifically deleted within the config dialog. Choosing
-# one of the default themes or keysets just applies the relevant settings
-# from the default file.
+# the relevant user config file. Reverting any general or extension
+# setting to the default causes that entry to be wiped from the user
+# file and re-read from the default file. This rule applies to each
+# item, except that the three editor font items are saved as a group.
#
-# Additional help sources are listed in the [HelpFiles] section and must be
-# viewable by a web browser (or the Windows Help viewer in the case of .chm
-# files). These sources will be listed on the Help menu. The pattern is
+# User highlighting themes and keybinding sets must have (section) names
+# distinct from the default names. All items are added and saved as a
+# group. They are retained unless specifically deleted within the config
+# dialog. Choosing one of the default themes or keysets just applies the
+# relevant settings from the default file.
+#
+# Additional help sources are listed in the [HelpFiles] section below
+# and should be viewable by a web browser (or the Windows Help viewer in
+# the case of .chm files). These sources will be listed on the Help
+# menu. The pattern, and two examples, are
+#
# <sequence_number = menu item;/path/to/help/source>
-# You can't use a semi-colon in a menu item or path. The path will be platform
-# specific because of path separators, drive specs etc.
+# 1 = IDLE;C:/Programs/Python36/Lib/idlelib/help.html
+# 2 = Pillow;https://pillow.readthedocs.io/en/latest/
#
-# It is best to use the Configuration GUI to set up additional help sources!
-# Example:
-#1 = My Extra Help Source;/usr/share/doc/foo/index.html
-#2 = Another Help Source;/path/to/another.pdf
+# You can't use a semi-colon in a menu item or path. The path will be
+# platform specific because of path separators, drive specs etc.
+#
+# The default files should not be edited except to add new sections to
+# config-extensions.def for added extensions . The user files should be
+# modified through the Settings dialog.
[General]
editor-on-startup= 0
diff --git a/Lib/idlelib/config.py b/Lib/idlelib/config.py
--- a/Lib/idlelib/config.py
+++ b/Lib/idlelib/config.py
@@ -1,13 +1,20 @@
-"""Provides access to stored IDLE configuration information.
+"""idlelib.config -- Manage IDLE configuration information.
-Refer to the comments at the beginning of config-main.def for a description of
-the available configuration files and the design implemented to update user
-configuration information. In particular, user configuration choices which
-duplicate the defaults will be removed from the user's configuration files,
-and if a file becomes empty, it will be deleted.
+The comments at the beginning of config-main.def describe the
+configuration files and the design implemented to update user
+configuration information. In particular, user configuration choices
+which duplicate the defaults will be removed from the user's
+configuration files, and if a user file becomes empty, it will be
+deleted.
-The contents of the user files may be altered using the Options/Configure IDLE
-menu to access the configuration GUI (configdialog.py), or manually.
+The configuration database maps options to values. Comceptually, the
+database keys are tuples (config-type, section, item). As implemented,
+there are separate dicts for default and user values. Each has
+config-type keys 'main', 'extensions', 'highlight', and 'keys'. The
+value for each key is a ConfigParser instance that maps section and item
+to values. For 'main' and 'extenstons', user values override
+default values. For 'highlight' and 'keys', user sections augment the
+default sections (and must, therefore, have distinct names).
Throughout this module there is an emphasis on returning useable defaults
when a problem occurs in returning a requested configuration value back to
diff --git a/Lib/idlelib/configdialog.py b/Lib/idlelib/configdialog.py
--- a/Lib/idlelib/configdialog.py
+++ b/Lib/idlelib/configdialog.py
@@ -392,28 +392,28 @@
text=' Additional Help Sources ')
#frameRun
labelRunChoiceTitle = Label(frameRun, text='At Startup')
- radioStartupEdit = Radiobutton(
+ self.radioStartupEdit = Radiobutton(
frameRun, variable=self.startupEdit, value=1,
- command=self.SetKeysType, text="Open Edit Window")
- radioStartupShell = Radiobutton(
+ text="Open Edit Window")
+ self.radioStartupShell = Radiobutton(
frameRun, variable=self.startupEdit, value=0,
- command=self.SetKeysType, text='Open Shell Window')
+ text='Open Shell Window')
#frameSave
labelRunSaveTitle = Label(frameSave, text='At Start of Run (F5) ')
- radioSaveAsk = Radiobutton(
+ self.radioSaveAsk = Radiobutton(
frameSave, variable=self.autoSave, value=0,
- command=self.SetKeysType, text="Prompt to Save")
- radioSaveAuto = Radiobutton(
+ text="Prompt to Save")
+ self.radioSaveAuto = Radiobutton(
frameSave, variable=self.autoSave, value=1,
- command=self.SetKeysType, text='No Prompt')
+ text='No Prompt')
#frameWinSize
labelWinSizeTitle = Label(
frameWinSize, text='Initial Window Size (in characters)')
labelWinWidthTitle = Label(frameWinSize, text='Width')
- entryWinWidth = Entry(
+ self.entryWinWidth = Entry(
frameWinSize, textvariable=self.winWidth, width=3)
labelWinHeightTitle = Label(frameWinSize, text='Height')
- entryWinHeight = Entry(
+ self.entryWinHeight = Entry(
frameWinSize, textvariable=self.winHeight, width=3)
#frameHelp
frameHelpList = Frame(frameHelp)
@@ -443,17 +443,17 @@
frameHelp.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
#frameRun
labelRunChoiceTitle.pack(side=LEFT, anchor=W, padx=5, pady=5)
- radioStartupShell.pack(side=RIGHT, anchor=W, padx=5, pady=5)
- radioStartupEdit.pack(side=RIGHT, anchor=W, padx=5, pady=5)
+ self.radioStartupShell.pack(side=RIGHT, anchor=W, padx=5, pady=5)
+ self.radioStartupEdit.pack(side=RIGHT, anchor=W, padx=5, pady=5)
#frameSave
labelRunSaveTitle.pack(side=LEFT, anchor=W, padx=5, pady=5)
- radioSaveAuto.pack(side=RIGHT, anchor=W, padx=5, pady=5)
- radioSaveAsk.pack(side=RIGHT, anchor=W, padx=5, pady=5)
+ self.radioSaveAuto.pack(side=RIGHT, anchor=W, padx=5, pady=5)
+ self.radioSaveAsk.pack(side=RIGHT, anchor=W, padx=5, pady=5)
#frameWinSize
labelWinSizeTitle.pack(side=LEFT, anchor=W, padx=5, pady=5)
- entryWinHeight.pack(side=RIGHT, anchor=E, padx=10, pady=5)
+ self.entryWinHeight.pack(side=RIGHT, anchor=E, padx=10, pady=5)
labelWinHeightTitle.pack(side=RIGHT, anchor=E, pady=5)
- entryWinWidth.pack(side=RIGHT, anchor=E, padx=10, pady=5)
+ self.entryWinWidth.pack(side=RIGHT, anchor=E, padx=10, pady=5)
labelWinWidthTitle.pack(side=RIGHT, anchor=E, pady=5)
#frameHelp
frameHelpListButtons.pack(side=RIGHT, padx=5, pady=5, fill=Y)
diff --git a/Lib/idlelib/idle_test/test_configdialog.py b/Lib/idlelib/idle_test/test_configdialog.py
--- a/Lib/idlelib/idle_test/test_configdialog.py
+++ b/Lib/idlelib/idle_test/test_configdialog.py
@@ -1,30 +1,123 @@
-'''Test idlelib.configdialog.
+"""Test idlelib.configdialog.
-Coverage: 46% just by creating dialog.
-The other half is code for working with user customizations.
-'''
-from idlelib.configdialog import ConfigDialog # always test import
+Half the class creates dialog, half works with user customizations.
+Coverage: 46% just by creating dialog, 56% with current tests.
+"""
+from idlelib.configdialog import ConfigDialog, idleConf # test import
from test.support import requires
requires('gui')
from tkinter import Tk
import unittest
+import idlelib.config as config
-class ConfigDialogTest(unittest.TestCase):
+# Tests should not depend on fortuitous user configurations.
+# They must not affect actual user .cfg files.
+# Use solution from test_config: empty parsers with no filename.
+usercfg = idleConf.userCfg
+testcfg = {
+ 'main': config.IdleUserConfParser(''),
+ 'highlight': config.IdleUserConfParser(''),
+ 'keys': config.IdleUserConfParser(''),
+ 'extensions': config.IdleUserConfParser(''),
+}
- @classmethod
- def setUpClass(cls):
- cls.root = Tk()
- cls.root.withdraw()
+# ConfigDialog.changedItems is a 3-level hierarchical dictionary of
+# pending changes that mirrors the multilevel user config dict.
+# For testing, record args in a list for comparison with expected.
+changes = []
+class TestDialog(ConfigDialog):
+ def AddChangedItem(self, *args):
+ changes.append(args)
- @classmethod
- def tearDownClass(cls):
- cls.root.update_idletasks()
- cls.root.destroy()
- del cls.root
+def setUpModule():
+ global root, configure
+ idleConf.userCfg = testcfg
+ root = Tk()
+ root.withdraw()
+ configure = TestDialog(root, 'Test', _utest=True)
- def test_configdialog(self):
- d = ConfigDialog(self.root, 'Test', _utest=True)
- d.remove_var_callbacks()
+
+def tearDownModule():
+ global root, configure
+ idleConf.userCfg = testcfg
+ configure.remove_var_callbacks()
+ del configure
+ root.update_idletasks()
+ root.destroy()
+ del root
+
+
+class FontTabTest(unittest.TestCase):
+
+
+ def setUp(self):
+ changes.clear()
+
+ def test_font(self):
+ configure.fontName.set('Test Font')
+ expected = [
+ ('main', 'EditorWindow', 'font', 'Test Font'),
+ ('main', 'EditorWindow', 'font-size', '10'),
+ ('main', 'EditorWindow', 'font-bold', False)]
+ self.assertEqual(changes, expected)
+ changes.clear()
+ configure.fontSize.set(12)
+ expected = [
+ ('main', 'EditorWindow', 'font', 'Test Font'),
+ ('main', 'EditorWindow', 'font-size', '12'),
+ ('main', 'EditorWindow', 'font-bold', False)]
+ self.assertEqual(changes, expected)
+ changes.clear()
+ configure.fontBold.set(True)
+ expected = [
+ ('main', 'EditorWindow', 'font', 'Test Font'),
+ ('main', 'EditorWindow', 'font-size', '12'),
+ ('main', 'EditorWindow', 'font-bold', True)]
+ self.assertEqual(changes, expected)
+
+ #def test_sample(self): pass # TODO
+
+ def test_tabspace(self):
+ configure.spaceNum.set(6)
+ self.assertEqual(changes, [('main', 'Indent', 'num-spaces', 6)])
+
+
+class HighlightTest(unittest.TestCase):
+
+ def setUp(self):
+ changes.clear()
+
+ #def test_colorchoose(self): pass # TODO
+
+
+class KeysTest(unittest.TestCase):
+
+ def setUp(self):
+ changes.clear()
+
+
+class GeneralTest(unittest.TestCase):
+
+ def setUp(self):
+ changes.clear()
+
+ def test_startup(self):
+ configure.radioStartupEdit.invoke()
+ self.assertEqual(changes,
+ [('main', 'General', 'editor-on-startup', 1)])
+
+ def test_autosave(self):
+ configure.radioSaveAuto.invoke()
+ self.assertEqual(changes, [('main', 'General', 'autosave', 1)])
+
+ def test_editor_size(self):
+ configure.entryWinHeight.insert(0, '1')
+ self.assertEqual(changes, [('main', 'EditorWindow', 'height', '140')])
+ changes.clear()
+ configure.entryWinWidth.insert(0, '1')
+ self.assertEqual(changes, [('main', 'EditorWindow', 'width', '180')])
+
+ #def test_help_sources(self): pass # TODO
if __name__ == '__main__':
--
Repository URL: https://hg.python.org/cpython
1
0
Nov. 7, 2016
https://hg.python.org/cpython/rev/38c806f0943b
changeset: 104956:38c806f0943b
parent: 104954:44c1ec7689e5
parent: 104955:5cf13fd36af1
user: Yury Selivanov <yury(a)magic.io>
date: Mon Nov 07 16:44:27 2016 -0500
summary:
Merge 3.6 (issue #28635)
files:
Doc/whatsnew/3.6.rst | 588 ++++++++++++++++++------------
1 files changed, 360 insertions(+), 228 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
@@ -4,6 +4,7 @@
:Release: |release|
:Date: |today|
+:Editors: Elvis Pranskevichus <elvis(a)magic.io>, Yury Selivanov <yury(a)magic.io>
.. Rules for maintenance:
@@ -45,16 +46,17 @@
This saves the maintainer the effort of going through the Mercurial log
when researching a change.
+.. note::
+
+ Prerelease users should be aware that this document is currently in draft
+ form. It will be updated substantially as Python 3.6 moves towards release,
+ so it's worth checking back even after reading earlier versions.
+
This article explains the new features in Python 3.6, compared to 3.5.
-For full details, see the
-`changelog <https://docs.python.org/3.6/whatsnew/changelog.html>`_.
+.. seealso::
-.. note::
-
- Prerelease users should be aware that this document is currently in draft
- form. It will be updated substantially as Python 3.6 moves towards release,
- so it's worth checking back even after reading earlier versions.
+ :pep:`494` - Python 3.6 Release Schedule
Summary -- Release highlights
@@ -65,40 +67,73 @@
New syntax features:
-* A ``global`` or ``nonlocal`` statement must now textually appear
- before the first use of the affected name in the same scope.
- Previously this was a SyntaxWarning.
+* :ref:`PEP 498 <whatsnew36-pep498>`, formatted string literals.
-* PEP 498: :ref:`Formatted string literals <whatsnew-fstrings>`
+* :ref:`PEP 515 <whatsnew36-pep515>`, underscores in numeric literals.
-* PEP 515: Underscores in Numeric Literals
+* :ref:`PEP 526 <whatsnew36-pep526>`, syntax for variable annotations.
-* PEP 526: :ref:`Syntax for Variable Annotations <variable-annotations>`
+* :ref:`PEP 525 <whatsnew36-pep525>`, asynchronous generators.
-* PEP 525: Asynchronous Generators
+* :ref:`PEP 530 <whatsnew36-pep530>`: asynchronous comprehensions.
-* PEP 530: Asynchronous Comprehensions
-Standard library improvements:
+New library modules:
+
+* :mod:`secrets`: :ref:`PEP 506 -- Adding A Secrets Module To The Standard Library <whatsnew36-pep506>`.
+
+
+CPython implementation improvements:
+
+* The :ref:`dict <typesmapping>` type has been reimplemented to use
+ a :ref:`faster, more compact representation <whatsnew36-compactdict>`
+ similar to the `PyPy dict implementation`_. This resulted in dictionaries
+ using 20% to 25% less memory when compared to Python 3.5.
+
+* Customization of class creation has been simplified with the
+ :ref:`new protocol <whatsnew36-pep487>`.
+
+* The class attibute definition order is
+ :ref:`now preserved <whatsnew36-pep520>`.
+
+* The order of elements in ``**kwargs`` now corresponds to the order in
+ the function signature:
+ :ref:`Preserving Keyword Argument Order <whatsnew36-pep468>`.
+
+* DTrace and SystemTap :ref:`probing support <whatsnew36-tracing>`.
+
+
+Significant improvements in the standard library:
+
+* A new :ref:`file system path protocol <whatsnew36-pep519>` has been
+ implemented to support :term:`path-like objects <path-like object>`.
+ All standard library functions operating on paths have been updated to
+ work with the new protocol.
+
+* The overhead of :mod:`asyncio` implementation has been reduced by
+ up to 50% thanks to the new C implementation of the :class:`asyncio.Future`
+ and :class:`asyncio.Task` classes and other optimizations.
+
Security improvements:
-* On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
- is initialized to increase the security. See the :pep:`524` for the
+* On Linux, :func:`os.urandom` now blocks until the system urandom entropy
+ pool is initialized to increase the security. See the :pep:`524` for the
rationale.
-* :mod:`hashlib` and :mod:`ssl` now support OpenSSL 1.1.0.
+* The :mod:`hashlib` and :mod:`ssl` modules now support OpenSSL 1.1.0.
-* The default settings and feature set of the :mod:`ssl` have been improved.
+* The default settings and feature set of the :mod:`ssl` module have been
+ improved.
-* The :mod:`hashlib` module has got support for BLAKE2, SHA-3 and SHAKE hash
- algorithms and :func:`~hashlib.scrypt` key derivation function.
+* The :mod:`hashlib` module received support for the BLAKE2, SHA-3 and SHAKE
+ hash algorithms and the :func:`~hashlib.scrypt` key derivation function.
+
Windows improvements:
-* PEP 529: :ref:`Change Windows filesystem encoding to UTF-8 <pep-529>`
-
-* PEP 528: :ref:`Change Windows console encoding to UTF-8 <pep-528>`
+* :ref:`PEP 528 <whatsnew36-pep529>` and :ref:`PEP 529 <whatsnew36-pep529>`,
+ Windows filesystem and console encoding changed to UTF-8.
* The ``py.exe`` launcher, when used interactively, no longer prefers
Python 2 over Python 3 when the user doesn't specify a version (via
@@ -117,66 +152,111 @@
:envvar:`PYTHONHOME`. See :ref:`the documentation <finding_modules>` for
more information.
-.. PEP-sized items next.
-
-.. _pep-4XX:
-
-.. PEP 4XX: Virtual Environments
-.. =============================
-
-
-.. (Implemented by Foo Bar.)
-
-.. .. seealso::
-
- :pep:`4XX` - Python Virtual Environments
- PEP written by Carl Meyer
-
-New built-in features:
-
-* PEP 520: :ref:`Preserving Class Attribute Definition Order<whatsnew-deforder>`
-
-* PEP 468: :ref:`Preserving Keyword Argument Order<whatsnew-kwargs>`
A complete list of PEP's implemented in Python 3.6:
-* :pep:`468`, :ref:`Preserving Keyword Argument Order<whatsnew-kwargs>`
-* :pep:`487`, :ref:`Simpler customization of class creation<whatsnew-pep487>`
+* :pep:`468`, :ref:`Preserving Keyword Argument Order <whatsnew36-pep468>`
+* :pep:`487`, :ref:`Simpler customization of class creation <whatsnew36-pep487>`
* :pep:`495`, Local Time Disambiguation
-* :pep:`498`, :ref:`Formatted string literals <whatsnew-fstrings>`
+* :pep:`498`, :ref:`Formatted string literals <whatsnew36-pep498>`
* :pep:`506`, Adding A Secrets Module To The Standard Library
-* :pep:`509`, :ref:`Add a private version to dict<whatsnew-pep509>`
-* :pep:`515`, :ref:`Underscores in Numeric Literals<pep-515>`
-* :pep:`519`, :ref:`Adding a file system path protocol<pep-519>`
-* :pep:`520`, :ref:`Preserving Class Attribute Definition Order<whatsnew-deforder>`
-* :pep:`523`, :ref:`Adding a frame evaluation API to CPython<pep-523>`
+* :pep:`509`, :ref:`Add a private version to dict <whatsnew36-pep509>`
+* :pep:`515`, :ref:`Underscores in Numeric Literals <whatsnew36-pep515>`
+* :pep:`519`, :ref:`Adding a file system path protocol <whatsnew36-pep519>`
+* :pep:`520`, :ref:`Preserving Class Attribute Definition Order <whatsnew36-pep520>`
+* :pep:`523`, :ref:`Adding a frame evaluation API to CPython <whatsnew36-pep523>`
* :pep:`524`, Make os.urandom() blocking on Linux (during system startup)
* :pep:`525`, Asynchronous Generators (provisional)
-* :pep:`526`, :ref:`Syntax for Variable Annotations (provisional)<variable-annotations>`
-* :pep:`528`, :ref:`Change Windows console encoding to UTF-8 (provisional)<pep-528>`
-* :pep:`529`, :ref:`Change Windows filesystem encoding to UTF-8 (provisional)<pep-529>`
+* :pep:`526`, :ref:`Syntax for Variable Annotations (provisional) <whatsnew36-pep526>`
+* :pep:`528`, :ref:`Change Windows console encoding to UTF-8 (provisional) <whatsnew36-pep528>`
+* :pep:`529`, :ref:`Change Windows filesystem encoding to UTF-8 (provisional) <whatsnew36-pep529>`
* :pep:`530`, Asynchronous Comprehensions
+.. _PyPy dict implementation: https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more…
+
+
New Features
============
-.. _pep-515:
+.. _whatsnew36-pep498:
+
+PEP 498: Formatted string literals
+----------------------------------
+
+:pep:`498` introduces a new kind of string literals: *f-strings*, or
+*formatted string literals*.
+
+Formatted string literals are prefixed with ``'f'`` and are similar to
+the format strings accepted by :meth:`str.format`. They contain replacement
+fields surrounded by curly braces. The replacement fields are expressions,
+which are evaluated at run time, and then formatted using the
+:func:`format` protocol::
+
+ >>> name = "Fred"
+ >>> f"He said his name is {name}."
+ 'He said his name is Fred.'
+
+.. seealso::
+
+ :pep:`498` -- Literal String Interpolation.
+ PEP written and implemented by Eric V. Smith.
+
+ :ref:`Feature documentation <f-strings>`.
+
+
+.. _whatsnew36-pep526:
+
+PEP 526: Syntax for variable annotations
+----------------------------------------
+
+:pep:`484` introduced the standard for type annotations of function
+parameters, a.k.a. type hints. This PEP adds syntax to Python for annotating
+the types of variables including class variables and instance variables::
+
+ primes: List[int] = []
+
+ captain: str # Note: no initial value!
+
+ class Starship:
+ stats: Dict[str, int] = {}
+
+Just as for function annotations, the Python interpreter does not attach any
+particular meaning to variable annotations and only stores them in the
+``__annotations__`` attribute of a class or module.
+
+In contrast to variable declarations in statically typed languages,
+the goal of annotation syntax is to provide an easy way to specify structured
+type metadata for third party tools and libraries via the abstract syntax tree
+and the ``__annotations__`` attribute.
+
+.. seealso::
+
+ :pep:`526` -- Syntax for variable annotations.
+ PEP written by Ryan Gonzalez, Philip House, Ivan Levkivskyi, Lisa Roach,
+ and Guido van Rossum. Implemented by Ivan Levkivskyi.
+
+ Tools that use or will use the new syntax:
+ `mypy <http://github.com/python/mypy>`_,
+ `pytype <http://github.com/google/pytype>`_, PyCharm, etc.
+
+
+.. _whatsnew36-pep515:
PEP 515: Underscores in Numeric Literals
----------------------------------------
-Prior to PEP 515, there was no support for writing long numeric
-literals with some form of separator to improve readability. For
-instance, how big is ``1000000000000000``? With :pep:`515`, though,
-you can use underscores to separate digits as desired to make numeric
-literals easier to read: ``1_000_000_000_000_000``. Underscores can be
-used with other numeric literals beyond integers, e.g.
-``0x_FF_FF_FF_FF``.
+:pep:`515` adds the ability to use underscores in numeric literals for
+improved readability. For example::
+
+ >>> 1_000_000_000_000_000
+ 1000000000000000
+ >>> 0x_FF_FF_FF_FF
+ 4294967295
Single underscores are allowed between digits and after any base
-specifier. More than a single underscore in a row, leading, or
-trailing underscores are not allowed.
+specifier. Leading, trailing, or multiple underscores in a row are not
+allowed.
.. seealso::
@@ -184,36 +264,115 @@
PEP written by Georg Brandl and Serhiy Storchaka.
-.. _pep-523:
+.. _whatsnew36-pep525:
-PEP 523: Adding a frame evaluation API to CPython
--------------------------------------------------
+PEP 525: Asynchronous Generators
+--------------------------------
-While Python provides extensive support to customize how code
-executes, one place it has not done so is in the evaluation of frame
-objects. If you wanted some way to intercept frame evaluation in
-Python there really wasn't any way without directly manipulating
-function pointers for defined functions.
+:pep:`492` introduced support for native coroutines and ``async`` / ``await``
+syntax to Python 3.5. A notable limitation of the Python 3.5 implementation
+is that it was not possible to use ``await`` and ``yield`` in the same
+function body. In Python 3.6 this restriction has been lifted, making it
+possible to define *asynchronous generators*::
-:pep:`523` changes this by providing an API to make frame
-evaluation pluggable at the C level. This will allow for tools such
-as debuggers and JITs to intercept frame evaluation before the
-execution of Python code begins. This enables the use of alternative
-evaluation implementations for Python code, tracking frame
-evaluation, etc.
+ async def ticker(delay, to):
+ """Yield numbers from 0 to `to` every `delay` seconds."""
+ for i in range(to):
+ yield i
+ await asyncio.sleep(delay)
-This API is not part of the limited C API and is marked as private to
-signal that usage of this API is expected to be limited and only
-applicable to very select, low-level use-cases. Semantics of the
-API will change with Python as necessary.
+The new syntax allows for faster and more concise code.
.. seealso::
- :pep:`523` -- Adding a frame evaluation API to CPython
- PEP written by Brett Cannon and Dino Viehland.
+ :pep:`525` -- Asynchronous Generators
+ PEP written and implemented by Yury Selivanov.
-.. _pep-519:
+.. _whatsnew36-pep530:
+
+PEP 530: Asynchronous Comprehensions
+------------------------------------
+
+:pep:`530` adds support for using ``async for`` in list, set, dict
+comprehensions and generator expressions::
+
+ result = [i async for i in aiter() if i % 2]
+
+Additionally, ``await`` expressions are supported in all kinds
+of comprehensions::
+
+ result = [await fun() for fun in funcs]
+
+.. seealso::
+
+ :pep:`530` -- Asynchronous Comprehensions
+ PEP written and implemented by Yury Selivanov.
+
+
+.. _whatsnew36-pep487:
+
+PEP 487: Simpler customization of class creation
+------------------------------------------------
+
+It is now possible to customize subclass creation without using a metaclass.
+The new ``__init_subclass__`` classmethod will be called on the base class
+whenever a new subclass is created::
+
+ >>> class QuestBase:
+ ... # this is implicitly a @classmethod
+ ... def __init_subclass__(cls, swallow, **kwargs):
+ ... cls.swallow = swallow
+ ... super().__init_subclass__(**kwargs)
+
+ >>> class Quest(QuestBase, swallow="african"):
+ ... pass
+
+ >>> Quest.swallow
+ 'african'
+
+.. seealso::
+
+ :pep:`487` -- Simpler customization of class creation
+ PEP written and implemented by Martin Teichmann.
+
+ :ref:`Feature documentation <class-customization>`
+
+
+.. _whatsnew36-pep487-descriptors:
+
+PEP 487: Descriptor Protocol Enhancements
+-----------------------------------------
+
+:pep:`487` extends the descriptor protocol has to include the new optional
+``__set_name__`` method. Whenever a new class is defined, the new method
+will be called on all descriptors included in the definition, providing
+them with a reference to the class being defined and the name given to the
+descriptor within the class namespace.
+
+.. seealso::
+
+ :pep:`487` -- Simpler customization of class creation
+ PEP written and implemented by Martin Teichmann.
+
+ :ref:`Feature documentation <descriptors>`
+
+
+.. _whatsnew36-pep506:
+
+PEP 506: Adding A Secrets Module To The Standard Library
+--------------------------------------------------------
+
+
+
+.. seealso::
+
+ :pep:`506` -- Adding A Secrets Module To The Standard Library
+ PEP written and implemented by Steven D'Aprano.
+
+
+
+.. _whatsnew36-pep519:
PEP 519: Adding a file system path protocol
-------------------------------------------
@@ -280,60 +439,7 @@
PEP written by Brett Cannon and Koos Zevenhoven.
-.. _whatsnew-fstrings:
-
-PEP 498: Formatted string literals
-----------------------------------
-
-Formatted string literals are a new kind of string literal, prefixed
-with ``'f'``. They are similar to the format strings accepted by
-:meth:`str.format`. They contain replacement fields surrounded by
-curly braces. The replacement fields are expressions, which are
-evaluated at run time, and then formatted using the :func:`format` protocol::
-
- >>> name = "Fred"
- >>> f"He said his name is {name}."
- 'He said his name is Fred.'
-
-See :pep:`498` and the main documentation at :ref:`f-strings`.
-
-
-.. _variable-annotations:
-
-PEP 526: Syntax for variable annotations
-----------------------------------------
-
-:pep:`484` introduced standard for type annotations of function parameters,
-a.k.a. type hints. This PEP adds syntax to Python for annotating the
-types of variables including class variables and instance variables::
-
- primes: List[int] = []
-
- captain: str # Note: no initial value!
-
- class Starship:
- stats: Dict[str, int] = {}
-
-Just as for function annotations, the Python interpreter does not attach any
-particular meaning to variable annotations and only stores them in a special
-attribute ``__annotations__`` of a class or module.
-In contrast to variable declarations in statically typed languages,
-the goal of annotation syntax is to provide an easy way to specify structured
-type metadata for third party tools and libraries via the abstract syntax tree
-and the ``__annotations__`` attribute.
-
-.. seealso::
-
- :pep:`526` -- Syntax for variable annotations.
- PEP written by Ryan Gonzalez, Philip House, Ivan Levkivskyi, Lisa Roach,
- and Guido van Rossum. Implemented by Ivan Levkivskyi.
-
- Tools that use or will use the new syntax:
- `mypy <http://github.com/python/mypy>`_,
- `pytype <http://github.com/google/pytype>`_, PyCharm, etc.
-
-
-.. _pep-529:
+.. _whatsnew36-pep529:
PEP 529: Change Windows filesystem encoding to UTF-8
----------------------------------------------------
@@ -356,28 +462,8 @@
See :pep:`529` for more information and discussion of code modifications that
may be required.
-.. _whatsnew-pep487:
-PEP 487: Simpler customization of class creation
-------------------------------------------------
-
-Upon subclassing a class, the ``__init_subclass__`` classmethod (if defined) is
-called on the base class. This makes it straightforward to write classes that
-customize initialization of future subclasses without introducing the
-complexity of a full custom metaclass.
-
-The descriptor protocol has also been expanded to include a new optional method,
-``__set_name__``. Whenever a new class is defined, the new method will be called
-on all descriptors included in the definition, providing them with a reference
-to the class being defined and the name given to the descriptor within the
-class namespace.
-
-Also see :pep:`487` and the updated class customization documentation at
-:ref:`class-customization` and :ref:`descriptors`.
-
-(Contributed by Martin Teichmann in :issue:`27366`)
-
-.. _pep-528:
+.. _whatsnew36-pep528:
PEP 528: Change Windows console encoding to UTF-8
-------------------------------------------------
@@ -395,6 +481,104 @@
:pep:`528` -- Change Windows console encoding to UTF-8
PEP written and implemented by Steve Dower.
+
+.. _whatsnew36-pep520:
+
+PEP 520: Preserving Class Attribute Definition Order
+----------------------------------------------------
+
+Attributes in a class definition body have a natural ordering: the same
+order in which the names appear in the source. This order is now
+preserved in the new class's ``__dict__`` attribute.
+
+Also, the effective default class *execution* namespace (returned from
+``type.__prepare__()``) is now an insertion-order-preserving mapping.
+
+.. seealso::
+
+ :pep:`520` -- Preserving Class Attribute Definition Order
+ PEP written and implemented by Eric Snow.
+
+
+.. _whatsnew36-pep468:
+
+PEP 468: Preserving Keyword Argument Order
+------------------------------------------
+
+``**kwargs`` in a function signature is now guaranteed to be an
+insertion-order-preserving mapping.
+
+.. seealso::
+
+ :pep:`468` -- Preserving Keyword Argument Order
+ PEP written and implemented by Eric Snow.
+
+
+.. _whatsnew36-compactdict:
+
+New :ref:`dict <typesmapping>` implementation
+---------------------------------------------
+
+The :ref:`dict <typesmapping>` type now uses a "compact" representation
+`pioneered by PyPy <https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more…>`_.
+The memory usage of the new :func:`dict` is between 20% and 25% smaller
+compared to Python 3.5.
+:pep:`468` (Preserving the order of ``**kwargs`` in a function.) is
+implemented by this. The order-preserving aspect of this new
+implementation is considered an implementation detail and should
+not be relied upon (this may change in the future, but it is desired
+to have this new dict implementation in the language for a few
+releases before changing the language spec to mandate
+order-preserving semantics for all current and future Python
+implementations; this also helps preserve backwards-compatibility
+with older versions of the language where random iteration order is
+still in effect, e.g. Python 3.5).
+(Contributed by INADA Naoki in :issue:`27350`. Idea
+`originally suggested by Raymond Hettinger
+<https://mail.python.org/pipermail/python-dev/2012-December/123028.html>`_.)
+
+
+.. _whatsnew36-pep523:
+
+PEP 523: Adding a frame evaluation API to CPython
+-------------------------------------------------
+
+While Python provides extensive support to customize how code
+executes, one place it has not done so is in the evaluation of frame
+objects. If you wanted some way to intercept frame evaluation in
+Python there really wasn't any way without directly manipulating
+function pointers for defined functions.
+
+:pep:`523` changes this by providing an API to make frame
+evaluation pluggable at the C level. This will allow for tools such
+as debuggers and JITs to intercept frame evaluation before the
+execution of Python code begins. This enables the use of alternative
+evaluation implementations for Python code, tracking frame
+evaluation, etc.
+
+This API is not part of the limited C API and is marked as private to
+signal that usage of this API is expected to be limited and only
+applicable to very select, low-level use-cases. Semantics of the
+API will change with Python as necessary.
+
+.. seealso::
+
+ :pep:`523` -- Adding a frame evaluation API to CPython
+ PEP written by Brett Cannon and Dino Viehland.
+
+
+.. _whatsnew36-pep509:
+
+PEP 509: Add a private version to dict
+--------------------------------------
+
+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.
+
+(Contributed by Victor Stinner in :issue:`26058`.)
+
+
PYTHONMALLOC environment variable
---------------------------------
@@ -469,6 +653,8 @@
(Contributed by Victor Stinner in :issue:`26516` and :issue:`26564`.)
+.. _whatsnew36-tracing:
+
DTrace and SystemTap probing support
------------------------------------
@@ -494,71 +680,14 @@
Jesús Cea Avión, David Malcolm, and Nikhil Benesch.)
-.. _whatsnew-deforder:
-
-PEP 520: Preserving Class Attribute Definition Order
-----------------------------------------------------
-
-Attributes in a class definition body have a natural ordering: the same
-order in which the names appear in the source. This order is now
-preserved in the new class's ``__dict__`` attribute.
-
-Also, the effective default class *execution* namespace (returned from
-``type.__prepare__()``) is now an insertion-order-preserving mapping.
-
-.. seealso::
-
- :pep:`520` -- Preserving Class Attribute Definition Order
- PEP written and implemented by Eric Snow.
-
-
-.. _whatsnew-kwargs:
-
-PEP 468: Preserving Keyword Argument Order
-------------------------------------------
-
-``**kwargs`` in a function signature is now guaranteed to be an
-insertion-order-preserving mapping.
-
-.. seealso::
-
- :pep:`468` -- Preserving Keyword Argument Order
- PEP written and implemented by Eric Snow.
-
-.. _whatsnew-pep509:
-
-PEP 509: Add a private version to dict
---------------------------------------
-
-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.
-
-(Contributed by Victor Stinner in :issue:`26058`.)
-
-
Other Language Changes
======================
Some smaller changes made to the core Python language are:
-* :func:`dict` now uses a "compact" representation `pioneered by PyPy
- <https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more…>`_.
- The memory usage of the new :func:`dict` is between 20% and 25% smaller
- compared to Python 3.5.
- :pep:`468` (Preserving the order of ``**kwargs`` in a function.) is
- implemented by this. The order-preserving aspect of this new
- implementation is considered an implementation detail and should
- not be relied upon (this may change in the future, but it is desired
- to have this new dict implementation in the language for a few
- releases before changing the language spec to mandate
- order-preserving semantics for all current and future Python
- implementations; this also helps preserve backwards-compatibility
- with older versions of the language where random iteration order is
- still in effect, e.g. Python 3.5).
- (Contributed by INADA Naoki in :issue:`27350`. Idea
- `originally suggested by Raymond Hettinger
- <https://mail.python.org/pipermail/python-dev/2012-December/123028.html>`_.)
+* A ``global`` or ``nonlocal`` statement must now textually appear
+ before the first use of the affected name in the same scope.
+ Previously this was a ``SyntaxWarning``.
* Long sequences of repeated traceback lines are now abbreviated as
``"[Previous line repeated {count} more times]"`` (see
@@ -573,16 +702,15 @@
New Modules
===========
-* None yet.
+secrets
+-------
+
+The new :mod:`secrets` module.
Improved Modules
================
-On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
-is initialized to increase the security. See the :pep:`524` for the rationale.
-
-
asyncio
-------
@@ -784,11 +912,14 @@
will be emitted in its destructor.
(Contributed by Serhiy Storchaka in :issue:`25994`.)
+On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
+is initialized to increase the security. See the :pep:`524` for the rationale.
+
The Linux ``getrandom()`` syscall (get random bytes) is now exposed as the new
:func:`os.getrandom` function.
(Contributed by Victor Stinner, part of the :pep:`524`)
-See the summary for :ref:`PEP 519 <pep-519>` for details on how the
+See the summary for :ref:`PEP 519 <whatsnew36-pep519>` for details on how the
:mod:`os` and :mod:`os.path` modules now support
:term:`path-like objects <path-like object>`.
@@ -1160,6 +1291,7 @@
it is now about 1.5--4 times faster.
(Contributed by Serhiy Storchaka in :issue:`26032`).
+
Build and C API Changes
=======================
--
Repository URL: https://hg.python.org/cpython
1
0
Nov. 7, 2016
https://hg.python.org/cpython/rev/5cf13fd36af1
changeset: 104955:5cf13fd36af1
branch: 3.6
parent: 104953:a02915e4c165
user: Yury Selivanov <yury(a)magic.io>
date: Mon Nov 07 16:40:20 2016 -0500
summary:
whatsnew: Inital pass on "What's New in Python 3.6"
Patch by Elvis Pranskevichus.
files:
Doc/whatsnew/3.6.rst | 587 +++++++++++++++++++-----------
1 files changed, 360 insertions(+), 227 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
@@ -4,6 +4,7 @@
:Release: |release|
:Date: |today|
+:Editors: Elvis Pranskevichus <elvis(a)magic.io>, Yury Selivanov <yury(a)magic.io>
.. Rules for maintenance:
@@ -45,15 +46,17 @@
This saves the maintainer the effort of going through the Mercurial log
when researching a change.
+.. note::
+
+ Prerelease users should be aware that this document is currently in draft
+ form. It will be updated substantially as Python 3.6 moves towards release,
+ so it's worth checking back even after reading earlier versions.
+
This article explains the new features in Python 3.6, compared to 3.5.
-For full details, see the :ref:`changelog <changelog>`.
+.. seealso::
-.. note::
-
- Prerelease users should be aware that this document is currently in draft
- form. It will be updated substantially as Python 3.6 moves towards release,
- so it's worth checking back even after reading earlier versions.
+ :pep:`494` - Python 3.6 Release Schedule
Summary -- Release highlights
@@ -64,40 +67,73 @@
New syntax features:
-* A ``global`` or ``nonlocal`` statement must now textually appear
- before the first use of the affected name in the same scope.
- Previously this was a SyntaxWarning.
+* :ref:`PEP 498 <whatsnew36-pep498>`, formatted string literals.
-* PEP 498: :ref:`Formatted string literals <whatsnew-fstrings>`
+* :ref:`PEP 515 <whatsnew36-pep515>`, underscores in numeric literals.
-* PEP 515: Underscores in Numeric Literals
+* :ref:`PEP 526 <whatsnew36-pep526>`, syntax for variable annotations.
-* PEP 526: :ref:`Syntax for Variable Annotations <variable-annotations>`
+* :ref:`PEP 525 <whatsnew36-pep525>`, asynchronous generators.
-* PEP 525: Asynchronous Generators
+* :ref:`PEP 530 <whatsnew36-pep530>`: asynchronous comprehensions.
-* PEP 530: Asynchronous Comprehensions
-Standard library improvements:
+New library modules:
+
+* :mod:`secrets`: :ref:`PEP 506 -- Adding A Secrets Module To The Standard Library <whatsnew36-pep506>`.
+
+
+CPython implementation improvements:
+
+* The :ref:`dict <typesmapping>` type has been reimplemented to use
+ a :ref:`faster, more compact representation <whatsnew36-compactdict>`
+ similar to the `PyPy dict implementation`_. This resulted in dictionaries
+ using 20% to 25% less memory when compared to Python 3.5.
+
+* Customization of class creation has been simplified with the
+ :ref:`new protocol <whatsnew36-pep487>`.
+
+* The class attibute definition order is
+ :ref:`now preserved <whatsnew36-pep520>`.
+
+* The order of elements in ``**kwargs`` now corresponds to the order in
+ the function signature:
+ :ref:`Preserving Keyword Argument Order <whatsnew36-pep468>`.
+
+* DTrace and SystemTap :ref:`probing support <whatsnew36-tracing>`.
+
+
+Significant improvements in the standard library:
+
+* A new :ref:`file system path protocol <whatsnew36-pep519>` has been
+ implemented to support :term:`path-like objects <path-like object>`.
+ All standard library functions operating on paths have been updated to
+ work with the new protocol.
+
+* The overhead of :mod:`asyncio` implementation has been reduced by
+ up to 50% thanks to the new C implementation of the :class:`asyncio.Future`
+ and :class:`asyncio.Task` classes and other optimizations.
+
Security improvements:
-* On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
- is initialized to increase the security. See the :pep:`524` for the
+* On Linux, :func:`os.urandom` now blocks until the system urandom entropy
+ pool is initialized to increase the security. See the :pep:`524` for the
rationale.
-* :mod:`hashlib` and :mod:`ssl` now support OpenSSL 1.1.0.
+* The :mod:`hashlib` and :mod:`ssl` modules now support OpenSSL 1.1.0.
-* The default settings and feature set of the :mod:`ssl` have been improved.
+* The default settings and feature set of the :mod:`ssl` module have been
+ improved.
-* The :mod:`hashlib` module has got support for BLAKE2, SHA-3 and SHAKE hash
- algorithms and :func:`~hashlib.scrypt` key derivation function.
+* The :mod:`hashlib` module received support for the BLAKE2, SHA-3 and SHAKE
+ hash algorithms and the :func:`~hashlib.scrypt` key derivation function.
+
Windows improvements:
-* PEP 529: :ref:`Change Windows filesystem encoding to UTF-8 <pep-529>`
-
-* PEP 528: :ref:`Change Windows console encoding to UTF-8 <pep-528>`
+* :ref:`PEP 528 <whatsnew36-pep529>` and :ref:`PEP 529 <whatsnew36-pep529>`,
+ Windows filesystem and console encoding changed to UTF-8.
* The ``py.exe`` launcher, when used interactively, no longer prefers
Python 2 over Python 3 when the user doesn't specify a version (via
@@ -116,66 +152,111 @@
:envvar:`PYTHONHOME`. See :ref:`the documentation <finding_modules>` for
more information.
-.. PEP-sized items next.
-
-.. _pep-4XX:
-
-.. PEP 4XX: Virtual Environments
-.. =============================
-
-
-.. (Implemented by Foo Bar.)
-
-.. .. seealso::
-
- :pep:`4XX` - Python Virtual Environments
- PEP written by Carl Meyer
-
-New built-in features:
-
-* PEP 520: :ref:`Preserving Class Attribute Definition Order<whatsnew-deforder>`
-
-* PEP 468: :ref:`Preserving Keyword Argument Order<whatsnew-kwargs>`
A complete list of PEP's implemented in Python 3.6:
-* :pep:`468`, :ref:`Preserving Keyword Argument Order<whatsnew-kwargs>`
-* :pep:`487`, :ref:`Simpler customization of class creation<whatsnew-pep487>`
+* :pep:`468`, :ref:`Preserving Keyword Argument Order <whatsnew36-pep468>`
+* :pep:`487`, :ref:`Simpler customization of class creation <whatsnew36-pep487>`
* :pep:`495`, Local Time Disambiguation
-* :pep:`498`, :ref:`Formatted string literals <whatsnew-fstrings>`
+* :pep:`498`, :ref:`Formatted string literals <whatsnew36-pep498>`
* :pep:`506`, Adding A Secrets Module To The Standard Library
-* :pep:`509`, :ref:`Add a private version to dict<whatsnew-pep509>`
-* :pep:`515`, :ref:`Underscores in Numeric Literals<pep-515>`
-* :pep:`519`, :ref:`Adding a file system path protocol<pep-519>`
-* :pep:`520`, :ref:`Preserving Class Attribute Definition Order<whatsnew-deforder>`
-* :pep:`523`, :ref:`Adding a frame evaluation API to CPython<pep-523>`
+* :pep:`509`, :ref:`Add a private version to dict <whatsnew36-pep509>`
+* :pep:`515`, :ref:`Underscores in Numeric Literals <whatsnew36-pep515>`
+* :pep:`519`, :ref:`Adding a file system path protocol <whatsnew36-pep519>`
+* :pep:`520`, :ref:`Preserving Class Attribute Definition Order <whatsnew36-pep520>`
+* :pep:`523`, :ref:`Adding a frame evaluation API to CPython <whatsnew36-pep523>`
* :pep:`524`, Make os.urandom() blocking on Linux (during system startup)
* :pep:`525`, Asynchronous Generators (provisional)
-* :pep:`526`, :ref:`Syntax for Variable Annotations (provisional)<variable-annotations>`
-* :pep:`528`, :ref:`Change Windows console encoding to UTF-8 (provisional)<pep-528>`
-* :pep:`529`, :ref:`Change Windows filesystem encoding to UTF-8 (provisional)<pep-529>`
+* :pep:`526`, :ref:`Syntax for Variable Annotations (provisional) <whatsnew36-pep526>`
+* :pep:`528`, :ref:`Change Windows console encoding to UTF-8 (provisional) <whatsnew36-pep528>`
+* :pep:`529`, :ref:`Change Windows filesystem encoding to UTF-8 (provisional) <whatsnew36-pep529>`
* :pep:`530`, Asynchronous Comprehensions
+.. _PyPy dict implementation: https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more…
+
+
New Features
============
-.. _pep-515:
+.. _whatsnew36-pep498:
+
+PEP 498: Formatted string literals
+----------------------------------
+
+:pep:`498` introduces a new kind of string literals: *f-strings*, or
+*formatted string literals*.
+
+Formatted string literals are prefixed with ``'f'`` and are similar to
+the format strings accepted by :meth:`str.format`. They contain replacement
+fields surrounded by curly braces. The replacement fields are expressions,
+which are evaluated at run time, and then formatted using the
+:func:`format` protocol::
+
+ >>> name = "Fred"
+ >>> f"He said his name is {name}."
+ 'He said his name is Fred.'
+
+.. seealso::
+
+ :pep:`498` -- Literal String Interpolation.
+ PEP written and implemented by Eric V. Smith.
+
+ :ref:`Feature documentation <f-strings>`.
+
+
+.. _whatsnew36-pep526:
+
+PEP 526: Syntax for variable annotations
+----------------------------------------
+
+:pep:`484` introduced the standard for type annotations of function
+parameters, a.k.a. type hints. This PEP adds syntax to Python for annotating
+the types of variables including class variables and instance variables::
+
+ primes: List[int] = []
+
+ captain: str # Note: no initial value!
+
+ class Starship:
+ stats: Dict[str, int] = {}
+
+Just as for function annotations, the Python interpreter does not attach any
+particular meaning to variable annotations and only stores them in the
+``__annotations__`` attribute of a class or module.
+
+In contrast to variable declarations in statically typed languages,
+the goal of annotation syntax is to provide an easy way to specify structured
+type metadata for third party tools and libraries via the abstract syntax tree
+and the ``__annotations__`` attribute.
+
+.. seealso::
+
+ :pep:`526` -- Syntax for variable annotations.
+ PEP written by Ryan Gonzalez, Philip House, Ivan Levkivskyi, Lisa Roach,
+ and Guido van Rossum. Implemented by Ivan Levkivskyi.
+
+ Tools that use or will use the new syntax:
+ `mypy <http://github.com/python/mypy>`_,
+ `pytype <http://github.com/google/pytype>`_, PyCharm, etc.
+
+
+.. _whatsnew36-pep515:
PEP 515: Underscores in Numeric Literals
----------------------------------------
-Prior to PEP 515, there was no support for writing long numeric
-literals with some form of separator to improve readability. For
-instance, how big is ``1000000000000000``? With :pep:`515`, though,
-you can use underscores to separate digits as desired to make numeric
-literals easier to read: ``1_000_000_000_000_000``. Underscores can be
-used with other numeric literals beyond integers, e.g.
-``0x_FF_FF_FF_FF``.
+:pep:`515` adds the ability to use underscores in numeric literals for
+improved readability. For example::
+
+ >>> 1_000_000_000_000_000
+ 1000000000000000
+ >>> 0x_FF_FF_FF_FF
+ 4294967295
Single underscores are allowed between digits and after any base
-specifier. More than a single underscore in a row, leading, or
-trailing underscores are not allowed.
+specifier. Leading, trailing, or multiple underscores in a row are not
+allowed.
.. seealso::
@@ -183,36 +264,115 @@
PEP written by Georg Brandl and Serhiy Storchaka.
-.. _pep-523:
+.. _whatsnew36-pep525:
-PEP 523: Adding a frame evaluation API to CPython
--------------------------------------------------
+PEP 525: Asynchronous Generators
+--------------------------------
-While Python provides extensive support to customize how code
-executes, one place it has not done so is in the evaluation of frame
-objects. If you wanted some way to intercept frame evaluation in
-Python there really wasn't any way without directly manipulating
-function pointers for defined functions.
+:pep:`492` introduced support for native coroutines and ``async`` / ``await``
+syntax to Python 3.5. A notable limitation of the Python 3.5 implementation
+is that it was not possible to use ``await`` and ``yield`` in the same
+function body. In Python 3.6 this restriction has been lifted, making it
+possible to define *asynchronous generators*::
-:pep:`523` changes this by providing an API to make frame
-evaluation pluggable at the C level. This will allow for tools such
-as debuggers and JITs to intercept frame evaluation before the
-execution of Python code begins. This enables the use of alternative
-evaluation implementations for Python code, tracking frame
-evaluation, etc.
+ async def ticker(delay, to):
+ """Yield numbers from 0 to `to` every `delay` seconds."""
+ for i in range(to):
+ yield i
+ await asyncio.sleep(delay)
-This API is not part of the limited C API and is marked as private to
-signal that usage of this API is expected to be limited and only
-applicable to very select, low-level use-cases. Semantics of the
-API will change with Python as necessary.
+The new syntax allows for faster and more concise code.
.. seealso::
- :pep:`523` -- Adding a frame evaluation API to CPython
- PEP written by Brett Cannon and Dino Viehland.
+ :pep:`525` -- Asynchronous Generators
+ PEP written and implemented by Yury Selivanov.
-.. _pep-519:
+.. _whatsnew36-pep530:
+
+PEP 530: Asynchronous Comprehensions
+------------------------------------
+
+:pep:`530` adds support for using ``async for`` in list, set, dict
+comprehensions and generator expressions::
+
+ result = [i async for i in aiter() if i % 2]
+
+Additionally, ``await`` expressions are supported in all kinds
+of comprehensions::
+
+ result = [await fun() for fun in funcs]
+
+.. seealso::
+
+ :pep:`530` -- Asynchronous Comprehensions
+ PEP written and implemented by Yury Selivanov.
+
+
+.. _whatsnew36-pep487:
+
+PEP 487: Simpler customization of class creation
+------------------------------------------------
+
+It is now possible to customize subclass creation without using a metaclass.
+The new ``__init_subclass__`` classmethod will be called on the base class
+whenever a new subclass is created::
+
+ >>> class QuestBase:
+ ... # this is implicitly a @classmethod
+ ... def __init_subclass__(cls, swallow, **kwargs):
+ ... cls.swallow = swallow
+ ... super().__init_subclass__(**kwargs)
+
+ >>> class Quest(QuestBase, swallow="african"):
+ ... pass
+
+ >>> Quest.swallow
+ 'african'
+
+.. seealso::
+
+ :pep:`487` -- Simpler customization of class creation
+ PEP written and implemented by Martin Teichmann.
+
+ :ref:`Feature documentation <class-customization>`
+
+
+.. _whatsnew36-pep487-descriptors:
+
+PEP 487: Descriptor Protocol Enhancements
+-----------------------------------------
+
+:pep:`487` extends the descriptor protocol has to include the new optional
+``__set_name__`` method. Whenever a new class is defined, the new method
+will be called on all descriptors included in the definition, providing
+them with a reference to the class being defined and the name given to the
+descriptor within the class namespace.
+
+.. seealso::
+
+ :pep:`487` -- Simpler customization of class creation
+ PEP written and implemented by Martin Teichmann.
+
+ :ref:`Feature documentation <descriptors>`
+
+
+.. _whatsnew36-pep506:
+
+PEP 506: Adding A Secrets Module To The Standard Library
+--------------------------------------------------------
+
+
+
+.. seealso::
+
+ :pep:`506` -- Adding A Secrets Module To The Standard Library
+ PEP written and implemented by Steven D'Aprano.
+
+
+
+.. _whatsnew36-pep519:
PEP 519: Adding a file system path protocol
-------------------------------------------
@@ -279,60 +439,7 @@
PEP written by Brett Cannon and Koos Zevenhoven.
-.. _whatsnew-fstrings:
-
-PEP 498: Formatted string literals
-----------------------------------
-
-Formatted string literals are a new kind of string literal, prefixed
-with ``'f'``. They are similar to the format strings accepted by
-:meth:`str.format`. They contain replacement fields surrounded by
-curly braces. The replacement fields are expressions, which are
-evaluated at run time, and then formatted using the :func:`format` protocol::
-
- >>> name = "Fred"
- >>> f"He said his name is {name}."
- 'He said his name is Fred.'
-
-See :pep:`498` and the main documentation at :ref:`f-strings`.
-
-
-.. _variable-annotations:
-
-PEP 526: Syntax for variable annotations
-----------------------------------------
-
-:pep:`484` introduced standard for type annotations of function parameters,
-a.k.a. type hints. This PEP adds syntax to Python for annotating the
-types of variables including class variables and instance variables::
-
- primes: List[int] = []
-
- captain: str # Note: no initial value!
-
- class Starship:
- stats: Dict[str, int] = {}
-
-Just as for function annotations, the Python interpreter does not attach any
-particular meaning to variable annotations and only stores them in a special
-attribute ``__annotations__`` of a class or module.
-In contrast to variable declarations in statically typed languages,
-the goal of annotation syntax is to provide an easy way to specify structured
-type metadata for third party tools and libraries via the abstract syntax tree
-and the ``__annotations__`` attribute.
-
-.. seealso::
-
- :pep:`526` -- Syntax for variable annotations.
- PEP written by Ryan Gonzalez, Philip House, Ivan Levkivskyi, Lisa Roach,
- and Guido van Rossum. Implemented by Ivan Levkivskyi.
-
- Tools that use or will use the new syntax:
- `mypy <http://github.com/python/mypy>`_,
- `pytype <http://github.com/google/pytype>`_, PyCharm, etc.
-
-
-.. _pep-529:
+.. _whatsnew36-pep529:
PEP 529: Change Windows filesystem encoding to UTF-8
----------------------------------------------------
@@ -355,28 +462,8 @@
See :pep:`529` for more information and discussion of code modifications that
may be required.
-.. _whatsnew-pep487:
-PEP 487: Simpler customization of class creation
-------------------------------------------------
-
-Upon subclassing a class, the ``__init_subclass__`` classmethod (if defined) is
-called on the base class. This makes it straightforward to write classes that
-customize initialization of future subclasses without introducing the
-complexity of a full custom metaclass.
-
-The descriptor protocol has also been expanded to include a new optional method,
-``__set_name__``. Whenever a new class is defined, the new method will be called
-on all descriptors included in the definition, providing them with a reference
-to the class being defined and the name given to the descriptor within the
-class namespace.
-
-Also see :pep:`487` and the updated class customization documentation at
-:ref:`class-customization` and :ref:`descriptors`.
-
-(Contributed by Martin Teichmann in :issue:`27366`)
-
-.. _pep-528:
+.. _whatsnew36-pep528:
PEP 528: Change Windows console encoding to UTF-8
-------------------------------------------------
@@ -394,6 +481,104 @@
:pep:`528` -- Change Windows console encoding to UTF-8
PEP written and implemented by Steve Dower.
+
+.. _whatsnew36-pep520:
+
+PEP 520: Preserving Class Attribute Definition Order
+----------------------------------------------------
+
+Attributes in a class definition body have a natural ordering: the same
+order in which the names appear in the source. This order is now
+preserved in the new class's ``__dict__`` attribute.
+
+Also, the effective default class *execution* namespace (returned from
+``type.__prepare__()``) is now an insertion-order-preserving mapping.
+
+.. seealso::
+
+ :pep:`520` -- Preserving Class Attribute Definition Order
+ PEP written and implemented by Eric Snow.
+
+
+.. _whatsnew36-pep468:
+
+PEP 468: Preserving Keyword Argument Order
+------------------------------------------
+
+``**kwargs`` in a function signature is now guaranteed to be an
+insertion-order-preserving mapping.
+
+.. seealso::
+
+ :pep:`468` -- Preserving Keyword Argument Order
+ PEP written and implemented by Eric Snow.
+
+
+.. _whatsnew36-compactdict:
+
+New :ref:`dict <typesmapping>` implementation
+---------------------------------------------
+
+The :ref:`dict <typesmapping>` type now uses a "compact" representation
+`pioneered by PyPy <https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more…>`_.
+The memory usage of the new :func:`dict` is between 20% and 25% smaller
+compared to Python 3.5.
+:pep:`468` (Preserving the order of ``**kwargs`` in a function.) is
+implemented by this. The order-preserving aspect of this new
+implementation is considered an implementation detail and should
+not be relied upon (this may change in the future, but it is desired
+to have this new dict implementation in the language for a few
+releases before changing the language spec to mandate
+order-preserving semantics for all current and future Python
+implementations; this also helps preserve backwards-compatibility
+with older versions of the language where random iteration order is
+still in effect, e.g. Python 3.5).
+(Contributed by INADA Naoki in :issue:`27350`. Idea
+`originally suggested by Raymond Hettinger
+<https://mail.python.org/pipermail/python-dev/2012-December/123028.html>`_.)
+
+
+.. _whatsnew36-pep523:
+
+PEP 523: Adding a frame evaluation API to CPython
+-------------------------------------------------
+
+While Python provides extensive support to customize how code
+executes, one place it has not done so is in the evaluation of frame
+objects. If you wanted some way to intercept frame evaluation in
+Python there really wasn't any way without directly manipulating
+function pointers for defined functions.
+
+:pep:`523` changes this by providing an API to make frame
+evaluation pluggable at the C level. This will allow for tools such
+as debuggers and JITs to intercept frame evaluation before the
+execution of Python code begins. This enables the use of alternative
+evaluation implementations for Python code, tracking frame
+evaluation, etc.
+
+This API is not part of the limited C API and is marked as private to
+signal that usage of this API is expected to be limited and only
+applicable to very select, low-level use-cases. Semantics of the
+API will change with Python as necessary.
+
+.. seealso::
+
+ :pep:`523` -- Adding a frame evaluation API to CPython
+ PEP written by Brett Cannon and Dino Viehland.
+
+
+.. _whatsnew36-pep509:
+
+PEP 509: Add a private version to dict
+--------------------------------------
+
+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.
+
+(Contributed by Victor Stinner in :issue:`26058`.)
+
+
PYTHONMALLOC environment variable
---------------------------------
@@ -468,6 +653,8 @@
(Contributed by Victor Stinner in :issue:`26516` and :issue:`26564`.)
+.. _whatsnew36-tracing:
+
DTrace and SystemTap probing support
------------------------------------
@@ -493,71 +680,14 @@
Jesús Cea Avión, David Malcolm, and Nikhil Benesch.)
-.. _whatsnew-deforder:
-
-PEP 520: Preserving Class Attribute Definition Order
-----------------------------------------------------
-
-Attributes in a class definition body have a natural ordering: the same
-order in which the names appear in the source. This order is now
-preserved in the new class's ``__dict__`` attribute.
-
-Also, the effective default class *execution* namespace (returned from
-``type.__prepare__()``) is now an insertion-order-preserving mapping.
-
-.. seealso::
-
- :pep:`520` -- Preserving Class Attribute Definition Order
- PEP written and implemented by Eric Snow.
-
-
-.. _whatsnew-kwargs:
-
-PEP 468: Preserving Keyword Argument Order
-------------------------------------------
-
-``**kwargs`` in a function signature is now guaranteed to be an
-insertion-order-preserving mapping.
-
-.. seealso::
-
- :pep:`468` -- Preserving Keyword Argument Order
- PEP written and implemented by Eric Snow.
-
-.. _whatsnew-pep509:
-
-PEP 509: Add a private version to dict
---------------------------------------
-
-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.
-
-(Contributed by Victor Stinner in :issue:`26058`.)
-
-
Other Language Changes
======================
Some smaller changes made to the core Python language are:
-* :func:`dict` now uses a "compact" representation `pioneered by PyPy
- <https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more…>`_.
- The memory usage of the new :func:`dict` is between 20% and 25% smaller
- compared to Python 3.5.
- :pep:`468` (Preserving the order of ``**kwargs`` in a function.) is
- implemented by this. The order-preserving aspect of this new
- implementation is considered an implementation detail and should
- not be relied upon (this may change in the future, but it is desired
- to have this new dict implementation in the language for a few
- releases before changing the language spec to mandate
- order-preserving semantics for all current and future Python
- implementations; this also helps preserve backwards-compatibility
- with older versions of the language where random iteration order is
- still in effect, e.g. Python 3.5).
- (Contributed by INADA Naoki in :issue:`27350`. Idea
- `originally suggested by Raymond Hettinger
- <https://mail.python.org/pipermail/python-dev/2012-December/123028.html>`_.)
+* A ``global`` or ``nonlocal`` statement must now textually appear
+ before the first use of the affected name in the same scope.
+ Previously this was a ``SyntaxWarning``.
* Long sequences of repeated traceback lines are now abbreviated as
``"[Previous line repeated {count} more times]"`` (see
@@ -572,16 +702,15 @@
New Modules
===========
-* None yet.
+secrets
+-------
+
+The new :mod:`secrets` module.
Improved Modules
================
-On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
-is initialized to increase the security. See the :pep:`524` for the rationale.
-
-
asyncio
-------
@@ -783,11 +912,14 @@
will be emitted in its destructor.
(Contributed by Serhiy Storchaka in :issue:`25994`.)
+On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
+is initialized to increase the security. See the :pep:`524` for the rationale.
+
The Linux ``getrandom()`` syscall (get random bytes) is now exposed as the new
:func:`os.getrandom` function.
(Contributed by Victor Stinner, part of the :pep:`524`)
-See the summary for :ref:`PEP 519 <pep-519>` for details on how the
+See the summary for :ref:`PEP 519 <whatsnew36-pep519>` for details on how the
:mod:`os` and :mod:`os.path` modules now support
:term:`path-like objects <path-like object>`.
@@ -1159,6 +1291,7 @@
it is now about 1.5--4 times faster.
(Contributed by Serhiy Storchaka in :issue:`26032`).
+
Build and C API Changes
=======================
--
Repository URL: https://hg.python.org/cpython
1
0
https://hg.python.org/cpython/rev/a02915e4c165
changeset: 104953:a02915e4c165
branch: 3.6
parent: 104950:6811df9e9797
parent: 104952:0669dcf1eb36
user: Yury Selivanov <yury(a)magic.io>
date: Mon Nov 07 16:07:30 2016 -0500
summary:
Merge 3.5 (issue #28634)
files:
Lib/asyncio/base_futures.py | 3 +-
Lib/test/test_asyncio/test_futures.py | 23 +++++++++++++++
Misc/NEWS | 2 +
3 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/Lib/asyncio/base_futures.py b/Lib/asyncio/base_futures.py
--- a/Lib/asyncio/base_futures.py
+++ b/Lib/asyncio/base_futures.py
@@ -27,7 +27,8 @@
itself as duck-type compatible by setting _asyncio_future_blocking.
See comment in Future for more details.
"""
- return getattr(obj, '_asyncio_future_blocking', None) is not None
+ return (hasattr(obj.__class__, '_asyncio_future_blocking') and
+ obj._asyncio_future_blocking is not None)
def _format_callbacks(cb):
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -105,6 +105,29 @@
self.loop = self.new_test_loop()
self.addCleanup(self.loop.close)
+ def test_isfuture(self):
+ class MyFuture:
+ _asyncio_future_blocking = None
+
+ def __init__(self):
+ self._asyncio_future_blocking = False
+
+ self.assertFalse(asyncio.isfuture(MyFuture))
+ self.assertTrue(asyncio.isfuture(MyFuture()))
+ self.assertFalse(asyncio.isfuture(1))
+
+ # As `isinstance(Mock(), Future)` returns `False`
+ self.assertFalse(asyncio.isfuture(mock.Mock()))
+
+ f = self._new_future(loop=self.loop)
+ self.assertTrue(asyncio.isfuture(f))
+ self.assertFalse(asyncio.isfuture(type(f)))
+
+ # As `isinstance(Mock(Future), Future)` returns `True`
+ self.assertTrue(asyncio.isfuture(mock.Mock(type(f))))
+
+ f.cancel()
+
def test_initial_state(self):
f = self._new_future(loop=self.loop)
self.assertFalse(f.cancelled())
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -25,6 +25,8 @@
- Issue #28613: Fix get_event_loop() return the current loop if
called from coroutines/callbacks.
+- Issue #28634: Fix asyncio.isfuture() to support unittest.Mock.
+
Documentation
-------------
--
Repository URL: https://hg.python.org/cpython
1
0
Nov. 7, 2016
https://hg.python.org/cpython/rev/0669dcf1eb36
changeset: 104952:0669dcf1eb36
branch: 3.5
parent: 104949:3e6570231c80
user: Yury Selivanov <yury(a)magic.io>
date: Mon Nov 07 16:00:50 2016 -0500
summary:
Issue #28634: Fix asyncio.isfuture() to support mocks
files:
Lib/asyncio/futures.py | 5 +-
Lib/test/test_asyncio/test_futures.py | 23 +++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py
--- a/Lib/asyncio/futures.py
+++ b/Lib/asyncio/futures.py
@@ -2,7 +2,7 @@
__all__ = ['CancelledError', 'TimeoutError',
'InvalidStateError',
- 'Future', 'wrap_future',
+ 'Future', 'wrap_future', 'isfuture',
]
import concurrent.futures._base
@@ -117,7 +117,8 @@
itself as duck-type compatible by setting _asyncio_future_blocking.
See comment in Future for more details.
"""
- return getattr(obj, '_asyncio_future_blocking', None) is not None
+ return (hasattr(obj.__class__, '_asyncio_future_blocking') and
+ obj._asyncio_future_blocking is not None)
class Future:
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -101,6 +101,29 @@
self.loop = self.new_test_loop()
self.addCleanup(self.loop.close)
+ def test_isfuture(self):
+ class MyFuture:
+ _asyncio_future_blocking = None
+
+ def __init__(self):
+ self._asyncio_future_blocking = False
+
+ self.assertFalse(asyncio.isfuture(MyFuture))
+ self.assertTrue(asyncio.isfuture(MyFuture()))
+
+ self.assertFalse(asyncio.isfuture(1))
+ self.assertFalse(asyncio.isfuture(asyncio.Future))
+
+ # As `isinstance(Mock(), Future)` returns `False`
+ self.assertFalse(asyncio.isfuture(mock.Mock()))
+
+ # As `isinstance(Mock(Future), Future)` returns `True`
+ self.assertTrue(asyncio.isfuture(mock.Mock(asyncio.Future)))
+
+ f = asyncio.Future(loop=self.loop)
+ self.assertTrue(asyncio.isfuture(f))
+ f.cancel()
+
def test_initial_state(self):
f = asyncio.Future(loop=self.loop)
self.assertFalse(f.cancelled())
--
Repository URL: https://hg.python.org/cpython
1
0
Nov. 7, 2016
https://hg.python.org/cpython/rev/44c1ec7689e5
changeset: 104954:44c1ec7689e5
parent: 104951:573bc1f9900e
parent: 104953:a02915e4c165
user: Yury Selivanov <yury(a)magic.io>
date: Mon Nov 07 16:07:58 2016 -0500
summary:
Merge 3.6 (issue #28634)
files:
Lib/asyncio/base_futures.py | 3 +-
Lib/test/test_asyncio/test_futures.py | 23 +++++++++++++++
2 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/Lib/asyncio/base_futures.py b/Lib/asyncio/base_futures.py
--- a/Lib/asyncio/base_futures.py
+++ b/Lib/asyncio/base_futures.py
@@ -27,7 +27,8 @@
itself as duck-type compatible by setting _asyncio_future_blocking.
See comment in Future for more details.
"""
- return getattr(obj, '_asyncio_future_blocking', None) is not None
+ return (hasattr(obj.__class__, '_asyncio_future_blocking') and
+ obj._asyncio_future_blocking is not None)
def _format_callbacks(cb):
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -105,6 +105,29 @@
self.loop = self.new_test_loop()
self.addCleanup(self.loop.close)
+ def test_isfuture(self):
+ class MyFuture:
+ _asyncio_future_blocking = None
+
+ def __init__(self):
+ self._asyncio_future_blocking = False
+
+ self.assertFalse(asyncio.isfuture(MyFuture))
+ self.assertTrue(asyncio.isfuture(MyFuture()))
+ self.assertFalse(asyncio.isfuture(1))
+
+ # As `isinstance(Mock(), Future)` returns `False`
+ self.assertFalse(asyncio.isfuture(mock.Mock()))
+
+ f = self._new_future(loop=self.loop)
+ self.assertTrue(asyncio.isfuture(f))
+ self.assertFalse(asyncio.isfuture(type(f)))
+
+ # As `isinstance(Mock(Future), Future)` returns `True`
+ self.assertTrue(asyncio.isfuture(mock.Mock(type(f))))
+
+ f.cancel()
+
def test_initial_state(self):
f = self._new_future(loop=self.loop)
self.assertFalse(f.cancelled())
--
Repository URL: https://hg.python.org/cpython
1
0
Nov. 7, 2016
https://hg.python.org/cpython/rev/3e6570231c80
changeset: 104949:3e6570231c80
branch: 3.5
parent: 104946:f4e86b1b051e
user: Yury Selivanov <yury(a)magic.io>
date: Mon Nov 07 15:35:25 2016 -0500
summary:
Issue #27392: Document loop.connect_accepted_socket()
Patch by Jim Fulton.
files:
Doc/library/asyncio-eventloop.rst | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
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
@@ -461,6 +461,23 @@
Availability: UNIX.
+.. coroutinemethod:: BaseEventLoop.connect_accepted_socket(protocol_factory, sock, \*, ssl=None)
+
+ Handle an accepted connection.
+
+ This is used by servers that accept connections outside of
+ asyncio but that use asyncio to handle them.
+
+ Parameters:
+
+ * *sock* is a preexisting socket object returned from an ``accept``
+ call.
+
+ * *ssl* can be set to an :class:`~ssl.SSLContext` to enable SSL over the
+ accepted connections.
+
+ This method is a :ref:`coroutine <coroutine>`. When completed, the
+ coroutine returns a ``(transport, protocol)`` pair.
Watch file descriptors
----------------------
--
Repository URL: https://hg.python.org/cpython
1
0