Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion stdlib/@tests/test_cases/check_logging.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

import io
import logging
import logging.handlers
import multiprocessing
import queue
from typing import Any
from typing import Any, Union
from typing_extensions import assert_type

# This pattern comes from the logging docs, and should therefore pass a type checker
# See https://docs.python.org/3/library/logging.html#logrecord-objects
Expand All @@ -28,3 +30,7 @@ def record_factory(*args: Any, **kwargs: Any) -> logging.LogRecord:
logging.handlers.QueueListener(queue.Queue())
logging.handlers.QueueListener(queue.SimpleQueue())
logging.handlers.QueueListener(multiprocessing.Queue())

# FileHandler.stream can be None when delay=True or after close()
fh = logging.FileHandler("test.log", delay=True)
assert_type(fh.stream, Union[io.TextIOWrapper, None])
1 change: 1 addition & 0 deletions stdlib/logging/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ class FileHandler(StreamHandler[TextIOWrapper]):
encoding: str | None # undocumented
delay: bool # undocumented
errors: str | None # undocumented
stream: TextIOWrapper | None # type: ignore[assignment] # None when delay=True or after close()
def __init__(
self, filename: StrPath, mode: str = "a", encoding: str | None = None, delay: bool = False, errors: str | None = None
) -> None: ...
Expand Down