clj-python / libpython-clj

Python bindings for Clojure
Eclipse Public License 2.0
1.08k stars 68 forks source link

Handle conversion of generic-alias and union-type types in ->jvm #251

Closed markgdawson closed 1 year ago

markgdawson commented 1 year ago

See issue #250.

Some python types (in particular GenericAlias and Union) cannot be handled by the default ->jvm handler.

Note on tests: The only way I could find to instantiate an object of type types.UnionType for testing is directly with python syntax and the | operator. I don't know of a way to test objects created via syntax without creating global variables in the python interpreter (e.g. with run-simple-string). For that reason, I've left the test for this out for now. I have tested by hand. Suggestions for good approaches to this welcome.

Note: types.UnionType is not the same as typing.Union, which can be used via __get_item__ to produces objects of type typing._UnionGenericAlias.