From 22aa5a0fb0316c845ecc2c1d45fec18b9e2fe917 Mon Sep 17 00:00:00 2001 From: Midgard Date: Sun, 26 Jan 2020 01:45:20 +0100 Subject: [PATCH] Fix issues reported by pylint And silence the self-use warning: Tatsu requires it this way --- app/hlds/definitions.py | 8 ++++---- app/hlds/models.py | 11 +++++++++-- app/hlds/parser.py | 15 ++++++--------- parse_hlds.py | 1 - 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/hlds/definitions.py b/app/hlds/definitions.py index 3d16f8c..252e746 100644 --- a/app/hlds/definitions.py +++ b/app/hlds/definitions.py @@ -1,13 +1,13 @@ # Import this class to load the standard HLDS definitions from os import path -import itertools from .parser import parse_all_directory -__all__ = ["definitions"] +__all__ = ["location_definitions"] # TODO Use proper way to get resources, see https://stackoverflow.com/a/10935674 -data_dir = path.join(path.dirname(__file__), "..", "..", "data") +DATA_DIR = path.join(path.dirname(__file__), "..", "..", "data") -location_definitions = parse_all_directory(data_dir) +# pylint: disable=invalid-name +location_definitions = parse_all_directory(DATA_DIR) diff --git a/app/hlds/models.py b/app/hlds/models.py index 6b948b8..13ad06c 100644 --- a/app/hlds/models.py +++ b/app/hlds/models.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# pylint: disable=too-few-public-methods from typing import List @@ -73,7 +74,13 @@ class Location: self.dishes: List[Dish] = dishes def __str__(self): - return "============================\n{0.id}: {0.name}\n============================\n\n{1}".format( + return ( + "============================\n" + "{0.id}: {0.name}\n" + "============================\n" + "\n" + "{1}" + ).format( self, - "\n\n".join(map(str, self.dishes)) + "\n".join(map(str, self.dishes)) ) diff --git a/app/hlds/parser.py b/app/hlds/parser.py index d8e1b20..4127204 100644 --- a/app/hlds/parser.py +++ b/app/hlds/parser.py @@ -1,11 +1,10 @@ #!/usr/bin/env python3 from glob import glob -from os import path, walk -from tatsu import parse as tatsu_parse +from os import path import itertools +from tatsu import parse as tatsu_parse from .models import Location, Choice, Option, Dish -import operator # TODO Use proper way to get resources, see https://stackoverflow.com/a/10935674 @@ -17,6 +16,7 @@ def filter_instance(cls, iterable): return [item for item in iterable if isinstance(item, cls)] +# pylint: disable=no-self-use class HldsSemanticActions: def location(self, ast): choices = {choice.id: choice for choice in filter_instance(Choice, ast["items_"])} @@ -53,10 +53,7 @@ class HldsSemanticActions: ) def indent_choice_block(self, ast): - if ast["kind"] == "declaration": - return self.choice_block(ast) - else: - return ast + return self.choice_block(ast) if ast["kind"] == "declaration" else ast def indent_choice_entry(self, ast): return Option( @@ -84,8 +81,8 @@ def parse(menu): def parse_file(filename): - with open(filename, "r") as fh: - return parse(fh.read()) + with open(filename, "r") as file_handle: + return parse(file_handle.read()) def parse_files(files): diff --git a/parse_hlds.py b/parse_hlds.py index 9957f4d..6a6961f 100755 --- a/parse_hlds.py +++ b/parse_hlds.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -import json from tatsu.util import asjson from app.hlds.parser import parse_files