From 8023397c7a7db8ec04f2b16adeb84dfe2baefd9b Mon Sep 17 00:00:00 2001 From: Kadir Can Ozden <101993364+bysiber@users.noreply.github.com> Date: Fri, 20 Feb 2026 05:13:51 +0300 Subject: [PATCH] fix: correct return type annotation for Locale.format_day format_day returns a formatted string, not a bool. --- pr_body2.md | 16 ++++++++++++++++ tornado/locale.py | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 pr_body2.md diff --git a/pr_body2.md b/pr_body2.md new file mode 100644 index 0000000000..2eddbf14d2 --- /dev/null +++ b/pr_body2.md @@ -0,0 +1,16 @@ +In `TCPClient._create_stream`, if `IOStream()` constructor raises `OSError`, the except handler references `stream` which was never assigned: + +```python +try: + stream = IOStream(socket_obj, max_buffer_size=max_buffer_size) +except OSError as e: + fu = Future() + fu.set_exception(e) + return stream, fu # NameError: 'stream' is not defined +``` + +This causes a `NameError` that masks the original `OSError`, making it impossible to diagnose the root cause from the traceback. + +Additionally the socket object would be leaked since it's never closed in the error path. + +Fixed by returning the `socket_obj` instead of the undefined `stream` variable, and closing the socket before returning. diff --git a/tornado/locale.py b/tornado/locale.py index abd8668c6e..f3b80b2b87 100644 --- a/tornado/locale.py +++ b/tornado/locale.py @@ -433,7 +433,7 @@ def format_date( def format_day( self, date: datetime.datetime, gmt_offset: int = 0, dow: bool = True - ) -> bool: + ) -> str: """Formats the given date as a day of week. Example: "Monday, January 22". You can remove the day of week with