Python-checkins
Threads by month
- ----- 2025 -----
- 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
December 2018
- 2 participants
- 504 discussions

bpo-35598: IDLE - Globalize some config_key objects (GH-11392)
by Miss Islington (bot) Dec. 31, 2018
by Miss Islington (bot) Dec. 31, 2018
Dec. 31, 2018
https://github.com/python/cpython/commit/74e46483773fa2ed03ed02f1b5e3fb0a46…
commit: 74e46483773fa2ed03ed02f1b5e3fb0a4691535e
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: GitHub <noreply(a)github.com>
date: 2018-12-31T12:19:53-08:00
summary:
bpo-35598: IDLE - Globalize some config_key objects (GH-11392)
Move translate_key() and constant tuples to module level.
Inline the remnant one-line function.
(cherry picked from commit b4ea8bb080f63ef27682f3f9bbaa4d12a83030b1)
Co-authored-by: Cheryl Sabella <cheryl.sabella(a)gmail.com>
files:
M Lib/idlelib/config_key.py
M Lib/idlelib/idle_test/test_config_key.py
M Misc/NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst
diff --git a/Lib/idlelib/config_key.py b/Lib/idlelib/config_key.py
index 466830566042..21e84a94c9ff 100644
--- a/Lib/idlelib/config_key.py
+++ b/Lib/idlelib/config_key.py
@@ -8,6 +8,38 @@
import sys
+FUNCTION_KEYS = ('F1', 'F2' ,'F3' ,'F4' ,'F5' ,'F6',
+ 'F7', 'F8' ,'F9' ,'F10' ,'F11' ,'F12')
+ALPHANUM_KEYS = tuple(string.ascii_lowercase + string.digits)
+PUNCTUATION_KEYS = tuple('~!@#%^&*()_-+={}[]|;:,.<>/?')
+WHITESPACE_KEYS = ('Tab', 'Space', 'Return')
+EDIT_KEYS = ('BackSpace', 'Delete', 'Insert')
+MOVE_KEYS = ('Home', 'End', 'Page Up', 'Page Down', 'Left Arrow',
+ 'Right Arrow', 'Up Arrow', 'Down Arrow')
+AVAILABLE_KEYS = (ALPHANUM_KEYS + PUNCTUATION_KEYS + FUNCTION_KEYS +
+ WHITESPACE_KEYS + EDIT_KEYS + MOVE_KEYS)
+
+
+def translate_key(key, modifiers):
+ "Translate from keycap symbol to the Tkinter keysym."
+ mapping = {'Space':'space',
+ '~':'asciitilde', '!':'exclam', '@':'at', '#':'numbersign',
+ '%':'percent', '^':'asciicircum', '&':'ampersand',
+ '*':'asterisk', '(':'parenleft', ')':'parenright',
+ '_':'underscore', '-':'minus', '+':'plus', '=':'equal',
+ '{':'braceleft', '}':'braceright',
+ '[':'bracketleft', ']':'bracketright', '|':'bar',
+ ';':'semicolon', ':':'colon', ',':'comma', '.':'period',
+ '<':'less', '>':'greater', '/':'slash', '?':'question',
+ 'Page Up':'Prior', 'Page Down':'Next',
+ 'Left Arrow':'Left', 'Right Arrow':'Right',
+ 'Up Arrow':'Up', 'Down Arrow': 'Down', 'Tab':'Tab'}
+ key = mapping.get(key, key)
+ if 'Shift' in modifiers and key in string.ascii_lowercase:
+ key = key.upper()
+ return f'Key-{key}'
+
+
class GetKeysDialog(Toplevel):
# Dialog title for invalid key sequence
@@ -48,7 +80,6 @@ def __init__(self, parent, title, action, current_key_sequences,
self.modifier_vars.append(variable)
self.advanced = False
self.create_widgets()
- self.load_final_key_list()
self.update_idletasks()
self.geometry(
"+%d+%d" % (
@@ -122,6 +153,7 @@ def create_widgets(self):
# Basic entry key list.
self.list_keys_final = Listbox(self.frame_controls_basic, width=15,
height=10, selectmode='single')
+ self.list_keys_final.insert('end', *AVAILABLE_KEYS)
self.list_keys_final.bind('<ButtonRelease-1>', self.final_key_selected)
self.list_keys_final.grid(row=0, column=4, rowspan=4, sticky='ns')
scroll_keys_final = Scrollbar(self.frame_controls_basic,
@@ -206,7 +238,7 @@ def build_key_string(self):
keylist = modifiers = self.get_modifiers()
final_key = self.list_keys_final.get('anchor')
if final_key:
- final_key = self.translate_key(final_key, modifiers)
+ final_key = translate_key(final_key, modifiers)
keylist.append(final_key)
self.key_string.set(f"<{'-'.join(keylist)}>")
@@ -223,43 +255,6 @@ def clear_key_seq(self):
variable.set('')
self.key_string.set('')
- def load_final_key_list(self):
- "Populate listbox of available keys."
- # These tuples are also available for use in validity checks.
- self.function_keys = ('F1', 'F2' ,'F3' ,'F4' ,'F5' ,'F6',
- 'F7', 'F8' ,'F9' ,'F10' ,'F11' ,'F12')
- self.alphanum_keys = tuple(string.ascii_lowercase + string.digits)
- self.punctuation_keys = tuple('~!@#%^&*()_-+={}[]|;:,.<>/?')
- self.whitespace_keys = ('Tab', 'Space', 'Return')
- self.edit_keys = ('BackSpace', 'Delete', 'Insert')
- self.move_keys = ('Home', 'End', 'Page Up', 'Page Down', 'Left Arrow',
- 'Right Arrow', 'Up Arrow', 'Down Arrow')
- # Make a tuple of most of the useful common 'final' keys.
- keys = (self.alphanum_keys + self.punctuation_keys + self.function_keys +
- self.whitespace_keys + self.edit_keys + self.move_keys)
- self.list_keys_final.insert('end', *keys)
-
- @staticmethod
- def translate_key(key, modifiers):
- "Translate from keycap symbol to the Tkinter keysym."
- translate_dict = {'Space':'space',
- '~':'asciitilde', '!':'exclam', '@':'at', '#':'numbersign',
- '%':'percent', '^':'asciicircum', '&':'ampersand',
- '*':'asterisk', '(':'parenleft', ')':'parenright',
- '_':'underscore', '-':'minus', '+':'plus', '=':'equal',
- '{':'braceleft', '}':'braceright',
- '[':'bracketleft', ']':'bracketright', '|':'bar',
- ';':'semicolon', ':':'colon', ',':'comma', '.':'period',
- '<':'less', '>':'greater', '/':'slash', '?':'question',
- 'Page Up':'Prior', 'Page Down':'Next',
- 'Left Arrow':'Left', 'Right Arrow':'Right',
- 'Up Arrow':'Up', 'Down Arrow': 'Down', 'Tab':'Tab'}
- if key in translate_dict:
- key = translate_dict[key]
- if 'Shift' in modifiers and key in string.ascii_lowercase:
- key = key.upper()
- return f'Key-{key}'
-
def ok(self, event=None):
keys = self.key_string.get().strip()
if not keys:
@@ -291,12 +286,12 @@ def keys_ok(self, keys):
self.showerror(title, parent=self,
message='Missing the final Key')
elif (not modifiers
- and final_key not in self.function_keys + self.move_keys):
+ and final_key not in FUNCTION_KEYS + MOVE_KEYS):
self.showerror(title=title, parent=self,
message='No modifier key(s) specified.')
elif (modifiers == ['Shift']) \
and (final_key not in
- self.function_keys + self.move_keys + ('Tab', 'Space')):
+ FUNCTION_KEYS + MOVE_KEYS + ('Tab', 'Space')):
msg = 'The shift modifier by itself may not be used with'\
' this key symbol.'
self.showerror(title=title, parent=self, message=msg)
diff --git a/Lib/idlelib/idle_test/test_config_key.py b/Lib/idlelib/idle_test/test_config_key.py
index 8261f8da00c3..b7fe7fd6b5ec 100644
--- a/Lib/idlelib/idle_test/test_config_key.py
+++ b/Lib/idlelib/idle_test/test_config_key.py
@@ -206,25 +206,6 @@ def test_get_modifiers(self):
dialog.modifier_checkbuttons['foo'].invoke()
eq(gm(), ['BAZ'])
- def test_translate_key(self):
- dialog = self.dialog
- tr = dialog.translate_key
- eq = self.assertEqual
-
- # Letters return unchanged with no 'Shift'.
- eq(tr('q', []), 'Key-q')
- eq(tr('q', ['Control', 'Alt']), 'Key-q')
-
- # 'Shift' uppercases single lowercase letters.
- eq(tr('q', ['Shift']), 'Key-Q')
- eq(tr('q', ['Control', 'Shift']), 'Key-Q')
- eq(tr('q', ['Control', 'Alt', 'Shift']), 'Key-Q')
-
- # Convert key name to keysym.
- eq(tr('Page Up', []), 'Key-Prior')
- # 'Shift' doesn't change case.
- eq(tr('Page Down', ['Shift']), 'Key-Next')
-
@mock.patch.object(gkd, 'get_modifiers')
def test_build_key_string(self, mock_modifiers):
dialog = self.dialog
@@ -284,5 +265,27 @@ def test_cancel(self):
self.assertEqual(self.dialog.result, '')
+class HelperTest(unittest.TestCase):
+ "Test module level helper functions."
+
+ def test_translate_key(self):
+ tr = config_key.translate_key
+ eq = self.assertEqual
+
+ # Letters return unchanged with no 'Shift'.
+ eq(tr('q', []), 'Key-q')
+ eq(tr('q', ['Control', 'Alt']), 'Key-q')
+
+ # 'Shift' uppercases single lowercase letters.
+ eq(tr('q', ['Shift']), 'Key-Q')
+ eq(tr('q', ['Control', 'Shift']), 'Key-Q')
+ eq(tr('q', ['Control', 'Alt', 'Shift']), 'Key-Q')
+
+ # Convert key name to keysym.
+ eq(tr('Page Up', []), 'Key-Prior')
+ # 'Shift' doesn't change case when it's not a single char.
+ eq(tr('*', ['Shift']), 'Key-asterisk')
+
+
if __name__ == '__main__':
unittest.main(verbosity=2)
diff --git a/Misc/NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst b/Misc/NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst
index e20b01d991c4..d81cf2c44162 100644
--- a/Misc/NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst
+++ b/Misc/NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst
@@ -1 +1,2 @@
-Update config_key: use PEP 8 names, ttk widgets, and add tests.
+Update config_key: use PEP 8 names and ttk widgets,
+make some objects global, and add tests.
1
0

Dec. 31, 2018
https://github.com/python/cpython/commit/b4ea8bb080f63ef27682f3f9bbaa4d12a8…
commit: b4ea8bb080f63ef27682f3f9bbaa4d12a83030b1
branch: master
author: Cheryl Sabella <cheryl.sabella(a)gmail.com>
committer: Terry Jan Reedy <tjreedy(a)udel.edu>
date: 2018-12-31T15:06:35-05:00
summary:
bpo-35598: IDLE - Globalize some config_key objects (GH-11392)
Move translate_key() and constant tuples to module level.
Inline the remnant one-line function.
files:
M Lib/idlelib/config_key.py
M Lib/idlelib/idle_test/test_config_key.py
M Misc/NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst
diff --git a/Lib/idlelib/config_key.py b/Lib/idlelib/config_key.py
index 466830566042..21e84a94c9ff 100644
--- a/Lib/idlelib/config_key.py
+++ b/Lib/idlelib/config_key.py
@@ -8,6 +8,38 @@
import sys
+FUNCTION_KEYS = ('F1', 'F2' ,'F3' ,'F4' ,'F5' ,'F6',
+ 'F7', 'F8' ,'F9' ,'F10' ,'F11' ,'F12')
+ALPHANUM_KEYS = tuple(string.ascii_lowercase + string.digits)
+PUNCTUATION_KEYS = tuple('~!@#%^&*()_-+={}[]|;:,.<>/?')
+WHITESPACE_KEYS = ('Tab', 'Space', 'Return')
+EDIT_KEYS = ('BackSpace', 'Delete', 'Insert')
+MOVE_KEYS = ('Home', 'End', 'Page Up', 'Page Down', 'Left Arrow',
+ 'Right Arrow', 'Up Arrow', 'Down Arrow')
+AVAILABLE_KEYS = (ALPHANUM_KEYS + PUNCTUATION_KEYS + FUNCTION_KEYS +
+ WHITESPACE_KEYS + EDIT_KEYS + MOVE_KEYS)
+
+
+def translate_key(key, modifiers):
+ "Translate from keycap symbol to the Tkinter keysym."
+ mapping = {'Space':'space',
+ '~':'asciitilde', '!':'exclam', '@':'at', '#':'numbersign',
+ '%':'percent', '^':'asciicircum', '&':'ampersand',
+ '*':'asterisk', '(':'parenleft', ')':'parenright',
+ '_':'underscore', '-':'minus', '+':'plus', '=':'equal',
+ '{':'braceleft', '}':'braceright',
+ '[':'bracketleft', ']':'bracketright', '|':'bar',
+ ';':'semicolon', ':':'colon', ',':'comma', '.':'period',
+ '<':'less', '>':'greater', '/':'slash', '?':'question',
+ 'Page Up':'Prior', 'Page Down':'Next',
+ 'Left Arrow':'Left', 'Right Arrow':'Right',
+ 'Up Arrow':'Up', 'Down Arrow': 'Down', 'Tab':'Tab'}
+ key = mapping.get(key, key)
+ if 'Shift' in modifiers and key in string.ascii_lowercase:
+ key = key.upper()
+ return f'Key-{key}'
+
+
class GetKeysDialog(Toplevel):
# Dialog title for invalid key sequence
@@ -48,7 +80,6 @@ def __init__(self, parent, title, action, current_key_sequences,
self.modifier_vars.append(variable)
self.advanced = False
self.create_widgets()
- self.load_final_key_list()
self.update_idletasks()
self.geometry(
"+%d+%d" % (
@@ -122,6 +153,7 @@ def create_widgets(self):
# Basic entry key list.
self.list_keys_final = Listbox(self.frame_controls_basic, width=15,
height=10, selectmode='single')
+ self.list_keys_final.insert('end', *AVAILABLE_KEYS)
self.list_keys_final.bind('<ButtonRelease-1>', self.final_key_selected)
self.list_keys_final.grid(row=0, column=4, rowspan=4, sticky='ns')
scroll_keys_final = Scrollbar(self.frame_controls_basic,
@@ -206,7 +238,7 @@ def build_key_string(self):
keylist = modifiers = self.get_modifiers()
final_key = self.list_keys_final.get('anchor')
if final_key:
- final_key = self.translate_key(final_key, modifiers)
+ final_key = translate_key(final_key, modifiers)
keylist.append(final_key)
self.key_string.set(f"<{'-'.join(keylist)}>")
@@ -223,43 +255,6 @@ def clear_key_seq(self):
variable.set('')
self.key_string.set('')
- def load_final_key_list(self):
- "Populate listbox of available keys."
- # These tuples are also available for use in validity checks.
- self.function_keys = ('F1', 'F2' ,'F3' ,'F4' ,'F5' ,'F6',
- 'F7', 'F8' ,'F9' ,'F10' ,'F11' ,'F12')
- self.alphanum_keys = tuple(string.ascii_lowercase + string.digits)
- self.punctuation_keys = tuple('~!@#%^&*()_-+={}[]|;:,.<>/?')
- self.whitespace_keys = ('Tab', 'Space', 'Return')
- self.edit_keys = ('BackSpace', 'Delete', 'Insert')
- self.move_keys = ('Home', 'End', 'Page Up', 'Page Down', 'Left Arrow',
- 'Right Arrow', 'Up Arrow', 'Down Arrow')
- # Make a tuple of most of the useful common 'final' keys.
- keys = (self.alphanum_keys + self.punctuation_keys + self.function_keys +
- self.whitespace_keys + self.edit_keys + self.move_keys)
- self.list_keys_final.insert('end', *keys)
-
- @staticmethod
- def translate_key(key, modifiers):
- "Translate from keycap symbol to the Tkinter keysym."
- translate_dict = {'Space':'space',
- '~':'asciitilde', '!':'exclam', '@':'at', '#':'numbersign',
- '%':'percent', '^':'asciicircum', '&':'ampersand',
- '*':'asterisk', '(':'parenleft', ')':'parenright',
- '_':'underscore', '-':'minus', '+':'plus', '=':'equal',
- '{':'braceleft', '}':'braceright',
- '[':'bracketleft', ']':'bracketright', '|':'bar',
- ';':'semicolon', ':':'colon', ',':'comma', '.':'period',
- '<':'less', '>':'greater', '/':'slash', '?':'question',
- 'Page Up':'Prior', 'Page Down':'Next',
- 'Left Arrow':'Left', 'Right Arrow':'Right',
- 'Up Arrow':'Up', 'Down Arrow': 'Down', 'Tab':'Tab'}
- if key in translate_dict:
- key = translate_dict[key]
- if 'Shift' in modifiers and key in string.ascii_lowercase:
- key = key.upper()
- return f'Key-{key}'
-
def ok(self, event=None):
keys = self.key_string.get().strip()
if not keys:
@@ -291,12 +286,12 @@ def keys_ok(self, keys):
self.showerror(title, parent=self,
message='Missing the final Key')
elif (not modifiers
- and final_key not in self.function_keys + self.move_keys):
+ and final_key not in FUNCTION_KEYS + MOVE_KEYS):
self.showerror(title=title, parent=self,
message='No modifier key(s) specified.')
elif (modifiers == ['Shift']) \
and (final_key not in
- self.function_keys + self.move_keys + ('Tab', 'Space')):
+ FUNCTION_KEYS + MOVE_KEYS + ('Tab', 'Space')):
msg = 'The shift modifier by itself may not be used with'\
' this key symbol.'
self.showerror(title=title, parent=self, message=msg)
diff --git a/Lib/idlelib/idle_test/test_config_key.py b/Lib/idlelib/idle_test/test_config_key.py
index 8261f8da00c3..b7fe7fd6b5ec 100644
--- a/Lib/idlelib/idle_test/test_config_key.py
+++ b/Lib/idlelib/idle_test/test_config_key.py
@@ -206,25 +206,6 @@ def test_get_modifiers(self):
dialog.modifier_checkbuttons['foo'].invoke()
eq(gm(), ['BAZ'])
- def test_translate_key(self):
- dialog = self.dialog
- tr = dialog.translate_key
- eq = self.assertEqual
-
- # Letters return unchanged with no 'Shift'.
- eq(tr('q', []), 'Key-q')
- eq(tr('q', ['Control', 'Alt']), 'Key-q')
-
- # 'Shift' uppercases single lowercase letters.
- eq(tr('q', ['Shift']), 'Key-Q')
- eq(tr('q', ['Control', 'Shift']), 'Key-Q')
- eq(tr('q', ['Control', 'Alt', 'Shift']), 'Key-Q')
-
- # Convert key name to keysym.
- eq(tr('Page Up', []), 'Key-Prior')
- # 'Shift' doesn't change case.
- eq(tr('Page Down', ['Shift']), 'Key-Next')
-
@mock.patch.object(gkd, 'get_modifiers')
def test_build_key_string(self, mock_modifiers):
dialog = self.dialog
@@ -284,5 +265,27 @@ def test_cancel(self):
self.assertEqual(self.dialog.result, '')
+class HelperTest(unittest.TestCase):
+ "Test module level helper functions."
+
+ def test_translate_key(self):
+ tr = config_key.translate_key
+ eq = self.assertEqual
+
+ # Letters return unchanged with no 'Shift'.
+ eq(tr('q', []), 'Key-q')
+ eq(tr('q', ['Control', 'Alt']), 'Key-q')
+
+ # 'Shift' uppercases single lowercase letters.
+ eq(tr('q', ['Shift']), 'Key-Q')
+ eq(tr('q', ['Control', 'Shift']), 'Key-Q')
+ eq(tr('q', ['Control', 'Alt', 'Shift']), 'Key-Q')
+
+ # Convert key name to keysym.
+ eq(tr('Page Up', []), 'Key-Prior')
+ # 'Shift' doesn't change case when it's not a single char.
+ eq(tr('*', ['Shift']), 'Key-asterisk')
+
+
if __name__ == '__main__':
unittest.main(verbosity=2)
diff --git a/Misc/NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst b/Misc/NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst
index e20b01d991c4..d81cf2c44162 100644
--- a/Misc/NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst
+++ b/Misc/NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst
@@ -1 +1,2 @@
-Update config_key: use PEP 8 names, ttk widgets, and add tests.
+Update config_key: use PEP 8 names and ttk widgets,
+make some objects global, and add tests.
1
0
https://github.com/python/cpython/commit/ede0b6fae20290bf22b6ee1b9a1e1179d7…
commit: ede0b6fae20290bf22b6ee1b9a1e1179d750f360
branch: master
author: Tal Einat <taleinat+github(a)gmail.com>
committer: GitHub <noreply(a)github.com>
date: 2018-12-31T17:12:08+02:00
summary:
bpo-20182: AC convert Python/sysmodule.c (GH-11328)
files:
M Python/clinic/sysmodule.c.h
M Python/sysmodule.c
diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h
index f9415aea70fc..2d9c6e2beee1 100644
--- a/Python/clinic/sysmodule.c.h
+++ b/Python/clinic/sysmodule.c.h
@@ -2,15 +2,398 @@
preserve
[clinic start generated code]*/
+PyDoc_STRVAR(sys_displayhook__doc__,
+"displayhook($module, object, /)\n"
+"--\n"
+"\n"
+"Print an object to sys.stdout and also save it in builtins._");
+
+#define SYS_DISPLAYHOOK_METHODDEF \
+ {"displayhook", (PyCFunction)sys_displayhook, METH_O, sys_displayhook__doc__},
+
+PyDoc_STRVAR(sys_excepthook__doc__,
+"excepthook($module, exctype, value, traceback, /)\n"
+"--\n"
+"\n"
+"Handle an exception by displaying it with a traceback on sys.stderr.");
+
+#define SYS_EXCEPTHOOK_METHODDEF \
+ {"excepthook", (PyCFunction)(void(*)(void))sys_excepthook, METH_FASTCALL, sys_excepthook__doc__},
+
+static PyObject *
+sys_excepthook_impl(PyObject *module, PyObject *exctype, PyObject *value,
+ PyObject *traceback);
+
+static PyObject *
+sys_excepthook(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *exctype;
+ PyObject *value;
+ PyObject *traceback;
+
+ if (!_PyArg_UnpackStack(args, nargs, "excepthook",
+ 3, 3,
+ &exctype, &value, &traceback)) {
+ goto exit;
+ }
+ return_value = sys_excepthook_impl(module, exctype, value, traceback);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(sys_exc_info__doc__,
+"exc_info($module, /)\n"
+"--\n"
+"\n"
+"Return current exception information: (type, value, traceback).\n"
+"\n"
+"Return information about the most recent exception caught by an except\n"
+"clause in the current stack frame or in an older stack frame.");
+
+#define SYS_EXC_INFO_METHODDEF \
+ {"exc_info", (PyCFunction)sys_exc_info, METH_NOARGS, sys_exc_info__doc__},
+
+static PyObject *
+sys_exc_info_impl(PyObject *module);
+
+static PyObject *
+sys_exc_info(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_exc_info_impl(module);
+}
+
+PyDoc_STRVAR(sys_exit__doc__,
+"exit($module, status=None, /)\n"
+"--\n"
+"\n"
+"Exit the interpreter by raising SystemExit(status).\n"
+"\n"
+"If the status is omitted or None, it defaults to zero (i.e., success).\n"
+"If the status is an integer, it will be used as the system exit status.\n"
+"If it is another kind of object, it will be printed and the system\n"
+"exit status will be one (i.e., failure).");
+
+#define SYS_EXIT_METHODDEF \
+ {"exit", (PyCFunction)(void(*)(void))sys_exit, METH_FASTCALL, sys_exit__doc__},
+
+static PyObject *
+sys_exit_impl(PyObject *module, PyObject *status);
+
+static PyObject *
+sys_exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *status = NULL;
+
+ if (!_PyArg_UnpackStack(args, nargs, "exit",
+ 0, 1,
+ &status)) {
+ goto exit;
+ }
+ return_value = sys_exit_impl(module, status);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(sys_getdefaultencoding__doc__,
+"getdefaultencoding($module, /)\n"
+"--\n"
+"\n"
+"Return the current default encoding used by the Unicode implementation.");
+
+#define SYS_GETDEFAULTENCODING_METHODDEF \
+ {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, METH_NOARGS, sys_getdefaultencoding__doc__},
+
+static PyObject *
+sys_getdefaultencoding_impl(PyObject *module);
+
+static PyObject *
+sys_getdefaultencoding(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_getdefaultencoding_impl(module);
+}
+
+PyDoc_STRVAR(sys_getfilesystemencoding__doc__,
+"getfilesystemencoding($module, /)\n"
+"--\n"
+"\n"
+"Return the encoding used to convert Unicode filenames to OS filenames.");
+
+#define SYS_GETFILESYSTEMENCODING_METHODDEF \
+ {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding, METH_NOARGS, sys_getfilesystemencoding__doc__},
+
+static PyObject *
+sys_getfilesystemencoding_impl(PyObject *module);
+
+static PyObject *
+sys_getfilesystemencoding(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_getfilesystemencoding_impl(module);
+}
+
+PyDoc_STRVAR(sys_getfilesystemencodeerrors__doc__,
+"getfilesystemencodeerrors($module, /)\n"
+"--\n"
+"\n"
+"Return the error mode used Unicode to OS filename conversion.");
+
+#define SYS_GETFILESYSTEMENCODEERRORS_METHODDEF \
+ {"getfilesystemencodeerrors", (PyCFunction)sys_getfilesystemencodeerrors, METH_NOARGS, sys_getfilesystemencodeerrors__doc__},
+
+static PyObject *
+sys_getfilesystemencodeerrors_impl(PyObject *module);
+
+static PyObject *
+sys_getfilesystemencodeerrors(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_getfilesystemencodeerrors_impl(module);
+}
+
+PyDoc_STRVAR(sys_intern__doc__,
+"intern($module, string, /)\n"
+"--\n"
+"\n"
+"``Intern\'\' the given string.\n"
+"\n"
+"This enters the string in the (global) table of interned strings whose\n"
+"purpose is to speed up dictionary lookups. Return the string itself or\n"
+"the previously interned string object with the same value.");
+
+#define SYS_INTERN_METHODDEF \
+ {"intern", (PyCFunction)sys_intern, METH_O, sys_intern__doc__},
+
+static PyObject *
+sys_intern_impl(PyObject *module, PyObject *s);
+
+static PyObject *
+sys_intern(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ PyObject *s;
+
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("intern", "str", arg);
+ goto exit;
+ }
+ if (PyUnicode_READY(arg) == -1) {
+ goto exit;
+ }
+ s = arg;
+ return_value = sys_intern_impl(module, s);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(sys_gettrace__doc__,
+"gettrace($module, /)\n"
+"--\n"
+"\n"
+"Return the global debug tracing function set with sys.settrace.\n"
+"\n"
+"See the debugger chapter in the library manual.");
+
+#define SYS_GETTRACE_METHODDEF \
+ {"gettrace", (PyCFunction)sys_gettrace, METH_NOARGS, sys_gettrace__doc__},
+
+static PyObject *
+sys_gettrace_impl(PyObject *module);
+
+static PyObject *
+sys_gettrace(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_gettrace_impl(module);
+}
+
+PyDoc_STRVAR(sys_getprofile__doc__,
+"getprofile($module, /)\n"
+"--\n"
+"\n"
+"Return the profiling function set with sys.setprofile.\n"
+"\n"
+"See the profiler chapter in the library manual.");
+
+#define SYS_GETPROFILE_METHODDEF \
+ {"getprofile", (PyCFunction)sys_getprofile, METH_NOARGS, sys_getprofile__doc__},
+
+static PyObject *
+sys_getprofile_impl(PyObject *module);
+
+static PyObject *
+sys_getprofile(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_getprofile_impl(module);
+}
+
+PyDoc_STRVAR(sys_setcheckinterval__doc__,
+"setcheckinterval($module, n, /)\n"
+"--\n"
+"\n"
+"Set the async event check interval to n instructions.\n"
+"\n"
+"This tells the Python interpreter to check for asynchronous events\n"
+"every n instructions.\n"
+"\n"
+"This also affects how often thread switches occur.");
+
+#define SYS_SETCHECKINTERVAL_METHODDEF \
+ {"setcheckinterval", (PyCFunction)sys_setcheckinterval, METH_O, sys_setcheckinterval__doc__},
+
+static PyObject *
+sys_setcheckinterval_impl(PyObject *module, int n);
+
+static PyObject *
+sys_setcheckinterval(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ int n;
+
+ if (PyFloat_Check(arg)) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ n = _PyLong_AsInt(arg);
+ if (n == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = sys_setcheckinterval_impl(module, n);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(sys_getcheckinterval__doc__,
+"getcheckinterval($module, /)\n"
+"--\n"
+"\n"
+"Return the current check interval; see sys.setcheckinterval().");
+
+#define SYS_GETCHECKINTERVAL_METHODDEF \
+ {"getcheckinterval", (PyCFunction)sys_getcheckinterval, METH_NOARGS, sys_getcheckinterval__doc__},
+
+static PyObject *
+sys_getcheckinterval_impl(PyObject *module);
+
+static PyObject *
+sys_getcheckinterval(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_getcheckinterval_impl(module);
+}
+
+PyDoc_STRVAR(sys_setswitchinterval__doc__,
+"setswitchinterval($module, interval, /)\n"
+"--\n"
+"\n"
+"Set the ideal thread switching delay inside the Python interpreter.\n"
+"\n"
+"The actual frequency of switching threads can be lower if the\n"
+"interpreter executes long sequences of uninterruptible code\n"
+"(this is implementation-specific and workload-dependent).\n"
+"\n"
+"The parameter must represent the desired switching delay in seconds\n"
+"A typical value is 0.005 (5 milliseconds).");
+
+#define SYS_SETSWITCHINTERVAL_METHODDEF \
+ {"setswitchinterval", (PyCFunction)sys_setswitchinterval, METH_O, sys_setswitchinterval__doc__},
+
+static PyObject *
+sys_setswitchinterval_impl(PyObject *module, double interval);
+
+static PyObject *
+sys_setswitchinterval(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ double interval;
+
+ interval = PyFloat_AsDouble(arg);
+ if (PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = sys_setswitchinterval_impl(module, interval);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(sys_getswitchinterval__doc__,
+"getswitchinterval($module, /)\n"
+"--\n"
+"\n"
+"Return the current thread switch interval; see sys.setswitchinterval().");
+
+#define SYS_GETSWITCHINTERVAL_METHODDEF \
+ {"getswitchinterval", (PyCFunction)sys_getswitchinterval, METH_NOARGS, sys_getswitchinterval__doc__},
+
+static double
+sys_getswitchinterval_impl(PyObject *module);
+
+static PyObject *
+sys_getswitchinterval(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ PyObject *return_value = NULL;
+ double _return_value;
+
+ _return_value = sys_getswitchinterval_impl(module);
+ if ((_return_value == -1.0) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyFloat_FromDouble(_return_value);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(sys_setrecursionlimit__doc__,
+"setrecursionlimit($module, limit, /)\n"
+"--\n"
+"\n"
+"Set the maximum depth of the Python interpreter stack to n.\n"
+"\n"
+"This limit prevents infinite recursion from causing an overflow of the C\n"
+"stack and crashing Python. The highest possible limit is platform-\n"
+"dependent.");
+
+#define SYS_SETRECURSIONLIMIT_METHODDEF \
+ {"setrecursionlimit", (PyCFunction)sys_setrecursionlimit, METH_O, sys_setrecursionlimit__doc__},
+
+static PyObject *
+sys_setrecursionlimit_impl(PyObject *module, int new_limit);
+
+static PyObject *
+sys_setrecursionlimit(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ int new_limit;
+
+ if (PyFloat_Check(arg)) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ new_limit = _PyLong_AsInt(arg);
+ if (new_limit == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = sys_setrecursionlimit_impl(module, new_limit);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(sys_set_coroutine_origin_tracking_depth__doc__,
"set_coroutine_origin_tracking_depth($module, /, depth)\n"
"--\n"
"\n"
"Enable or disable origin tracking for coroutine objects in this thread.\n"
"\n"
-"Coroutine objects will track \'depth\' frames of traceback information about\n"
-"where they came from, available in their cr_origin attribute. Set depth of 0\n"
-"to disable.");
+"Coroutine objects will track \'depth\' frames of traceback information\n"
+"about where they came from, available in their cr_origin attribute.\n"
+"\n"
+"Set a depth of 0 to disable.");
#define SYS_SET_COROUTINE_ORIGIN_TRACKING_DEPTH_METHODDEF \
{"set_coroutine_origin_tracking_depth", (PyCFunction)(void(*)(void))sys_set_coroutine_origin_tracking_depth, METH_FASTCALL|METH_KEYWORDS, sys_set_coroutine_origin_tracking_depth__doc__},
@@ -63,4 +446,587 @@ sys_get_coroutine_origin_tracking_depth(PyObject *module, PyObject *Py_UNUSED(ig
exit:
return return_value;
}
-/*[clinic end generated code: output=dfd3eb5b137a9861 input=a9049054013a1b77]*/
+
+PyDoc_STRVAR(sys_set_coroutine_wrapper__doc__,
+"set_coroutine_wrapper($module, wrapper, /)\n"
+"--\n"
+"\n"
+"Set a wrapper for coroutine objects.");
+
+#define SYS_SET_COROUTINE_WRAPPER_METHODDEF \
+ {"set_coroutine_wrapper", (PyCFunction)sys_set_coroutine_wrapper, METH_O, sys_set_coroutine_wrapper__doc__},
+
+PyDoc_STRVAR(sys_get_coroutine_wrapper__doc__,
+"get_coroutine_wrapper($module, /)\n"
+"--\n"
+"\n"
+"Return the wrapper for coroutines set by sys.set_coroutine_wrapper.");
+
+#define SYS_GET_COROUTINE_WRAPPER_METHODDEF \
+ {"get_coroutine_wrapper", (PyCFunction)sys_get_coroutine_wrapper, METH_NOARGS, sys_get_coroutine_wrapper__doc__},
+
+static PyObject *
+sys_get_coroutine_wrapper_impl(PyObject *module);
+
+static PyObject *
+sys_get_coroutine_wrapper(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_get_coroutine_wrapper_impl(module);
+}
+
+PyDoc_STRVAR(sys_get_asyncgen_hooks__doc__,
+"get_asyncgen_hooks($module, /)\n"
+"--\n"
+"\n"
+"Return the installed asynchronous generators hooks.\n"
+"\n"
+"This returns a namedtuple of the form (firstiter, finalizer).");
+
+#define SYS_GET_ASYNCGEN_HOOKS_METHODDEF \
+ {"get_asyncgen_hooks", (PyCFunction)sys_get_asyncgen_hooks, METH_NOARGS, sys_get_asyncgen_hooks__doc__},
+
+static PyObject *
+sys_get_asyncgen_hooks_impl(PyObject *module);
+
+static PyObject *
+sys_get_asyncgen_hooks(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_get_asyncgen_hooks_impl(module);
+}
+
+PyDoc_STRVAR(sys_getrecursionlimit__doc__,
+"getrecursionlimit($module, /)\n"
+"--\n"
+"\n"
+"Return the current value of the recursion limit.\n"
+"\n"
+"The recursion limit is the maximum depth of the Python interpreter\n"
+"stack. This limit prevents infinite recursion from causing an overflow\n"
+"of the C stack and crashing Python.");
+
+#define SYS_GETRECURSIONLIMIT_METHODDEF \
+ {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS, sys_getrecursionlimit__doc__},
+
+static PyObject *
+sys_getrecursionlimit_impl(PyObject *module);
+
+static PyObject *
+sys_getrecursionlimit(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_getrecursionlimit_impl(module);
+}
+
+#if defined(MS_WINDOWS)
+
+PyDoc_STRVAR(sys_getwindowsversion__doc__,
+"getwindowsversion($module, /)\n"
+"--\n"
+"\n"
+"Return info about the running version of Windows as a named tuple.\n"
+"\n"
+"The members are named: major, minor, build, platform, service_pack,\n"
+"service_pack_major, service_pack_minor, suite_mask, product_type and\n"
+"platform_version. For backward compatibility, only the first 5 items\n"
+"are available by indexing. All elements are numbers, except\n"
+"service_pack and platform_type which are strings, and platform_version\n"
+"which is a 3-tuple. Platform is always 2. Product_type may be 1 for a\n"
+"workstation, 2 for a domain controller, 3 for a server.\n"
+"Platform_version is a 3-tuple containing a version number that is\n"
+"intended for identifying the OS rather than feature detection.");
+
+#define SYS_GETWINDOWSVERSION_METHODDEF \
+ {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS, sys_getwindowsversion__doc__},
+
+static PyObject *
+sys_getwindowsversion_impl(PyObject *module);
+
+static PyObject *
+sys_getwindowsversion(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_getwindowsversion_impl(module);
+}
+
+#endif /* defined(MS_WINDOWS) */
+
+#if defined(MS_WINDOWS)
+
+PyDoc_STRVAR(sys__enablelegacywindowsfsencoding__doc__,
+"_enablelegacywindowsfsencoding($module, /)\n"
+"--\n"
+"\n"
+"Changes the default filesystem encoding to mbcs:replace.\n"
+"\n"
+"This is done for consistency with earlier versions of Python. See PEP\n"
+"529 for more information.\n"
+"\n"
+"This is equivalent to defining the PYTHONLEGACYWINDOWSFSENCODING\n"
+"environment variable before launching Python.");
+
+#define SYS__ENABLELEGACYWINDOWSFSENCODING_METHODDEF \
+ {"_enablelegacywindowsfsencoding", (PyCFunction)sys__enablelegacywindowsfsencoding, METH_NOARGS, sys__enablelegacywindowsfsencoding__doc__},
+
+static PyObject *
+sys__enablelegacywindowsfsencoding_impl(PyObject *module);
+
+static PyObject *
+sys__enablelegacywindowsfsencoding(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys__enablelegacywindowsfsencoding_impl(module);
+}
+
+#endif /* defined(MS_WINDOWS) */
+
+#if defined(HAVE_DLOPEN)
+
+PyDoc_STRVAR(sys_setdlopenflags__doc__,
+"setdlopenflags($module, flags, /)\n"
+"--\n"
+"\n"
+"Set the flags used by the interpreter for dlopen calls.\n"
+"\n"
+"This is used, for example, when the interpreter loads extension\n"
+"modules. Among other things, this will enable a lazy resolving of\n"
+"symbols when importing a module, if called as sys.setdlopenflags(0).\n"
+"To share symbols across extension modules, call as\n"
+"sys.setdlopenflags(os.RTLD_GLOBAL). Symbolic names for the flag\n"
+"modules can be found in the os module (RTLD_xxx constants, e.g.\n"
+"os.RTLD_LAZY).");
+
+#define SYS_SETDLOPENFLAGS_METHODDEF \
+ {"setdlopenflags", (PyCFunction)sys_setdlopenflags, METH_O, sys_setdlopenflags__doc__},
+
+static PyObject *
+sys_setdlopenflags_impl(PyObject *module, int new_val);
+
+static PyObject *
+sys_setdlopenflags(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ int new_val;
+
+ if (PyFloat_Check(arg)) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ new_val = _PyLong_AsInt(arg);
+ if (new_val == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = sys_setdlopenflags_impl(module, new_val);
+
+exit:
+ return return_value;
+}
+
+#endif /* defined(HAVE_DLOPEN) */
+
+#if defined(HAVE_DLOPEN)
+
+PyDoc_STRVAR(sys_getdlopenflags__doc__,
+"getdlopenflags($module, /)\n"
+"--\n"
+"\n"
+"Return the current value of the flags that are used for dlopen calls.\n"
+"\n"
+"The flag constants are defined in the os module.");
+
+#define SYS_GETDLOPENFLAGS_METHODDEF \
+ {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, sys_getdlopenflags__doc__},
+
+static PyObject *
+sys_getdlopenflags_impl(PyObject *module);
+
+static PyObject *
+sys_getdlopenflags(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_getdlopenflags_impl(module);
+}
+
+#endif /* defined(HAVE_DLOPEN) */
+
+#if defined(USE_MALLOPT)
+
+PyDoc_STRVAR(sys_mdebug__doc__,
+"mdebug($module, flag, /)\n"
+"--\n"
+"\n");
+
+#define SYS_MDEBUG_METHODDEF \
+ {"mdebug", (PyCFunction)sys_mdebug, METH_O, sys_mdebug__doc__},
+
+static PyObject *
+sys_mdebug_impl(PyObject *module, int flag);
+
+static PyObject *
+sys_mdebug(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ int flag;
+
+ if (PyFloat_Check(arg)) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ flag = _PyLong_AsInt(arg);
+ if (flag == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = sys_mdebug_impl(module, flag);
+
+exit:
+ return return_value;
+}
+
+#endif /* defined(USE_MALLOPT) */
+
+PyDoc_STRVAR(sys_getrefcount__doc__,
+"getrefcount($module, object, /)\n"
+"--\n"
+"\n"
+"Return the reference count of object.\n"
+"\n"
+"The count returned is generally one higher than you might expect,\n"
+"because it includes the (temporary) reference as an argument to\n"
+"getrefcount().");
+
+#define SYS_GETREFCOUNT_METHODDEF \
+ {"getrefcount", (PyCFunction)sys_getrefcount, METH_O, sys_getrefcount__doc__},
+
+static Py_ssize_t
+sys_getrefcount_impl(PyObject *module, PyObject *object);
+
+static PyObject *
+sys_getrefcount(PyObject *module, PyObject *object)
+{
+ PyObject *return_value = NULL;
+ Py_ssize_t _return_value;
+
+ _return_value = sys_getrefcount_impl(module, object);
+ if ((_return_value == -1) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyLong_FromSsize_t(_return_value);
+
+exit:
+ return return_value;
+}
+
+#if defined(Py_REF_DEBUG)
+
+PyDoc_STRVAR(sys_gettotalrefcount__doc__,
+"gettotalrefcount($module, /)\n"
+"--\n"
+"\n");
+
+#define SYS_GETTOTALREFCOUNT_METHODDEF \
+ {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS, sys_gettotalrefcount__doc__},
+
+static Py_ssize_t
+sys_gettotalrefcount_impl(PyObject *module);
+
+static PyObject *
+sys_gettotalrefcount(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ PyObject *return_value = NULL;
+ Py_ssize_t _return_value;
+
+ _return_value = sys_gettotalrefcount_impl(module);
+ if ((_return_value == -1) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyLong_FromSsize_t(_return_value);
+
+exit:
+ return return_value;
+}
+
+#endif /* defined(Py_REF_DEBUG) */
+
+PyDoc_STRVAR(sys_getallocatedblocks__doc__,
+"getallocatedblocks($module, /)\n"
+"--\n"
+"\n"
+"Return the number of memory blocks currently allocated.");
+
+#define SYS_GETALLOCATEDBLOCKS_METHODDEF \
+ {"getallocatedblocks", (PyCFunction)sys_getallocatedblocks, METH_NOARGS, sys_getallocatedblocks__doc__},
+
+static Py_ssize_t
+sys_getallocatedblocks_impl(PyObject *module);
+
+static PyObject *
+sys_getallocatedblocks(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ PyObject *return_value = NULL;
+ Py_ssize_t _return_value;
+
+ _return_value = sys_getallocatedblocks_impl(module);
+ if ((_return_value == -1) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyLong_FromSsize_t(_return_value);
+
+exit:
+ return return_value;
+}
+
+#if defined(COUNT_ALLOCS)
+
+PyDoc_STRVAR(sys_getcounts__doc__,
+"getcounts($module, /)\n"
+"--\n"
+"\n");
+
+#define SYS_GETCOUNTS_METHODDEF \
+ {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS, sys_getcounts__doc__},
+
+static PyObject *
+sys_getcounts_impl(PyObject *module);
+
+static PyObject *
+sys_getcounts(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_getcounts_impl(module);
+}
+
+#endif /* defined(COUNT_ALLOCS) */
+
+PyDoc_STRVAR(sys__getframe__doc__,
+"_getframe($module, depth=0, /)\n"
+"--\n"
+"\n"
+"Return a frame object from the call stack.\n"
+"\n"
+"If optional integer depth is given, return the frame object that many\n"
+"calls below the top of the stack. If that is deeper than the call\n"
+"stack, ValueError is raised. The default for depth is zero, returning\n"
+"the frame at the top of the call stack.\n"
+"\n"
+"This function should be used for internal and specialized purposes\n"
+"only.");
+
+#define SYS__GETFRAME_METHODDEF \
+ {"_getframe", (PyCFunction)(void(*)(void))sys__getframe, METH_FASTCALL, sys__getframe__doc__},
+
+static PyObject *
+sys__getframe_impl(PyObject *module, int depth);
+
+static PyObject *
+sys__getframe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ int depth = 0;
+
+ if (!_PyArg_ParseStack(args, nargs, "|i:_getframe",
+ &depth)) {
+ goto exit;
+ }
+ return_value = sys__getframe_impl(module, depth);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(sys__current_frames__doc__,
+"_current_frames($module, /)\n"
+"--\n"
+"\n"
+"Return a dict mapping each thread\'s thread id to its current stack frame.\n"
+"\n"
+"This function should be used for specialized purposes only.");
+
+#define SYS__CURRENT_FRAMES_METHODDEF \
+ {"_current_frames", (PyCFunction)sys__current_frames, METH_NOARGS, sys__current_frames__doc__},
+
+static PyObject *
+sys__current_frames_impl(PyObject *module);
+
+static PyObject *
+sys__current_frames(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys__current_frames_impl(module);
+}
+
+PyDoc_STRVAR(sys_call_tracing__doc__,
+"call_tracing($module, func, args, /)\n"
+"--\n"
+"\n"
+"Call func(*args), while tracing is enabled.\n"
+"\n"
+"The tracing state is saved, and restored afterwards. This is intended\n"
+"to be called from a debugger from a checkpoint, to recursively debug\n"
+"some other code.");
+
+#define SYS_CALL_TRACING_METHODDEF \
+ {"call_tracing", (PyCFunction)(void(*)(void))sys_call_tracing, METH_FASTCALL, sys_call_tracing__doc__},
+
+static PyObject *
+sys_call_tracing_impl(PyObject *module, PyObject *func, PyObject *funcargs);
+
+static PyObject *
+sys_call_tracing(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *func;
+ PyObject *funcargs;
+
+ if (!_PyArg_ParseStack(args, nargs, "OO!:call_tracing",
+ &func, &PyTuple_Type, &funcargs)) {
+ goto exit;
+ }
+ return_value = sys_call_tracing_impl(module, func, funcargs);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(sys_callstats__doc__,
+"callstats($module, /)\n"
+"--\n"
+"\n"
+"Return a tuple of function call statistics.\n"
+"\n"
+"A tuple is returned only if CALL_PROFILE was defined when Python was\n"
+"built. Otherwise, this returns None.\n"
+"\n"
+"When enabled, this function returns detailed, implementation-specific\n"
+"details about the number of function calls executed. The return value\n"
+"is a 11-tuple where the entries in the tuple are counts of:\n"
+"0. all function calls\n"
+"1. calls to PyFunction_Type objects\n"
+"2. PyFunction calls that do not create an argument tuple\n"
+"3. PyFunction calls that do not create an argument tuple\n"
+" and bypass PyEval_EvalCodeEx()\n"
+"4. PyMethod calls\n"
+"5. PyMethod calls on bound methods\n"
+"6. PyType calls\n"
+"7. PyCFunction calls\n"
+"8. generator calls\n"
+"9. All other calls\n"
+"10. Number of stack pops performed by call_function()");
+
+#define SYS_CALLSTATS_METHODDEF \
+ {"callstats", (PyCFunction)sys_callstats, METH_NOARGS, sys_callstats__doc__},
+
+static PyObject *
+sys_callstats_impl(PyObject *module);
+
+static PyObject *
+sys_callstats(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_callstats_impl(module);
+}
+
+PyDoc_STRVAR(sys__debugmallocstats__doc__,
+"_debugmallocstats($module, /)\n"
+"--\n"
+"\n"
+"Print summary info to stderr about the state of pymalloc\'s structures.\n"
+"\n"
+"In Py_DEBUG mode, also perform some expensive internal consistency\n"
+"checks.");
+
+#define SYS__DEBUGMALLOCSTATS_METHODDEF \
+ {"_debugmallocstats", (PyCFunction)sys__debugmallocstats, METH_NOARGS, sys__debugmallocstats__doc__},
+
+static PyObject *
+sys__debugmallocstats_impl(PyObject *module);
+
+static PyObject *
+sys__debugmallocstats(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys__debugmallocstats_impl(module);
+}
+
+PyDoc_STRVAR(sys__clear_type_cache__doc__,
+"_clear_type_cache($module, /)\n"
+"--\n"
+"\n"
+"Clear the internal type lookup cache.");
+
+#define SYS__CLEAR_TYPE_CACHE_METHODDEF \
+ {"_clear_type_cache", (PyCFunction)sys__clear_type_cache, METH_NOARGS, sys__clear_type_cache__doc__},
+
+static PyObject *
+sys__clear_type_cache_impl(PyObject *module);
+
+static PyObject *
+sys__clear_type_cache(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys__clear_type_cache_impl(module);
+}
+
+PyDoc_STRVAR(sys_is_finalizing__doc__,
+"is_finalizing($module, /)\n"
+"--\n"
+"\n"
+"Return True if Python is exiting.");
+
+#define SYS_IS_FINALIZING_METHODDEF \
+ {"is_finalizing", (PyCFunction)sys_is_finalizing, METH_NOARGS, sys_is_finalizing__doc__},
+
+static PyObject *
+sys_is_finalizing_impl(PyObject *module);
+
+static PyObject *
+sys_is_finalizing(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_is_finalizing_impl(module);
+}
+
+#if defined(ANDROID_API_LEVEL)
+
+PyDoc_STRVAR(sys_getandroidapilevel__doc__,
+"getandroidapilevel($module, /)\n"
+"--\n"
+"\n"
+"Return the build time API version of Android as an integer.");
+
+#define SYS_GETANDROIDAPILEVEL_METHODDEF \
+ {"getandroidapilevel", (PyCFunction)sys_getandroidapilevel, METH_NOARGS, sys_getandroidapilevel__doc__},
+
+static PyObject *
+sys_getandroidapilevel_impl(PyObject *module);
+
+static PyObject *
+sys_getandroidapilevel(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return sys_getandroidapilevel_impl(module);
+}
+
+#endif /* defined(ANDROID_API_LEVEL) */
+
+#ifndef SYS_GETWINDOWSVERSION_METHODDEF
+ #define SYS_GETWINDOWSVERSION_METHODDEF
+#endif /* !defined(SYS_GETWINDOWSVERSION_METHODDEF) */
+
+#ifndef SYS__ENABLELEGACYWINDOWSFSENCODING_METHODDEF
+ #define SYS__ENABLELEGACYWINDOWSFSENCODING_METHODDEF
+#endif /* !defined(SYS__ENABLELEGACYWINDOWSFSENCODING_METHODDEF) */
+
+#ifndef SYS_SETDLOPENFLAGS_METHODDEF
+ #define SYS_SETDLOPENFLAGS_METHODDEF
+#endif /* !defined(SYS_SETDLOPENFLAGS_METHODDEF) */
+
+#ifndef SYS_GETDLOPENFLAGS_METHODDEF
+ #define SYS_GETDLOPENFLAGS_METHODDEF
+#endif /* !defined(SYS_GETDLOPENFLAGS_METHODDEF) */
+
+#ifndef SYS_MDEBUG_METHODDEF
+ #define SYS_MDEBUG_METHODDEF
+#endif /* !defined(SYS_MDEBUG_METHODDEF) */
+
+#ifndef SYS_GETTOTALREFCOUNT_METHODDEF
+ #define SYS_GETTOTALREFCOUNT_METHODDEF
+#endif /* !defined(SYS_GETTOTALREFCOUNT_METHODDEF) */
+
+#ifndef SYS_GETCOUNTS_METHODDEF
+ #define SYS_GETCOUNTS_METHODDEF
+#endif /* !defined(SYS_GETCOUNTS_METHODDEF) */
+
+#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
+ #define SYS_GETANDROIDAPILEVEL_METHODDEF
+#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
+/*[clinic end generated code: output=0e662f2e19293d57 input=a9049054013a1b77]*/
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 029de2d5ae7f..4150fbbbd997 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -252,8 +252,18 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o)
return ret;
}
+/*[clinic input]
+sys.displayhook
+
+ object as o: object
+ /
+
+Print an object to sys.stdout and also save it in builtins._
+[clinic start generated code]*/
+
static PyObject *
-sys_displayhook(PyObject *self, PyObject *o)
+sys_displayhook(PyObject *module, PyObject *o)
+/*[clinic end generated code: output=347477d006df92ed input=08ba730166d7ef72]*/
{
PyObject *outf;
PyObject *builtins;
@@ -305,30 +315,40 @@ sys_displayhook(PyObject *self, PyObject *o)
Py_RETURN_NONE;
}
-PyDoc_STRVAR(displayhook_doc,
-"displayhook(object) -> None\n"
-"\n"
-"Print an object to sys.stdout and also save it in builtins._\n"
-);
+
+/*[clinic input]
+sys.excepthook
+
+ exctype: object
+ value: object
+ traceback: object
+ /
+
+Handle an exception by displaying it with a traceback on sys.stderr.
+[clinic start generated code]*/
static PyObject *
-sys_excepthook(PyObject* self, PyObject* args)
+sys_excepthook_impl(PyObject *module, PyObject *exctype, PyObject *value,
+ PyObject *traceback)
+/*[clinic end generated code: output=18d99fdda21b6b5e input=ecf606fa826f19d9]*/
{
- PyObject *exc, *value, *tb;
- if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb))
- return NULL;
- PyErr_Display(exc, value, tb);
+ PyErr_Display(exctype, value, traceback);
Py_RETURN_NONE;
}
-PyDoc_STRVAR(excepthook_doc,
-"excepthook(exctype, value, traceback) -> None\n"
-"\n"
-"Handle an exception by displaying it with a traceback on sys.stderr.\n"
-);
+
+/*[clinic input]
+sys.exc_info
+
+Return current exception information: (type, value, traceback).
+
+Return information about the most recent exception caught by an except
+clause in the current stack frame or in an older stack frame.
+[clinic start generated code]*/
static PyObject *
-sys_exc_info(PyObject *self, PyObject *noargs)
+sys_exc_info_impl(PyObject *module)
+/*[clinic end generated code: output=3afd0940cf3a4d30 input=b5c5bf077788a3e5]*/
{
_PyErr_StackItem *err_info = _PyErr_GetTopmostException(_PyThreadState_GET());
return Py_BuildValue(
@@ -339,84 +359,92 @@ sys_exc_info(PyObject *self, PyObject *noargs)
err_info->exc_traceback : Py_None);
}
-PyDoc_STRVAR(exc_info_doc,
-"exc_info() -> (type, value, traceback)\n\
-\n\
-Return information about the most recent exception caught by an except\n\
-clause in the current stack frame or in an older stack frame."
-);
+
+/*[clinic input]
+sys.exit
+
+ status: object = NULL
+ /
+
+Exit the interpreter by raising SystemExit(status).
+
+If the status is omitted or None, it defaults to zero (i.e., success).
+If the status is an integer, it will be used as the system exit status.
+If it is another kind of object, it will be printed and the system
+exit status will be one (i.e., failure).
+[clinic start generated code]*/
static PyObject *
-sys_exit(PyObject *self, PyObject *args)
+sys_exit_impl(PyObject *module, PyObject *status)
+/*[clinic end generated code: output=13870986c1ab2ec0 input=a737351f86685e9c]*/
{
- PyObject *exit_code = 0;
- if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code))
- return NULL;
/* Raise SystemExit so callers may catch it or clean up. */
- PyErr_SetObject(PyExc_SystemExit, exit_code);
+ PyErr_SetObject(PyExc_SystemExit, status);
return NULL;
}
-PyDoc_STRVAR(exit_doc,
-"exit([status])\n\
-\n\
-Exit the interpreter by raising SystemExit(status).\n\
-If the status is omitted or None, it defaults to zero (i.e., success).\n\
-If the status is an integer, it will be used as the system exit status.\n\
-If it is another kind of object, it will be printed and the system\n\
-exit status will be one (i.e., failure)."
-);
+/*[clinic input]
+sys.getdefaultencoding
+
+Return the current default encoding used by the Unicode implementation.
+[clinic start generated code]*/
+
static PyObject *
-sys_getdefaultencoding(PyObject *self, PyObject *Py_UNUSED(ignored))
+sys_getdefaultencoding_impl(PyObject *module)
+/*[clinic end generated code: output=256d19dfcc0711e6 input=d416856ddbef6909]*/
{
return PyUnicode_FromString(PyUnicode_GetDefaultEncoding());
}
-PyDoc_STRVAR(getdefaultencoding_doc,
-"getdefaultencoding() -> string\n\
-\n\
-Return the current default string encoding used by the Unicode\n\
-implementation."
-);
+/*[clinic input]
+sys.getfilesystemencoding
+
+Return the encoding used to convert Unicode filenames to OS filenames.
+[clinic start generated code]*/
static PyObject *
-sys_getfilesystemencoding(PyObject *self, PyObject *Py_UNUSED(ignored))
+sys_getfilesystemencoding_impl(PyObject *module)
+/*[clinic end generated code: output=1dc4bdbe9be44aa7 input=8475f8649b8c7d8c]*/
{
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
const _PyCoreConfig *config = &interp->core_config;
return PyUnicode_FromString(config->filesystem_encoding);
}
-PyDoc_STRVAR(getfilesystemencoding_doc,
-"getfilesystemencoding() -> string\n\
-\n\
-Return the encoding used to convert Unicode filenames in\n\
-operating system filenames."
-);
+/*[clinic input]
+sys.getfilesystemencodeerrors
+
+Return the error mode used Unicode to OS filename conversion.
+[clinic start generated code]*/
static PyObject *
-sys_getfilesystemencodeerrors(PyObject *self, PyObject *Py_UNUSED(ignored))
+sys_getfilesystemencodeerrors_impl(PyObject *module)
+/*[clinic end generated code: output=ba77b36bbf7c96f5 input=22a1e8365566f1e5]*/
{
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
const _PyCoreConfig *config = &interp->core_config;
return PyUnicode_FromString(config->filesystem_errors);
}
-PyDoc_STRVAR(getfilesystemencodeerrors_doc,
- "getfilesystemencodeerrors() -> string\n\
-\n\
-Return the error mode used to convert Unicode filenames in\n\
-operating system filenames."
-);
+/*[clinic input]
+sys.intern
+
+ string as s: unicode
+ /
+
+``Intern'' the given string.
+
+This enters the string in the (global) table of interned strings whose
+purpose is to speed up dictionary lookups. Return the string itself or
+the previously interned string object with the same value.
+[clinic start generated code]*/
static PyObject *
-sys_intern(PyObject *self, PyObject *args)
+sys_intern_impl(PyObject *module, PyObject *s)
+/*[clinic end generated code: output=be680c24f5c9e5d6 input=849483c006924e2f]*/
{
- PyObject *s;
- if (!PyArg_ParseTuple(args, "U:intern", &s))
- return NULL;
if (PyUnicode_CheckExact(s)) {
Py_INCREF(s);
PyUnicode_InternInPlace(&s);
@@ -424,19 +452,11 @@ sys_intern(PyObject *self, PyObject *args)
}
else {
PyErr_Format(PyExc_TypeError,
- "can't intern %.400s", s->ob_type->tp_name);
+ "can't intern %.400s", s->ob_type->tp_name);
return NULL;
}
}
-PyDoc_STRVAR(intern_doc,
-"intern(string) -> string\n\
-\n\
-``Intern'' the given string. This enters the string in the (global)\n\
-table of interned strings whose purpose is to speed up dictionary lookups.\n\
-Return the string itself or the previously interned string object with the\n\
-same value.");
-
/*
* Cached interned string objects used for calling the profile and
@@ -556,8 +576,17 @@ Set the global debug tracing function. It will be called on each\n\
function call. See the debugger chapter in the library manual."
);
+/*[clinic input]
+sys.gettrace
+
+Return the global debug tracing function set with sys.settrace.
+
+See the debugger chapter in the library manual.
+[clinic start generated code]*/
+
static PyObject *
-sys_gettrace(PyObject *self, PyObject *args)
+sys_gettrace_impl(PyObject *module)
+/*[clinic end generated code: output=e97e3a4d8c971b6e input=373b51bb2147f4d8]*/
{
PyThreadState *tstate = _PyThreadState_GET();
PyObject *temp = tstate->c_traceobj;
@@ -568,13 +597,6 @@ sys_gettrace(PyObject *self, PyObject *args)
return temp;
}
-PyDoc_STRVAR(gettrace_doc,
-"gettrace()\n\
-\n\
-Return the global debug tracing function set with sys.settrace.\n\
-See the debugger chapter in the library manual."
-);
-
static PyObject *
sys_setprofile(PyObject *self, PyObject *args)
{
@@ -594,8 +616,17 @@ Set the profiling function. It will be called on each function call\n\
and return. See the profiler chapter in the library manual."
);
+/*[clinic input]
+sys.getprofile
+
+Return the profiling function set with sys.setprofile.
+
+See the profiler chapter in the library manual.
+[clinic start generated code]*/
+
static PyObject *
-sys_getprofile(PyObject *self, PyObject *args)
+sys_getprofile_impl(PyObject *module)
+/*[clinic end generated code: output=579b96b373448188 input=1b3209d89a32965d]*/
{
PyThreadState *tstate = _PyThreadState_GET();
PyObject *temp = tstate->c_profileobj;
@@ -606,15 +637,23 @@ sys_getprofile(PyObject *self, PyObject *args)
return temp;
}
-PyDoc_STRVAR(getprofile_doc,
-"getprofile()\n\
-\n\
-Return the profiling function set with sys.setprofile.\n\
-See the profiler chapter in the library manual."
-);
+/*[clinic input]
+sys.setcheckinterval
+
+ n: int
+ /
+
+Set the async event check interval to n instructions.
+
+This tells the Python interpreter to check for asynchronous events
+every n instructions.
+
+This also affects how often thread switches occur.
+[clinic start generated code]*/
static PyObject *
-sys_setcheckinterval(PyObject *self, PyObject *args)
+sys_setcheckinterval_impl(PyObject *module, int n)
+/*[clinic end generated code: output=3f686cef07e6e178 input=7a35b17bf22a6227]*/
{
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"sys.getcheckinterval() and sys.setcheckinterval() "
@@ -622,24 +661,20 @@ sys_setcheckinterval(PyObject *self, PyObject *args)
"instead.", 1) < 0)
return NULL;
- int check_interval;
- if (!PyArg_ParseTuple(args, "i:setcheckinterval", &check_interval))
- return NULL;
-
PyInterpreterState *interp = _PyInterpreterState_Get();
- interp->check_interval = check_interval;
+ interp->check_interval = n;
Py_RETURN_NONE;
}
-PyDoc_STRVAR(setcheckinterval_doc,
-"setcheckinterval(n)\n\
-\n\
-Tell the Python interpreter to check for asynchronous events every\n\
-n instructions. This also affects how often thread switches occur."
-);
+/*[clinic input]
+sys.getcheckinterval
+
+Return the current check interval; see sys.setcheckinterval().
+[clinic start generated code]*/
static PyObject *
-sys_getcheckinterval(PyObject *self, PyObject *args)
+sys_getcheckinterval_impl(PyObject *module)
+/*[clinic end generated code: output=1b5060bf2b23a47c input=4b6589cbcca1db4e]*/
{
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"sys.getcheckinterval() and sys.setcheckinterval() "
@@ -650,56 +685,69 @@ sys_getcheckinterval(PyObject *self, PyObject *args)
return PyLong_FromLong(interp->check_interval);
}
-PyDoc_STRVAR(getcheckinterval_doc,
-"getcheckinterval() -> current check interval; see setcheckinterval()."
-);
+/*[clinic input]
+sys.setswitchinterval
+
+ interval: double
+ /
+
+Set the ideal thread switching delay inside the Python interpreter.
+
+The actual frequency of switching threads can be lower if the
+interpreter executes long sequences of uninterruptible code
+(this is implementation-specific and workload-dependent).
+
+The parameter must represent the desired switching delay in seconds
+A typical value is 0.005 (5 milliseconds).
+[clinic start generated code]*/
static PyObject *
-sys_setswitchinterval(PyObject *self, PyObject *args)
+sys_setswitchinterval_impl(PyObject *module, double interval)
+/*[clinic end generated code: output=65a19629e5153983 input=561b477134df91d9]*/
{
- double d;
- if (!PyArg_ParseTuple(args, "d:setswitchinterval", &d))
- return NULL;
- if (d <= 0.0) {
+ if (interval <= 0.0) {
PyErr_SetString(PyExc_ValueError,
"switch interval must be strictly positive");
return NULL;
}
- _PyEval_SetSwitchInterval((unsigned long) (1e6 * d));
+ _PyEval_SetSwitchInterval((unsigned long) (1e6 * interval));
Py_RETURN_NONE;
}
-PyDoc_STRVAR(setswitchinterval_doc,
-"setswitchinterval(n)\n\
-\n\
-Set the ideal thread switching delay inside the Python interpreter\n\
-The actual frequency of switching threads can be lower if the\n\
-interpreter executes long sequences of uninterruptible code\n\
-(this is implementation-specific and workload-dependent).\n\
-\n\
-The parameter must represent the desired switching delay in seconds\n\
-A typical value is 0.005 (5 milliseconds)."
-);
-static PyObject *
-sys_getswitchinterval(PyObject *self, PyObject *args)
+/*[clinic input]
+sys.getswitchinterval -> double
+
+Return the current thread switch interval; see sys.setswitchinterval().
+[clinic start generated code]*/
+
+static double
+sys_getswitchinterval_impl(PyObject *module)
+/*[clinic end generated code: output=a38c277c85b5096d input=bdf9d39c0ebbbb6f]*/
{
- return PyFloat_FromDouble(1e-6 * _PyEval_GetSwitchInterval());
+ return 1e-6 * _PyEval_GetSwitchInterval();
}
-PyDoc_STRVAR(getswitchinterval_doc,
-"getswitchinterval() -> current thread switch interval; see setswitchinterval()."
-);
+/*[clinic input]
+sys.setrecursionlimit
+
+ limit as new_limit: int
+ /
+
+Set the maximum depth of the Python interpreter stack to n.
+
+This limit prevents infinite recursion from causing an overflow of the C
+stack and crashing Python. The highest possible limit is platform-
+dependent.
+[clinic start generated code]*/
static PyObject *
-sys_setrecursionlimit(PyObject *self, PyObject *args)
+sys_setrecursionlimit_impl(PyObject *module, int new_limit)
+/*[clinic end generated code: output=35e1c64754800ace input=b0f7a23393924af3]*/
{
- int new_limit, mark;
+ int mark;
PyThreadState *tstate;
- if (!PyArg_ParseTuple(args, "i:setrecursionlimit", &new_limit))
- return NULL;
-
if (new_limit < 1) {
PyErr_SetString(PyExc_ValueError,
"recursion limit must be greater or equal than 1");
@@ -736,14 +784,15 @@ sys.set_coroutine_origin_tracking_depth
Enable or disable origin tracking for coroutine objects in this thread.
-Coroutine objects will track 'depth' frames of traceback information about
-where they came from, available in their cr_origin attribute. Set depth of 0
-to disable.
+Coroutine objects will track 'depth' frames of traceback information
+about where they came from, available in their cr_origin attribute.
+
+Set a depth of 0 to disable.
[clinic start generated code]*/
static PyObject *
sys_set_coroutine_origin_tracking_depth_impl(PyObject *module, int depth)
-/*[clinic end generated code: output=0a2123c1cc6759c5 input=9083112cccc1bdcb]*/
+/*[clinic end generated code: output=0a2123c1cc6759c5 input=a1d0a05f89d2c426]*/
{
if (depth < 0) {
PyErr_SetString(PyExc_ValueError, "depth must be >= 0");
@@ -766,8 +815,18 @@ sys_get_coroutine_origin_tracking_depth_impl(PyObject *module)
return _PyEval_GetCoroutineOriginTrackingDepth();
}
+/*[clinic input]
+sys.set_coroutine_wrapper
+
+ wrapper: object
+ /
+
+Set a wrapper for coroutine objects.
+[clinic start generated code]*/
+
static PyObject *
-sys_set_coroutine_wrapper(PyObject *self, PyObject *wrapper)
+sys_set_coroutine_wrapper(PyObject *module, PyObject *wrapper)
+/*[clinic end generated code: output=9c7db52d65f6b188 input=df6ac09a06afef34]*/
{
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"set_coroutine_wrapper is deprecated", 1) < 0) {
@@ -789,14 +848,15 @@ sys_set_coroutine_wrapper(PyObject *self, PyObject *wrapper)
Py_RETURN_NONE;
}
-PyDoc_STRVAR(set_coroutine_wrapper_doc,
-"set_coroutine_wrapper(wrapper)\n\
-\n\
-Set a wrapper for coroutine objects."
-);
+/*[clinic input]
+sys.get_coroutine_wrapper
+
+Return the wrapper for coroutines set by sys.set_coroutine_wrapper.
+[clinic start generated code]*/
static PyObject *
-sys_get_coroutine_wrapper(PyObject *self, PyObject *args)
+sys_get_coroutine_wrapper_impl(PyObject *module)
+/*[clinic end generated code: output=b74a7e4b14fe898e input=ef0351fb9ece0bb4]*/
{
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"get_coroutine_wrapper is deprecated", 1) < 0) {
@@ -810,12 +870,6 @@ sys_get_coroutine_wrapper(PyObject *self, PyObject *args)
return wrapper;
}
-PyDoc_STRVAR(get_coroutine_wrapper_doc,
-"get_coroutine_wrapper()\n\
-\n\
-Return the wrapper for coroutine objects set by sys.set_coroutine_wrapper."
-);
-
static PyTypeObject AsyncGenHooksType;
@@ -838,7 +892,6 @@ static PyStructSequence_Desc asyncgen_hooks_desc = {
2
};
-
static PyObject *
sys_set_asyncgen_hooks(PyObject *self, PyObject *args, PyObject *kw)
{
@@ -882,13 +935,22 @@ sys_set_asyncgen_hooks(PyObject *self, PyObject *args, PyObject *kw)
}
PyDoc_STRVAR(set_asyncgen_hooks_doc,
-"set_asyncgen_hooks(*, firstiter=None, finalizer=None)\n\
+"set_asyncgen_hooks(* [, firstiter] [, finalizer])\n\
\n\
Set a finalizer for async generators objects."
);
+/*[clinic input]
+sys.get_asyncgen_hooks
+
+Return the installed asynchronous generators hooks.
+
+This returns a namedtuple of the form (firstiter, finalizer).
+[clinic start generated code]*/
+
static PyObject *
-sys_get_asyncgen_hooks(PyObject *self, PyObject *args)
+sys_get_asyncgen_hooks_impl(PyObject *module)
+/*[clinic end generated code: output=53a253707146f6cf input=3676b9ea62b14625]*/
{
PyObject *res;
PyObject *firstiter = _PyEval_GetAsyncGenFirstiter();
@@ -916,13 +978,6 @@ sys_get_asyncgen_hooks(PyObject *self, PyObject *args)
return res;
}
-PyDoc_STRVAR(get_asyncgen_hooks_doc,
-"get_asyncgen_hooks()\n\
-\n\
-Return a namedtuple of installed asynchronous generators hooks \
-(firstiter, finalizer)."
-);
-
static PyTypeObject Hash_InfoType;
@@ -988,45 +1043,24 @@ get_hash_info(void)
}
return hash_info;
}
+/*[clinic input]
+sys.getrecursionlimit
+Return the current value of the recursion limit.
-PyDoc_STRVAR(setrecursionlimit_doc,
-"setrecursionlimit(n)\n\
-\n\
-Set the maximum depth of the Python interpreter stack to n. This\n\
-limit prevents infinite recursion from causing an overflow of the C\n\
-stack and crashing Python. The highest possible limit is platform-\n\
-dependent."
-);
+The recursion limit is the maximum depth of the Python interpreter
+stack. This limit prevents infinite recursion from causing an overflow
+of the C stack and crashing Python.
+[clinic start generated code]*/
static PyObject *
-sys_getrecursionlimit(PyObject *self, PyObject *Py_UNUSED(ignored))
+sys_getrecursionlimit_impl(PyObject *module)
+/*[clinic end generated code: output=d571fb6b4549ef2e input=1c6129fd2efaeea8]*/
{
return PyLong_FromLong(Py_GetRecursionLimit());
}
-PyDoc_STRVAR(getrecursionlimit_doc,
-"getrecursionlimit()\n\
-\n\
-Return the current value of the recursion limit, the maximum depth\n\
-of the Python interpreter stack. This limit prevents infinite\n\
-recursion from causing an overflow of the C stack and crashing Python."
-);
-
#ifdef MS_WINDOWS
-PyDoc_STRVAR(getwindowsversion_doc,
-"getwindowsversion()\n\
-\n\
-Return information about the running version of Windows as a named tuple.\n\
-The members are named: major, minor, build, platform, service_pack,\n\
-service_pack_major, service_pack_minor, suite_mask, and product_type. For\n\
-backward compatibility, only the first 5 items are available by indexing.\n\
-All elements are numbers, except service_pack and platform_type which are\n\
-strings, and platform_version which is a 3-tuple. Platform is always 2.\n\
-Product_type may be 1 for a workstation, 2 for a domain controller, 3 for a\n\
-server. Platform_version is a 3-tuple containing a version number that is\n\
-intended for identifying the OS rather than feature detection."
-);
static PyTypeObject WindowsVersionType = {0, 0, 0, 0, 0, 0};
@@ -1045,12 +1079,12 @@ static PyStructSequence_Field windows_version_fields[] = {
};
static PyStructSequence_Desc windows_version_desc = {
- "sys.getwindowsversion", /* name */
- getwindowsversion_doc, /* doc */
- windows_version_fields, /* fields */
- 5 /* For backward compatibility,
- only the first 5 items are accessible
- via indexing, the rest are name only */
+ "sys.getwindowsversion", /* name */
+ sys_getwindowsversion__doc__, /* doc */
+ windows_version_fields, /* fields */
+ 5 /* For backward compatibility,
+ only the first 5 items are accessible
+ via indexing, the rest are name only */
};
/* Disable deprecation warnings about GetVersionEx as the result is
@@ -1059,8 +1093,25 @@ static PyStructSequence_Desc windows_version_desc = {
#pragma warning(push)
#pragma warning(disable:4996)
+/*[clinic input]
+sys.getwindowsversion
+
+Return info about the running version of Windows as a named tuple.
+
+The members are named: major, minor, build, platform, service_pack,
+service_pack_major, service_pack_minor, suite_mask, product_type and
+platform_version. For backward compatibility, only the first 5 items
+are available by indexing. All elements are numbers, except
+service_pack and platform_type which are strings, and platform_version
+which is a 3-tuple. Platform is always 2. Product_type may be 1 for a
+workstation, 2 for a domain controller, 3 for a server.
+Platform_version is a 3-tuple containing a version number that is
+intended for identifying the OS rather than feature detection.
+[clinic start generated code]*/
+
static PyObject *
-sys_getwindowsversion(PyObject *self)
+sys_getwindowsversion_impl(PyObject *module)
+/*[clinic end generated code: output=1ec063280b932857 input=73a228a328fee63a]*/
{
PyObject *version;
int pos = 0;
@@ -1128,18 +1179,21 @@ sys_getwindowsversion(PyObject *self)
#pragma warning(pop)
-PyDoc_STRVAR(enablelegacywindowsfsencoding_doc,
-"_enablelegacywindowsfsencoding()\n\
-\n\
-Changes the default filesystem encoding to mbcs:replace for consistency\n\
-with earlier versions of Python. See PEP 529 for more information.\n\
-\n\
-This is equivalent to defining the PYTHONLEGACYWINDOWSFSENCODING\n\
-environment variable before launching Python."
-);
+/*[clinic input]
+sys._enablelegacywindowsfsencoding
+
+Changes the default filesystem encoding to mbcs:replace.
+
+This is done for consistency with earlier versions of Python. See PEP
+529 for more information.
+
+This is equivalent to defining the PYTHONLEGACYWINDOWSFSENCODING
+environment variable before launching Python.
+[clinic start generated code]*/
static PyObject *
-sys_enablelegacywindowsfsencoding(PyObject *self)
+sys__enablelegacywindowsfsencoding_impl(PyObject *module)
+/*[clinic end generated code: output=f5c3855b45e24fe9 input=2bfa931a20704492]*/
{
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
_PyCoreConfig *config = &interp->core_config;
@@ -1171,52 +1225,68 @@ sys_enablelegacywindowsfsencoding(PyObject *self)
#endif /* MS_WINDOWS */
#ifdef HAVE_DLOPEN
+
+/*[clinic input]
+sys.setdlopenflags
+
+ flags as new_val: int
+ /
+
+Set the flags used by the interpreter for dlopen calls.
+
+This is used, for example, when the interpreter loads extension
+modules. Among other things, this will enable a lazy resolving of
+symbols when importing a module, if called as sys.setdlopenflags(0).
+To share symbols across extension modules, call as
+sys.setdlopenflags(os.RTLD_GLOBAL). Symbolic names for the flag
+modules can be found in the os module (RTLD_xxx constants, e.g.
+os.RTLD_LAZY).
+[clinic start generated code]*/
+
static PyObject *
-sys_setdlopenflags(PyObject *self, PyObject *args)
+sys_setdlopenflags_impl(PyObject *module, int new_val)
+/*[clinic end generated code: output=ec918b7fe0a37281 input=4c838211e857a77f]*/
{
- int new_val;
- if (!PyArg_ParseTuple(args, "i:setdlopenflags", &new_val))
- return NULL;
PyInterpreterState *interp = _PyInterpreterState_Get();
interp->dlopenflags = new_val;
Py_RETURN_NONE;
}
-PyDoc_STRVAR(setdlopenflags_doc,
-"setdlopenflags(n) -> None\n\
-\n\
-Set the flags used by the interpreter for dlopen calls, such as when the\n\
-interpreter loads extension modules. Among other things, this will enable\n\
-a lazy resolving of symbols when importing a module, if called as\n\
-sys.setdlopenflags(0). To share symbols across extension modules, call as\n\
-sys.setdlopenflags(os.RTLD_GLOBAL). Symbolic names for the flag modules\n\
-can be found in the os module (RTLD_xxx constants, e.g. os.RTLD_LAZY).");
+
+/*[clinic input]
+sys.getdlopenflags
+
+Return the current value of the flags that are used for dlopen calls.
+
+The flag constants are defined in the os module.
+[clinic start generated code]*/
static PyObject *
-sys_getdlopenflags(PyObject *self, PyObject *args)
+sys_getdlopenflags_impl(PyObject *module)
+/*[clinic end generated code: output=e92cd1bc5005da6e input=dc4ea0899c53b4b6]*/
{
PyInterpreterState *interp = _PyInterpreterState_Get();
return PyLong_FromLong(interp->dlopenflags);
}
-PyDoc_STRVAR(getdlopenflags_doc,
-"getdlopenflags() -> int\n\
-\n\
-Return the current value of the flags that are used for dlopen calls.\n\
-The flag constants are defined in the os module.");
-
#endif /* HAVE_DLOPEN */
#ifdef USE_MALLOPT
/* Link with -lmalloc (or -lmpc) on an SGI */
#include <malloc.h>
+/*[clinic input]
+sys.mdebug
+
+ flag: int
+ /
+[clinic start generated code]*/
+
static PyObject *
-sys_mdebug(PyObject *self, PyObject *args)
+sys_mdebug_impl(PyObject *module, int flag)
+/*[clinic end generated code: output=5431d545847c3637 input=151d150ae1636f8a]*/
{
int flag;
- if (!PyArg_ParseTuple(args, "i:mdebug", &flag))
- return NULL;
mallopt(M_DEBUG, flag);
Py_RETURN_NONE;
}
@@ -1292,48 +1362,64 @@ sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds)
}
PyDoc_STRVAR(getsizeof_doc,
-"getsizeof(object, default) -> int\n\
+"getsizeof(object [, default]) -> int\n\
\n\
Return the size of object in bytes.");
-static PyObject *
-sys_getrefcount(PyObject *self, PyObject *arg)
+/*[clinic input]
+sys.getrefcount -> Py_ssize_t
+
+ object: object
+ /
+
+Return the reference count of object.
+
+The count returned is generally one higher than you might expect,
+because it includes the (temporary) reference as an argument to
+getrefcount().
+[clinic start generated code]*/
+
+static Py_ssize_t
+sys_getrefcount_impl(PyObject *module, PyObject *object)
+/*[clinic end generated code: output=5fd477f2264b85b2 input=bf474efd50a21535]*/
{
- return PyLong_FromSsize_t(arg->ob_refcnt);
+ return object->ob_refcnt;
}
#ifdef Py_REF_DEBUG
-static PyObject *
-sys_gettotalrefcount(PyObject *self, PyObject *Py_UNUSED(ignored))
+/*[clinic input]
+sys.gettotalrefcount -> Py_ssize_t
+[clinic start generated code]*/
+
+static Py_ssize_t
+sys_gettotalrefcount_impl(PyObject *module)
+/*[clinic end generated code: output=4103886cf17c25bc input=53b744faa5d2e4f6]*/
{
- return PyLong_FromSsize_t(_Py_GetRefTotal());
+ return _Py_GetRefTotal();
}
#endif /* Py_REF_DEBUG */
-PyDoc_STRVAR(getrefcount_doc,
-"getrefcount(object) -> integer\n\
-\n\
-Return the reference count of object. The count returned is generally\n\
-one higher than you might expect, because it includes the (temporary)\n\
-reference as an argument to getrefcount()."
-);
+/*[clinic input]
+sys.getallocatedblocks -> Py_ssize_t
-static PyObject *
-sys_getallocatedblocks(PyObject *self, PyObject *Py_UNUSED(ignored))
+Return the number of memory blocks currently allocated.
+[clinic start generated code]*/
+
+static Py_ssize_t
+sys_getallocatedblocks_impl(PyObject *module)
+/*[clinic end generated code: output=f0c4e873f0b6dcf7 input=dab13ee346a0673e]*/
{
- return PyLong_FromSsize_t(_Py_GetAllocatedBlocks());
+ return _Py_GetAllocatedBlocks();
}
-PyDoc_STRVAR(getallocatedblocks_doc,
-"getallocatedblocks() -> integer\n\
-\n\
-Return the number of memory blocks currently allocated, regardless of their\n\
-size."
-);
-
#ifdef COUNT_ALLOCS
+/*[clinic input]
+sys.getcounts
+[clinic start generated code]*/
+
static PyObject *
-sys_getcounts(PyObject *self)
+sys_getcounts_impl(PyObject *module)
+/*[clinic end generated code: output=20df00bc164f43cb input=ad2ec7bda5424953]*/
{
extern PyObject *_Py_get_counts(void);
@@ -1341,26 +1427,28 @@ sys_getcounts(PyObject *self)
}
#endif
-PyDoc_STRVAR(getframe_doc,
-"_getframe([depth]) -> frameobject\n\
-\n\
-Return a frame object from the call stack. If optional integer depth is\n\
-given, return the frame object that many calls below the top of the stack.\n\
-If that is deeper than the call stack, ValueError is raised. The default\n\
-for depth is zero, returning the frame at the top of the call stack.\n\
-\n\
-This function should be used for internal and specialized\n\
-purposes only."
-);
+/*[clinic input]
+sys._getframe
+
+ depth: int = 0
+ /
+
+Return a frame object from the call stack.
+
+If optional integer depth is given, return the frame object that many
+calls below the top of the stack. If that is deeper than the call
+stack, ValueError is raised. The default for depth is zero, returning
+the frame at the top of the call stack.
+
+This function should be used for internal and specialized purposes
+only.
+[clinic start generated code]*/
static PyObject *
-sys_getframe(PyObject *self, PyObject *args)
+sys__getframe_impl(PyObject *module, int depth)
+/*[clinic end generated code: output=d438776c04d59804 input=c1be8a6464b11ee5]*/
{
PyFrameObject *f = _PyThreadState_GET()->frame;
- int depth = -1;
-
- if (!PyArg_ParseTuple(args, "|i:_getframe", &depth))
- return NULL;
while (depth > 0 && f != NULL) {
f = f->f_back;
@@ -1375,63 +1463,70 @@ sys_getframe(PyObject *self, PyObject *args)
return (PyObject*)f;
}
-PyDoc_STRVAR(current_frames_doc,
-"_current_frames() -> dictionary\n\
-\n\
-Return a dictionary mapping each current thread T's thread id to T's\n\
-current stack frame.\n\
-\n\
-This function should be used for specialized purposes only."
-);
+/*[clinic input]
+sys._current_frames
+
+Return a dict mapping each thread's thread id to its current stack frame.
+
+This function should be used for specialized purposes only.
+[clinic start generated code]*/
static PyObject *
-sys_current_frames(PyObject *self, PyObject *noargs)
+sys__current_frames_impl(PyObject *module)
+/*[clinic end generated code: output=d2a41ac0a0a3809a input=2a9049c5f5033691]*/
{
return _PyThread_CurrentFrames();
}
-PyDoc_STRVAR(call_tracing_doc,
-"call_tracing(func, args) -> object\n\
-\n\
-Call func(*args), while tracing is enabled. The tracing state is\n\
-saved, and restored afterwards. This is intended to be called from\n\
-a debugger from a checkpoint, to recursively debug some other code."
-);
+/*[clinic input]
+sys.call_tracing
+
+ func: object
+ args as funcargs: object(subclass_of='&PyTuple_Type')
+ /
+
+Call func(*args), while tracing is enabled.
+
+The tracing state is saved, and restored afterwards. This is intended
+to be called from a debugger from a checkpoint, to recursively debug
+some other code.
+[clinic start generated code]*/
static PyObject *
-sys_call_tracing(PyObject *self, PyObject *args)
+sys_call_tracing_impl(PyObject *module, PyObject *func, PyObject *funcargs)
+/*[clinic end generated code: output=7e4999853cd4e5a6 input=5102e8b11049f92f]*/
{
- PyObject *func, *funcargs;
- if (!PyArg_ParseTuple(args, "OO!:call_tracing", &func, &PyTuple_Type, &funcargs))
- return NULL;
return _PyEval_CallTracing(func, funcargs);
}
-PyDoc_STRVAR(callstats_doc,
-"callstats() -> tuple of integers\n\
-\n\
-Return a tuple of function call statistics, if CALL_PROFILE was defined\n\
-when Python was built. Otherwise, return None.\n\
-\n\
-When enabled, this function returns detailed, implementation-specific\n\
-details about the number of function calls executed. The return value is\n\
-a 11-tuple where the entries in the tuple are counts of:\n\
-0. all function calls\n\
-1. calls to PyFunction_Type objects\n\
-2. PyFunction calls that do not create an argument tuple\n\
-3. PyFunction calls that do not create an argument tuple\n\
- and bypass PyEval_EvalCodeEx()\n\
-4. PyMethod calls\n\
-5. PyMethod calls on bound methods\n\
-6. PyType calls\n\
-7. PyCFunction calls\n\
-8. generator calls\n\
-9. All other calls\n\
-10. Number of stack pops performed by call_function()"
-);
+/*[clinic input]
+sys.callstats
+
+Return a tuple of function call statistics.
+
+A tuple is returned only if CALL_PROFILE was defined when Python was
+built. Otherwise, this returns None.
+
+When enabled, this function returns detailed, implementation-specific
+details about the number of function calls executed. The return value
+is a 11-tuple where the entries in the tuple are counts of:
+0. all function calls
+1. calls to PyFunction_Type objects
+2. PyFunction calls that do not create an argument tuple
+3. PyFunction calls that do not create an argument tuple
+ and bypass PyEval_EvalCodeEx()
+4. PyMethod calls
+5. PyMethod calls on bound methods
+6. PyType calls
+7. PyCFunction calls
+8. generator calls
+9. All other calls
+10. Number of stack pops performed by call_function()
+[clinic start generated code]*/
static PyObject *
-sys_callstats(PyObject *self, PyObject *Py_UNUSED(ignored))
+sys_callstats_impl(PyObject *module)
+/*[clinic end generated code: output=edc4a74957fa8def input=d447d8d224d5d175]*/
{
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"sys.callstats() has been deprecated in Python 3.7 "
@@ -1447,8 +1542,18 @@ sys_callstats(PyObject *self, PyObject *Py_UNUSED(ignored))
extern "C" {
#endif
+/*[clinic input]
+sys._debugmallocstats
+
+Print summary info to stderr about the state of pymalloc's structures.
+
+In Py_DEBUG mode, also perform some expensive internal consistency
+checks.
+[clinic start generated code]*/
+
static PyObject *
-sys_debugmallocstats(PyObject *self, PyObject *args)
+sys__debugmallocstats_impl(PyObject *module)
+/*[clinic end generated code: output=ec3565f8c7cee46a input=33c0c9c416f98424]*/
{
#ifdef WITH_PYMALLOC
if (_PyObject_DebugMallocStats(stderr)) {
@@ -1459,15 +1564,6 @@ sys_debugmallocstats(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
-PyDoc_STRVAR(debugmallocstats_doc,
-"_debugmallocstats()\n\
-\n\
-Print summary info to stderr about the state of\n\
-pymalloc's structures.\n\
-\n\
-In Py_DEBUG mode, also perform some expensive internal consistency\n\
-checks.\n\
-");
#ifdef Py_TRACE_REFS
/* Defined in objects.c because it uses static globals if that file */
@@ -1483,8 +1579,16 @@ extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *);
}
#endif
+
+/*[clinic input]
+sys._clear_type_cache
+
+Clear the internal type lookup cache.
+[clinic start generated code]*/
+
static PyObject *
-sys_clear_type_cache(PyObject* self, PyObject* args)
+sys__clear_type_cache_impl(PyObject *module)
+/*[clinic end generated code: output=20e48ca54a6f6971 input=127f3e04a8d9b555]*/
{
PyType_ClearCache();
Py_RETURN_NONE;
@@ -1494,25 +1598,29 @@ PyDoc_STRVAR(sys_clear_type_cache__doc__,
"_clear_type_cache() -> None\n\
Clear the internal type lookup cache.");
+/*[clinic input]
+sys.is_finalizing
+
+Return True if Python is exiting.
+[clinic start generated code]*/
+
static PyObject *
-sys_is_finalizing(PyObject* self, PyObject* args)
+sys_is_finalizing_impl(PyObject *module)
+/*[clinic end generated code: output=735b5ff7962ab281 input=f0df747a039948a5]*/
{
return PyBool_FromLong(_Py_IsFinalizing());
}
-PyDoc_STRVAR(is_finalizing_doc,
-"is_finalizing()\n\
-Return True if Python is exiting.");
-
-
#ifdef ANDROID_API_LEVEL
-PyDoc_STRVAR(getandroidapilevel_doc,
-"getandroidapilevel()\n\
-\n\
-Return the build time API version of Android as an integer.");
+/*[clinic input]
+sys.getandroidapilevel
+
+Return the build time API version of Android as an integer.
+[clinic start generated code]*/
static PyObject *
-sys_getandroidapilevel(PyObject *self)
+sys_getandroidapilevel_impl(PyObject *module)
+/*[clinic end generated code: output=214abf183a1c70c1 input=3e6d6c9fcdd24ac6]*/
{
return PyLong_FromLong(ANDROID_API_LEVEL);
}
@@ -1523,92 +1631,56 @@ static PyMethodDef sys_methods[] = {
/* Might as well keep this in alphabetic order */
{"breakpointhook", (PyCFunction)(void(*)(void))sys_breakpointhook,
METH_FASTCALL | METH_KEYWORDS, breakpointhook_doc},
- {"callstats", sys_callstats, METH_NOARGS,
- callstats_doc},
- {"_clear_type_cache", sys_clear_type_cache, METH_NOARGS,
- sys_clear_type_cache__doc__},
- {"_current_frames", sys_current_frames, METH_NOARGS,
- current_frames_doc},
- {"displayhook", sys_displayhook, METH_O, displayhook_doc},
- {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
- {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
- {"exit", sys_exit, METH_VARARGS, exit_doc},
- {"getdefaultencoding", sys_getdefaultencoding,
- METH_NOARGS, getdefaultencoding_doc},
-#ifdef HAVE_DLOPEN
- {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,
- getdlopenflags_doc},
-#endif
- {"getallocatedblocks", sys_getallocatedblocks, METH_NOARGS,
- getallocatedblocks_doc},
-#ifdef COUNT_ALLOCS
- {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS},
-#endif
+ SYS_CALLSTATS_METHODDEF
+ SYS__CLEAR_TYPE_CACHE_METHODDEF
+ SYS__CURRENT_FRAMES_METHODDEF
+ SYS_DISPLAYHOOK_METHODDEF
+ SYS_EXC_INFO_METHODDEF
+ SYS_EXCEPTHOOK_METHODDEF
+ SYS_EXIT_METHODDEF
+ SYS_GETDEFAULTENCODING_METHODDEF
+ SYS_GETDLOPENFLAGS_METHODDEF
+ SYS_GETALLOCATEDBLOCKS_METHODDEF
+ SYS_GETCOUNTS_METHODDEF
#ifdef DYNAMIC_EXECUTION_PROFILE
{"getdxp", _Py_GetDXProfile, METH_VARARGS},
#endif
- {"getfilesystemencoding", sys_getfilesystemencoding,
- METH_NOARGS, getfilesystemencoding_doc},
- { "getfilesystemencodeerrors", sys_getfilesystemencodeerrors,
- METH_NOARGS, getfilesystemencodeerrors_doc },
+ SYS_GETFILESYSTEMENCODING_METHODDEF
+ SYS_GETFILESYSTEMENCODEERRORS_METHODDEF
#ifdef Py_TRACE_REFS
{"getobjects", _Py_GetObjects, METH_VARARGS},
#endif
-#ifdef Py_REF_DEBUG
- {"gettotalrefcount", sys_gettotalrefcount, METH_NOARGS},
-#endif
- {"getrefcount", (PyCFunction)sys_getrefcount, METH_O, getrefcount_doc},
- {"getrecursionlimit", sys_getrecursionlimit, METH_NOARGS,
- getrecursionlimit_doc},
+ SYS_GETTOTALREFCOUNT_METHODDEF
+ SYS_GETREFCOUNT_METHODDEF
+ SYS_GETRECURSIONLIMIT_METHODDEF
{"getsizeof", (PyCFunction)(void(*)(void))sys_getsizeof,
METH_VARARGS | METH_KEYWORDS, getsizeof_doc},
- {"_getframe", sys_getframe, METH_VARARGS, getframe_doc},
-#ifdef MS_WINDOWS
- {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS,
- getwindowsversion_doc},
- {"_enablelegacywindowsfsencoding", (PyCFunction)sys_enablelegacywindowsfsencoding,
- METH_NOARGS, enablelegacywindowsfsencoding_doc },
-#endif /* MS_WINDOWS */
- {"intern", sys_intern, METH_VARARGS, intern_doc},
- {"is_finalizing", sys_is_finalizing, METH_NOARGS, is_finalizing_doc},
-#ifdef USE_MALLOPT
- {"mdebug", sys_mdebug, METH_VARARGS},
-#endif
- {"setcheckinterval", sys_setcheckinterval, METH_VARARGS,
- setcheckinterval_doc},
- {"getcheckinterval", sys_getcheckinterval, METH_NOARGS,
- getcheckinterval_doc},
- {"setswitchinterval", sys_setswitchinterval, METH_VARARGS,
- setswitchinterval_doc},
- {"getswitchinterval", sys_getswitchinterval, METH_NOARGS,
- getswitchinterval_doc},
-#ifdef HAVE_DLOPEN
- {"setdlopenflags", sys_setdlopenflags, METH_VARARGS,
- setdlopenflags_doc},
-#endif
+ SYS__GETFRAME_METHODDEF
+ SYS_GETWINDOWSVERSION_METHODDEF
+ SYS__ENABLELEGACYWINDOWSFSENCODING_METHODDEF
+ SYS_INTERN_METHODDEF
+ SYS_IS_FINALIZING_METHODDEF
+ SYS_MDEBUG_METHODDEF
+ SYS_SETCHECKINTERVAL_METHODDEF
+ SYS_GETCHECKINTERVAL_METHODDEF
+ SYS_SETSWITCHINTERVAL_METHODDEF
+ SYS_GETSWITCHINTERVAL_METHODDEF
+ SYS_SETDLOPENFLAGS_METHODDEF
{"setprofile", sys_setprofile, METH_O, setprofile_doc},
- {"getprofile", sys_getprofile, METH_NOARGS, getprofile_doc},
- {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
- setrecursionlimit_doc},
+ SYS_GETPROFILE_METHODDEF
+ SYS_SETRECURSIONLIMIT_METHODDEF
{"settrace", sys_settrace, METH_O, settrace_doc},
- {"gettrace", sys_gettrace, METH_NOARGS, gettrace_doc},
- {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
- {"_debugmallocstats", sys_debugmallocstats, METH_NOARGS,
- debugmallocstats_doc},
+ SYS_GETTRACE_METHODDEF
+ SYS_CALL_TRACING_METHODDEF
+ SYS__DEBUGMALLOCSTATS_METHODDEF
SYS_SET_COROUTINE_ORIGIN_TRACKING_DEPTH_METHODDEF
SYS_GET_COROUTINE_ORIGIN_TRACKING_DEPTH_METHODDEF
- {"set_coroutine_wrapper", sys_set_coroutine_wrapper, METH_O,
- set_coroutine_wrapper_doc},
- {"get_coroutine_wrapper", sys_get_coroutine_wrapper, METH_NOARGS,
- get_coroutine_wrapper_doc},
+ SYS_SET_COROUTINE_WRAPPER_METHODDEF
+ SYS_GET_COROUTINE_WRAPPER_METHODDEF
{"set_asyncgen_hooks", (PyCFunction)(void(*)(void))sys_set_asyncgen_hooks,
METH_VARARGS | METH_KEYWORDS, set_asyncgen_hooks_doc},
- {"get_asyncgen_hooks", sys_get_asyncgen_hooks, METH_NOARGS,
- get_asyncgen_hooks_doc},
-#ifdef ANDROID_API_LEVEL
- {"getandroidapilevel", (PyCFunction)sys_getandroidapilevel, METH_NOARGS,
- getandroidapilevel_doc},
-#endif
+ SYS_GET_ASYNCGEN_HOOKS_METHODDEF
+ SYS_GETANDROIDAPILEVEL_METHODDEF
{NULL, NULL} /* sentinel */
};
1
0

Dec. 31, 2018
https://github.com/python/cpython/commit/052b2dfdc967a8c061ff9561534e905009…
commit: 052b2dfdc967a8c061ff9561534e905009b88b8c
branch: master
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: GitHub <noreply(a)github.com>
date: 2018-12-31T14:15:16+02:00
summary:
bpo-32492: Tweak _collections._tuplegetter. (GH-11367)
* Replace the docstrings cache with sys.intern().
* Improve tests.
* Unify names of tp_descr_get and tp_descr_set functions.
files:
M Lib/collections/__init__.py
M Lib/test/test_collections.py
M Lib/test/test_pydoc.py
M Modules/_collectionsmodule.c
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index 0b74c3f8915f..c31d7b79185d 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -316,8 +316,6 @@ def __eq__(self, other):
except ImportError:
_tuplegetter = lambda index, doc: property(_itemgetter(index), doc=doc)
-_nt_itemgetters = {}
-
def namedtuple(typename, field_names, *, rename=False, defaults=None, module=None):
"""Returns a new subclass of tuple with named fields.
@@ -456,16 +454,9 @@ def __getnewargs__(self):
'_asdict': _asdict,
'__getnewargs__': __getnewargs__,
}
- cache = _nt_itemgetters
for index, name in enumerate(field_names):
- try:
- doc = cache[index]
- except KeyError:
- doc = f'Alias for field number {index}'
- cache[index] = doc
-
- tuplegetter_object = _tuplegetter(index, doc)
- class_namespace[name] = tuplegetter_object
+ doc = _sys.intern(f'Alias for field number {index}')
+ class_namespace[name] = _tuplegetter(index, doc)
result = type(typename, (tuple,), class_namespace)
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index c0815947f908..74372d28ed05 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -3,6 +3,7 @@
import collections
import copy
import doctest
+import inspect
import operator
import pickle
from random import choice, randrange
@@ -281,20 +282,50 @@ def test_defaults(self):
self.assertEqual(Point(1), (1, 20))
self.assertEqual(Point(), (10, 20))
+ def test_readonly(self):
+ Point = namedtuple('Point', 'x y')
+ p = Point(11, 22)
+ with self.assertRaises(AttributeError):
+ p.x = 33
+ with self.assertRaises(AttributeError):
+ del p.x
+ with self.assertRaises(TypeError):
+ p[0] = 33
+ with self.assertRaises(TypeError):
+ del p[0]
+ self.assertEqual(p.x, 11)
+ self.assertEqual(p[0], 11)
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_factory_doc_attr(self):
Point = namedtuple('Point', 'x y')
self.assertEqual(Point.__doc__, 'Point(x, y)')
+ Point.__doc__ = '2D point'
+ self.assertEqual(Point.__doc__, '2D point')
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
- def test_doc_writable(self):
+ def test_field_doc(self):
Point = namedtuple('Point', 'x y')
self.assertEqual(Point.x.__doc__, 'Alias for field number 0')
+ self.assertEqual(Point.y.__doc__, 'Alias for field number 1')
Point.x.__doc__ = 'docstring for Point.x'
self.assertEqual(Point.x.__doc__, 'docstring for Point.x')
+ # namedtuple can mutate doc of descriptors independently
+ Vector = namedtuple('Vector', 'x y')
+ self.assertEqual(Vector.x.__doc__, 'Alias for field number 0')
+ Vector.x.__doc__ = 'docstring for Vector.x'
+ self.assertEqual(Vector.x.__doc__, 'docstring for Vector.x')
+
+ @support.cpython_only
+ @unittest.skipIf(sys.flags.optimize >= 2,
+ "Docstrings are omitted with -O2 and above")
+ def test_field_doc_reuse(self):
+ P = namedtuple('P', ['m', 'n'])
+ Q = namedtuple('Q', ['o', 'p'])
+ self.assertIs(P.m.__doc__, Q.o.__doc__)
+ self.assertIs(P.n.__doc__, Q.p.__doc__)
def test_name_fixer(self):
for spec, renamed in [
@@ -319,16 +350,18 @@ def test_instance(self):
self.assertEqual(p, Point(y=22, x=11))
self.assertEqual(p, Point(*(11, 22)))
self.assertEqual(p, Point(**dict(x=11, y=22)))
- self.assertRaises(TypeError, Point, 1) # too few args
- self.assertRaises(TypeError, Point, 1, 2, 3) # too many args
- self.assertRaises(TypeError, eval, 'Point(XXX=1, y=2)', locals()) # wrong keyword argument
- self.assertRaises(TypeError, eval, 'Point(x=1)', locals()) # missing keyword argument
+ self.assertRaises(TypeError, Point, 1) # too few args
+ self.assertRaises(TypeError, Point, 1, 2, 3) # too many args
+ with self.assertRaises(TypeError): # wrong keyword argument
+ Point(XXX=1, y=2)
+ with self.assertRaises(TypeError): # missing keyword argument
+ Point(x=1)
self.assertEqual(repr(p), 'Point(x=11, y=22)')
self.assertNotIn('__weakref__', dir(p))
- self.assertEqual(p, Point._make([11, 22])) # test _make classmethod
- self.assertEqual(p._fields, ('x', 'y')) # test _fields attribute
- self.assertEqual(p._replace(x=1), (1, 22)) # test _replace method
- self.assertEqual(p._asdict(), dict(x=11, y=22)) # test _asdict method
+ self.assertEqual(p, Point._make([11, 22])) # test _make classmethod
+ self.assertEqual(p._fields, ('x', 'y')) # test _fields attribute
+ self.assertEqual(p._replace(x=1), (1, 22)) # test _replace method
+ self.assertEqual(p._asdict(), dict(x=11, y=22)) # test _asdict method
try:
p._replace(x=1, error=2)
@@ -360,11 +393,15 @@ def test_tupleness(self):
x, y = p
self.assertEqual(p, (x, y)) # unpacks like a tuple
self.assertEqual((p[0], p[1]), (11, 22)) # indexable like a tuple
- self.assertRaises(IndexError, p.__getitem__, 3)
+ with self.assertRaises(IndexError):
+ p[3]
+ self.assertEqual(p[-1], 22)
+ self.assertEqual(hash(p), hash((11, 22)))
self.assertEqual(p.x, x)
self.assertEqual(p.y, y)
- self.assertRaises(AttributeError, eval, 'p.z', locals())
+ with self.assertRaises(AttributeError):
+ p.z
def test_odd_sizes(self):
Zero = namedtuple('Zero', '')
@@ -514,13 +551,13 @@ class Point(namedtuple('_Point', ['x', 'y'])):
a.w = 5
self.assertEqual(a.__dict__, {'w': 5})
- def test_namedtuple_can_mutate_doc_of_descriptors_independently(self):
- A = namedtuple('A', 'x y')
- B = namedtuple('B', 'x y')
- A.x.__doc__ = 'foo'
- B.x.__doc__ = 'bar'
- self.assertEqual(A.x.__doc__, 'foo')
- self.assertEqual(B.x.__doc__, 'bar')
+ def test_field_descriptor(self):
+ Point = namedtuple('Point', 'x y')
+ p = Point(11, 22)
+ self.assertTrue(inspect.isdatadescriptor(Point.x))
+ self.assertEqual(Point.x.__get__(p), 11)
+ self.assertRaises(AttributeError, Point.x.__set__, p, 33)
+ self.assertRaises(AttributeError, Point.x.__delete__, p)
################################################################################
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
index c58a8b13e76d..ffe80fc06fc6 100644
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -687,6 +687,16 @@ def test_help_output_redirect(self):
finally:
pydoc.getpager = getpager_old
+ def test_namedtuple_fields(self):
+ Person = namedtuple('Person', ['nickname', 'firstname'])
+ with captured_stdout() as help_io:
+ pydoc.help(Person)
+ helptext = help_io.getvalue()
+ self.assertIn("nickname", helptext)
+ self.assertIn("firstname", helptext)
+ self.assertIn("Alias for field number 0", helptext)
+ self.assertIn("Alias for field number 1", helptext)
+
def test_namedtuple_public_underscore(self):
NT = namedtuple('NT', ['abc', 'def'], rename=True)
with captured_stdout() as help_io:
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index cc325e1aaac4..a2b683e16663 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -2336,7 +2336,7 @@ _count_elements(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
-/* Helper functions for namedtuples */
+/* Helper function for namedtuple() ************************************/
typedef struct {
PyObject_HEAD
@@ -2369,9 +2369,11 @@ tuplegetter_new_impl(PyTypeObject *type, Py_ssize_t index, PyObject *doc)
}
static PyObject *
-tuplegetterdescr_get(PyObject *self, PyObject *obj, PyObject *type)
+tuplegetter_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
+ Py_ssize_t index = ((_tuplegetterobject*)self)->index;
PyObject *result;
+
if (obj == NULL) {
Py_INCREF(self);
return self;
@@ -2384,13 +2386,11 @@ tuplegetterdescr_get(PyObject *self, PyObject *obj, PyObject *type)
PyErr_Format(PyExc_TypeError,
"descriptor for index '%d' for tuple subclasses "
"doesn't apply to '%s' object",
- ((_tuplegetterobject*)self)->index,
+ index,
obj->ob_type->tp_name);
return NULL;
}
- Py_ssize_t index = ((_tuplegetterobject*)self)->index;
-
if (!valid_index(index, PyTuple_GET_SIZE(obj))) {
PyErr_SetString(PyExc_IndexError, "tuple index out of range");
return NULL;
@@ -2402,7 +2402,7 @@ tuplegetterdescr_get(PyObject *self, PyObject *obj, PyObject *type)
}
static int
-tuplegetter_set(PyObject *self, PyObject *obj, PyObject *value)
+tuplegetter_descr_set(PyObject *self, PyObject *obj, PyObject *value)
{
if (value == NULL) {
PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
@@ -2476,8 +2476,8 @@ static PyTypeObject tuplegetter_type = {
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
- tuplegetterdescr_get, /* tp_descr_get */
- tuplegetter_set, /* tp_descr_set */
+ tuplegetter_descr_get, /* tp_descr_get */
+ tuplegetter_descr_set, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
1
0
results for 4243df51fe43 on branch "default"
--------------------------------------------
test_collections leaked [0, 7, -7] memory blocks, sum=0
test_functools leaked [0, 3, 1] memory blocks, sum=4
test_multiprocessing_fork leaked [-2, 1, 0] memory blocks, sum=-1
Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/psf-users/antoine/refleaks/reflogqOKdZg', '--timeout', '7200']
1
0

bpo-35609: Remove examples for deprecated decorators in the abc module. (GH-11355)
by Serhiy Storchaka Dec. 31, 2018
by Serhiy Storchaka Dec. 31, 2018
Dec. 31, 2018
https://github.com/python/cpython/commit/5c117dd227e1b4c4f0a62564d8592f1ba4…
commit: 5c117dd227e1b4c4f0a62564d8592f1ba45c91eb
branch: master
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: GitHub <noreply(a)github.com>
date: 2018-12-31T09:56:21+02:00
summary:
bpo-35609: Remove examples for deprecated decorators in the abc module. (GH-11355)
files:
M Lib/abc.py
diff --git a/Lib/abc.py b/Lib/abc.py
index 7094141277ae..431b64040a66 100644
--- a/Lib/abc.py
+++ b/Lib/abc.py
@@ -11,7 +11,8 @@ def abstractmethod(funcobj):
class that has a metaclass derived from ABCMeta cannot be
instantiated unless all of its abstract methods are overridden.
The abstract methods can be called using any of the normal
- 'super' call mechanisms.
+ 'super' call mechanisms. abstractmethod() may be used to declare
+ abstract methods for properties and descriptors.
Usage:
@@ -27,17 +28,7 @@ def my_abstract_method(self, ...):
class abstractclassmethod(classmethod):
"""A decorator indicating abstract classmethods.
- Similar to abstractmethod.
-
- Usage:
-
- class C(metaclass=ABCMeta):
- @abstractclassmethod
- def my_abstract_classmethod(cls, ...):
- ...
-
- 'abstractclassmethod' is deprecated. Use 'classmethod' with
- 'abstractmethod' instead.
+ Deprecated, use 'classmethod' with 'abstractmethod' instead.
"""
__isabstractmethod__ = True
@@ -50,17 +41,7 @@ def __init__(self, callable):
class abstractstaticmethod(staticmethod):
"""A decorator indicating abstract staticmethods.
- Similar to abstractmethod.
-
- Usage:
-
- class C(metaclass=ABCMeta):
- @abstractstaticmethod
- def my_abstract_staticmethod(...):
- ...
-
- 'abstractstaticmethod' is deprecated. Use 'staticmethod' with
- 'abstractmethod' instead.
+ Deprecated, use 'staticmethod' with 'abstractmethod' instead.
"""
__isabstractmethod__ = True
@@ -73,29 +54,7 @@ def __init__(self, callable):
class abstractproperty(property):
"""A decorator indicating abstract properties.
- Requires that the metaclass is ABCMeta or derived from it. A
- class that has a metaclass derived from ABCMeta cannot be
- instantiated unless all of its abstract properties are overridden.
- The abstract properties can be called using any of the normal
- 'super' call mechanisms.
-
- Usage:
-
- class C(metaclass=ABCMeta):
- @abstractproperty
- def my_abstract_property(self):
- ...
-
- This defines a read-only property; you can also define a read-write
- abstract property using the 'long' form of property declaration:
-
- class C(metaclass=ABCMeta):
- def getx(self): ...
- def setx(self, value): ...
- x = abstractproperty(getx, setx)
-
- 'abstractproperty' is deprecated. Use 'property' with 'abstractmethod'
- instead.
+ Deprecated, use 'property' with 'abstractmethod' instead.
"""
__isabstractmethod__ = True
1
0

[3.7] bpo-35214: Annotate posix calls for clang MSan. (GH-11389) (GH-11391)
by Gregory P. Smith Dec. 31, 2018
by Gregory P. Smith Dec. 31, 2018
Dec. 31, 2018
https://github.com/python/cpython/commit/efcf08d8ca9084d8248715f0634c21b705…
commit: efcf08d8ca9084d8248715f0634c21b705f02ca2
branch: 3.7
author: Gregory P. Smith <greg(a)krypto.org>
committer: GitHub <noreply(a)github.com>
date: 2018-12-30T22:14:33-08:00
summary:
[3.7] bpo-35214: Annotate posix calls for clang MSan. (GH-11389) (GH-11391)
It doesn't know the details of a few less common libc functions..
(cherry picked from commit 1d300ce1d8238136595c8fea76266a4755cd73a2)
Co-authored-by: Gregory P. Smith <greg(a)krypto.org> [Google]
files:
M Misc/NEWS.d/next/Core and Builtins/2018-12-30-15-36-23.bpo-35214.GWDQcv.rst
M Modules/posixmodule.c
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-12-30-15-36-23.bpo-35214.GWDQcv.rst b/Misc/NEWS.d/next/Core and Builtins/2018-12-30-15-36-23.bpo-35214.GWDQcv.rst
index 62dee0e37008..fa61f78a9328 100644
--- a/Misc/NEWS.d/next/Core and Builtins/2018-12-30-15-36-23.bpo-35214.GWDQcv.rst
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-12-30-15-36-23.bpo-35214.GWDQcv.rst
@@ -1,2 +1,2 @@
clang Memory Sanitizer build instrumentation was added to work around false
-positives from socket, time, test_io, and test_faulthandler.
+positives from posix, socket, time, test_io, and test_faulthandler.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 909b06e5a9dd..f58572b2ceb4 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -393,6 +393,10 @@ static int win32_can_symlink = 0;
#define HAVE_STRUCT_STAT_ST_FSTYPE 1
#endif
+#ifdef _Py_MEMORY_SANITIZER
+# include <sanitizer/msan_interface.h>
+#endif
+
#ifdef HAVE_FORK
static void
run_at_forkers(PyObject *lst, int reverse)
@@ -5689,6 +5693,9 @@ os_sched_rr_get_interval_impl(PyObject *module, pid_t pid)
posix_error();
return -1.0;
}
+#ifdef _Py_MEMORY_SANITIZER
+ __msan_unpoison(&interval, sizeof(interval));
+#endif
return (double)interval.tv_sec + 1e-9*interval.tv_nsec;
}
#endif /* HAVE_SCHED_RR_GET_INTERVAL */
@@ -6155,6 +6162,12 @@ posix_getgrouplist(PyObject *self, PyObject *args)
return posix_error();
}
+#ifdef _Py_MEMORY_SANITIZER
+ /* Clang memory sanitizer libc intercepts don't know getgrouplist. */
+ __msan_unpoison(&ngroups, sizeof(ngroups));
+ __msan_unpoison(groups, ngroups*sizeof(*groups));
+#endif
+
list = PyList_New(ngroups);
if (list == NULL) {
PyMem_Del(groups);
1
0

Dec. 31, 2018
https://github.com/python/cpython/commit/75bf2b1e23ee7672fccb1e0fa23d6113cc…
commit: 75bf2b1e23ee7672fccb1e0fa23d6113cc3d38d7
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: GitHub <noreply(a)github.com>
date: 2018-12-30T21:59:08-08:00
summary:
Fix typo in test module usage message (GH-11374)
A minor typo in the output of `python -m test -h`.
A space was missing in between two words.
howmuch -> how much
(cherry picked from commit 7108aab49c2b6d6d81766c354f9a809278e03d4c)
Co-authored-by: sth <sth.dev(a)tejp.de>
files:
M Lib/test/libregrtest/cmdline.py
diff --git a/Lib/test/libregrtest/cmdline.py b/Lib/test/libregrtest/cmdline.py
index 09270323611f..7cd85bf2803a 100644
--- a/Lib/test/libregrtest/cmdline.py
+++ b/Lib/test/libregrtest/cmdline.py
@@ -68,7 +68,7 @@
2 billion objects, which only works on 64-bit systems. There are also some
tests that try to exhaust the address space of the process, which only makes
sense on 32-bit systems with at least 2Gb of memory. The passed-in memlimit,
-which is a string in the form of '2.5Gb', determines howmuch memory the
+which is a string in the form of '2.5Gb', determines how much memory the
tests will limit themselves to (but they may go slightly over.) The number
shouldn't be more memory than the machine has (including swap memory). You
should also keep in mind that swap memory is generally much, much slower
1
0

Dec. 31, 2018
https://github.com/python/cpython/commit/7108aab49c2b6d6d81766c354f9a809278…
commit: 7108aab49c2b6d6d81766c354f9a809278e03d4c
branch: master
author: sth <sth.dev(a)tejp.de>
committer: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
date: 2018-12-30T21:41:39-08:00
summary:
Fix typo in test module usage message (GH-11374)
A minor typo in the output of `python -m test -h`.
A space was missing in between two words.
howmuch -> how much
files:
M Lib/test/libregrtest/cmdline.py
diff --git a/Lib/test/libregrtest/cmdline.py b/Lib/test/libregrtest/cmdline.py
index 09270323611f..7cd85bf2803a 100644
--- a/Lib/test/libregrtest/cmdline.py
+++ b/Lib/test/libregrtest/cmdline.py
@@ -68,7 +68,7 @@
2 billion objects, which only works on 64-bit systems. There are also some
tests that try to exhaust the address space of the process, which only makes
sense on 32-bit systems with at least 2Gb of memory. The passed-in memlimit,
-which is a string in the form of '2.5Gb', determines howmuch memory the
+which is a string in the form of '2.5Gb', determines how much memory the
tests will limit themselves to (but they may go slightly over.) The number
shouldn't be more memory than the machine has (including swap memory). You
should also keep in mind that swap memory is generally much, much slower
1
0
https://github.com/python/cpython/commit/b539cef31c060c7eecc331d25a23b80ded…
commit: b539cef31c060c7eecc331d25a23b80ded0baf08
branch: master
author: Sanyam Khurana <8039608+CuriousLearner(a)users.noreply.github.com>
committer: Nick Coghlan <ncoghlan(a)gmail.com>
date: 2018-12-31T15:14:47+10:00
summary:
bpo-35614: Fix pydoc help() on metaclasses (#11357)
files:
A Misc/NEWS.d/next/Library/2018-12-30-01-10-50.bpo-35614.cnkM4f.rst
M Lib/pydoc.py
M Lib/test/test_pydoc.py
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 1d84b847cf9f..59f6e3935135 100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1255,7 +1255,7 @@ def makename(c, m=object.__module__):
# List the built-in subclasses, if any:
subclasses = sorted(
- (str(cls.__name__) for cls in object.__subclasses__()
+ (str(cls.__name__) for cls in type.__subclasses__(object)
if not cls.__name__.startswith("_") and cls.__module__ == "builtins"),
key=str.lower
)
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
index 409fea4a5e94..c58a8b13e76d 100644
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -636,6 +636,17 @@ class ZeroDivisionError(ArithmeticError)
# Testing that the subclasses section does not appear
self.assertNotIn('Built-in subclasses', text)
+ def test_builtin_on_metaclasses(self):
+ """Tests help on metaclasses.
+
+ When running help() on a metaclasses such as type, it
+ should not contain any "Built-in subclasses" section.
+ """
+ doc = pydoc.TextDoc()
+ text = doc.docclass(type)
+ # Testing that the subclasses section does not appear
+ self.assertNotIn('Built-in subclasses', text)
+
@unittest.skipIf(sys.flags.optimize >= 2,
'Docstrings are omitted with -O2 and above')
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
diff --git a/Misc/NEWS.d/next/Library/2018-12-30-01-10-50.bpo-35614.cnkM4f.rst b/Misc/NEWS.d/next/Library/2018-12-30-01-10-50.bpo-35614.cnkM4f.rst
new file mode 100644
index 000000000000..4d6beffa2be6
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-12-30-01-10-50.bpo-35614.cnkM4f.rst
@@ -0,0 +1 @@
+Fixed help() on metaclasses. Patch by Sanyam Khurana.
1
0