Skip to content

Commit 745545b

Browse files
authored
gh-99482: remove jython compatibility parts from stdlib and tests (#99484)
1 parent c5726b7 commit 745545b

20 files changed

+136
-234
lines changed

Doc/whatsnew/3.12.rst

+3
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,9 @@ Removed
955955
``SSTATE_INTERNED_IMMORTAL`` macro.
956956
(Contributed by Victor Stinner in :gh:`85858`.)
957957

958+
* Remove ``Jython`` compatibility hacks from several stdlib modules and tests.
959+
(Contributed by Nikita Sobolev in :gh:`99482`.)
960+
958961
* Remove ``_use_broken_old_ctypes_structure_semantics_`` flag
959962
from :mod:`ctypes` module.
960963
(Contributed by Nikita Sobolev in :gh:`99285`.)

Lib/copy.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ class Error(Exception):
5656
pass
5757
error = Error # backward compatibility
5858

59-
try:
60-
from org.python.core import PyStringMap
61-
except ImportError:
62-
PyStringMap = None
63-
6459
__all__ = ["Error", "copy", "deepcopy"]
6560

6661
def copy(x):
@@ -120,9 +115,6 @@ def _copy_immutable(x):
120115
d[set] = set.copy
121116
d[bytearray] = bytearray.copy
122117

123-
if PyStringMap is not None:
124-
d[PyStringMap] = PyStringMap.copy
125-
126118
del d, t
127119

128120
def deepcopy(x, memo=None, _nil=[]):
@@ -231,8 +223,6 @@ def _deepcopy_dict(x, memo, deepcopy=deepcopy):
231223
y[deepcopy(key, memo)] = deepcopy(value, memo)
232224
return y
233225
d[dict] = _deepcopy_dict
234-
if PyStringMap is not None:
235-
d[PyStringMap] = _deepcopy_dict
236226

237227
def _deepcopy_method(x, memo): # Copy instance methods
238228
return type(x)(x.__func__, deepcopy(x.__self__, memo))
@@ -301,4 +291,4 @@ def _reconstruct(x, memo, func, args,
301291
y[key] = value
302292
return y
303293

304-
del types, weakref, PyStringMap
294+
del types, weakref

Lib/pickle.py

-8
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,6 @@ class _Stop(Exception):
9898
def __init__(self, value):
9999
self.value = value
100100

101-
# Jython has PyStringMap; it's a dict subclass with string keys
102-
try:
103-
from org.python.core import PyStringMap
104-
except ImportError:
105-
PyStringMap = None
106-
107101
# Pickle opcodes. See pickletools.py for extensive docs. The listing
108102
# here is in kind-of alphabetical order of 1-character pickle code.
109103
# pickletools groups them by purpose.
@@ -972,8 +966,6 @@ def save_dict(self, obj):
972966
self._batch_setitems(obj.items())
973967

974968
dispatch[dict] = save_dict
975-
if PyStringMap is not None:
976-
dispatch[PyStringMap] = save_dict
977969

978970
def _batch_setitems(self, items):
979971
# Helper to batch up SETITEMS sequences; proto >= 1 only

Lib/platform.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ def platform(aliased=0, terse=0):
12901290
else:
12911291
platform = _platform(system, release, version, csd)
12921292

1293-
elif system in ('Linux',):
1293+
elif system == 'Linux':
12941294
# check for libc vs. glibc
12951295
libcname, libcversion = libc_ver()
12961296
platform = _platform(system, release, machine, processor,

Lib/site.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,7 @@ def setquit():
404404
def setcopyright():
405405
"""Set 'copyright' and 'credits' in builtins"""
406406
builtins.copyright = _sitebuiltins._Printer("copyright", sys.copyright)
407-
if sys.platform[:4] == 'java':
408-
builtins.credits = _sitebuiltins._Printer(
409-
"credits",
410-
"Jython is maintained by the Jython developers (www.jython.org).")
411-
else:
412-
builtins.credits = _sitebuiltins._Printer("credits", """\
407+
builtins.credits = _sitebuiltins._Printer("credits", """\
413408
Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
414409
for supporting Python development. See www.python.org for more information.""")
415410
files, dirs = [], []

Lib/test/support/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
505505
requires_legacy_unicode_capi = unittest.skipUnless(unicode_legacy_string,
506506
'requires legacy Unicode C API')
507507

508+
# Is not actually used in tests, but is kept for compatibility.
508509
is_jython = sys.platform.startswith('java')
509510

510511
is_android = hasattr(sys, 'getandroidapilevel')
@@ -736,8 +737,6 @@ def gc_collect():
736737
"""
737738
import gc
738739
gc.collect()
739-
if is_jython:
740-
time.sleep(0.1)
741740
gc.collect()
742741
gc.collect()
743742

Lib/test/support/os_helper.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111

1212

1313
# Filename used for testing
14-
if os.name == 'java':
15-
# Jython disallows @ in module names
16-
TESTFN_ASCII = '$test'
17-
else:
18-
TESTFN_ASCII = '@test'
14+
TESTFN_ASCII = '@test'
1915

2016
# Disambiguate TESTFN for parallel testing, while letting it remain a valid
2117
# module name.

Lib/test/test___all__.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ def test_all(self):
100100
'__future__',
101101
])
102102

103-
if not sys.platform.startswith('java'):
104-
# In case _socket fails to build, make this test fail more gracefully
105-
# than an AttributeError somewhere deep in CGIHTTPServer.
106-
import _socket
103+
# In case _socket fails to build, make this test fail more gracefully
104+
# than an AttributeError somewhere deep in CGIHTTPServer.
105+
import _socket
107106

108107
ignored = []
109108
failed_imports = []

Lib/test/test_codeop.py

+8-41
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,18 @@
22
Test cases for codeop.py
33
Nick Mathewson
44
"""
5-
import sys
65
import unittest
76
import warnings
8-
from test import support
97
from test.support import warnings_helper
108

119
from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT
12-
import io
13-
14-
if support.is_jython:
15-
16-
def unify_callables(d):
17-
for n,v in d.items():
18-
if hasattr(v, '__call__'):
19-
d[n] = True
20-
return d
2110

2211
class CodeopTests(unittest.TestCase):
2312

2413
def assertValid(self, str, symbol='single'):
2514
'''succeed iff str is a valid piece of code'''
26-
if support.is_jython:
27-
code = compile_command(str, "<input>", symbol)
28-
self.assertTrue(code)
29-
if symbol == "single":
30-
d,r = {},{}
31-
saved_stdout = sys.stdout
32-
sys.stdout = io.StringIO()
33-
try:
34-
exec(code, d)
35-
exec(compile(str,"<input>","single"), r)
36-
finally:
37-
sys.stdout = saved_stdout
38-
elif symbol == 'eval':
39-
ctx = {'a': 2}
40-
d = { 'value': eval(code,ctx) }
41-
r = { 'value': eval(str,ctx) }
42-
self.assertEqual(unify_callables(r),unify_callables(d))
43-
else:
44-
expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT)
45-
self.assertEqual(compile_command(str, "<input>", symbol), expected)
15+
expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT)
16+
self.assertEqual(compile_command(str, "<input>", symbol), expected)
4617

4718
def assertIncomplete(self, str, symbol='single'):
4819
'''succeed iff str is the start of a valid piece of code'''
@@ -62,16 +33,12 @@ def test_valid(self):
6233
av = self.assertValid
6334

6435
# special case
65-
if not support.is_jython:
66-
self.assertEqual(compile_command(""),
67-
compile("pass", "<input>", 'single',
68-
PyCF_DONT_IMPLY_DEDENT))
69-
self.assertEqual(compile_command("\n"),
70-
compile("pass", "<input>", 'single',
71-
PyCF_DONT_IMPLY_DEDENT))
72-
else:
73-
av("")
74-
av("\n")
36+
self.assertEqual(compile_command(""),
37+
compile("pass", "<input>", 'single',
38+
PyCF_DONT_IMPLY_DEDENT))
39+
self.assertEqual(compile_command("\n"),
40+
compile("pass", "<input>", 'single',
41+
PyCF_DONT_IMPLY_DEDENT))
7542

7643
av("a = 1")
7744
av("\na = 1")

Lib/test/test_exceptions.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,9 @@ def test_capi3():
360360
self.assertRaises(SystemError, _testcapi.raise_exception,
361361
InvalidException, 1)
362362

363-
if not sys.platform.startswith('java'):
364-
test_capi1()
365-
test_capi2()
366-
test_capi3()
363+
test_capi1()
364+
test_capi2()
365+
test_capi3()
367366

368367
def test_WindowsError(self):
369368
try:

Lib/test/test_import/__init__.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from test.support import os_helper
2222
from test.support import (
23-
STDLIB_DIR, is_jython, swap_attr, swap_item, cpython_only, is_emscripten,
23+
STDLIB_DIR, swap_attr, swap_item, cpython_only, is_emscripten,
2424
is_wasi)
2525
from test.support.import_helper import (
2626
forget, make_legacy_pyc, unlink, unload, DirsOnSysPath, CleanImport)
@@ -163,10 +163,7 @@ def test_import(self):
163163
def test_with_extension(ext):
164164
# The extension is normally ".py", perhaps ".pyw".
165165
source = TESTFN + ext
166-
if is_jython:
167-
pyc = TESTFN + "$py.class"
168-
else:
169-
pyc = TESTFN + ".pyc"
166+
pyc = TESTFN + ".pyc"
170167

171168
with open(source, "w", encoding='utf-8') as f:
172169
print("# This tests Python's ability to import a",

Lib/test/test_platform.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def raises_oserror(*a):
329329

330330
def test_java_ver(self):
331331
res = platform.java_ver()
332-
if sys.platform == 'java':
332+
if sys.platform == 'java': # Is never actually checked in CI
333333
self.assertTrue(all(res))
334334

335335
def test_win32_ver(self):

Lib/test/test_strftime.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,10 @@ def _update_variables(self, now):
5454
self.now = now
5555

5656
def setUp(self):
57-
try:
58-
import java
59-
java.util.Locale.setDefault(java.util.Locale.US)
60-
except ImportError:
61-
from locale import setlocale, LC_TIME
62-
saved_locale = setlocale(LC_TIME)
63-
setlocale(LC_TIME, 'C')
64-
self.addCleanup(setlocale, LC_TIME, saved_locale)
57+
from locale import setlocale, LC_TIME
58+
saved_locale = setlocale(LC_TIME)
59+
setlocale(LC_TIME, 'C')
60+
self.addCleanup(setlocale, LC_TIME, saved_locale)
6561

6662
def test_strftime(self):
6763
now = time.time()

0 commit comments

Comments
 (0)