I have my custom class that represents an object. I want to make that object compatible with "ast.literal_eval()"
How can I do that? I can add necessary method/code to my class if necessary.
You cannot. You will need to reimplement it from scratch, adding support for your class within it.
ast.literal_eval() chooses what it accepts.Because you tagged your question with Pyro, I assume you're asking it in the context of serializing your own classes when using Pyro's remote method calls. Pyro provides a mechanism to do that.
ast.literal_evalevaluates literals. Python does not support user defined literals. Ergo, you can't useast.literal_evalto produce a user defined type. If you could, all the security guarantees ofast.literal_evalwould go out the window.