Skip to content

Commit

Permalink
Merge pull request #159 from wimglenn/repl
Browse files Browse the repository at this point in the history
Fix REPL detection for Python 3.13
  • Loading branch information
wimglenn authored Jan 4, 2025
2 parents c4b091e + e99305c commit 30bbea4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions aocd/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime
import os
import re
import sys
import traceback
from logging import getLogger
from logging import Logger
Expand Down Expand Up @@ -174,9 +175,7 @@ def giveup(msg):
return day, year
log.debug("skipping frame %s", filename)
else:
import __main__

if getattr(__main__, "__file__", "<input>") == "<input>":
if hasattr(sys, "ps1"):
log.debug("running within REPL")
day = current_day()
year = most_recent_year()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_aocd.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_submit_doesnt_bind_day_and_year_when_introspection_failed(mocker):

def test_data_in_interactive_mode(monkeypatch, mocker, freezer):
freezer.move_to("2017-12-10 12:00:00Z")
monkeypatch.delattr("__main__.__file__")
monkeypatch.setattr("sys.ps1", ">>>>> ", raising=False)
mock = mocker.patch("aocd.get_data", return_value="repl data")
data = aocd.data
mock.assert_called_once_with(day=10, year=2017)
Expand Down

0 comments on commit 30bbea4

Please sign in to comment.