diff --git a/CHANGELOG.md b/CHANGELOG.md index f015b7d..c5a1247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## [0.6.6] 2026-08-20 +### Fixed +- `setup_logging_level` isinstance check. + ## [0.6.5] 2026-08-20 ### Added - `return_single_namespace` option for `parse_args_using_dataclass` function. diff --git a/CITATION.cff b/CITATION.cff index 325b383..d361872 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -17,5 +17,5 @@ keywords: - tools - utilities license: MIT -version: 0.6.5 +version: 0.6.6 date-released: '2026-08-20' diff --git a/src/pythonwrench/__init__.py b/src/pythonwrench/__init__.py index 12a5f82..7075833 100644 --- a/src/pythonwrench/__init__.py +++ b/src/pythonwrench/__init__.py @@ -9,7 +9,7 @@ __license__ = "MIT" __maintainer__ = "Étienne Labbé (Labbeti)" __status__ = "Development" -__version__ = "0.6.5" +__version__ = "0.6.6" from typing import TYPE_CHECKING diff --git a/src/pythonwrench/logging.py b/src/pythonwrench/logging.py index c3dda87..2835f5d 100644 --- a/src/pythonwrench/logging.py +++ b/src/pythonwrench/logging.py @@ -5,10 +5,11 @@ import logging import sys from functools import lru_cache +from io import TextIOBase from logging import FileHandler, Formatter, Logger, StreamHandler from pathlib import Path from types import ModuleType -from typing import IO, Iterable, List, Literal, Optional, TypeVar, Union +from typing import IO, Iterable, List, Literal, Optional, TextIO, TypeVar, Union from typing_extensions import TypeAlias @@ -117,11 +118,11 @@ def setup_logging_level( for handler in logging.getLogger().handlers if isinstance(handler, StreamHandler) ] - elif isinstance(stream, IO): + elif isinstance(stream, (TextIOBase, TextIO)): streams = [stream] elif stream is None: streams = stream - elif isinstance_generic(stream, Iterable[IO]): + elif isinstance_generic(stream, Iterable[Union[TextIOBase, TextIO]]): streams = list(stream) else: raise TypeError(f"Invalid argument type {type(stream)=}.") diff --git a/tests/test_typing.py b/tests/test_typing.py index cf5b650..676937a 100644 --- a/tests/test_typing.py +++ b/tests/test_typing.py @@ -1,8 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import logging import unittest from dataclasses import dataclass +from io import TextIOBase +from logging import StreamHandler from numbers import Number from pathlib import Path from typing import ( @@ -331,6 +334,18 @@ def test_check_only_first(self) -> None: assert isinstance_generic([], List[int], check_only_first=True) assert isinstance_generic([1, 2], List, check_only_first=True) + def test_io_check(self) -> None: + assert isinstance_generic([], Iterable[TextIOBase]) + assert not isinstance_generic([1], Iterable[TextIOBase]) + + logger = logging.getLogger() + streams = [ + handler.stream + for handler in logger.handlers + if isinstance(handler, StreamHandler) + ] + assert isinstance_generic(streams, Iterable[TextIOBase]) + class TestCheckArgsType(TestCase): def test_example_1(self) -> None: