Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typed versions of PyObject container views #1207

Open
mhsmith opened this issue Jul 6, 2024 · 1 comment
Open

Add typed versions of PyObject container views #1207

mhsmith opened this issue Jul 6, 2024 · 1 comment

Comments

@mhsmith
Copy link
Member

mhsmith commented Jul 6, 2024

This would be particularly helpful in avoiding the need to call fromJava when modifying the container. For example, see the os.environ example on the Java API documentation page.

API could be something like List<T> asList(Class<T> elementType) -- see note at PyList.set.

@mhsmith
Copy link
Member Author

mhsmith commented Jul 6, 2024

It's worse in Kotlin because the Map get/remove/containsKey functions, which apparently used to accept any object like Java, now appear to be fully type-safe. For example, attempting to call pyobject.asMap().containsKey("string") fails to compile with a type inference error, and the IDE shows it's resolved to an extension function whose purpose is unclear to me.

Ideally we'd like to be able to change this (from Electron Cash):

val iMap = i.asMap()
iMap[fromJava("address")] = fromJava(iMap[fromJava("address")].toString())

To something like this:

val iMap = i.asMap(String::class, Any::class)
iMap["address"] = iMap["address"].toString()

Also consider how element nullability could be expressed, e.g. SendContactsDialog.contacts in Electron Cash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant