From 5818107ca1c35283ec2b200f694a07a7238e5bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 10 May 2025 11:24:12 +0200 Subject: [PATCH] remove `platform.java_ver` --- Doc/deprecations/pending-removal-in-3.15.rst | 2 +- Doc/library/platform.rst | 18 ----- Doc/whatsnew/3.13.rst | 2 +- Doc/whatsnew/3.15.rst | 7 +- Lib/platform.py | 66 +------------------ Lib/test/test_platform.py | 9 --- Misc/NEWS.d/3.13.0a5.rst | 2 +- ...-05-10-11-23-47.gh-issue-133812.062Sda.rst | 2 + 8 files changed, 11 insertions(+), 97 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-05-10-11-23-47.gh-issue-133812.062Sda.rst diff --git a/Doc/deprecations/pending-removal-in-3.15.rst b/Doc/deprecations/pending-removal-in-3.15.rst index 7b32275ad867608..c56a05cb31660c2 100644 --- a/Doc/deprecations/pending-removal-in-3.15.rst +++ b/Doc/deprecations/pending-removal-in-3.15.rst @@ -51,7 +51,7 @@ Pending removal in Python 3.15 * :mod:`platform`: - * :func:`~platform.java_ver` has been deprecated since Python 3.13. + * :func:`!platform.java_ver` has been deprecated since Python 3.13. This function is only useful for Jython support, has a confusing API, and is largely untested. diff --git a/Doc/library/platform.rst b/Doc/library/platform.rst index 5c999054323be55..06de152a742f28e 100644 --- a/Doc/library/platform.rst +++ b/Doc/library/platform.rst @@ -188,24 +188,6 @@ Cross platform :attr:`processor` is resolved late instead of immediately. -Java platform -------------- - - -.. function:: java_ver(release='', vendor='', vminfo=('','',''), osinfo=('','','')) - - Version interface for Jython. - - Returns a tuple ``(release, vendor, vminfo, osinfo)`` with *vminfo* being a - tuple ``(vm_name, vm_release, vm_vendor)`` and *osinfo* being a tuple - ``(os_name, os_version, os_arch)``. Values which cannot be determined are set to - the defaults given as parameters (which all default to ``''``). - - .. deprecated-removed:: 3.13 3.15 - It was largely untested, had a confusing API, - and was only useful for Jython support. - - Windows platform ---------------- diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index b3530f75b2fa407..2b2ccfff1b7bd59 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -1908,7 +1908,7 @@ New Deprecations * :mod:`platform`: - * Deprecate :func:`~platform.java_ver`, + * Deprecate :func:`!platform.java_ver`, to be removed in Python 3.15. This function is only useful for Jython support, has a confusing API, and is largely untested. diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index d1e58c1b764eb90..d6c756c021e3d6b 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -118,10 +118,11 @@ Deprecated Removed ======= -module_name ------------ +platform +-------- -* TODO +* The barely tested :func:`!platform.java_ver` function. + (Contributed by Bénédikt Tran in :gh:`133812`.) Porting to Python 3.15 diff --git a/Lib/platform.py b/Lib/platform.py index 55e211212d42097..7f8b079b22a23ee 100644 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -31,6 +31,7 @@ # # # +# 1.1.0 - removed deprecated java_ver() function # 1.0.9 - added invalidate_caches() function to invalidate cached values # 1.0.8 - changed Windows support to read version from kernel32.dll # 1.0.7 - added DEV_NULL @@ -110,7 +111,7 @@ """ -__version__ = '1.0.9' +__version__ = '1.1.0' import collections import os @@ -528,53 +529,6 @@ def ios_ver(system="", release="", model="", is_simulator=False): return IOSVersionInfo(system, release, model, is_simulator) -def _java_getprop(name, default): - """This private helper is deprecated in 3.13 and will be removed in 3.15""" - from java.lang import System - try: - value = System.getProperty(name) - if value is None: - return default - return value - except AttributeError: - return default - -def java_ver(release='', vendor='', vminfo=('', '', ''), osinfo=('', '', '')): - - """ Version interface for Jython. - - Returns a tuple (release, vendor, vminfo, osinfo) with vminfo being - a tuple (vm_name, vm_release, vm_vendor) and osinfo being a - tuple (os_name, os_version, os_arch). - - Values which cannot be determined are set to the defaults - given as parameters (which all default to ''). - - """ - import warnings - warnings._deprecated('java_ver', remove=(3, 15)) - # Import the needed APIs - try: - import java.lang # noqa: F401 - except ImportError: - return release, vendor, vminfo, osinfo - - vendor = _java_getprop('java.vendor', vendor) - release = _java_getprop('java.version', release) - vm_name, vm_release, vm_vendor = vminfo - vm_name = _java_getprop('java.vm.name', vm_name) - vm_vendor = _java_getprop('java.vm.vendor', vm_vendor) - vm_release = _java_getprop('java.vm.version', vm_release) - vminfo = vm_name, vm_release, vm_vendor - os_name, os_version, os_arch = osinfo - os_arch = _java_getprop('java.os.arch', os_arch) - os_name = _java_getprop('java.os.name', os_name) - os_version = _java_getprop('java.os.version', os_version) - osinfo = os_name, os_version, os_arch - - return release, vendor, vminfo, osinfo - - AndroidVer = collections.namedtuple( "AndroidVer", "release api_level manufacturer model device is_emulator") @@ -1034,13 +988,6 @@ def uname(): version = '16bit' system = 'Windows' - elif system[:4] == 'java': - release, vendor, vminfo, osinfo = java_ver() - system = 'Java' - version = ', '.join(vminfo) - if not version: - version = vendor - # System specific extensions if system == 'OpenVMS': # OpenVMS seems to have release and version mixed up @@ -1370,15 +1317,6 @@ def platform(aliased=False, terse=False): platform = _platform(system, release, machine, processor, 'with', libcname+libcversion) - elif system == 'Java': - # Java platforms - r, v, vminfo, (os_name, os_version, os_arch) = java_ver() - if terse or not os_name: - platform = _platform(system, release, version) - else: - platform = _platform(system, release, version, - 'on', - os_name, os_version, os_arch) else: # Generic handler diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index 818e807dd3a6fb6..3b673a47c8c137b 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -383,15 +383,6 @@ def raises_oserror(*a): finally: platform._uname_cache = None - def test_java_ver(self): - import re - msg = re.escape( - "'java_ver' is deprecated and slated for removal in Python 3.15" - ) - with self.assertWarnsRegex(DeprecationWarning, msg): - res = platform.java_ver() - self.assertEqual(len(res), 4) - @unittest.skipUnless(support.MS_WINDOWS, 'This test only makes sense on Windows') def test_win32_ver(self): release1, version1, csd1, ptype1 = 'a', 'b', 'c', 'd' diff --git a/Misc/NEWS.d/3.13.0a5.rst b/Misc/NEWS.d/3.13.0a5.rst index d56b1542b018230..37d1e556bf12ebf 100644 --- a/Misc/NEWS.d/3.13.0a5.rst +++ b/Misc/NEWS.d/3.13.0a5.rst @@ -211,7 +211,7 @@ Fix :func:`repr` for global :class:`~enum.Flag` members. .. nonce: fD2pbP .. section: Library -:func:`platform.java_ver` is deprecated and will be removed in 3.15. It was +:func:`!platform.java_ver` is deprecated and will be removed in 3.15. It was largely untested, had a confusing API, and was only useful for Jython support. diff --git a/Misc/NEWS.d/next/Library/2025-05-10-11-23-47.gh-issue-133812.062Sda.rst b/Misc/NEWS.d/next/Library/2025-05-10-11-23-47.gh-issue-133812.062Sda.rst new file mode 100644 index 000000000000000..c2f1a17fdd4a1fe --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-05-10-11-23-47.gh-issue-133812.062Sda.rst @@ -0,0 +1,2 @@ +Remove deprecated and barely tested function :func:`!platform.java_ver`. +Patch by Bénédikt Tran.