Skip to content

Commit

Permalink
remove str support from JArray __class_getitem__
Browse files Browse the repository at this point in the history
  • Loading branch information
astrelsky committed Sep 9, 2024
1 parent a7a7a70 commit 262eabb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion doc/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Latest Changes:

- **1.5.1_dev0 - 2023-12-15**

- Added support for typing ``JArray``. ``JArray[java.lang.Object]`` ``JArray["java.lang.Object"]``
- Added support for typing ``JArray`` (Java type only), e.g. ``JArray[java.lang.Object]`` ``"JArray[java.lang.Object]"``

- Fixed uncaught exception while setting traceback causing issues in Python 3.11/3.12.

Expand Down
7 changes: 4 additions & 3 deletions jpype/_jarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#
# *****************************************************************************
import _jpype
import typing

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'typing' is not used.
from . import _jcustomizer


Expand All @@ -29,7 +30,7 @@ class JArray(_jpype._JObject, internal=True): # type: ignore[call-arg]
The resulting Java array class can be used to construct a new
array with a given size or specified members.
JPype arrays support Python operators for iterating, length, equals,
JPype arrays support Python operators for iterating, length, equals,
not equals, subscripting, and slicing. They also support Java
object methods, clone, and length property. Java arrays may not
be resized, and as such elements cannot be added nor deleted. Currently,
Expand Down Expand Up @@ -96,9 +97,9 @@ def __class_getitem__(cls, key):
if key is _jpype.JClass:
# explicit check for JClass
# _toJavaClass cannot be used
# passing int, float, etc is not allowed
# passing int, float, str, etc is not allowed
key = _jpype._java_lang_Class
if isinstance(key, (str, _jpype._java_lang_Class)):
if isinstance(key, _jpype._java_lang_Class):
key = _jpype.JClass(key)
if isinstance(key, _jpype.JClass):
return type(key[0])
Expand Down
9 changes: 1 addition & 8 deletions test/jpypetest/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,6 @@ def testJArrayGeneric_Init(self):
def testJArrayInvalidGeneric(self):
with self.assertRaises(TypeError):
jpype.JArray[object]

def testJArrayGenericJClass(self):
self.assertEqual(type(JClass[0]), JArray[JClass])

def testJArrayGenericString(self):
self.assertEqual(type(JClass[0]), JArray["java.lang.Class"])

def testJArrayGenericStringInvalid(self):
with self.assertRaises(TypeError):
JArray["foo.bar"] # type: ignore

0 comments on commit 262eabb

Please sign in to comment.