def attr___annotations__(self): obj = node_classes.Dict(parent=self._instance) if not self._instance.returns: returns = None else: returns = self._instance.returns args = self._instance.args pair_annotations = itertools.chain( zip(args.args or [], args.annotations), zip(args.kwonlyargs, args.kwonlyargs_annotations), zip(args.posonlyargs or [], args.posonlyargs_annotations), ) annotations = { arg.name: annotation for (arg, annotation) in pair_annotations if annotation } if args.varargannotation: annotations[args.vararg] = args.varargannotation if args.kwargannotation: annotations[args.kwarg] = args.kwargannotation if returns: annotations["return"] = returns items = [(node_classes.Const(key, parent=obj), value) for (key, value) in annotations.items()] obj.postinit(items) return obj
def py__annotations__(self): obj = node_classes.Dict(parent=self._instance) if not self._instance.returns: returns = None else: returns = self._instance.returns args = self._instance.args annotations = { arg.name: annotation for (arg, annotation) in zip(args.args, args.annotations) if annotation } if args.varargannotation: annotations[args.vararg] = args.varargannotation if args.kwargannotation: annotations[args.kwarg] = args.kwargannotation if returns: annotations['return'] = returns items = [(node_classes.Const(key, parent=obj), value) for (key, value) in annotations.items()] obj.postinit(items) return obj
def _dunder_dict(instance, attributes): obj = node_classes.Dict(parent=instance) # Convert the keys to node strings keys = [node_classes.Const(value=value, parent=obj) for value in list(attributes.keys())] # The original attribute has a list of elements for each key, # but that is not useful for retrieving the special attribute's value. # In this case, we're picking the last value from each list. values = [elem[-1] for elem in attributes.values()] obj.postinit(list(zip(keys, values))) return obj
def attr___kwdefaults__(self): def _default_args(args, parent): for arg in args.kwonlyargs: try: default = args.default_value(arg.name) except exceptions.NoDefault: continue name = node_classes.Const(arg.name, parent=parent) yield name, default args = self._instance.args obj = node_classes.Dict(parent=self._instance) defaults = dict(_default_args(args, obj)) obj.postinit(list(defaults.items())) return obj
def attr___dict__(self): return node_classes.Dict(parent=self._instance)
def _dunder_dict(instance, attributes): obj = node_classes.Dict(parent=instance)
def attr___annotations__(self): obj = node_classes.Dict(parent=self._instance) if not self._instance.returns: