True
should be expr is True
495
496 content_added = False
497 embed = discord.Embed(color=discord.Color.random())
498 embed.set_author(name=f"{last_message.author.display_name} {'edited' if last_message.edited_at == True else 'deleted'} a message", icon_url=last_message.author.display_avatar.url)499 if last_message.content:
500 embed.description = last_message.content[:2000] + "..." if len(last_message.content) > 2000 else last_message.content
501 content_added = True
None
should be expr is None
1439 @bridge.bridge_command(name='search', description=loc["descriptions"]["search"])
1440 async def search(self, ctx, *, keyword=None):
1441 # Search from Youtube and returns 10 songs
1442 if keyword == None:1443 return await self.respond(ctx.ctx, loc["messages"]["play_no_keyword"], color=0xff0000)
1444 originalkeyword = keyword
1445 keyword = "ytsearch10:" + keyword
None
should be expr is None
1344 A list of these sites can be found here: https://rg3.github.io/youtube-dl/supportedsites.html
1345 """
1346
1347 if search == None:1348 return await self.respond(ctx.ctx, loc["messages"]["provide_url"], color=0xff0000)
1349 # Joins the channel if it hasn't
1350 if not ctx.voice_state.voice:
None
should be expr is None
735
736 ctx = self.ctx
737 search = self.data[int(self.values[0])]["url"]
738 if search == None: 739 return await self.respond(interaction.message, loc["messages"]["provide_url"], color=0xff0000)
740 # Joins the channel if it hasn't
741 if not ctx.voice_state.voice:
Comparisons to the singleton objects, like True
, False
, and None
, should be done with identity, not equality. Use is
or is not
.
Identity checks are faster than equality checks.
Also, the equality checks can result in unintended behaviour in some cases:
>>> 1 is True
False
>>> 1 == True
True
>>> 1.0 is True
False
>>> 1.0 == True
True
value = fx()
if value == True: # `==` can cause unintended behaviour
print(value)
if value != None:
print(value)
value = fx()
if value is True: # `is` for Identity comparison
print(value)
if value is not None:
print(value)
Equality comparisons might be required in some cases, especially in SQLAlchemy, SQLObject, ORMs, etc. In these cases, it is safe to ignore this issue.