Fix #33243: Move return out of finally block in niconico downloader

Python 3.14 emits SyntaxWarning for 'return' in a 'finally' block.
Move 'return success' after the try/finally to eliminate the warning
while preserving identical behavior (success is always set before
the finally block runs).

Added test_niconico_downloader.py verifying no SyntaxWarning on import.
This commit is contained in:
cobyfrombrooklyn-bot 2026-02-26 06:39:14 -05:00
parent 956b8c5855
commit ac752723ba
2 changed files with 25 additions and 1 deletions

View file

@ -0,0 +1,24 @@
#!/usr/bin/env python
# coding: utf-8
from __future__ import unicode_literals
import subprocess
import sys
import unittest
class TestNiconicoDownloader(unittest.TestCase):
def test_no_syntax_warning_return_in_finally(self):
"""Issue #33243: 'return' in a 'finally' block triggers SyntaxWarning in Python 3.14+"""
result = subprocess.run(
[sys.executable, '-W', 'error::SyntaxWarning', '-c',
'from youtube_dl.downloader.niconico import NiconicoDmcFD'],
capture_output=True, text=True)
self.assertEqual(
result.returncode, 0,
'Importing niconico downloader raised SyntaxWarning '
'(return in finally block):\n' + result.stderr)
if __name__ == '__main__':
unittest.main()

View file

@ -63,4 +63,4 @@ class NiconicoDmcFD(FileDownloader):
with heartbeat_lock:
timer[0].cancel()
download_complete = True
return success
return success