Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0acc2b2

Browse files
authored
Merge branch 'main' into gh-100926-ctypes-pointers-cache
2 parents b33890d + 2590774 commit 0acc2b2

17 files changed

+244
-69
lines changed

Doc/library/turtle.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
=================================
2-
:mod:`turtle` --- Turtle graphics
3-
=================================
1+
==================================
2+
:mod:`!turtle` --- Turtle graphics
3+
==================================
44

55
.. module:: turtle
66
:synopsis: An educational framework for simple graphics applications

Doc/library/typing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
========================================
2-
:mod:`typing` --- Support for type hints
3-
========================================
1+
=========================================
2+
:mod:`!typing` --- Support for type hints
3+
=========================================
44

55
.. testsetup:: *
66

Doc/whatsnew/3.14.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,9 @@ tkinter
13771377
arguments passed by keyword.
13781378
(Contributed by Zhikang Yan in :gh:`126899`.)
13791379

1380+
* Add ability to specify name for :class:`!tkinter.OptionMenu` and
1381+
:class:`!tkinter.ttk.OptionMenu`.
1382+
(Contributed by Zhikang Yan in :gh:`130482`.)
13801383

13811384
turtle
13821385
------

Lib/test/test_ctypes/test_pointers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,5 +461,17 @@ def test_get_not_registered(self):
461461
with self.assertWarns(DeprecationWarning):
462462
self.assertIsNone(_pointer_type_cache.get(str, None))
463463

464+
def test_repeated_set_type(self):
465+
# Regression test for gh-133290
466+
class C(Structure):
467+
_fields_ = [('a', c_int)]
468+
ptr = POINTER(C)
469+
# Read _type_ several times to warm up cache
470+
for i in range(5):
471+
self.assertIs(ptr._type_, C)
472+
ptr.set_type(c_int)
473+
self.assertIs(ptr._type_, c_int)
474+
475+
464476
if __name__ == '__main__':
465477
unittest.main()

Lib/test/test_fstring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ def test_invalid_string_prefixes(self):
13041304
"Bf''",
13051305
"BF''",]
13061306
double_quote_cases = [case.replace("'", '"') for case in single_quote_cases]
1307-
self.assertAllRaise(SyntaxError, 'invalid syntax',
1307+
self.assertAllRaise(SyntaxError, 'prefixes are incompatible',
13081308
single_quote_cases + double_quote_cases)
13091309

13101310
def test_leading_trailing_spaces(self):

Lib/test/test_grammar.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,27 @@ def test_string_literals(self):
216216
'
217217
self.assertEqual(x, y)
218218

219+
def test_string_prefixes(self):
220+
def check(s):
221+
parsed = eval(s)
222+
self.assertIs(type(parsed), str)
223+
self.assertGreater(len(parsed), 0)
224+
225+
check("u'abc'")
226+
check("r'abc\t'")
227+
check("rf'abc\a {1 + 1}'")
228+
check("fr'abc\a {1 + 1}'")
229+
230+
def test_bytes_prefixes(self):
231+
def check(s):
232+
parsed = eval(s)
233+
self.assertIs(type(parsed), bytes)
234+
self.assertGreater(len(parsed), 0)
235+
236+
check("b'abc'")
237+
check("br'abc\t'")
238+
check("rb'abc\a'")
239+
219240
def test_ellipsis(self):
220241
x = ...
221242
self.assertTrue(x is Ellipsis)

Lib/test/test_pydoc/test_pydoc.py

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,18 +1927,28 @@ def test_text_doc_routines_in_class(self, cls=pydocfodder.B):
19271927
self.assertIn(' | global_func(x, y) from test.test_pydoc.pydocfodder', lines)
19281928
self.assertIn(' | global_func_alias = global_func(x, y)', lines)
19291929
self.assertIn(' | global_func2_alias = global_func2(x, y) from test.test_pydoc.pydocfodder', lines)
1930-
self.assertIn(' | count(self, value, /) from builtins.list', lines)
1931-
self.assertIn(' | list_count = count(self, value, /)', lines)
1932-
self.assertIn(' | __repr__(self, /) from builtins.object', lines)
1933-
self.assertIn(' | object_repr = __repr__(self, /)', lines)
1930+
if not support.MISSING_C_DOCSTRINGS:
1931+
self.assertIn(' | count(self, value, /) from builtins.list', lines)
1932+
self.assertIn(' | list_count = count(self, value, /)', lines)
1933+
self.assertIn(' | __repr__(self, /) from builtins.object', lines)
1934+
self.assertIn(' | object_repr = __repr__(self, /)', lines)
1935+
else:
1936+
self.assertIn(' | count(self, object, /) from builtins.list', lines)
1937+
self.assertIn(' | list_count = count(self, object, /)', lines)
1938+
self.assertIn(' | __repr__(...) from builtins.object', lines)
1939+
self.assertIn(' | object_repr = __repr__(...)', lines)
19341940

19351941
lines = self.getsection(result, f' | Static methods {where}:', ' | ' + '-'*70)
19361942
self.assertIn(' | A_classmethod_ref = A_classmethod(x) class method of test.test_pydoc.pydocfodder.A', lines)
19371943
note = '' if cls is pydocfodder.B else ' class method of test.test_pydoc.pydocfodder.B'
19381944
self.assertIn(' | B_classmethod_ref = B_classmethod(x)' + note, lines)
19391945
self.assertIn(' | A_method_ref = A_method() method of test.test_pydoc.pydocfodder.A instance', lines)
1940-
self.assertIn(' | get(key, default=None, /) method of builtins.dict instance', lines)
1941-
self.assertIn(' | dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
1946+
if not support.MISSING_C_DOCSTRINGS:
1947+
self.assertIn(' | get(key, default=None, /) method of builtins.dict instance', lines)
1948+
self.assertIn(' | dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
1949+
else:
1950+
self.assertIn(' | get(...) method of builtins.dict instance', lines)
1951+
self.assertIn(' | dict_get = get(...) method of builtins.dict instance', lines)
19421952

19431953
lines = self.getsection(result, f' | Class methods {where}:', ' | ' + '-'*70)
19441954
self.assertIn(' | B_classmethod(x)', lines)
@@ -1957,10 +1967,16 @@ def test_html_doc_routines_in_class(self, cls=pydocfodder.B):
19571967
self.assertIn('global_func(x, y) from test.test_pydoc.pydocfodder', lines)
19581968
self.assertIn('global_func_alias = global_func(x, y)', lines)
19591969
self.assertIn('global_func2_alias = global_func2(x, y) from test.test_pydoc.pydocfodder', lines)
1960-
self.assertIn('count(self, value, /) from builtins.list', lines)
1961-
self.assertIn('list_count = count(self, value, /)', lines)
1962-
self.assertIn('__repr__(self, /) from builtins.object', lines)
1963-
self.assertIn('object_repr = __repr__(self, /)', lines)
1970+
if not support.MISSING_C_DOCSTRINGS:
1971+
self.assertIn('count(self, value, /) from builtins.list', lines)
1972+
self.assertIn('list_count = count(self, value, /)', lines)
1973+
self.assertIn('__repr__(self, /) from builtins.object', lines)
1974+
self.assertIn('object_repr = __repr__(self, /)', lines)
1975+
else:
1976+
self.assertIn('count(self, object, /) from builtins.list', lines)
1977+
self.assertIn('list_count = count(self, object, /)', lines)
1978+
self.assertIn('__repr__(...) from builtins.object', lines)
1979+
self.assertIn('object_repr = __repr__(...)', lines)
19641980

19651981
lines = self.getsection(result, f'Static methods {where}:', '-'*70)
19661982
self.assertIn('A_classmethod_ref = A_classmethod(x) class method of test.test_pydoc.pydocfodder.A', lines)
@@ -1997,15 +2013,27 @@ def test_text_doc_routines_in_module(self):
19972013
self.assertIn(' A_method3 = A_method() method of B instance', lines)
19982014
self.assertIn(' A_staticmethod_ref = A_staticmethod(x, y)', lines)
19992015
self.assertIn(' A_staticmethod_ref2 = A_staticmethod(y) method of B instance', lines)
2000-
self.assertIn(' get(key, default=None, /) method of builtins.dict instance', lines)
2001-
self.assertIn(' dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
2016+
if not support.MISSING_C_DOCSTRINGS:
2017+
self.assertIn(' get(key, default=None, /) method of builtins.dict instance', lines)
2018+
self.assertIn(' dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
2019+
else:
2020+
self.assertIn(' get(...) method of builtins.dict instance', lines)
2021+
self.assertIn(' dict_get = get(...) method of builtins.dict instance', lines)
2022+
20022023
# unbound methods
20032024
self.assertIn(' B_method(self)', lines)
20042025
self.assertIn(' B_method2 = B_method(self)', lines)
2005-
self.assertIn(' count(self, value, /) unbound builtins.list method', lines)
2006-
self.assertIn(' list_count = count(self, value, /) unbound builtins.list method', lines)
2007-
self.assertIn(' __repr__(self, /) unbound builtins.object method', lines)
2008-
self.assertIn(' object_repr = __repr__(self, /) unbound builtins.object method', lines)
2026+
if not support.MISSING_C_DOCSTRINGS:
2027+
self.assertIn(' count(self, value, /) unbound builtins.list method', lines)
2028+
self.assertIn(' list_count = count(self, value, /) unbound builtins.list method', lines)
2029+
self.assertIn(' __repr__(self, /) unbound builtins.object method', lines)
2030+
self.assertIn(' object_repr = __repr__(self, /) unbound builtins.object method', lines)
2031+
else:
2032+
self.assertIn(' count(self, object, /) unbound builtins.list method', lines)
2033+
self.assertIn(' list_count = count(self, object, /) unbound builtins.list method', lines)
2034+
self.assertIn(' __repr__(...) unbound builtins.object method', lines)
2035+
self.assertIn(' object_repr = __repr__(...) unbound builtins.object method', lines)
2036+
20092037

20102038
def test_html_doc_routines_in_module(self):
20112039
doc = pydoc.HTMLDoc()
@@ -2026,15 +2054,25 @@ def test_html_doc_routines_in_module(self):
20262054
self.assertIn(' A_method3 = A_method() method of B instance', lines)
20272055
self.assertIn(' A_staticmethod_ref = A_staticmethod(x, y)', lines)
20282056
self.assertIn(' A_staticmethod_ref2 = A_staticmethod(y) method of B instance', lines)
2029-
self.assertIn(' get(key, default=None, /) method of builtins.dict instance', lines)
2030-
self.assertIn(' dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
2057+
if not support.MISSING_C_DOCSTRINGS:
2058+
self.assertIn(' get(key, default=None, /) method of builtins.dict instance', lines)
2059+
self.assertIn(' dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
2060+
else:
2061+
self.assertIn(' get(...) method of builtins.dict instance', lines)
2062+
self.assertIn(' dict_get = get(...) method of builtins.dict instance', lines)
20312063
# unbound methods
20322064
self.assertIn(' B_method(self)', lines)
20332065
self.assertIn(' B_method2 = B_method(self)', lines)
2034-
self.assertIn(' count(self, value, /) unbound builtins.list method', lines)
2035-
self.assertIn(' list_count = count(self, value, /) unbound builtins.list method', lines)
2036-
self.assertIn(' __repr__(self, /) unbound builtins.object method', lines)
2037-
self.assertIn(' object_repr = __repr__(self, /) unbound builtins.object method', lines)
2066+
if not support.MISSING_C_DOCSTRINGS:
2067+
self.assertIn(' count(self, value, /) unbound builtins.list method', lines)
2068+
self.assertIn(' list_count = count(self, value, /) unbound builtins.list method', lines)
2069+
self.assertIn(' __repr__(self, /) unbound builtins.object method', lines)
2070+
self.assertIn(' object_repr = __repr__(self, /) unbound builtins.object method', lines)
2071+
else:
2072+
self.assertIn(' count(self, object, /) unbound builtins.list method', lines)
2073+
self.assertIn(' list_count = count(self, object, /) unbound builtins.list method', lines)
2074+
self.assertIn(' __repr__(...) unbound builtins.object method', lines)
2075+
self.assertIn(' object_repr = __repr__(...) unbound builtins.object method', lines)
20382076

20392077

20402078
@unittest.skipIf(

Lib/test/test_syntax.py

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,21 +1877,77 @@
18771877
Traceback (most recent call last):
18781878
SyntaxError: cannot assign to f-string expression here. Maybe you meant '==' instead of '='?
18791879
1880-
>>> ft'abc'
1880+
>>> ub''
18811881
Traceback (most recent call last):
1882-
SyntaxError: can't use 'f' and 't' string prefixes together
1882+
SyntaxError: 'u' and 'b' prefixes are incompatible
18831883
1884-
>>> tf"{x=}"
1884+
>>> bu"привет"
18851885
Traceback (most recent call last):
1886-
SyntaxError: can't use 'f' and 't' string prefixes together
1886+
SyntaxError: 'u' and 'b' prefixes are incompatible
18871887
1888-
>>> tb''
1888+
>>> ur''
1889+
Traceback (most recent call last):
1890+
SyntaxError: 'u' and 'r' prefixes are incompatible
1891+
1892+
>>> ru"\t"
1893+
Traceback (most recent call last):
1894+
SyntaxError: 'u' and 'r' prefixes are incompatible
1895+
1896+
>>> uf'{1 + 1}'
1897+
Traceback (most recent call last):
1898+
SyntaxError: 'u' and 'f' prefixes are incompatible
1899+
1900+
>>> fu""
1901+
Traceback (most recent call last):
1902+
SyntaxError: 'u' and 'f' prefixes are incompatible
1903+
1904+
>>> ut'{1}'
1905+
Traceback (most recent call last):
1906+
SyntaxError: 'u' and 't' prefixes are incompatible
1907+
1908+
>>> tu"234"
1909+
Traceback (most recent call last):
1910+
SyntaxError: 'u' and 't' prefixes are incompatible
1911+
1912+
>>> bf'{x!r}'
1913+
Traceback (most recent call last):
1914+
SyntaxError: 'b' and 'f' prefixes are incompatible
1915+
1916+
>>> fb"text"
18891917
Traceback (most recent call last):
1890-
SyntaxError: can't use 'b' and 't' string prefixes together
1918+
SyntaxError: 'b' and 'f' prefixes are incompatible
18911919
18921920
>>> bt"text"
18931921
Traceback (most recent call last):
1894-
SyntaxError: can't use 'b' and 't' string prefixes together
1922+
SyntaxError: 'b' and 't' prefixes are incompatible
1923+
1924+
>>> tb''
1925+
Traceback (most recent call last):
1926+
SyntaxError: 'b' and 't' prefixes are incompatible
1927+
1928+
>>> tf"{0.3:.02f}"
1929+
Traceback (most recent call last):
1930+
SyntaxError: 'f' and 't' prefixes are incompatible
1931+
1932+
>>> ft'{x=}'
1933+
Traceback (most recent call last):
1934+
SyntaxError: 'f' and 't' prefixes are incompatible
1935+
1936+
>>> tfu"{x=}"
1937+
Traceback (most recent call last):
1938+
SyntaxError: 'u' and 'f' prefixes are incompatible
1939+
1940+
>>> turf"{x=}"
1941+
Traceback (most recent call last):
1942+
SyntaxError: 'u' and 'r' prefixes are incompatible
1943+
1944+
>>> burft"{x=}"
1945+
Traceback (most recent call last):
1946+
SyntaxError: 'u' and 'b' prefixes are incompatible
1947+
1948+
>>> brft"{x=}"
1949+
Traceback (most recent call last):
1950+
SyntaxError: 'b' and 'f' prefixes are incompatible
18951951
18961952
>>> t'{x}' = 42
18971953
Traceback (most recent call last):

Lib/test/test_tkinter/test_widgets.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ def test_bad_kwarg(self):
354354
with self.assertRaisesRegex(TclError, r"^unknown option -image$"):
355355
tkinter.OptionMenu(self.root, None, 'b', image='')
356356

357+
def test_specify_name(self):
358+
widget = tkinter.OptionMenu(self.root, None, ':)', name="option_menu")
359+
self.assertEqual(str(widget), ".option_menu")
360+
self.assertIs(self.root.children["option_menu"], widget)
361+
357362
@add_configure_tests(IntegerSizeTests, StandardOptionsTests)
358363
class EntryTest(AbstractWidgetTest, unittest.TestCase):
359364
_rounds_pixels = (tk_version < (9, 0))

Lib/test/test_ttk/test_extensions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ def cb_test(*args):
319319
textvar.trace_remove("write", cb_name)
320320
optmenu.destroy()
321321

322+
def test_specify_name(self):
323+
textvar = tkinter.StringVar(self.root)
324+
widget = ttk.OptionMenu(self.root, textvar, ":)", name="option_menu_ex")
325+
self.assertEqual(str(widget), ".option_menu_ex")
326+
self.assertIs(self.root.children["option_menu_ex"], widget)
327+
322328

323329
class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase):
324330

Lib/tkinter/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4199,7 +4199,7 @@ def __init__(self, master, variable, value, *values, **kwargs):
41994199
keyword argument command."""
42004200
kw = {"borderwidth": 2, "textvariable": variable,
42014201
"indicatoron": 1, "relief": RAISED, "anchor": "c",
4202-
"highlightthickness": 2}
4202+
"highlightthickness": 2, "name": kwargs.pop("name", None)}
42034203
Widget.__init__(self, master, "menubutton", kw)
42044204
self.widgetName = 'tk_optionMenu'
42054205
menu = self.__menu = Menu(self, name="menu", tearoff=0)

Lib/tkinter/ttk.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,8 @@ def __init__(self, master, variable, default=None, *values, **kwargs):
16031603
A callback that will be invoked after selecting an item.
16041604
"""
16051605
kw = {'textvariable': variable, 'style': kwargs.pop('style', None),
1606-
'direction': kwargs.pop('direction', None)}
1606+
'direction': kwargs.pop('direction', None),
1607+
'name': kwargs.pop('name', None)}
16071608
Menubutton.__init__(self, master, **kw)
16081609
self['menu'] = tkinter.Menu(self, tearoff=False)
16091610

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improve :exc:`SyntaxError` error messages for incompatible string / bytes
2+
prefixes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add ability to specify name for :class:`!tkinter.OptionMenu` and
2+
:class:`!tkinter.ttk.OptionMenu`.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix attribute caching issue when setting :attr:`ctypes._Pointer._type_` in
2+
the undocumented and deprecated :func:`!ctypes.SetPointerType` function and the
3+
undocumented :meth:`!set_type` method.

Modules/_ctypes/_ctypes.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,36 +1356,23 @@ PyCPointerType_set_type_impl(PyTypeObject *self, PyTypeObject *cls,
13561356
PyObject *type)
13571357
/*[clinic end generated code: output=51459d8f429a70ac input=67e1e8df921f123e]*/
13581358
{
1359-
PyObject *attrdict = PyType_GetDict(self);
1360-
if (!attrdict) {
1361-
return NULL;
1362-
}
13631359
ctypes_state *st = get_module_state_by_class(cls);
13641360
StgInfo *info;
13651361
if (PyStgInfo_FromType(st, (PyObject *)self, &info) < 0) {
1366-
Py_DECREF(attrdict);
13671362
return NULL;
13681363
}
13691364
if (!info) {
13701365
PyErr_SetString(PyExc_TypeError,
13711366
"abstract class");
1372-
Py_DECREF(attrdict);
13731367
return NULL;
13741368
}
13751369

13761370
if (PyCPointerType_SetProto(st, (PyObject *)self, info, type) < 0) {
1377-
Py_DECREF(attrdict);
13781371
return NULL;
13791372
}
1380-
1381-
if (-1 == PyDict_SetItem(attrdict, &_Py_ID(_type_), type)) {
1382-
Py_DECREF(attrdict);
1373+
if (PyObject_SetAttr((PyObject *)self, &_Py_ID(_type_), type) < 0) {
13831374
return NULL;
13841375
}
1385-
1386-
PyType_Modified(self);
1387-
1388-
Py_DECREF(attrdict);
13891376
Py_RETURN_NONE;
13901377
}
13911378

0 commit comments

Comments
 (0)