Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop py35 and py36 #1203

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
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
4 changes: 0 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ jobs:
- 3.13-dev
- pypy-3.9
include:
- os: ubuntu-20.04
python-version: '3.5'
- os: ubuntu-20.04
python-version: '3.6'
- os: windows-2022
python-version: '3.12'
- os: macos-13
Expand Down
44 changes: 17 additions & 27 deletions loguru/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ from asyncio import AbstractEventLoop
from datetime import datetime, time, timedelta
from logging import Handler
from multiprocessing.context import BaseContext
from os import PathLike
from types import TracebackType
from typing import (
Any,
Awaitable,
BinaryIO,
Callable,
ContextManager,
Dict,
Generator,
Generic,
Expand All @@ -114,26 +117,13 @@ from typing import (
overload,
)

if sys.version_info >= (3, 5, 3):
from typing import Awaitable
else:
from typing_extensions import Awaitable

if sys.version_info >= (3, 6):
from os import PathLike
from typing import ContextManager

PathLikeStr = PathLike[str]
else:
from pathlib import PurePath as PathLikeStr

from typing_extensions import ContextManager

if sys.version_info >= (3, 8):
from typing import Protocol, TypedDict
else:
from typing_extensions import Protocol, TypedDict

PathLikeStr = PathLike[str]

_T = TypeVar("_T")
_F = TypeVar("_F", bound=Callable[..., Any])
ExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]]
Expand Down Expand Up @@ -248,7 +238,7 @@ class Logger:
diagnose: bool = ...,
enqueue: bool = ...,
context: Optional[Union[str, BaseContext]] = ...,
catch: bool = ...
catch: bool = ...,
) -> int: ...
@overload
def add(
Expand All @@ -265,7 +255,7 @@ class Logger:
enqueue: bool = ...,
context: Optional[Union[str, BaseContext]] = ...,
catch: bool = ...,
loop: Optional[AbstractEventLoop] = ...
loop: Optional[AbstractEventLoop] = ...,
) -> int: ...
@overload
def add(
Expand All @@ -290,7 +280,7 @@ class Logger:
mode: str = ...,
buffering: int = ...,
encoding: str = ...,
**kwargs: Any
**kwargs: Any,
) -> int: ...
def remove(self, handler_id: Optional[int] = ...) -> None: ...
def complete(self) -> AwaitableCompleter: ...
Expand All @@ -304,7 +294,7 @@ class Logger:
onerror: Optional[Callable[[BaseException], None]] = ...,
exclude: Optional[Union[Type[BaseException], Tuple[Type[BaseException], ...]]] = ...,
default: Any = ...,
message: str = ...
message: str = ...,
) -> Catcher: ...
@overload
def catch(self, function: _F) -> _F: ...
Expand All @@ -318,10 +308,10 @@ class Logger:
raw: bool = ...,
capture: bool = ...,
depth: int = ...,
ansi: bool = ...
ansi: bool = ...,
) -> Logger: ...
def bind(__self, **kwargs: Any) -> Logger: ... # noqa: N805
def contextualize(__self, **kwargs: Any) -> Contextualizer: ... # noqa: N805
def bind(self, **kwargs: Any) -> Logger: ... # noqa: N805
def contextualize(self, **kwargs: Any) -> Contextualizer: ... # noqa: N805
def patch(self, patcher: PatcherFunction) -> Logger: ...
@overload
def level(self, name: str) -> Level: ...
Expand All @@ -346,7 +336,7 @@ class Logger:
levels: Optional[Sequence[LevelConfig]] = ...,
extra: Optional[Dict[Any, Any]] = ...,
patcher: Optional[PatcherFunction] = ...,
activation: Optional[Sequence[ActivationConfig]] = ...
activation: Optional[Sequence[ActivationConfig]] = ...,
) -> List[int]: ...
# @staticmethod cannot be used with @overload in mypy (python/mypy#7781).
# However Logger is not exposed and logger is an instance of Logger
Expand All @@ -359,7 +349,7 @@ class Logger:
pattern: Union[str, Pattern[str]],
*,
cast: Union[Dict[str, Callable[[str], Any]], Callable[[Dict[str, str]], None]] = ...,
chunk: int = ...
chunk: int = ...,
) -> Generator[Dict[str, Any], None, None]: ...
@overload
def parse(
Expand All @@ -368,7 +358,7 @@ class Logger:
pattern: Union[bytes, Pattern[bytes]],
*,
cast: Union[Dict[str, Callable[[bytes], Any]], Callable[[Dict[str, bytes]], None]] = ...,
chunk: int = ...
chunk: int = ...,
) -> Generator[Dict[str, Any], None, None]: ...
@overload
def trace(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805
Expand Down Expand Up @@ -404,10 +394,10 @@ class Logger:
def exception(__self, __message: Any) -> None: ... # noqa: N805
@overload
def log(
__self, __level: Union[int, str], __message: str, *args: Any, **kwargs: Any # noqa: N805
self, __level: Union[int, str], __message: str, *args: Any, **kwargs: Any # noqa: N805
) -> None: ...
@overload
def log(__self, __level: Union[int, str], __message: Any) -> None: ... # noqa: N805
def log(self, __level: Union[int, str], __message: Any) -> None: ... # noqa: N805
def start(self, *args: Any, **kwargs: Any) -> int: ...
def stop(self, *args: Any, **kwargs: Any) -> None: ...

Expand Down
27 changes: 0 additions & 27 deletions loguru/_asyncio_loop.py

This file was deleted.

19 changes: 4 additions & 15 deletions loguru/_better_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,12 @@
import tokenize
import traceback

if sys.version_info >= (3, 11):
if sys.version_info < (3, 11):
from exceptiongroup import ExceptionGroup

def is_exception_group(exc):
return isinstance(exc, ExceptionGroup)

else:
try:
from exceptiongroup import ExceptionGroup
except ImportError:

def is_exception_group(exc):
return False

else:

def is_exception_group(exc):
return isinstance(exc, ExceptionGroup)
def is_exception_group(exc):
return isinstance(exc, ExceptionGroup)


class SyntaxHighlighter:
Expand Down
15 changes: 0 additions & 15 deletions loguru/_contextvars.py

This file was deleted.

8 changes: 4 additions & 4 deletions loguru/_file_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def generate_rename_path(root, ext, creation_time):
creation_datetime = datetime.datetime.fromtimestamp(creation_time)
date = FileDateFormatter(creation_datetime)

renamed_path = "{}.{}{}".format(root, date, ext)
renamed_path = f"{root}.{date}{ext}"
counter = 1

while os.path.exists(renamed_path):
counter += 1
renamed_path = "{}.{}.{}{}".format(root, date, counter, ext)
renamed_path = f"{root}.{date}.{counter}{ext}"

return renamed_path

Expand Down Expand Up @@ -56,7 +56,7 @@ def copy_compress(path_in, path_out, opener, **kwargs):

@staticmethod
def compression(path_in, ext, compress_function):
path_out = "{}{}".format(path_in, ext)
path_out = f"{path_in}{ext}"

if os.path.exists(path_out):
creation_time = get_ctime(path_out)
Expand Down Expand Up @@ -167,7 +167,7 @@ def __init__(
mode="a",
buffering=1,
encoding="utf8",
**kwargs
**kwargs,
):
self.encoding = encoding

Expand Down
2 changes: 1 addition & 1 deletion loguru/_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(
error_interceptor,
exception_formatter,
id_,
levels_ansi_codes
levels_ansi_codes,
):
self._name = name
self._sink = sink
Expand Down
26 changes: 14 additions & 12 deletions loguru/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,19 @@
import re
import sys
import warnings
from collections import namedtuple
from asyncio import get_running_loop
from contextvars import ContextVar
from inspect import isclass, iscoroutinefunction, isgeneratorfunction
from multiprocessing import current_process, get_context
from multiprocessing.context import BaseContext
from os import PathLike
from os.path import basename, splitext
from threading import current_thread
from typing import NamedTuple

from . import _asyncio_loop, _colorama, _defaults, _filters
from . import _colorama, _defaults, _filters
from ._better_exceptions import ExceptionFormatter
from ._colorizer import Colorizer
from ._contextvars import ContextVar
from ._datetime import aware_now
from ._error_interceptor import ErrorInterceptor
from ._file_sink import FileSink
Expand All @@ -110,13 +112,13 @@
from ._recattrs import RecordException, RecordFile, RecordLevel, RecordProcess, RecordThread
from ._simple_sinks import AsyncSink, CallableSink, StandardSink, StreamSink

if sys.version_info >= (3, 6):
from os import PathLike
else:
from pathlib import PurePath as PathLike

class Level(NamedTuple):
name: str
no: int
color: str
icon: str

Level = namedtuple("Level", ["name", "no", "color", "icon"])

start_time = aware_now()

Expand Down Expand Up @@ -249,7 +251,7 @@ def add(
enqueue=_defaults.LOGURU_ENQUEUE,
context=_defaults.LOGURU_CONTEXT,
catch=_defaults.LOGURU_CATCH,
**kwargs
**kwargs,
):
r"""Add a handler sending log messages to a sink adequately configured.

Expand Down Expand Up @@ -840,7 +842,7 @@ def add(
# running loop in Python 3.5.2 and earlier versions, see python/asyncio#452.
if enqueue and loop is None:
try:
loop = _asyncio_loop.get_running_loop()
loop = get_running_loop()
except RuntimeError as e:
raise ValueError(
"An event loop is required to add a coroutine sink with `enqueue=True`, "
Expand Down Expand Up @@ -1136,7 +1138,7 @@ def catch(
default=None,
message="An error has been caught in function '{record[function]}', "
"process '{record[process].name}' ({record[process].id}), "
"thread '{record[thread].name}' ({record[thread].id}):"
"thread '{record[thread].name}' ({record[thread].id}):",
):
"""Return a decorator to automatically log possibly caught error in wrapped function.

Expand Down Expand Up @@ -1293,7 +1295,7 @@ def opt(
raw=False,
capture=True,
depth=0,
ansi=False
ansi=False,
):
r"""Parametrize a logging call to slightly change generated log message.

Expand Down
12 changes: 7 additions & 5 deletions loguru/_recattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, name, no, icon):
self.icon = icon

def __repr__(self):
return "(name=%r, no=%r, icon=%r)" % (self.name, self.no, self.icon)
return f"(name={self.name!r}, no={self.no!r}, icon={self.icon!r})"

def __format__(self, spec):
return self.name.__format__(spec)
Expand All @@ -25,7 +25,7 @@ def __init__(self, name, path):
self.path = path

def __repr__(self):
return "(name=%r, path=%r)" % (self.name, self.path)
return f"(name={self.name!r}, path={self.path!r})"

def __format__(self, spec):
return self.name.__format__(spec)
Expand All @@ -39,7 +39,7 @@ def __init__(self, id_, name):
self.name = name

def __repr__(self):
return "(id=%r, name=%r)" % (self.id, self.name)
return f"(id={self.id!r}, name={self.name!r})"

def __format__(self, spec):
return self.id.__format__(spec)
Expand All @@ -53,15 +53,17 @@ def __init__(self, id_, name):
self.name = name

def __repr__(self):
return "(id=%r, name=%r)" % (self.id, self.name)
return f"(id={self.id!r}, name={self.name!r})"

def __format__(self, spec):
return self.id.__format__(spec)


class RecordException(namedtuple("RecordException", ("type", "value", "traceback"))):
def __repr__(self):
return "(type=%r, value=%r, traceback=%r)" % (self.type, self.value, self.traceback)
return "(type={!r}, value={!r}, traceback={!r})".format(
self.type, self.value, self.traceback
)

def __reduce__(self):
# The traceback is not picklable, therefore it needs to be removed. Additionally, there's a
Expand Down
Loading