satisfactory: add typing to Cookbook member functions

This commit is contained in:
Danny Robson 2019-07-14 11:15:29 +10:00
parent 9f4858c885
commit 51001d66a5

View File

@ -1,7 +1,7 @@
import os import os
import json import json
from typing import Dict from typing import Dict, Generator
class Cookbook(object): class Cookbook(object):
__recipes: Dict[str, Dict] __recipes: Dict[str, Dict]
@ -16,23 +16,23 @@ class Cookbook(object):
with open(path, 'r') as src: with open(path, 'r') as src:
self.__recipes[name] = json.load(src) self.__recipes[name] = json.load(src)
def __getitem__(self, item: str): def __getitem__(self, item: str) -> Dict[str, Dict]:
return self.__recipes[item] return self.__recipes[item]
def all(self): def all(self):
return self.__recipes.keys() return self.__recipes.keys()
def recipes(self, name: str) -> dict: def recipes(self, name: str) -> Dict:
return self.__recipes[name]['recipes'] return self.__recipes[name]['recipes']
def is_component(self, name): def is_component(self, name: str) -> bool:
return 'component' in self.__recipes[name]['type'] return 'component' in self.__recipes[name]['type']
def components(self): def components(self) -> Generator[Dict, None, None]:
return (i for i in self.all() if self.is_component(i)) return (i for i in self.all() if self.is_component(i))
def is_resource(self, name): def is_resource(self, name: str) -> bool:
return 'resource' in self.__recipes[name]['type'] return 'resource' in self.__recipes[name]['type']
def resources(self): def resources(self) -> Generator[Dict, None, None]:
return (i for i in self.all() if self.is_resource(i)) return (i for i in self.all() if self.is_resource(i))