Skip to content

Commit

Permalink
Chore: Use x is None rather than x == None (#600)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: facebook/facebook-python-business-sdk#600

Reviewed By: mengxuanzhangz

Differential Revision: D49887287

Pulled By: stcheng

fbshipit-source-id: c8933acd73ac3c89c5c1d67aa840c2c436182c30
  • Loading branch information
yezz123 authored and facebook-github-bot committed Oct 4, 2023
1 parent c2a2f74 commit f462e60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
5 changes: 2 additions & 3 deletions templates/python/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 templates/python/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 templates/python/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

0 comments on commit f462e60

Please sign in to comment.