diff options
| author | 2021-05-05 18:33:15 +0200 | |
|---|---|---|
| committer | 2021-05-05 18:33:15 +0200 | |
| commit | bdb1ca730c929633c998c573df98f8e7f257f5c3 (patch) | |
| tree | af5659c06a7aa6266111a36f97add870f3dfb757 | |
| parent | Add more celebrities to stars.json (diff) | |
| parent | Merge pull request #1441 from asleep-cult/master (diff) | |
Merge branch 'main' into patch-1
| -rw-r--r-- | bot/exts/info/reddit.py | 6 | ||||
| -rw-r--r-- | bot/resources/tags/identity.md | 24 | 
2 files changed, 27 insertions, 3 deletions
| diff --git a/bot/exts/info/reddit.py b/bot/exts/info/reddit.py index 6790be762..e1f0c5f9f 100644 --- a/bot/exts/info/reddit.py +++ b/bot/exts/info/reddit.py @@ -4,6 +4,7 @@ import random  import textwrap  from collections import namedtuple  from datetime import datetime, timedelta +from html import unescape  from typing import List  from aiohttp import BasicAuth, ClientError @@ -179,8 +180,7 @@ class Reddit(Cog):          for post in posts:              data = post["data"] -            text = data["selftext"] -            if text: +            if text := unescape(data["selftext"]):                  text = textwrap.shorten(text, width=128, placeholder="...")                  text += "\n"  # Add newline to separate embed info @@ -188,7 +188,7 @@ class Reddit(Cog):              comments = data["num_comments"]              author = data["author"] -            title = textwrap.shorten(data["title"], width=64, placeholder="...") +            title = textwrap.shorten(unescape(data["title"]), width=64, placeholder="...")              # Normal brackets interfere with Markdown.              title = escape_markdown(title).replace("[", "⦋").replace("]", "⦌")              link = self.URL + data["permalink"] diff --git a/bot/resources/tags/identity.md b/bot/resources/tags/identity.md new file mode 100644 index 000000000..fb2010759 --- /dev/null +++ b/bot/resources/tags/identity.md @@ -0,0 +1,24 @@ +**Identity vs. Equality** + +Should I be using `is` or `==`? + +To check if two objects are equal, use the equality operator (`==`). +```py +x = 5 +if x == 5: +    print("x equals 5") +if x == 3: +    print("x equals 3") +# Prints 'x equals 5' +``` +To check if two objects are actually the same thing in memory, use the identity comparison operator (`is`). +```py +list_1 = [1, 2, 3] +list_2 = [1, 2, 3] +if list_1 is [1, 2, 3]: +    print("list_1 is list_2") +reference_to_list_1 = list_1 +if list_1 is reference_to_list_1: +    print("list_1 is reference_to_list_1") +# Prints 'list_1 is reference_to_list_1' +``` | 
