Ahh thank-you so much! I ended up with this so I can define list, seq, dict, etc def argument_annotation_inference(node, context=None): _type = next(node._annotype.infer()) klass = vars(builtins)[_type.name] return iter([CONST_CLS[klass](klass())]) On Thu, May 7, 2015 at 10:39 PM, Claudiu Popa <pcmanticore@gmail.com> wrote:
On Thu, May 7, 2015 at 6:02 PM, Jarrad Hope <me@jarradhope.com> wrote:
This is how far I got with this, https://gist.github.com/jarradh/02dd8f5ad07527c9fd10
In the example go through Arguments(i imagine I'll have to apply transform on functiondef later) and apply an explicit transformation, and I manage to apply a Const type to all of them but I got stuck at how to switch based on node._annotype.name since Const instantiates with the name as a value and therefore it's a string type.
How can I switch the Const type based on node._annotype.name ? Or is there a better way of going about this?
You'll have to infer node._annontype.name (which can be a Class) and get its name. Then retrieving the name from builtins and try to go from there. Something along these lines:
import builtins
type = next(node._annotype.infer()) const = Const(vars(builtins)[type.name]())