From a049ec04577145fca40a16074a9b7ac3d098ed39 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 7 Mar 2024 21:58:32 +0300 Subject: [PATCH 1/3] gh-116349: Deprecate `platform.java_ver` function --- Doc/library/platform.rst | 3 +++ Doc/whatsnew/3.13.rst | 4 ++++ Lib/platform.py | 4 +++- Lib/test/test_platform.py | 10 +++++++--- .../2024-03-07-21-57-50.gh-issue-116349.fD2pbP.rst | 2 ++ 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-03-07-21-57-50.gh-issue-116349.fD2pbP.rst diff --git a/Doc/library/platform.rst b/Doc/library/platform.rst index ec2a7ebd5d6e0b..57eda54ee2c980 100644 --- a/Doc/library/platform.rst +++ b/Doc/library/platform.rst @@ -196,6 +196,9 @@ Java Platform ``(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 only useful for Jython support. + Windows Platform ---------------- diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index dc7dce969a695a..ceb741e594e892 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -973,6 +973,10 @@ Pending Removal in Python 3.15 They will be removed in Python 3.15. (Contributed by Victor Stinner in :gh:`105096`.) +* :func:`platform.java_ver` is deprecated and will be removed in 3.15. + It was only useful for Jython support. + (Contributed by Nikita Sobolev in :gh:`116349`.) + Pending Removal in Python 3.16 ------------------------------ diff --git a/Lib/platform.py b/Lib/platform.py index b56472235ee9e4..21dcc1d5c1116f 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -503,7 +503,7 @@ def mac_ver(release='', versioninfo=('', '', ''), machine=''): return release, versioninfo, machine def _java_getprop(name, default): - + """This protected helper is deprecated in 3.13 and will be removed in 3.15""" from java.lang import System try: value = System.getProperty(name) @@ -525,6 +525,8 @@ def java_ver(release='', vendor='', vminfo=('', '', ''), osinfo=('', '', '')): given as parameters (which all default to ''). """ + import warnings + warnings._deprecated('java_ver', remove=(3, 15)) # Import the needed APIs try: import java.lang diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index 648e18d0150ef0..bbd0c06efed2c9 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -318,9 +318,13 @@ def raises_oserror(*a): platform._uname_cache = None def test_java_ver(self): - res = platform.java_ver() - if sys.platform == 'java': # Is never actually checked in CI - self.assertTrue(all(res)) + 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) def test_win32_ver(self): res = platform.win32_ver() diff --git a/Misc/NEWS.d/next/Library/2024-03-07-21-57-50.gh-issue-116349.fD2pbP.rst b/Misc/NEWS.d/next/Library/2024-03-07-21-57-50.gh-issue-116349.fD2pbP.rst new file mode 100644 index 00000000000000..b42a1f0b69389f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-03-07-21-57-50.gh-issue-116349.fD2pbP.rst @@ -0,0 +1,2 @@ +:func:`platform.java_ver` is deprecated and will be removed in 3.15. It was +only useful for Jython support. From cbfdb5b9de24c9565ff8465cb6a349a279eb6d7a Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 7 Mar 2024 22:12:14 +0300 Subject: [PATCH 2/3] Update Doc/library/platform.rst Co-authored-by: Alex Waygood --- Doc/library/platform.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/platform.rst b/Doc/library/platform.rst index 57eda54ee2c980..4bc3956449b930 100644 --- a/Doc/library/platform.rst +++ b/Doc/library/platform.rst @@ -197,7 +197,8 @@ Java Platform the defaults given as parameters (which all default to ``''``). .. deprecated-removed:: 3.13 3.15 - It was only useful for Jython support. + It was largely untested, had a confusing API, + and was only useful for Jython support. Windows Platform From 38c9ded295011e379c99633c7d7c49e15c579483 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 7 Mar 2024 22:37:48 +0300 Subject: [PATCH 3/3] Address review --- Doc/whatsnew/3.13.rst | 7 ++++++- Lib/platform.py | 2 +- .../Library/2024-03-07-21-57-50.gh-issue-116349.fD2pbP.rst | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index ceb741e594e892..51939909000960 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -814,6 +814,10 @@ Deprecated * The undocumented and unused ``tarfile`` attribute of :class:`tarfile.TarFile` is deprecated and scheduled for removal in Python 3.16. +* :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. + (Contributed by Nikita Sobolev in :gh:`116349`.) Pending Removal in Python 3.14 ------------------------------ @@ -974,7 +978,8 @@ Pending Removal in Python 3.15 (Contributed by Victor Stinner in :gh:`105096`.) * :func:`platform.java_ver` is deprecated and will be removed in 3.15. - It was only useful for Jython support. + It was largely untested, had a confusing API, + and was only useful for Jython support. (Contributed by Nikita Sobolev in :gh:`116349`.) Pending Removal in Python 3.16 diff --git a/Lib/platform.py b/Lib/platform.py index 21dcc1d5c1116f..6764e0d5f75063 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -503,7 +503,7 @@ def mac_ver(release='', versioninfo=('', '', ''), machine=''): return release, versioninfo, machine def _java_getprop(name, default): - """This protected helper is deprecated in 3.13 and will be removed in 3.15""" + """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) diff --git a/Misc/NEWS.d/next/Library/2024-03-07-21-57-50.gh-issue-116349.fD2pbP.rst b/Misc/NEWS.d/next/Library/2024-03-07-21-57-50.gh-issue-116349.fD2pbP.rst index b42a1f0b69389f..89eb4197348410 100644 --- a/Misc/NEWS.d/next/Library/2024-03-07-21-57-50.gh-issue-116349.fD2pbP.rst +++ b/Misc/NEWS.d/next/Library/2024-03-07-21-57-50.gh-issue-116349.fD2pbP.rst @@ -1,2 +1,3 @@ -:func:`platform.java_ver` is deprecated and will be removed in 3.15. It was -only useful for Jython support. +: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.