Fix Pylint warnings.

This commit is contained in:
Sergey Vartanov 2021-11-08 02:53:51 +03:00
parent d2b208ea51
commit 5746edaa3f
22 changed files with 94 additions and 197 deletions

View file

@ -152,9 +152,7 @@ def try_to_glue(
class Constructor:
"""
Map Machine node and way constructor.
"""
"""Map Machine node and way constructor."""
def __init__(
self,

View file

@ -116,9 +116,9 @@ class ArgumentParser(argparse.ArgumentParser):
class MapMachineMoire(Default, ABC):
"""Moire extension stub for Map Machine."""
def osm(self, args: Arguments) -> str:
def osm(self, arg: Arguments) -> str:
"""OSM tag key or keyvalue pair of tag."""
spec: str = self.clear(args[0])
spec: str = self.clear(arg[0])
if "=" in spec:
key, tag = spec.split("=")
return (
@ -129,26 +129,26 @@ class MapMachineMoire(Default, ABC):
return self.get_ref_(f"{PREFIX}Key:{spec}", self.m([spec]))
def color(self, args: Arguments) -> str:
def color(self, arg: Arguments) -> str:
"""Simple color sample."""
raise NotImplementedError("color")
def page_icon(self, args: Arguments) -> str:
def page_icon(self, arg: Arguments) -> str:
"""HTML page icon."""
return ""
def command(self, args: Arguments) -> str:
def command(self, arg: Arguments) -> str:
"""Bash command from integration tests."""
return "map-machine " + " ".join(COMMAND_LINES[self.clear(args[0])])
return "map-machine " + " ".join(COMMAND_LINES[self.clear(arg[0])])
def icon(self, args: Arguments) -> str:
def icon(self, arg: Arguments) -> str:
"""Image with Röntgen icon."""
raise NotImplementedError("icon")
def options(self, args: Arguments) -> str:
def options(self, arg: Arguments) -> str:
"""Table with option descriptions."""
parser: ArgumentParser = ArgumentParser()
command: str = self.clear(args[0])
command: str = self.clear(arg[0])
if command == "render":
cli.add_render_arguments(parser)
elif command == "server":
@ -167,13 +167,13 @@ class MapMachineMoire(Default, ABC):
)
return self.parse(parser.get_moire_help())
def kbd(self, args: Arguments) -> str:
def kbd(self, arg: Arguments) -> str:
"""Keyboard key."""
return self.m(args)
return self.m(arg)
def no_wrap(self, args: Arguments) -> str:
def no_wrap(self, arg: Arguments) -> str:
"""Do not wrap text at white spaces."""
return self.parse(args[0])
return self.parse(arg[0])
class MapMachineHTML(MapMachineMoire, DefaultHTML):
@ -197,41 +197,39 @@ class MapMachineHTML(MapMachineMoire, DefaultHTML):
content += f"<tr>{cell}</tr>"
return f"<table>{content}</table>"
def color(self, args: Arguments) -> str:
def color(self, arg: Arguments) -> str:
"""Simple color sample."""
return (
f'<span class="color" '
f'style="background-color: {self.clear(args[0])};"></span>'
f'style="background-color: {self.clear(arg[0])};"></span>'
)
def icon(self, args: Arguments) -> str:
def icon(self, arg: Arguments) -> str:
"""Image with Röntgen icon."""
size: str = self.clear(args[1]) if len(args) > 1 else 16
size: str = self.clear(arg[1]) if len(arg) > 1 else 16
return (
f'<img class="icon" style="width: {size}px; height: {size}px;" '
f'src="out/icons_by_id/{self.clear(args[0])}.svg" />'
f'src="out/icons_by_id/{self.clear(arg[0])}.svg" />'
)
def kbd(self, args: Arguments) -> str:
def kbd(self, arg: Arguments) -> str:
"""Keyboard key."""
return f"<kbd>{self.clear(args[0])}</kbd>"
return f"<kbd>{self.clear(arg[0])}</kbd>"
def page_icon(self, args: Arguments) -> str:
def page_icon(self, arg: Arguments) -> str:
"""HTML page icon."""
return (
f'<link rel="icon" type="image/svg" href="{self.clear(args[0])}"'
f'<link rel="icon" type="image/svg" href="{self.clear(arg[0])}"'
' sizes="16x16">'
)
def no_wrap(self, args: Arguments) -> str:
def no_wrap(self, arg: Arguments) -> str:
"""Do not wrap text at white spaces."""
return (
f'<span style="white-space: nowrap;">{self.parse(args[0])}</span>'
)
return f'<span style="white-space: nowrap;">{self.parse(arg[0])}</span>'
def formal(self, args: Arguments) -> str:
def formal(self, arg: Arguments) -> str:
"""Formal variable."""
return f'<span class="formal">{self.parse(args[0])}</span>'
return f'<span class="formal">{self.parse(arg[0])}</span>'
class MapMachineOSMWiki(MapMachineMoire, DefaultWiki):
@ -248,23 +246,23 @@ class MapMachineOSMWiki(MapMachineMoire, DefaultWiki):
workspace.ICONS_PATH, workspace.ICONS_CONFIG_PATH
)
def osm(self, args: Arguments) -> str:
def osm(self, arg: Arguments) -> str:
"""OSM tag key or keyvalue pair of tag."""
spec: str = self.clear(args[0])
spec: str = self.clear(arg[0])
if "=" in spec:
key, tag = spec.split("=")
return f"{{{{Key|{key}|{tag}}}}}"
return f"{{{{Tag|{spec}}}}}"
def color(self, args: Arguments) -> str:
def color(self, arg: Arguments) -> str:
"""Simple color sample."""
return f"{{{{Color box|{self.clear(args[0])}}}}}"
return f"{{{{Color box|{self.clear(arg[0])}}}}}"
def icon(self, args: Arguments) -> str:
def icon(self, arg: Arguments) -> str:
"""Image with Röntgen icon."""
size: str = self.clear(args[1]) if len(args) > 1 else 16
shape_id: str = self.clear(args[0])
size: str = self.clear(arg[1]) if len(arg) > 1 else 16
shape_id: str = self.clear(arg[0])
name: str = self.extractor.get_shape(shape_id).name
return f"[[File:Röntgen {name}.svg|{size}px]]"
@ -274,27 +272,25 @@ class MapMachineMarkdown(MapMachineMoire, DefaultMarkdown):
images = {}
def color(self, args: Arguments) -> str:
def color(self, arg: Arguments) -> str:
"""Simple color sample."""
return self.clear(args[0])
return self.clear(arg[0])
def icon(self, args: Arguments) -> str:
def icon(self, arg: Arguments) -> str:
"""Image with Röntgen icon."""
return f"[{self.clear(args[0])}]"
return f"[{self.clear(arg[0])}]"
def kbd(self, args: Arguments) -> str:
def kbd(self, arg: Arguments) -> str:
"""Keyboard key."""
return f"<kbd>{self.clear(args[0])}</kbd>"
return f"<kbd>{self.clear(arg[0])}</kbd>"
def no_wrap(self, args: Arguments) -> str:
def no_wrap(self, arg: Arguments) -> str:
"""Do not wrap text at white spaces."""
return (
f'<span style="white-space: nowrap;">{self.parse(args[0])}</span>'
)
return f'<span style="white-space: nowrap;">{self.parse(arg[0])}</span>'
def formal(self, args: Arguments) -> str:
def formal(self, arg: Arguments) -> str:
"""Formal variable."""
return f"<{self.parse(args[0])}>"
return f"<{self.parse(arg[0])}>"
def convert(input_path: Path, output_path: Path) -> None:

View file

@ -21,9 +21,7 @@ from map_machine.workspace import workspace
class TaginfoProjectFile:
"""
JSON structure with OpenStreetMap tag usage.
"""
"""JSON structure with OpenStreetMap tag usage."""
def __init__(self, path: Path, scheme: Scheme) -> None:
self.path: Path = path

View file

@ -23,9 +23,7 @@ PathCommands = list[Union[float, str, np.ndarray]]
@dataclass
class Style:
"""
Drawing element style.
"""
"""Drawing element style."""
fill: Optional[Color] = None
stroke: Optional[Color] = None
@ -60,9 +58,7 @@ class Style:
class Drawing:
"""
Image.
"""
"""Image."""
def __init__(self, file_path: Path, width: int, height: int) -> None:
self.file_path: Path = file_path
@ -95,9 +91,7 @@ class Drawing:
class SVGDrawing(Drawing):
"""
SVG image.
"""
"""SVG image."""
def __init__(self, file_path: Path, width: int, height: int) -> None:
super().__init__(file_path, width, height)
@ -145,9 +139,7 @@ class SVGDrawing(Drawing):
class PNGDrawing(Drawing):
"""
PNG image.
"""
"""PNG image."""
def __init__(self, file_path: Path, width: int, height: int) -> None:
super().__init__(file_path, width, height)

View file

@ -51,9 +51,7 @@ def rotation_matrix(angle: float) -> np.ndarray:
class Sector:
"""
Sector described by two vectors.
"""
"""Sector described by two vectors."""
def __init__(self, text: str, angle: Optional[float] = None) -> None:
"""
@ -120,9 +118,7 @@ class Sector:
class DirectionSet:
"""
Describes direction, set of directions.
"""
"""Describes direction, set of directions."""
def __init__(self, text: str) -> None:
"""

View file

@ -33,9 +33,7 @@ USE_BLUR: bool = False
@dataclass
class Lane:
"""
Road lane specification.
"""
"""Road lane specification."""
width: Optional[float] = None # Width in meters
is_forward: Optional[bool] = None # Whether lane is forward or backward
@ -57,9 +55,7 @@ class Lane:
class RoadPart:
"""
Line part of the road.
"""
"""Line part of the road."""
def __init__(
self,
@ -366,9 +362,7 @@ class Intersection:
class Road(Tagged):
"""
Road or track on the map.
"""
"""Road or track on the map."""
def __init__(
self,
@ -755,16 +749,9 @@ class ComplexConnector(Connector):
class SimpleIntersection(Connector):
"""Connection between more than two roads."""
def __init__(
self,
connections: list[tuple[Road, int]],
flinger: Flinger,
) -> None:
super().__init__(connections, flinger)
def draw(self, svg: Drawing) -> None:
"""Draw connection fill."""
for road, index in sorted(
for road, _ in sorted(
self.connections, key=lambda x: x[0].matcher.priority
):
node: OSMNode = self.road_1.nodes[self.index_1]
@ -776,7 +763,7 @@ class SimpleIntersection(Connector):
def draw_border(self, svg: Drawing) -> None:
"""Draw connection outline."""
for road, index in self.connections:
for road, _ in self.connections:
node: OSMNode = self.road_1.nodes[self.index_1]
point: np.ndarray = self.flinger.fling(node.coordinates)
circle: Circle = svg.circle(
@ -817,13 +804,13 @@ class Roads:
layered_roads[road.layer] = []
layered_roads[road.layer].append(road)
for id_ in self.nodes:
connected: list[tuple[Road, int]] = self.nodes[id_]
for _, connected in self.nodes.items():
connector: Connector
if len(self.nodes[id_]) <= 1:
if len(connected) <= 1:
continue
elif len(self.nodes[id_]) == 2:
if len(connected) == 2:
road_1, index_1 = connected[0]
road_2, index_2 = connected[1]
if (
@ -851,11 +838,7 @@ class Roads:
roads: list[Road] = sorted(
layered_roads[layer], key=lambda x: x.matcher.priority
)
connectors: list[Connector]
if layer in layered_connectors:
connectors = layered_connectors[layer]
else:
connectors = []
connectors: list[Connector] = layered_connectors.get(layer)
# Draw borders.

View file

@ -26,9 +26,7 @@ BUILDING_MINIMAL_HEIGHT: float = 8.0
class Figure(Tagged):
"""
Some figure on the map: way or area.
"""
"""Some figure on the map: way or area."""
def __init__(
self,
@ -64,9 +62,7 @@ class Figure(Tagged):
class Building(Figure):
"""
Building on the map.
"""
"""Building on the map."""
def __init__(
self,
@ -193,9 +189,7 @@ class Building(Figure):
class StyledFigure(Figure):
"""
Figure with stroke and fill style.
"""
"""Figure with stroke and fill style."""
def __init__(
self,
@ -209,9 +203,7 @@ class StyledFigure(Figure):
class Crater(Tagged):
"""
Volcano or impact crater on the map.
"""
"""Volcano or impact crater on the map."""
def __init__(
self, tags: dict[str, str], coordinates: np.ndarray, point: np.ndarray
@ -248,9 +240,7 @@ class Crater(Tagged):
class Tree(Tagged):
"""
Tree on the map.
"""
"""Tree on the map."""
def __init__(
self, tags: dict[str, str], coordinates: np.ndarray, point: np.ndarray
@ -280,9 +270,7 @@ class Tree(Tagged):
class DirectionSector(Tagged):
"""
Sector that represents direction.
"""
"""Sector that represents direction."""
def __init__(self, tags: dict[str, str], point: np.ndarray) -> None:
super().__init__(tags)
@ -354,9 +342,7 @@ class DirectionSector(Tagged):
class Segment:
"""
Closed line segment.
"""
"""Closed line segment."""
def __init__(self, point_1: np.ndarray, point_2: np.ndarray) -> None:
self.point_1: np.ndarray = point_1

View file

@ -17,9 +17,7 @@ LONGITUDE_MAX_DIFFERENCE: float = 0.5
@dataclass
class BoundaryBox:
"""
Rectangle that limit space on the map.
"""
"""Rectangle that limit space on the map."""
left: float # Minimum longitude.
bottom: float # Minimum latitude.

View file

@ -40,9 +40,7 @@ def osm_zoom_level_to_pixels_per_meter(
class Flinger:
"""
Convert geo coordinates into SVG position points.
"""
"""Convert geo coordinates into SVG position points."""
def __init__(
self,

View file

@ -41,9 +41,7 @@ def norm(vector: np.ndarray) -> np.ndarray:
class Polyline:
"""
List of connected points.
"""
"""List of connected points."""
def __init__(self, points: list[np.ndarray]) -> None:
self.points: list[np.ndarray] = points

View file

@ -67,9 +67,7 @@ meta {{
class MapCSSWriter:
"""
Writer that converts Map Machine scheme into MapCSS 0.2 format.
"""
"""Writer that converts Map Machine scheme into MapCSS 0.2 format."""
def __init__(
self,

View file

@ -33,9 +33,7 @@ __email__ = "me@enzet.ru"
class Map:
"""
Map drawing.
"""
"""Map drawing."""
def __init__(
self,

View file

@ -59,9 +59,7 @@ def parse_levels(string: str) -> list[float]:
@dataclass
class Tagged:
"""
Something with tags (string to string mapping).
"""
"""Something with tags (string to string mapping)."""
tags: dict[str, str]
@ -224,9 +222,7 @@ class OSMWay(Tagged):
@dataclass
class OSMMember:
"""
Member of OpenStreetMap relation.
"""
"""Member of OpenStreetMap relation."""
type_: str
ref: int
@ -298,15 +294,11 @@ class OSMRelation(Tagged):
class NotWellFormedOSMDataException(Exception):
"""
OSM data structure is not well-formed.
"""
"""OSM data structure is not well-formed."""
class OSMData:
"""
The whole OpenStreetMap information about nodes, ways, and relations.
"""
"""The whole OpenStreetMap information about nodes, ways, and relations."""
def __init__(self) -> None:
self.nodes: dict[int, OSMNode] = {}

View file

@ -38,9 +38,7 @@ GRID_STEP: int = 16
@dataclass
class Shape:
"""
SVG icon path description.
"""
"""SVG icon path description."""
path: str # SVG icon path
offset: np.ndarray # vector that should be used to shift the path
@ -257,9 +255,7 @@ class ShapeExtractor:
@dataclass
class ShapeSpecification:
"""
Specification for shape as a part of an icon.
"""
"""Specification for shape as a part of an icon."""
shape: Shape
color: Color = DEFAULT_COLOR
@ -335,9 +331,7 @@ class ShapeSpecification:
@dataclass
class Icon:
"""
Icon that consists of (probably) multiple shapes.
"""
"""Icon that consists of (probably) multiple shapes."""
shape_specifications: list[ShapeSpecification]
opacity: float = 1.0
@ -450,9 +444,7 @@ class Icon:
@dataclass
class IconSet:
"""
Node representation: icons and color.
"""
"""Node representation: icons and color."""
main_icon: Icon
extra_icons: list[Icon]

View file

@ -25,9 +25,7 @@ __email__ = "me@enzet.ru"
@dataclass
class IconCollection:
"""
Collection of icons.
"""
"""Collection of icons."""
icons: list[Icon]

View file

@ -33,18 +33,14 @@ IconDescription = list[Union[str, dict[str, str]]]
@dataclass
class LineStyle:
"""
SVG line style and its priority.
"""
"""SVG line style and its priority."""
style: dict[str, Union[int, float, str]]
priority: float = 0.0
class MatchingType(Enum):
"""
Description on how tag was matched.
"""
"""Description on how tag was matched."""
NOT_MATCHED = 0
MATCHED_BY_SET = 1
@ -106,9 +102,7 @@ def match_location(restrictions: dict[str, str], country: str) -> bool:
class Matcher:
"""
Tag matching.
"""
"""Tag matching."""
def __init__(
self, structure: dict[str, Any], group: Optional[dict[str, Any]] = None
@ -215,9 +209,7 @@ def get_shape_specifications(
class NodeMatcher(Matcher):
"""
Tag specification matcher.
"""
"""Tag specification matcher."""
def __init__(
self, structure: dict[str, Any], group: dict[str, Any]
@ -265,9 +257,7 @@ class NodeMatcher(Matcher):
class WayMatcher(Matcher):
"""
Special tag matcher for ways.
"""
"""Special tag matcher for ways."""
def __init__(self, structure: dict[str, Any], scheme: "Scheme") -> None:
super().__init__(structure)
@ -289,9 +279,7 @@ class WayMatcher(Matcher):
class RoadMatcher(Matcher):
"""
Special tag matcher for highways.
"""
"""Special tag matcher for highways."""
def __init__(self, structure: dict[str, Any], scheme: "Scheme") -> None:
super().__init__(structure)

View file

@ -17,9 +17,7 @@ __email__ = "me@enzet.ru"
class _Handler(SimpleHTTPRequestHandler):
"""
HTTP request handler that process sloppy map tile requests.
"""
"""HTTP request handler that process sloppy map tile requests."""
cache: Path = Path("cache")
update_cache: bool = False

View file

@ -212,9 +212,7 @@ class Tile:
@dataclass
class Tiles:
"""
Collection of tiles.
"""
"""Collection of tiles."""
tiles: list[Tile]
tile_1: Tile # Left top tile.

View file

@ -17,9 +17,7 @@ DEFAULT_COLOR: Color = Color("#444444")
@dataclass
class Label:
"""
Text label.
"""
"""Text label."""
text: str
fill: Color = DEFAULT_COLOR

View file

@ -12,9 +12,7 @@ from map_machine.ui.cli import COMMANDS
class ArgumentParser(argparse.ArgumentParser):
"""
Argument parser that generates fish shell autocompletion commands.
"""
"""Argument parser that generates fish shell autocompletion commands."""
def __init__(self, *args, **kwargs) -> None:
self.arguments: list[dict[str, Any]] = []

View file

@ -10,9 +10,7 @@ __email__ = "me@enzet.ru"
@dataclass
class MinMax:
"""
Minimum and maximum.
"""
"""Minimum and maximum."""
min_: Any = None
max_: Any = None

View file

@ -17,9 +17,7 @@ def check_and_create(directory: Path) -> Path:
class Workspace:
"""
Project file and directory paths and generated files and directories.
"""
"""Project file and directory paths and generated files and directories."""
# Project directories and files, that are the part of the repository.