diff --git a/facebook_business/bootstrap.py b/facebook_business/bootstrap.py index dcee96b6..1810f881 100644 --- a/facebook_business/bootstrap.py +++ b/facebook_business/bootstrap.py @@ -41,9 +41,8 @@ def is_authenticated(cls): @classmethod def load_config(cls): - config_file = open(os.path.join(repo_dir, 'config.json')) - config = json.load(config_file) - config_file.close() + with open(os.path.join(repo_dir, 'config.json')) as config_file: + config = json.load(config_file) return config @classmethod diff --git a/facebook_business/crashreporter.py b/facebook_business/crashreporter.py index 8ae01a10..8884b2ff 100644 --- a/facebook_business/crashreporter.py +++ b/facebook_business/crashreporter.py @@ -34,7 +34,7 @@ def __init__(self, app_id, excepthook): @classmethod def enable(cls): - if cls.reporter_instance == None: + if cls.reporter_instance is None: api = FacebookAdsApi.get_default_api() cls.reporter_instance = cls(api._session.app_id, sys.excepthook) sys.excepthook = cls.reporter_instance.__exception_handler @@ -50,7 +50,7 @@ def disable(cls): @classmethod def enableLogging(cls): - if cls.logger == None: + if cls.logger is None: logging.basicConfig() cls.logger = logging.getLogger(__name__) cls.logger.setLevel(logging.INFO) diff --git a/facebook_business/typechecker.py b/facebook_business/typechecker.py index 56a17d76..12edd1dd 100644 --- a/facebook_business/typechecker.py +++ b/facebook_business/typechecker.py @@ -37,9 +37,7 @@ def convert_string_to_prim_type(self, primitive_type, value): elif primitive_type in ("unsigned int", "int"): return int(value) elif primitive_type == "bool": - if value in ("false", "0", "null"): - return False - return True + return value not in ("false", "0", "null") elif primitive_type == "float": return float(value) elif primitive_type == "datetime": @@ -98,15 +96,15 @@ def is_type(self, value_type, value, allow_dict_as_obj=True): if not isinstance(value, list): return False sub_type = self.get_type_from_collection(value_type, 'list')[0] - return all([self.is_type(sub_type, item) for item in value]) + return all(self.is_type(sub_type, item) for item in value) if self.is_type_collection(value_type, 'map'): if not isinstance(value, dict): return False sub_types = self.get_type_from_collection(value_type, 'map') sub_type_key = sub_types[0] sub_type_value = sub_types[1] - return all([self.is_type(sub_type_key, k) and - self.is_type(sub_type_value, v) for k, v in value.items()]) + return all(self.is_type(sub_type_key, k) and + self.is_type(sub_type_value, v) for k, v in value.items()) if (type(value).__name__ == value_type or hasattr(value, '_is' + value_type)): @@ -164,11 +162,13 @@ def get_typed_value(self, key, value): else: sub_type_key = 'string' sub_type_value = sub_types[0] - typed_value = dict( - (self.get_typed_value(sub_type_key, k), - self.get_typed_value(sub_type_value, v)) + typed_value = { + self.get_typed_value(sub_type_key, k): self.get_typed_value( + sub_type_value, v + ) for (k, v) in value.items() - ) + } + elif isinstance(value, dict): try: typed_value = self._create_field_object(field_type, value)