Skip to content

Conversation

@vtjnash
Copy link
Contributor

@vtjnash vtjnash commented May 12, 2013

this extends pytype_query() to allow the user to add custom type mappings.

example usage (based upon SymPy):

type Sym
     x::PyCall.PyObject
end
Sym(s::Sym) = s
convert(::Type{Sym}, o::PyCall.PyObject) = Sym(o)
PyCall.pytype_query_add(sympy.basic[Basic], Sym)

note: I see this would address item 3 in #9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if this needed to be handled differently given the above extension to pytype_query, so I left is alone

@stevengj
Copy link
Member

Thanks! Perhaps pytype_mapping(pyT, T) (or pytype_mapping[pyT] = T?) would be a better name than pytype_query_add? And exported?

Also, maybe pytype_queries should be a Dict instead of an Array of pairs, so that it avoids adding duplicate entries if pytype_mapping is called more than once.

(What I had in mind for #9 was more like an automatic mapping of a Julia composite type to a Python composite type with the same fields, which is different from this.)

@vtjnash
Copy link
Contributor Author

vtjnash commented May 13, 2013

Thanks, I'll update when I have time. My thought was that an Array would be much faster for iteration (which will happen much more often than insertion), so I think I'll keep it the same, but I'll also add a check for duplicates to mimic a Dict.

@stevengj
Copy link
Member

Sounds good.

vtjnash added 3 commits May 31, 2013 18:15
example usage (for SymPy):
type Sym
     x::PyCall.PyObject
end
Sym(s::Sym) = s
convert(::Type{Sym}, o::PyCall.PyObject) = Sym(o)
PyCall.pytype_query_add(sympy.basic[Basic], Sym)
@vtjnash
Copy link
Contributor Author

vtjnash commented May 31, 2013

OK. This should be set.

As an example, note that this would have allowed BigFloat support to be added without editing PyCall (except perhaps for adding finalizer support). This would by done by adding to mpmath_init the following lines:

pytype_mapping(PyCall.mpf, BigFloat)
pytype_mapping(PyCall.mpc, Complex{BigFloat})

instead of adding it directly to pytype_query and creating pymp_query

@vtjnash
Copy link
Contributor Author

vtjnash commented Jun 13, 2013

bump @stevengj

@stevengj
Copy link
Member

Sorry about the delay. I'm on vacation this week with family and may not get to PyCall until I get back in the last week of June.

stevengj added a commit that referenced this pull request Jun 24, 2013
allow custom pytype return values
@stevengj stevengj merged commit abe8b98 into JuliaPy:master Jun 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants