def node_frame_class(node: astroid.node_classes.NodeNG) -> Optional[astroid.node_classes.NodeNG]: """return klass node for a method node (or a staticmethod or a classmethod), return null otherwise """ klass = node.frame() while klass is not None and not isinstance(klass, astroid.ClassDef): if klass.parent is None: klass = None else: klass = klass.parent.frame() return klass
def node_frame_class(node: astroid.node_classes.NodeNG) -> Optional[astroid.ClassDef]: """Return the class that is wrapping the given node The function returns a class for a method node (or a staticmethod or a classmethod), otherwise it returns `None`. """ klass = node.frame() while klass is not None and not isinstance(klass, astroid.ClassDef): if klass.parent is None: klass = None else: klass = klass.parent.frame() return klass
def node_frame_class( node: astroid.node_classes.NodeNG) -> Optional[astroid.ClassDef]: """Return the class that is wrapping the given node The function returns a class for a method node (or a staticmethod or a classmethod), otherwise it returns `None`. """ klass = node.frame() nodes_to_check = ( astroid.node_classes.NodeNG, astroid.UnboundMethod, astroid.BaseInstance, ) while (klass and isinstance(klass, nodes_to_check) and not isinstance(klass, astroid.ClassDef)): if klass.parent is None: klass = None else: klass = klass.parent.frame() return klass