Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/asyncio-policy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The abstract event loop policy base class is defined as follows:

.. method:: set_child_watcher(watcher)

Get the current child process watcher to *watcher*.
Set the current child process watcher to *watcher*.

This function is Unix specific.

Expand Down
10 changes: 10 additions & 0 deletions Include/Python.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@
#include <unistd.h>
#endif
#ifdef HAVE_CRYPT_H
#if defined(HAVE_CRYPT_R) && !defined(_GNU_SOURCE)
/* Required for glibc to expose the crypt_r() function prototype. */
# define _GNU_SOURCE
# define _Py_GNU_SOURCE_FOR_CRYPT
#endif
#include <crypt.h>
#ifdef _Py_GNU_SOURCE_FOR_CRYPT
/* Don't leak the _GNU_SOURCE define to other headers. */
# undef _GNU_SOURCE
# undef _Py_GNU_SOURCE_FOR_CRYPT
#endif
#endif

/* For size_t? */
Expand Down
51 changes: 5 additions & 46 deletions Lib/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 2 additions & 11 deletions Lib/collections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)

Expand Down
73 changes: 36 additions & 37 deletions Lib/idlelib/config_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)}>")

Expand All @@ -225,40 +257,7 @@ def clear_key_seq(self):

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}'
self.list_keys_final.insert('end', *AVAILABLE_KEYS)

def ok(self, event=None):
keys = self.key_string.get().strip()
Expand Down Expand Up @@ -291,12 +290,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)
Expand Down
41 changes: 22 additions & 19 deletions Lib/idlelib/idle_test/test_config_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading