Skip to content

Commit 95f406c

Browse files
authored
Merge pull request #1638 from LilSpazJoekp/fix_for_3.6
Fixes for 3.6
2 parents 0f82960 + 49ff934 commit 95f406c

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

CHANGES.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Change Log
22
==========
33

4+
Unreleased
5+
----------
6+
7+
**Fixed**
8+
9+
* Asynchronous check would not work on Python 3.6 as ``asyncio.get_running_loop`` only
10+
exists on Python 3.7+.
11+
412
7.1.1 (2021/02/02)
513
------------------
614

praw/reddit.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import configparser
44
import os
55
import re
6+
import sys
67
import time
78
from itertools import islice
89
from logging import getLogger
@@ -367,11 +368,16 @@ def request(self, *args, **kwargs):
367368

368369
def _check_for_async(self):
369370
if self.config.check_for_async:
370-
try:
371-
asyncio.get_running_loop()
372-
except RuntimeError:
373-
pass
374-
else:
371+
in_async = False
372+
if sys.version_info >= (3, 7, 0):
373+
try:
374+
asyncio.get_running_loop()
375+
in_async = True
376+
except RuntimeError:
377+
pass
378+
else: # pragma: no cover # not able to be covered in > Python 3.6.12
379+
in_async = asyncio.get_event_loop().is_running()
380+
if in_async:
375381
logger.warning(
376382
"It appears that you are using PRAW in an asynchronous"
377383
" environment.\nIt is strongly recommended to use Async PRAW:"

tests/integration/models/reddit/test_modmail.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from datetime import datetime
23
from unittest import mock
34

@@ -42,9 +43,19 @@ def test_mute_duration(self, _):
4243
conversation.mute(7)
4344
conversation = self.reddit.subreddit("all").modmail("g46rw")
4445
assert conversation.user.mute_status["isMuted"]
45-
diff = datetime.fromisoformat(
46-
conversation.user.mute_status["endDate"]
47-
) - datetime.fromisoformat(conversation.mod_actions[-1].date)
46+
if sys.version_info >= (3, 7, 0):
47+
diff = datetime.fromisoformat(
48+
conversation.user.mute_status["endDate"]
49+
) - datetime.fromisoformat(conversation.mod_actions[-1].date)
50+
else:
51+
end_date = "".join(
52+
conversation.user.mute_status["endDate"].rsplit(":", 1)
53+
)
54+
start_date = "".join(conversation.mod_actions[-1].date.rsplit(":", 1))
55+
date_format = "%Y-%m-%dT%H:%M:%S.%f%z"
56+
diff = datetime.strptime(end_date, date_format) - datetime.strptime(
57+
start_date, date_format
58+
)
4859
assert diff.days == 6 # 6 here because it is not 7 whole days
4960

5061
@mock.patch("time.sleep", return_value=None)

0 commit comments

Comments
 (0)