Skip to content

Commit

Permalink
tell: restore py2/py3 compatibility layer (unicode vs. str)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgw committed Aug 12, 2021
1 parent 791b0ff commit 1dc50ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sopel/modules/tell.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io # don't use `codecs` for loading the DB; it will split lines on some IRC formatting
import logging
import os
import sys
import threading
import time
import unicodedata
Expand All @@ -22,6 +23,10 @@
from sopel.tools.time import format_time, get_timezone


if sys.version_info.major >= 3:
unicode = str


LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -141,7 +146,7 @@ def _format_safe_lstrip(text):
Stolen and tweaked from the ``choose`` plugin's ``_format_safe()``
function by the person who wrote it.
"""
if not isinstance(text, str):
if not isinstance(text, unicode):
raise TypeError("A string is required.")
elif not text:
# unnecessary optimization
Expand Down
5 changes: 5 additions & 0 deletions test/modules/test_modules_tell.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
import datetime
import io
import os
import sys

import pytest

from sopel import formatting
from sopel.modules import tell


if sys.version_info.major >= 3:
unicode = str


def test_load_reminders_empty(tmpdir):
tmpfile = tmpdir.join('tell.db')
tmpfile.write('\n')
Expand Down

0 comments on commit 1dc50ee

Please sign in to comment.