Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Use x is None rather than x == None #600

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions facebook_business/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions facebook_business/crashreporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions facebook_business/typechecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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)):
Expand Down Expand Up @@ -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)
Expand Down