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

Skip to content

Commit 09a3848

Browse files
Merge remote-tracking branch 'upstream/main' into stackref_all
2 parents d2c14f7 + ac37a80 commit 09a3848

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+109
-92
lines changed

Lib/test/_test_embed_set_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# (before the site module is run).
77

88
import _testinternalcapi
9-
import os
109
import sys
1110
import unittest
1211
from test import support

Lib/test/support/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
raise ImportError('support must be imported from the test package')
55

66
import contextlib
7-
import dataclasses
87
import functools
98
import _opcode
109
import os

Lib/test/test___all__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from test.support import warnings_helper
44
import os
55
import sys
6-
import types
76

87

98
if support.check_sanitizer(address=True, memory=True):

Lib/test/test_bdb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,9 @@ def main():
10461046
('return', 1, '<module>'), ('quit', ),
10471047
]
10481048
import test_module_for_bdb
1049+
ns = {'test_module_for_bdb': test_module_for_bdb}
10491050
with TracerRun(self) as tracer:
1050-
tracer.runeval('test_module_for_bdb.main()', globals(), locals())
1051+
tracer.runeval('test_module_for_bdb.main()', ns, ns)
10511052

10521053
class IssuesTestCase(BaseTestCase):
10531054
"""Test fixed bdb issues."""

Lib/test/test_call.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
from test.support import (cpython_only, is_wasi, requires_limited_api, Py_DEBUG,
3-
set_recursion_limit, skip_on_s390x, import_helper)
3+
set_recursion_limit, skip_on_s390x)
44
try:
55
import _testcapi
66
except ImportError:
@@ -14,7 +14,6 @@
1414
import itertools
1515
import gc
1616
import contextlib
17-
import sys
1817
import types
1918

2019

Lib/test/test_capi/test_list.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import gc
2-
import weakref
31
import unittest
42
from test.support import import_helper
53
from collections import UserList

Lib/test/test_capi/test_misc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import time
1818
import types
1919
import unittest
20-
import warnings
2120
import weakref
2221
import operator
2322
from test import support

Lib/test/test_capi/test_structmembers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import unittest
22
from test.support import import_helper
3-
from test.support import warnings_helper
43

54
# Skip this test if the _testcapi module isn't available.
65
import_helper.import_module('_testcapi')

Lib/test/test_concurrent_futures/executor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import threading
22
import time
3-
import unittest
43
import weakref
54
from concurrent import futures
65
from test import support

Lib/test/test_ctypes/test_generated_structs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
import re
1515
from dataclasses import dataclass
1616
from functools import cached_property
17-
import sys
1817

1918
import ctypes
20-
from ctypes import Structure, Union, _SimpleCData
19+
from ctypes import Structure, Union
2120
from ctypes import sizeof, alignment, pointer, string_at
2221
_ctypes_test = import_helper.import_module("_ctypes_test")
2322

Lib/test/test_ctypes/test_structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import struct
33
import sys
44
import unittest
5-
from ctypes import (CDLL, Array, Structure, Union, POINTER, sizeof, byref, alignment,
5+
from ctypes import (CDLL, Structure, Union, POINTER, sizeof, byref, alignment,
66
c_void_p, c_char, c_wchar, c_byte, c_ubyte,
77
c_uint8, c_uint16, c_uint32,
88
c_short, c_ushort, c_int, c_uint,

Lib/test/test_dbm_sqlite3.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import sys
2-
import test.support
32
import unittest
43
from contextlib import closing
54
from functools import partial
65
from pathlib import Path
7-
from test.support import cpython_only, import_helper, os_helper
6+
from test.support import import_helper, os_helper
87

98
dbm_sqlite3 = import_helper.import_module("dbm.sqlite3")
109
# N.B. The test will fail on some platforms without sqlite3

Lib/test/test_decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from types import MethodType
2+
33

44
def funcattrs(**kwds):
55
def decorate(func):

Lib/test/test_descr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ class X(object):
13141314
# Inherit from object on purpose to check some backwards compatibility paths
13151315
class X(object):
13161316
__slots__ = "a"
1317-
with self.assertRaisesRegex(AttributeError, "'X' object has no attribute 'a'"):
1317+
with self.assertRaisesRegex(AttributeError, "'test.test_descr.ClassPropertiesAndMethods.test_slots.<locals>.X' object has no attribute 'a'"):
13181318
X().a
13191319

13201320
# Test string subclass in `__slots__`, see gh-98783

Lib/test/test_email/test_headerregistry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from test.test_email import TestEmailBase, parameterize
88
from email import headerregistry
99
from email.headerregistry import Address, Group
10-
from email.header import decode_header
1110
from test.support import ALWAYS_EQ, is_wasi, Py_DEBUG
1211

1312

Lib/test/test_email/test_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import test.support
44
import time
55
import unittest
6-
import sys
7-
import os.path
8-
import zoneinfo
6+
97

108
class DateTimeTests(unittest.TestCase):
119

Lib/test/test_ensurepip.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import test.support
77
import unittest
88
import unittest.mock
9-
from importlib.resources.abc import Traversable
109
from pathlib import Path
1110

1211
import ensurepip

Lib/test/test_fractions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests for Lib/fractions.py."""
22

3-
import cmath
43
from decimal import Decimal
54
from test.support import requires_IEEE_754
65
import math

Lib/test/test_frame.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import copy
2-
import gc
32
import operator
43
import re
54
import sys
65
import textwrap
76
import threading
8-
import types
97
import unittest
108
import weakref
119
try:
@@ -14,7 +12,7 @@
1412
_testcapi = None
1513

1614
from test import support
17-
from test.support import import_helper, threading_helper, Py_GIL_DISABLED
15+
from test.support import import_helper, threading_helper
1816
from test.support.script_helper import assert_python_ok
1917

2018

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import threading
2+
from test.support import threading_helper
3+
from unittest import TestCase
4+
5+
6+
def run_in_threads(targets):
7+
"""Run `targets` in separate threads"""
8+
threads = [
9+
threading.Thread(target=target)
10+
for target in targets
11+
]
12+
for thread in threads:
13+
thread.start()
14+
for thread in threads:
15+
thread.join()
16+
17+
18+
@threading_helper.requires_working_threading()
19+
class TestSlots(TestCase):
20+
21+
def test_object(self):
22+
class Spam:
23+
__slots__ = [
24+
"eggs",
25+
]
26+
27+
def __init__(self, initial_value):
28+
self.eggs = initial_value
29+
30+
spam = Spam(0)
31+
iters = 20_000
32+
33+
def writer():
34+
for _ in range(iters):
35+
spam.eggs += 1
36+
37+
def reader():
38+
for _ in range(iters):
39+
eggs = spam.eggs
40+
assert type(eggs) is int
41+
assert 0 <= eggs <= iters
42+
43+
run_in_threads([writer, reader, reader, reader])

Lib/test/test_free_threading/test_str.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import unittest
32

43
from itertools import cycle

Lib/test/test_free_threading/test_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from threading import Thread
66
from unittest import TestCase
77

8-
from test.support import threading_helper, import_helper
8+
from test.support import threading_helper
99

1010

1111

Lib/test/test_fstring.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import types
1515
import decimal
1616
import unittest
17-
import warnings
1817
from test import support
1918
from test.support.os_helper import temp_cwd
2019
from test.support.script_helper import assert_python_failure, assert_python_ok

Lib/test/test_imaplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import re
1212
import socket
1313

14-
from test.support import verbose, run_with_tz, run_with_locale, cpython_only, requires_resource
14+
from test.support import verbose, run_with_tz, run_with_locale, cpython_only
1515
from test.support import hashlib_helper
1616
from test.support import threading_helper
1717
import unittest

Lib/test/test_inspect/test_inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from test.support.import_helper import DirsOnSysPath, ready_to_import
4141
from test.support.os_helper import TESTFN, temp_cwd
4242
from test.support.script_helper import assert_python_ok, assert_python_failure, kill_python
43-
from test.support import has_subprocess_support, SuppressCrashReport
43+
from test.support import has_subprocess_support
4444
from test import support
4545

4646
from test.test_inspect import inspect_fodder as mod

Lib/test/test_int.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sys
2-
import time
32

43
import unittest
54
from unittest import mock

Lib/test/test_interpreters/test_api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22
import pickle
3-
import sys
4-
from textwrap import dedent, indent
3+
from textwrap import dedent
54
import threading
65
import types
76
import unittest

Lib/test/test_interpreters/test_queues.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import threading
44
from textwrap import dedent
55
import unittest
6-
import time
76

87
from test.support import import_helper, Py_DEBUG
98
# Raise SkipTest if subinterpreters not supported.

Lib/test/test_interpreters/test_stress.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def test_create_many_sequential(self):
2222
interp = interpreters.create()
2323
alive.append(interp)
2424

25-
@unittest.skip('(temporary) gh-120524: there is a race that needs fixing')
2625
@support.requires_resource('cpu')
2726
def test_create_many_threaded(self):
2827
alive = []

Lib/test/test_interpreters/utils.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
from collections import namedtuple
22
import contextlib
33
import json
4-
import io
54
import os
65
import os.path
7-
import pickle
8-
import queue
96
#import select
107
import subprocess
118
import sys
129
import tempfile
13-
from textwrap import dedent, indent
10+
from textwrap import dedent
1411
import threading
1512
import types
1613
import unittest

Lib/test/test_mailbox.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22
import sys
33
import time
4-
import stat
54
import socket
65
import email
76
import email.message

Lib/test/test_monitoring.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import textwrap
1010
import types
1111
import unittest
12-
import asyncio
1312

1413
import test.support
1514
from test.support import requires_specialization, script_helper

Lib/test/test_peepholer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import dis
22
from itertools import combinations, product
3-
import opcode
43
import sys
54
import textwrap
65
import unittest

Lib/test/test_perf_profiler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import sysconfig
66
import os
77
import pathlib
8-
import shutil
98
from test import support
109
from test.support.script_helper import (
1110
make_script,

Lib/test/test_zipimport.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,12 @@ def testLargestPossibleComment(self):
807807
files = {TESTMOD + ".py": (NOW, test_src)}
808808
self.doTest(".py", files, TESTMOD, comment=b"c" * ((1 << 16) - 1))
809809

810+
@support.requires_resource('cpu')
810811
def testZip64(self):
811812
files = self.getZip64Files()
812813
self.doTest(".py", files, "f6")
813814

815+
@support.requires_resource('cpu')
814816
def testZip64CruftAndComment(self):
815817
files = self.getZip64Files()
816818
self.doTest(".py", files, "f65536", comment=b"c" * ((1 << 16) - 1))

Objects/typeobject.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ managed_static_type_state_init(PyInterpreterState *interp, PyTypeObject *self,
246246

247247
assert((initial == 1) ==
248248
(_PyRuntime.types.managed_static.types[full_index].interp_count == 0));
249-
_PyRuntime.types.managed_static.types[full_index].interp_count += 1;
249+
(void)_Py_atomic_add_int64(
250+
&_PyRuntime.types.managed_static.types[full_index].interp_count, 1);
250251

251252
if (initial) {
252253
assert(_PyRuntime.types.managed_static.types[full_index].type == NULL);
@@ -300,7 +301,8 @@ managed_static_type_state_clear(PyInterpreterState *interp, PyTypeObject *self,
300301
state->type = NULL;
301302
assert(state->tp_weaklist == NULL); // It was already cleared out.
302303

303-
_PyRuntime.types.managed_static.types[full_index].interp_count -= 1;
304+
(void)_Py_atomic_add_int64(
305+
&_PyRuntime.types.managed_static.types[full_index].interp_count, -1);
304306
if (final) {
305307
assert(!_PyRuntime.types.managed_static.types[full_index].interp_count);
306308
_PyRuntime.types.managed_static.types[full_index].type = NULL;

0 commit comments

Comments
 (0)