fname stringlengths 63 176 | rel_fname stringclasses 706
values | line int64 -1 4.5k | name stringlengths 1 81 | kind stringclasses 2
values | category stringclasses 2
values | info stringlengths 0 77.9k ⌀ |
|---|---|---|---|---|---|---|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 225 | module | def | function | def module(self, name):
"""Return a module by its name, raise KeyError if not found."""
for mod in self.modules():
if mod.node.name == name:
return mod
raise KeyError(name)
def get_module(self, name, node):
"""Return a module by its name, looking also for relative imports;
raise KeyError if not found
"""
for mod in self.modules():
mod_name = mod.node.name
if mod_name == name:
return mod
# search for fullname of relative import modules
package = node.root().name
if mod_name == f"{package}.{name}":
return mod
if mod_name == f"{package.rsplit('.', 1)[0]}.{name}":
return mod
raise KeyError(name)
def add_from_depend(self, node, from_module):
"""Add dependencies created by from-imports."""
mod_name = node.root().name
obj = self.module(mod_name)
if from_module not in obj.node.depends:
obj.node.depends.append(from_module)
def extract_relationships(self):
"""Extract relationships between nodes in the diagram."""
super().extract_relationships()
for obj in self.classes():
# ownership
try:
mod = self.object_from_node(obj.node.root())
self.add_relationship(obj, mod, "ownership")
except KeyError:
continue
for obj in self.modules():
obj.shape = "package"
# dependencies
for dep_name in obj.node.depends:
try:
dep = self.get_module(dep_name, obj.node)
except KeyError:
continue
self.add_relationship(obj, dep, "depends")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 227 | modules | ref | function | for mod in self.modules():
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 232 | get_module | def | function | def get_module(self, name, node):
"""Return a module by its name, looking also for relative imports;
raise KeyError if not found
"""
for mod in self.modules():
mod_name = mod.node.name
if mod_name == name:
return mod
# search for fullname of relative import modules
package = node.root().name
if mod_name == f"{package}.{name}":
return mod
if mod_name == f"{package.rsplit('.', 1)[0]}.{name}":
return mod
raise KeyError(name)
def add_from_depend(self, node, from_module):
"""Add dependencies created by from-imports."""
mod_name = node.root().name
obj = self.module(mod_name)
if from_module not in obj.node.depends:
obj.node.depends.append(from_module)
def extract_relationships(self):
"""Extract relationships between nodes in the diagram."""
super().extract_relationships()
for obj in self.classes():
# ownership
try:
mod = self.object_from_node(obj.node.root())
self.add_relationship(obj, mod, "ownership")
except KeyError:
continue
for obj in self.modules():
obj.shape = "package"
# dependencies
for dep_name in obj.node.depends:
try:
dep = self.get_module(dep_name, obj.node)
except KeyError:
continue
self.add_relationship(obj, dep, "depends")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 236 | modules | ref | function | for mod in self.modules():
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 241 | root | ref | function | package = node.root().name
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 248 | add_from_depend | def | function | def add_from_depend(self, node, from_module):
"""Add dependencies created by from-imports."""
mod_name = node.root().name
obj = self.module(mod_name)
if from_module not in obj.node.depends:
obj.node.depends.append(from_module)
def extract_relationships(self):
"""Extract relationships between nodes in the diagram."""
super().extract_relationships()
for obj in self.classes():
# ownership
try:
mod = self.object_from_node(obj.node.root())
self.add_relationship(obj, mod, "ownership")
except KeyError:
continue
for obj in self.modules():
obj.shape = "package"
# dependencies
for dep_name in obj.node.depends:
try:
dep = self.get_module(dep_name, obj.node)
except KeyError:
continue
self.add_relationship(obj, dep, "depends")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 250 | root | ref | function | mod_name = node.root().name
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 251 | module | ref | function | obj = self.module(mod_name)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 255 | extract_relationships | def | function | def extract_relationships(self):
"""Extract relationships between nodes in the diagram."""
for obj in self.classes():
node = obj.node
obj.attrs = self.get_attrs(node)
obj.methods = self.get_methods(node)
# shape
if is_interface(node):
obj.shape = "interface"
else:
obj.shape = "class"
# inheritance link
for par_node in node.ancestors(recurs=_False):
try:
par_obj = self.object_from_node(par_node)
self.add_relationship(obj, par_obj, "specialization")
except KeyError:
continue
# implements link
for impl_node in node.implements:
try:
impl_obj = self.object_from_node(impl_node)
self.add_relationship(obj, impl_obj, "implements")
except KeyError:
continue
# associations link
for name, values in list(node.instance_attrs_type.items()) + list(
node.locals_type.items()
):
for value in values:
if value is astroid.Uninferable:
continue
if isinstance(value, astroid.Instance):
value = value._proxied
try:
associated_obj = self.object_from_node(value)
self.add_relationship(associated_obj, obj, "association", name)
except KeyError:
continue
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 257 | extract_relationships | ref | function | super().extract_relationships()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 258 | classes | ref | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 261 | object_from_node | ref | function | mod = self.object_from_node(obj.node.root())
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 261 | root | ref | function | mod = self.object_from_node(obj.node.root())
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 262 | add_relationship | ref | function | self.add_relationship(obj, mod, "ownership")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 265 | modules | ref | function | for obj in self.modules():
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 270 | get_module | ref | function | dep = self.get_module(dep_name, obj.node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/diagrams.py | pylint/pyreverse/diagrams.py | 273 | add_relationship | ref | function | self.add_relationship(obj, dep, "depends")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 39 | DotPrinter | def | class | __init__ _open_graph emit_node _build_label_for_node emit_edge generate _close_graph |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 52 | _open_graph | def | function | def _open_graph(self) -> None:
"""Emit the header lines."""
self.emit(f'digraph "{self.title}" {{')
if self.layout:
self.emit(f"rankdir={self.layout.value}")
if self.charset:
assert (
self.charset.lower() in ALLOWED_CHARSETS
), f"unsupported charset {self.charset}"
self.emit(f'charset="{self.charset}"')
def emit_node(
self,
name: str,
type_: NodeType,
properties: Optional[NodeProperties] = None,
) -> None:
"""Create a new node. Nodes can be classes, packages, participants etc."""
if properties is None:
properties = NodeProperties(label=name)
shape = SHAPES[type_]
color = properties.color if properties.color is not None else self.DEFAULT_COLOR
style = "filled" if color != self.DEFAULT_COLOR else "solid"
label = self._build_label_for_node(properties)
label_part = f', label="{label}"' if label else ""
fontcolor_part = (
f', fontcolor="{properties.fontcolor}"' if properties.fontcolor else ""
)
self.emit(
f'"{name}" [color="{color}"{fontcolor_part}{label_part}, shape="{shape}", style="{style}"];'
)
def _build_label_for_node(
self, properties: NodeProperties, is_interface: Optional[bool] = _False
) -> str:
if not properties.label:
return ""
label: str = properties.label
if is_interface:
# add a stereotype
label = "<<interface>>\\n" + label
if properties.attrs is None and properties.methods is None:
# return a "compact" form which only displays the class name in a box
return label
# Add class attributes
attrs: List[str] = properties.attrs or []
label = "{" + label + "|" + r"\l".join(attrs) + r"\l|"
# Add class methods
methods: List[nodes.FunctionDef] = properties.methods or []
for func in methods:
args = self._get_method_arguments(func)
label += rf"{func.name}({', '.join(args)})"
if func.returns:
label += ": " + get_annotation_label(func.returns)
label += r"\l"
label += "}"
return label
def emit_edge(
self,
from_node: str,
to_node: str,
type_: EdgeType,
label: Optional[str] = None,
) -> None:
"""Create an edge from one node to another to display relationships."""
arrowstyle = ARROWS[type_]
attrs = [f'{prop}="{value}"' for prop, value in arrowstyle.items()]
if label:
attrs.append(f'label="{label}"')
self.emit(f'"{from_node}" -> "{to_node}" [{", ".join(sorted(attrs))}];')
def generate(self, outputfile: str) -> None:
self._close_graph()
graphviz_extensions = ("dot", "gv")
name = self.title
if outputfile is None:
target = "png"
pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
ppng, outputfile = tempfile.mkstemp(".png", name)
os.close(pdot)
os.close(ppng)
else:
target = Path(outputfile).suffix.lstrip(".")
if not target:
target = "png"
outputfile = outputfile + "." + target
if target not in graphviz_extensions:
pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
os.close(pdot)
else:
dot_sourcepath = outputfile
with open(dot_sourcepath, "w", encoding="utf8") as outfile:
outfile.writelines(self.lines)
if target not in graphviz_extensions:
check_graphviz_availability()
use_shell = sys.platform == "win32"
subprocess.call(
["dot", "-T", target, dot_sourcepath, "-o", outputfile],
shell=use_shell,
)
os.unlink(dot_sourcepath)
def _close_graph(self) -> None:
"""Emit the lines needed to properly close the graph."""
self.emit("}\n")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 54 | emit | ref | function | self.emit(f'digraph "{self.title}" {{')
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 56 | emit | ref | function | self.emit(f"rankdir={self.layout.value}")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 61 | emit | ref | function | self.emit(f'charset="{self.charset}"')
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 63 | emit_node | def | function | def emit_node(
self,
name: str,
type_: NodeType,
properties: Optional[NodeProperties] = None,
) -> None:
"""Create a new node. Nodes can be classes, packages, participants etc."""
if properties is None:
properties = NodeProperties(label=name)
shape = SHAPES[type_]
color = properties.color if properties.color is not None else self.DEFAULT_COLOR
style = "filled" if color != self.DEFAULT_COLOR else "solid"
label = self._build_label_for_node(properties)
label_part = f', label="{label}"' if label else ""
fontcolor_part = (
f', fontcolor="{properties.fontcolor}"' if properties.fontcolor else ""
)
self.emit(
f'"{name}" [color="{color}"{fontcolor_part}{label_part}, shape="{shape}", style="{style}"];'
)
def _build_label_for_node(
self, properties: NodeProperties, is_interface: Optional[bool] = _False
) -> str:
if not properties.label:
return ""
label: str = properties.label
if is_interface:
# add a stereotype
label = "<<interface>>\\n" + label
if properties.attrs is None and properties.methods is None:
# return a "compact" form which only displays the class name in a box
return label
# Add class attributes
attrs: List[str] = properties.attrs or []
label = "{" + label + "|" + r"\l".join(attrs) + r"\l|"
# Add class methods
methods: List[nodes.FunctionDef] = properties.methods or []
for func in methods:
args = self._get_method_arguments(func)
label += rf"{func.name}({', '.join(args)})"
if func.returns:
label += ": " + get_annotation_label(func.returns)
label += r"\l"
label += "}"
return label
def emit_edge(
self,
from_node: str,
to_node: str,
type_: EdgeType,
label: Optional[str] = None,
) -> None:
"""Create an edge from one node to another to display relationships."""
arrowstyle = ARROWS[type_]
attrs = [f'{prop}="{value}"' for prop, value in arrowstyle.items()]
if label:
attrs.append(f'label="{label}"')
self.emit(f'"{from_node}" -> "{to_node}" [{", ".join(sorted(attrs))}];')
def generate(self, outputfile: str) -> None:
self._close_graph()
graphviz_extensions = ("dot", "gv")
name = self.title
if outputfile is None:
target = "png"
pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
ppng, outputfile = tempfile.mkstemp(".png", name)
os.close(pdot)
os.close(ppng)
else:
target = Path(outputfile).suffix.lstrip(".")
if not target:
target = "png"
outputfile = outputfile + "." + target
if target not in graphviz_extensions:
pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
os.close(pdot)
else:
dot_sourcepath = outputfile
with open(dot_sourcepath, "w", encoding="utf8") as outfile:
outfile.writelines(self.lines)
if target not in graphviz_extensions:
check_graphviz_availability()
use_shell = sys.platform == "win32"
subprocess.call(
["dot", "-T", target, dot_sourcepath, "-o", outputfile],
shell=use_shell,
)
os.unlink(dot_sourcepath)
def _close_graph(self) -> None:
"""Emit the lines needed to properly close the graph."""
self.emit("}\n")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 71 | NodeProperties | ref | function | properties = NodeProperties(label=name)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 75 | _build_label_for_node | ref | function | label = self._build_label_for_node(properties)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 80 | emit | ref | function | self.emit(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 84 | _build_label_for_node | def | function | def _build_label_for_node(
self, properties: NodeProperties, is_interface: Optional[bool] = _False
) -> str:
if not properties.label:
return ""
label: str = properties.label
if is_interface:
# add a stereotype
label = "<<interface>>\\n" + label
if properties.attrs is None and properties.methods is None:
# return a "compact" form which only displays the class name in a box
return label
# Add class attributes
attrs: List[str] = properties.attrs or []
label = "{" + label + "|" + r"\l".join(attrs) + r"\l|"
# Add class methods
methods: List[nodes.FunctionDef] = properties.methods or []
for func in methods:
args = self._get_method_arguments(func)
label += rf"{func.name}({', '.join(args)})"
if func.returns:
label += ": " + get_annotation_label(func.returns)
label += r"\l"
label += "}"
return label
def emit_edge(
self,
from_node: str,
to_node: str,
type_: EdgeType,
label: Optional[str] = None,
) -> None:
"""Create an edge from one node to another to display relationships."""
arrowstyle = ARROWS[type_]
attrs = [f'{prop}="{value}"' for prop, value in arrowstyle.items()]
if label:
attrs.append(f'label="{label}"')
self.emit(f'"{from_node}" -> "{to_node}" [{", ".join(sorted(attrs))}];')
def generate(self, outputfile: str) -> None:
self._close_graph()
graphviz_extensions = ("dot", "gv")
name = self.title
if outputfile is None:
target = "png"
pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
ppng, outputfile = tempfile.mkstemp(".png", name)
os.close(pdot)
os.close(ppng)
else:
target = Path(outputfile).suffix.lstrip(".")
if not target:
target = "png"
outputfile = outputfile + "." + target
if target not in graphviz_extensions:
pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
os.close(pdot)
else:
dot_sourcepath = outputfile
with open(dot_sourcepath, "w", encoding="utf8") as outfile:
outfile.writelines(self.lines)
if target not in graphviz_extensions:
check_graphviz_availability()
use_shell = sys.platform == "win32"
subprocess.call(
["dot", "-T", target, dot_sourcepath, "-o", outputfile],
shell=use_shell,
)
os.unlink(dot_sourcepath)
def _close_graph(self) -> None:
"""Emit the lines needed to properly close the graph."""
self.emit("}\n")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 106 | _get_method_arguments | ref | function | args = self._get_method_arguments(func)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 109 | get_annotation_label | ref | function | label += ": " + get_annotation_label(func.returns)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 114 | emit_edge | def | function | def emit_edge(
self,
from_node: str,
to_node: str,
type_: EdgeType,
label: Optional[str] = None,
) -> None:
"""Create an edge from one node to another to display relationships."""
arrowstyle = ARROWS[type_]
attrs = [f'{prop}="{value}"' for prop, value in arrowstyle.items()]
if label:
attrs.append(f'label="{label}"')
self.emit(f'"{from_node}" -> "{to_node}" [{", ".join(sorted(attrs))}];')
def generate(self, outputfile: str) -> None:
self._close_graph()
graphviz_extensions = ("dot", "gv")
name = self.title
if outputfile is None:
target = "png"
pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
ppng, outputfile = tempfile.mkstemp(".png", name)
os.close(pdot)
os.close(ppng)
else:
target = Path(outputfile).suffix.lstrip(".")
if not target:
target = "png"
outputfile = outputfile + "." + target
if target not in graphviz_extensions:
pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
os.close(pdot)
else:
dot_sourcepath = outputfile
with open(dot_sourcepath, "w", encoding="utf8") as outfile:
outfile.writelines(self.lines)
if target not in graphviz_extensions:
check_graphviz_availability()
use_shell = sys.platform == "win32"
subprocess.call(
["dot", "-T", target, dot_sourcepath, "-o", outputfile],
shell=use_shell,
)
os.unlink(dot_sourcepath)
def _close_graph(self) -> None:
"""Emit the lines needed to properly close the graph."""
self.emit("}\n")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 126 | emit | ref | function | self.emit(f'"{from_node}" -> "{to_node}" [{", ".join(sorted(attrs))}];')
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 128 | generate | def | function | def generate(self, outputfile: str) -> None:
self._close_graph()
graphviz_extensions = ("dot", "gv")
name = self.title
if outputfile is None:
target = "png"
pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
ppng, outputfile = tempfile.mkstemp(".png", name)
os.close(pdot)
os.close(ppng)
else:
target = Path(outputfile).suffix.lstrip(".")
if not target:
target = "png"
outputfile = outputfile + "." + target
if target not in graphviz_extensions:
pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
os.close(pdot)
else:
dot_sourcepath = outputfile
with open(dot_sourcepath, "w", encoding="utf8") as outfile:
outfile.writelines(self.lines)
if target not in graphviz_extensions:
check_graphviz_availability()
use_shell = sys.platform == "win32"
subprocess.call(
["dot", "-T", target, dot_sourcepath, "-o", outputfile],
shell=use_shell,
)
os.unlink(dot_sourcepath)
def _close_graph(self) -> None:
"""Emit the lines needed to properly close the graph."""
self.emit("}\n")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 129 | _close_graph | ref | function | self._close_graph()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 149 | writelines | ref | function | outfile.writelines(self.lines)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 151 | check_graphviz_availability | ref | function | check_graphviz_availability()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 159 | _close_graph | def | function | def _close_graph(self) -> None:
"""Emit the lines needed to properly close the graph."""
self.emit("}\n")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/dot_printer.py | pylint/pyreverse/dot_printer.py | 161 | emit | ref | function | self.emit("}\n")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 29 | _iface_hdlr | def | function | def _iface_hdlr(_):
"""Handler used by interfaces to handle suspicious interface nodes."""
return _True
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 34 | _astroid_wrapper | def | function | def _astroid_wrapper(func, modname):
print(f"parsing {modname}...")
try:
return func(modname)
except astroid.exceptions.AstroidBuildingException as exc:
print(exc)
except Exception: # pylint: disable=broad-except
traceback.print_exc()
return None
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 37 | func | ref | function | return func(modname)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 45 | interfaces | def | function | null |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 48 | Instance | ref | function | implements = astroid.bases.Instance(node).getattr("__implements__")[0]
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 51 | frame | ref | function | if not herited and implements.frame(future=True) is not node:
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 55 | unpack_infer | ref | function | for iface in nodes.unpack_infer(implements):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 59 | handler_func | ref | function | if iface not in found and handler_func(iface):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 63 | InferenceError | ref | function | raise astroid.exceptions.InferenceError()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 66 | IdGeneratorMixIn | def | class | __init__ init_counter generate_id |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 72 | init_counter | def | function | def init_counter(self, start_value=0):
"""Init the id counter."""
self.id_count = start_value
def generate_id(self):
"""Generate a new identifier."""
self.id_count += 1
return self.id_count
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 76 | generate_id | def | function | def generate_id(self):
"""Generate a new identifier."""
self.id_count += 1
return self.id_count
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 82 | Project | def | class | __init__ add_module get_module get_children __repr__ |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 97 | add_module | def | function | def add_module(self, node):
self.locals[node.name] = node
self.modules.append(node)
def get_module(self, name):
return self.locals[name]
def get_children(self):
return self.modules
def __repr__(self):
return f"<Project {self.name!r} at {id(self)} ({len(self.modules)} modules)>"
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 101 | get_module | def | function | def get_module(self, name):
return self.locals[name]
def get_children(self):
return self.modules
def __repr__(self):
return f"<Project {self.name!r} at {id(self)} ({len(self.modules)} modules)>"
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 104 | get_children | def | function | def get_children(self):
return self.modules
def __repr__(self):
return f"<Project {self.name!r} at {id(self)} ({len(self.modules)} modules)>"
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 111 | Linker | def | class | __init__ visit_project visit_module visit_classdef visit_functiondef visit_assignname handle_assignattr_type visit_import visit_importfrom compute_module _imported_module |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 144 | visit_project | def | function | def visit_project(self, node: Project) -> None:
"""Visit a pyreverse.utils.Project node.
* optionally tag the node with a unique id
"""
if self.tag:
node.uid = self.generate_id()
for module in node.modules:
self.visit(module)
def visit_module(self, node: nodes.Module) -> None:
"""Visit an astroid.Module node.
* set the locals_type mapping
* set the depends mapping
* optionally tag the node with a unique id
"""
if hasattr(node, "locals_type"):
return
node.locals_type = collections.defaultdict(list)
node.depends = []
if self.tag:
node.uid = self.generate_id()
def visit_classdef(self, node: nodes.ClassDef) -> None:
"""Visit an astroid.Class node.
* set the locals_type and instance_attrs_type mappings
* set the implements list and build it
* optionally tag the node with a unique id
"""
if hasattr(node, "locals_type"):
return
node.locals_type = collections.defaultdict(list)
if self.tag:
node.uid = self.generate_id()
# resolve ancestors
for baseobj in node.ancestors(recurs=_False):
specializations = getattr(baseobj, "specializations", [])
specializations.append(node)
baseobj.specializations = specializations
# resolve instance attributes
node.instance_attrs_type = collections.defaultdict(list)
for assignattrs in node.instance_attrs.values():
for assignattr in assignattrs:
if not isinstance(assignattr, nodes.Unknown):
self.handle_assignattr_type(assignattr, node)
# resolve implemented interface
try:
node.implements = list(interfaces(node, self.inherited_interfaces))
except astroid.InferenceError:
node.implements = []
def visit_functiondef(self, node: nodes.FunctionDef) -> None:
"""Visit an astroid.Function node.
* set the locals_type mapping
* optionally tag the node with a unique id
"""
if hasattr(node, "locals_type"):
return
node.locals_type = collections.defaultdict(list)
if self.tag:
node.uid = self.generate_id()
link_project = visit_project
link_module = visit_module
link_class = visit_classdef
link_function = visit_functiondef
def visit_assignname(self, node: nodes.AssignName) -> None:
"""Visit an astroid.AssignName node.
handle locals_type
"""
# avoid double parsing done by different Linkers.visit
# running over the same project:
if hasattr(node, "_handled"):
return
node._handled = _True
if node.name in node.frame(future=_True):
frame = node.frame(future=_True)
else:
# the name has been defined as 'global' in the frame and belongs
# there.
frame = node.root()
if not hasattr(frame, "locals_type"):
# If the frame doesn't have a locals_type yet,
# it means it wasn't yet visited. Visit it now
# to add what's missing from it.
if isinstance(frame, nodes.ClassDef):
self.visit_classdef(frame)
elif isinstance(frame, nodes.FunctionDef):
self.visit_functiondef(frame)
else:
self.visit_module(frame)
current = frame.locals_type[node.name]
frame.locals_type[node.name] = list(set(current) | utils.infer_node(node))
@staticmethod
def handle_assignattr_type(node, parent):
"""Handle an astroid.assignattr node.
handle instance_attrs_type
"""
current = set(parent.instance_attrs_type[node.attrname])
parent.instance_attrs_type[node.attrname] = list(
current | utils.infer_node(node)
)
def visit_import(self, node: nodes.Import) -> None:
"""Visit an astroid.Import node.
resolve module dependencies
"""
context_file = node.root().file
for name in node.names:
relative = astroid.modutils.is_relative(name[0], context_file)
self._imported_module(node, name[0], relative)
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
"""Visit an astroid.ImportFrom node.
resolve module dependencies
"""
basename = node.modname
context_file = node.root().file
if context_file is not None:
relative = astroid.modutils.is_relative(basename, context_file)
else:
relative = _False
for name in node.names:
if name[0] == "*":
continue
# analyze dependencies
fullname = f"{basename}.{name[0]}"
if fullname.find(".") > -1:
try:
fullname = astroid.modutils.get_module_part(fullname, context_file)
except ImportError:
continue
if fullname != basename:
self._imported_module(node, fullname, relative)
def compute_module(self, context_name, mod_path):
"""Return true if the module should be added to dependencies."""
package_dir = os.path.dirname(self.project.path)
if context_name == mod_path:
return 0
if astroid.modutils.is_standard_module(mod_path, (package_dir,)):
return 1
return 0
def _imported_module(self, node, mod_path, relative):
"""Notify an imported module, used to analyze dependencies."""
module = node.root()
context_name = module.name
if relative:
mod_path = f"{'.'.join(context_name.split('.')[:-1])}.{mod_path}"
if self.compute_module(context_name, mod_path):
# handle dependencies
if not hasattr(module, "depends"):
module.depends = []
mod_paths = module.depends
if mod_path not in mod_paths:
mod_paths.append(mod_path)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 150 | generate_id | ref | function | node.uid = self.generate_id()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 152 | visit | ref | function | self.visit(module)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 154 | visit_module | def | function | def visit_module(self, node: nodes.Module) -> None:
"""Visit an astroid.Module node.
* set the locals_type mapping
* set the depends mapping
* optionally tag the node with a unique id
"""
if hasattr(node, "locals_type"):
return
node.locals_type = collections.defaultdict(list)
node.depends = []
if self.tag:
node.uid = self.generate_id()
def visit_classdef(self, node: nodes.ClassDef) -> None:
"""Visit an astroid.Class node.
* set the locals_type and instance_attrs_type mappings
* set the implements list and build it
* optionally tag the node with a unique id
"""
if hasattr(node, "locals_type"):
return
node.locals_type = collections.defaultdict(list)
if self.tag:
node.uid = self.generate_id()
# resolve ancestors
for baseobj in node.ancestors(recurs=_False):
specializations = getattr(baseobj, "specializations", [])
specializations.append(node)
baseobj.specializations = specializations
# resolve instance attributes
node.instance_attrs_type = collections.defaultdict(list)
for assignattrs in node.instance_attrs.values():
for assignattr in assignattrs:
if not isinstance(assignattr, nodes.Unknown):
self.handle_assignattr_type(assignattr, node)
# resolve implemented interface
try:
node.implements = list(interfaces(node, self.inherited_interfaces))
except astroid.InferenceError:
node.implements = []
def visit_functiondef(self, node: nodes.FunctionDef) -> None:
"""Visit an astroid.Function node.
* set the locals_type mapping
* optionally tag the node with a unique id
"""
if hasattr(node, "locals_type"):
return
node.locals_type = collections.defaultdict(list)
if self.tag:
node.uid = self.generate_id()
link_project = visit_project
link_module = visit_module
link_class = visit_classdef
link_function = visit_functiondef
def visit_assignname(self, node: nodes.AssignName) -> None:
"""Visit an astroid.AssignName node.
handle locals_type
"""
# avoid double parsing done by different Linkers.visit
# running over the same project:
if hasattr(node, "_handled"):
return
node._handled = _True
if node.name in node.frame(future=_True):
frame = node.frame(future=_True)
else:
# the name has been defined as 'global' in the frame and belongs
# there.
frame = node.root()
if not hasattr(frame, "locals_type"):
# If the frame doesn't have a locals_type yet,
# it means it wasn't yet visited. Visit it now
# to add what's missing from it.
if isinstance(frame, nodes.ClassDef):
self.visit_classdef(frame)
elif isinstance(frame, nodes.FunctionDef):
self.visit_functiondef(frame)
else:
self.visit_module(frame)
current = frame.locals_type[node.name]
frame.locals_type[node.name] = list(set(current) | utils.infer_node(node))
@staticmethod
def handle_assignattr_type(node, parent):
"""Handle an astroid.assignattr node.
handle instance_attrs_type
"""
current = set(parent.instance_attrs_type[node.attrname])
parent.instance_attrs_type[node.attrname] = list(
current | utils.infer_node(node)
)
def visit_import(self, node: nodes.Import) -> None:
"""Visit an astroid.Import node.
resolve module dependencies
"""
context_file = node.root().file
for name in node.names:
relative = astroid.modutils.is_relative(name[0], context_file)
self._imported_module(node, name[0], relative)
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
"""Visit an astroid.ImportFrom node.
resolve module dependencies
"""
basename = node.modname
context_file = node.root().file
if context_file is not None:
relative = astroid.modutils.is_relative(basename, context_file)
else:
relative = _False
for name in node.names:
if name[0] == "*":
continue
# analyze dependencies
fullname = f"{basename}.{name[0]}"
if fullname.find(".") > -1:
try:
fullname = astroid.modutils.get_module_part(fullname, context_file)
except ImportError:
continue
if fullname != basename:
self._imported_module(node, fullname, relative)
def compute_module(self, context_name, mod_path):
"""Return true if the module should be added to dependencies."""
package_dir = os.path.dirname(self.project.path)
if context_name == mod_path:
return 0
if astroid.modutils.is_standard_module(mod_path, (package_dir,)):
return 1
return 0
def _imported_module(self, node, mod_path, relative):
"""Notify an imported module, used to analyze dependencies."""
module = node.root()
context_name = module.name
if relative:
mod_path = f"{'.'.join(context_name.split('.')[:-1])}.{mod_path}"
if self.compute_module(context_name, mod_path):
# handle dependencies
if not hasattr(module, "depends"):
module.depends = []
mod_paths = module.depends
if mod_path not in mod_paths:
mod_paths.append(mod_path)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 166 | generate_id | ref | function | node.uid = self.generate_id()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 168 | visit_classdef | def | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 179 | generate_id | ref | function | node.uid = self.generate_id()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 181 | ancestors | ref | function | for baseobj in node.ancestors(recurs=False):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 190 | handle_assignattr_type | ref | function | self.handle_assignattr_type(assignattr, node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 193 | interfaces | ref | function | node.implements = list(interfaces(node, self.inherited_interfaces))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 197 | visit_functiondef | def | function | def visit_functiondef(self, node: nodes.FunctionDef) -> None:
"""Visit an astroid.Function node.
* set the locals_type mapping
* optionally tag the node with a unique id
"""
if hasattr(node, "locals_type"):
return
node.locals_type = collections.defaultdict(list)
if self.tag:
node.uid = self.generate_id()
link_project = visit_project
link_module = visit_module
link_class = visit_classdef
link_function = visit_functiondef
def visit_assignname(self, node: nodes.AssignName) -> None:
"""Visit an astroid.AssignName node.
handle locals_type
"""
# avoid double parsing done by different Linkers.visit
# running over the same project:
if hasattr(node, "_handled"):
return
node._handled = _True
if node.name in node.frame(future=_True):
frame = node.frame(future=_True)
else:
# the name has been defined as 'global' in the frame and belongs
# there.
frame = node.root()
if not hasattr(frame, "locals_type"):
# If the frame doesn't have a locals_type yet,
# it means it wasn't yet visited. Visit it now
# to add what's missing from it.
if isinstance(frame, nodes.ClassDef):
self.visit_classdef(frame)
elif isinstance(frame, nodes.FunctionDef):
self.visit_functiondef(frame)
else:
self.visit_module(frame)
current = frame.locals_type[node.name]
frame.locals_type[node.name] = list(set(current) | utils.infer_node(node))
@staticmethod
def handle_assignattr_type(node, parent):
"""Handle an astroid.assignattr node.
handle instance_attrs_type
"""
current = set(parent.instance_attrs_type[node.attrname])
parent.instance_attrs_type[node.attrname] = list(
current | utils.infer_node(node)
)
def visit_import(self, node: nodes.Import) -> None:
"""Visit an astroid.Import node.
resolve module dependencies
"""
context_file = node.root().file
for name in node.names:
relative = astroid.modutils.is_relative(name[0], context_file)
self._imported_module(node, name[0], relative)
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
"""Visit an astroid.ImportFrom node.
resolve module dependencies
"""
basename = node.modname
context_file = node.root().file
if context_file is not None:
relative = astroid.modutils.is_relative(basename, context_file)
else:
relative = _False
for name in node.names:
if name[0] == "*":
continue
# analyze dependencies
fullname = f"{basename}.{name[0]}"
if fullname.find(".") > -1:
try:
fullname = astroid.modutils.get_module_part(fullname, context_file)
except ImportError:
continue
if fullname != basename:
self._imported_module(node, fullname, relative)
def compute_module(self, context_name, mod_path):
"""Return true if the module should be added to dependencies."""
package_dir = os.path.dirname(self.project.path)
if context_name == mod_path:
return 0
if astroid.modutils.is_standard_module(mod_path, (package_dir,)):
return 1
return 0
def _imported_module(self, node, mod_path, relative):
"""Notify an imported module, used to analyze dependencies."""
module = node.root()
context_name = module.name
if relative:
mod_path = f"{'.'.join(context_name.split('.')[:-1])}.{mod_path}"
if self.compute_module(context_name, mod_path):
# handle dependencies
if not hasattr(module, "depends"):
module.depends = []
mod_paths = module.depends
if mod_path not in mod_paths:
mod_paths.append(mod_path)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 207 | generate_id | ref | function | node.uid = self.generate_id()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 214 | visit_assignname | def | function | def visit_assignname(self, node: nodes.AssignName) -> None:
"""Visit an astroid.AssignName node.
handle locals_type
"""
# avoid double parsing done by different Linkers.visit
# running over the same project:
if hasattr(node, "_handled"):
return
node._handled = _True
if node.name in node.frame(future=_True):
frame = node.frame(future=_True)
else:
# the name has been defined as 'global' in the frame and belongs
# there.
frame = node.root()
if not hasattr(frame, "locals_type"):
# If the frame doesn't have a locals_type yet,
# it means it wasn't yet visited. Visit it now
# to add what's missing from it.
if isinstance(frame, nodes.ClassDef):
self.visit_classdef(frame)
elif isinstance(frame, nodes.FunctionDef):
self.visit_functiondef(frame)
else:
self.visit_module(frame)
current = frame.locals_type[node.name]
frame.locals_type[node.name] = list(set(current) | utils.infer_node(node))
@staticmethod
def handle_assignattr_type(node, parent):
"""Handle an astroid.assignattr node.
handle instance_attrs_type
"""
current = set(parent.instance_attrs_type[node.attrname])
parent.instance_attrs_type[node.attrname] = list(
current | utils.infer_node(node)
)
def visit_import(self, node: nodes.Import) -> None:
"""Visit an astroid.Import node.
resolve module dependencies
"""
context_file = node.root().file
for name in node.names:
relative = astroid.modutils.is_relative(name[0], context_file)
self._imported_module(node, name[0], relative)
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
"""Visit an astroid.ImportFrom node.
resolve module dependencies
"""
basename = node.modname
context_file = node.root().file
if context_file is not None:
relative = astroid.modutils.is_relative(basename, context_file)
else:
relative = _False
for name in node.names:
if name[0] == "*":
continue
# analyze dependencies
fullname = f"{basename}.{name[0]}"
if fullname.find(".") > -1:
try:
fullname = astroid.modutils.get_module_part(fullname, context_file)
except ImportError:
continue
if fullname != basename:
self._imported_module(node, fullname, relative)
def compute_module(self, context_name, mod_path):
"""Return true if the module should be added to dependencies."""
package_dir = os.path.dirname(self.project.path)
if context_name == mod_path:
return 0
if astroid.modutils.is_standard_module(mod_path, (package_dir,)):
return 1
return 0
def _imported_module(self, node, mod_path, relative):
"""Notify an imported module, used to analyze dependencies."""
module = node.root()
context_name = module.name
if relative:
mod_path = f"{'.'.join(context_name.split('.')[:-1])}.{mod_path}"
if self.compute_module(context_name, mod_path):
# handle dependencies
if not hasattr(module, "depends"):
module.depends = []
mod_paths = module.depends
if mod_path not in mod_paths:
mod_paths.append(mod_path)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 224 | frame | ref | function | if node.name in node.frame(future=True):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 225 | frame | ref | function | frame = node.frame(future=True)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 229 | root | ref | function | frame = node.root()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 235 | visit_classdef | ref | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 237 | visit_functiondef | ref | function | self.visit_functiondef(frame)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 239 | visit_module | ref | function | self.visit_module(frame)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 242 | infer_node | ref | function | frame.locals_type[node.name] = list(set(current) | utils.infer_node(node))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 245 | handle_assignattr_type | def | function | def handle_assignattr_type(node, parent):
"""Handle an astroid.assignattr node.
handle instance_attrs_type
"""
current = set(parent.instance_attrs_type[node.attrname])
parent.instance_attrs_type[node.attrname] = list(
current | utils.infer_node(node)
)
def visit_import(self, node: nodes.Import) -> None:
"""Visit an astroid.Import node.
resolve module dependencies
"""
context_file = node.root().file
for name in node.names:
relative = astroid.modutils.is_relative(name[0], context_file)
self._imported_module(node, name[0], relative)
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
"""Visit an astroid.ImportFrom node.
resolve module dependencies
"""
basename = node.modname
context_file = node.root().file
if context_file is not None:
relative = astroid.modutils.is_relative(basename, context_file)
else:
relative = _False
for name in node.names:
if name[0] == "*":
continue
# analyze dependencies
fullname = f"{basename}.{name[0]}"
if fullname.find(".") > -1:
try:
fullname = astroid.modutils.get_module_part(fullname, context_file)
except ImportError:
continue
if fullname != basename:
self._imported_module(node, fullname, relative)
def compute_module(self, context_name, mod_path):
"""Return true if the module should be added to dependencies."""
package_dir = os.path.dirname(self.project.path)
if context_name == mod_path:
return 0
if astroid.modutils.is_standard_module(mod_path, (package_dir,)):
return 1
return 0
def _imported_module(self, node, mod_path, relative):
"""Notify an imported module, used to analyze dependencies."""
module = node.root()
context_name = module.name
if relative:
mod_path = f"{'.'.join(context_name.split('.')[:-1])}.{mod_path}"
if self.compute_module(context_name, mod_path):
# handle dependencies
if not hasattr(module, "depends"):
module.depends = []
mod_paths = module.depends
if mod_path not in mod_paths:
mod_paths.append(mod_path)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 252 | infer_node | ref | function | current | utils.infer_node(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 255 | visit_import | def | function | def visit_import(self, node: nodes.Import) -> None:
"""Visit an astroid.Import node.
resolve module dependencies
"""
context_file = node.root().file
for name in node.names:
relative = astroid.modutils.is_relative(name[0], context_file)
self._imported_module(node, name[0], relative)
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
"""Visit an astroid.ImportFrom node.
resolve module dependencies
"""
basename = node.modname
context_file = node.root().file
if context_file is not None:
relative = astroid.modutils.is_relative(basename, context_file)
else:
relative = _False
for name in node.names:
if name[0] == "*":
continue
# analyze dependencies
fullname = f"{basename}.{name[0]}"
if fullname.find(".") > -1:
try:
fullname = astroid.modutils.get_module_part(fullname, context_file)
except ImportError:
continue
if fullname != basename:
self._imported_module(node, fullname, relative)
def compute_module(self, context_name, mod_path):
"""Return true if the module should be added to dependencies."""
package_dir = os.path.dirname(self.project.path)
if context_name == mod_path:
return 0
if astroid.modutils.is_standard_module(mod_path, (package_dir,)):
return 1
return 0
def _imported_module(self, node, mod_path, relative):
"""Notify an imported module, used to analyze dependencies."""
module = node.root()
context_name = module.name
if relative:
mod_path = f"{'.'.join(context_name.split('.')[:-1])}.{mod_path}"
if self.compute_module(context_name, mod_path):
# handle dependencies
if not hasattr(module, "depends"):
module.depends = []
mod_paths = module.depends
if mod_path not in mod_paths:
mod_paths.append(mod_path)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 260 | root | ref | function | context_file = node.root().file
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 262 | is_relative | ref | function | relative = astroid.modutils.is_relative(name[0], context_file)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 263 | _imported_module | ref | function | self._imported_module(node, name[0], relative)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 265 | visit_importfrom | def | function | def visit_importfrom(self, node: nodes.ImportFrom) -> None:
"""Visit an astroid.ImportFrom node.
resolve module dependencies
"""
basename = node.modname
context_file = node.root().file
if context_file is not None:
relative = astroid.modutils.is_relative(basename, context_file)
else:
relative = _False
for name in node.names:
if name[0] == "*":
continue
# analyze dependencies
fullname = f"{basename}.{name[0]}"
if fullname.find(".") > -1:
try:
fullname = astroid.modutils.get_module_part(fullname, context_file)
except ImportError:
continue
if fullname != basename:
self._imported_module(node, fullname, relative)
def compute_module(self, context_name, mod_path):
"""Return true if the module should be added to dependencies."""
package_dir = os.path.dirname(self.project.path)
if context_name == mod_path:
return 0
if astroid.modutils.is_standard_module(mod_path, (package_dir,)):
return 1
return 0
def _imported_module(self, node, mod_path, relative):
"""Notify an imported module, used to analyze dependencies."""
module = node.root()
context_name = module.name
if relative:
mod_path = f"{'.'.join(context_name.split('.')[:-1])}.{mod_path}"
if self.compute_module(context_name, mod_path):
# handle dependencies
if not hasattr(module, "depends"):
module.depends = []
mod_paths = module.depends
if mod_path not in mod_paths:
mod_paths.append(mod_path)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 271 | root | ref | function | context_file = node.root().file
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 273 | is_relative | ref | function | relative = astroid.modutils.is_relative(basename, context_file)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 283 | get_module_part | ref | function | fullname = astroid.modutils.get_module_part(fullname, context_file)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 287 | _imported_module | ref | function | self._imported_module(node, fullname, relative)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 289 | compute_module | def | function | def compute_module(self, context_name, mod_path):
"""Return true if the module should be added to dependencies."""
package_dir = os.path.dirname(self.project.path)
if context_name == mod_path:
return 0
if astroid.modutils.is_standard_module(mod_path, (package_dir,)):
return 1
return 0
def _imported_module(self, node, mod_path, relative):
"""Notify an imported module, used to analyze dependencies."""
module = node.root()
context_name = module.name
if relative:
mod_path = f"{'.'.join(context_name.split('.')[:-1])}.{mod_path}"
if self.compute_module(context_name, mod_path):
# handle dependencies
if not hasattr(module, "depends"):
module.depends = []
mod_paths = module.depends
if mod_path not in mod_paths:
mod_paths.append(mod_path)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 291 | dirname | ref | function | package_dir = os.path.dirname(self.project.path)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 294 | is_standard_module | ref | function | if astroid.modutils.is_standard_module(mod_path, (package_dir,)):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 298 | _imported_module | def | function | def _imported_module(self, node, mod_path, relative):
"""Notify an imported module, used to analyze dependencies."""
module = node.root()
context_name = module.name
if relative:
mod_path = f"{'.'.join(context_name.split('.')[:-1])}.{mod_path}"
if self.compute_module(context_name, mod_path):
# handle dependencies
if not hasattr(module, "depends"):
module.depends = []
mod_paths = module.depends
if mod_path not in mod_paths:
mod_paths.append(mod_path)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 300 | root | ref | function | module = node.root()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 304 | compute_module | ref | function | if self.compute_module(context_name, mod_path):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 313 | project_from_files | def | function | def project_from_files(
files, func_wrapper=_astroid_wrapper, project_name="no name", black_list=("CVS",)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 318 | AstroidManager | ref | function | astroid_manager = astroid.manager.AstroidManager()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 319 | Project | ref | function | project = Project(project_name)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 321 | exists | ref | function | if not os.path.exists(something):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 322 | file_from_modpath | ref | function | fpath = astroid.modutils.file_from_modpath(something.split("."))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 323 | isdir | ref | function | elif os.path.isdir(something):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 327 | func_wrapper | ref | function | ast = func_wrapper(astroid_manager.ast_from_file, fpath)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 331 | add_module | ref | function | project.add_module(ast)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/pyreverse/inspector.py | pylint/pyreverse/inspector.py | 336 | get_module_files | ref | function | for fpath in astroid.modutils.get_module_files(
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.