Fix issues reported by pylint

And silence the self-use warning: Tatsu requires it this way
This commit is contained in:
Midgard 2020-01-26 01:45:20 +01:00
parent 5fcac5f937
commit 22aa5a0fb0
Signed by: midgard
GPG key ID: 511C112F1331BBB4
4 changed files with 19 additions and 16 deletions

View file

@ -1,13 +1,13 @@
# Import this class to load the standard HLDS definitions # Import this class to load the standard HLDS definitions
from os import path from os import path
import itertools
from .parser import parse_all_directory from .parser import parse_all_directory
__all__ = ["definitions"] __all__ = ["location_definitions"]
# TODO Use proper way to get resources, see https://stackoverflow.com/a/10935674 # 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)

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# pylint: disable=too-few-public-methods
from typing import List from typing import List
@ -73,7 +74,13 @@ class Location:
self.dishes: List[Dish] = dishes self.dishes: List[Dish] = dishes
def __str__(self): 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, self,
"\n\n".join(map(str, self.dishes)) "\n".join(map(str, self.dishes))
) )

View file

@ -1,11 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from glob import glob from glob import glob
from os import path, walk from os import path
from tatsu import parse as tatsu_parse
import itertools import itertools
from tatsu import parse as tatsu_parse
from .models import Location, Choice, Option, Dish from .models import Location, Choice, Option, Dish
import operator
# TODO Use proper way to get resources, see https://stackoverflow.com/a/10935674 # 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)] return [item for item in iterable if isinstance(item, cls)]
# pylint: disable=no-self-use
class HldsSemanticActions: class HldsSemanticActions:
def location(self, ast): def location(self, ast):
choices = {choice.id: choice for choice in filter_instance(Choice, ast["items_"])} choices = {choice.id: choice for choice in filter_instance(Choice, ast["items_"])}
@ -53,10 +53,7 @@ class HldsSemanticActions:
) )
def indent_choice_block(self, ast): def indent_choice_block(self, ast):
if ast["kind"] == "declaration": return self.choice_block(ast) if ast["kind"] == "declaration" else ast
return self.choice_block(ast)
else:
return ast
def indent_choice_entry(self, ast): def indent_choice_entry(self, ast):
return Option( return Option(
@ -84,8 +81,8 @@ def parse(menu):
def parse_file(filename): def parse_file(filename):
with open(filename, "r") as fh: with open(filename, "r") as file_handle:
return parse(fh.read()) return parse(file_handle.read())
def parse_files(files): def parse_files(files):

View file

@ -1,6 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import json
from tatsu.util import asjson from tatsu.util import asjson
from app.hlds.parser import parse_files from app.hlds.parser import parse_files