dora-rs / dora

DORA (Dataflow-Oriented Robotic Architecture) is middleware designed to streamline and simplify the creation of AI-based robotic applications. It offers low latency, composable, and distributed dataflow capabilities. Applications are modeled as directed graphs, also referred to as pipelines.
https://dora-rs.ai
Apache License 2.0
1.5k stars 79 forks source link

Derive `__dir__`, `__str__`, `__repr__` with a proc macro crate #547

Closed EricLBuehler closed 3 months ago

EricLBuehler commented 3 months ago

This PR uses a proc macro to retrieve the field names for the __dir__ method.

Currently, this will show all field names regardless of visibility or accessibility from Python. Perhaps we should change this such that only methods which are marked somehow as accessible from Python can be exposed?

haixuanTao commented 3 months ago

Awesome work by the way!

Pinging @ArthurZucker as this might be useful. Do you want this to be an individual repo that you can use?

This basically would make it possible to auto-generate the python __dir__ and in the future __dict__ that is used by the python debugger.

Additionally we could integrate your display code as a derive macro so that anyone who want to have a quick implementation of it can use it.

EricLBuehler commented 3 months ago

Maybe we can check if we can use: https://pyo3.rs/v0.21.2/features.html#multiple-pymethods ?

I added this feature.

This basically would make it possible to auto-generate the python dir and in the future dict that is used by the python debugger.

I think the __dict__ would end up being very similar to the implementation of the Display derive macro in tokenizers, so that can be done quickly.

haixuanTao commented 3 months ago

So just played further with it! And really like it! Could be really good to have a skip method. I think that it's quite a common use case to not want to expose the rust implementation, it would also make it easier to check by iteration. Let's do this in a follow up PR within its own repo :)

Thanks a lot!

EricLBuehler commented 3 months ago

Ok, great! I'll make a separate repo. Should I close this PR and reopen to use the new crate?

haixuanTao commented 3 months ago

So, let's publish a new crate on crates.io and link it in this PR if that's ok?

EricLBuehler commented 3 months ago

I published a v0.1.0 version of that crate: https://docs.rs/pyo3_special_method_derive/

Here is the Github: https://github.com/EricLBuehler/pyo3-special-method-derive