Skip to content

Commit

Permalink
feat: Download.bittorrent returns None if no "bittorrent" key pre…
Browse files Browse the repository at this point in the history
…sent

BREAKING CHANGE: this could be a breaking change if your code does not
check if `download.bittorrent` is an instance of `BitTorrent`
before accessing its attributes.

Reference: issue #53.
  • Loading branch information
pawamoy committed Apr 7, 2020
1 parent 56d7d7a commit 74106fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/aria2p/downloads.py
Expand Up @@ -638,7 +638,7 @@ def bittorrent(self):
BitTorrent only.
"""
if not self._bittorrent:
if not self._bittorrent and "bittorrent" in self._struct:
self._bittorrent = BitTorrent(self._struct.get("bittorrent"))
return self._bittorrent

Expand Down
5 changes: 5 additions & 0 deletions tests/test_downloads.py
Expand Up @@ -119,6 +119,11 @@ def test_bittorrent(self):
self.download._struct["bittorrent"] = {"mode": "single"}
assert self.download.bittorrent.mode is None

# assert is None when "bittorrent" key is not in struct
del self.download._struct["bittorrent"]
self.download._bittorrent = None
assert self.download.bittorrent is None

def test_completed_length(self):
assert self.download.completed_length == 889_592_532

Expand Down

0 comments on commit 74106fe

Please sign in to comment.