Skip to content

Commit 1dc50ee

Browse files
committed
tell: restore py2/py3 compatibility layer (unicode vs. str)
1 parent 791b0ff commit 1dc50ee

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

sopel/modules/tell.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io # don't use `codecs` for loading the DB; it will split lines on some IRC formatting
1414
import logging
1515
import os
16+
import sys
1617
import threading
1718
import time
1819
import unicodedata
@@ -22,6 +23,10 @@
2223
from sopel.tools.time import format_time, get_timezone
2324

2425

26+
if sys.version_info.major >= 3:
27+
unicode = str
28+
29+
2530
LOGGER = logging.getLogger(__name__)
2631

2732

@@ -141,7 +146,7 @@ def _format_safe_lstrip(text):
141146
Stolen and tweaked from the ``choose`` plugin's ``_format_safe()``
142147
function by the person who wrote it.
143148
"""
144-
if not isinstance(text, str):
149+
if not isinstance(text, unicode):
145150
raise TypeError("A string is required.")
146151
elif not text:
147152
# unnecessary optimization

test/modules/test_modules_tell.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
import datetime
66
import io
77
import os
8+
import sys
89

910
import pytest
1011

1112
from sopel import formatting
1213
from sopel.modules import tell
1314

1415

16+
if sys.version_info.major >= 3:
17+
unicode = str
18+
19+
1520
def test_load_reminders_empty(tmpdir):
1621
tmpfile = tmpdir.join('tell.db')
1722
tmpfile.write('\n')

0 commit comments

Comments
 (0)