Skip to content

Commit

Permalink
Merge Remove os dois shims bind_loop e loop_compat
Browse files Browse the repository at this point in the history
refs #22, #18
  • Loading branch information
daltonmatos authored Oct 5, 2022
2 parents cbb713b + db987ef commit 0b6a6bd
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 38 deletions.
2 changes: 0 additions & 2 deletions aiologger/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Optional, Union

from aiologger import settings
from aiologger.utils import loop_compat
from aiologger.filters import Filterer
from aiologger.formatters.base import Formatter
from aiologger.formatters.json import JsonFormatter
Expand All @@ -18,7 +17,6 @@
_default_formatter = Formatter()


@loop_compat
class Handler(Filterer):
"""
Handler instances dispatch logging events to specific destinations.
Expand Down
3 changes: 1 addition & 2 deletions aiologger/handlers/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

from aiologger.handlers.base import Handler
from aiologger.records import LogRecord
from aiologger.utils import classproperty, get_running_loop, loop_compat
from aiologger.utils import classproperty, get_running_loop


@loop_compat
class AsyncFileHandler(Handler):
terminator = "\n"

Expand Down
3 changes: 1 addition & 2 deletions aiologger/handlers/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from asyncio import AbstractEventLoop, StreamWriter
from typing import Union, Optional

from aiologger.utils import get_running_loop, loop_compat
from aiologger.utils import get_running_loop
from aiologger.filters import Filter
from aiologger.formatters.base import Formatter
from aiologger.handlers.base import Handler
Expand All @@ -12,7 +12,6 @@
from aiologger.records import LogRecord


@loop_compat
class AsyncStreamHandler(Handler):
terminator = "\n"

Expand Down
10 changes: 2 additions & 8 deletions aiologger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
from aiologger.handlers.streams import AsyncStreamHandler
from aiologger.levels import LogLevel, check_level
from aiologger.records import LogRecord
from aiologger.utils import (
get_current_frame,
create_task,
loop_compat,
bind_loop,
)
from aiologger.utils import get_current_frame, create_task

_HandlerFactory = Callable[[], Awaitable[Iterable[Handler]]]

Expand Down Expand Up @@ -48,7 +43,6 @@ def o_o():
_srcfile = o_o.__code__.co_filename


@loop_compat
class Logger(Filterer):
def __init__(self, *, name="aiologger", level=LogLevel.NOTSET) -> None:
super(Logger, self).__init__()
Expand All @@ -73,7 +67,7 @@ def with_default_handlers(
):
self = cls(name=name, level=level, **kwargs) # type: ignore

_AsyncStreamHandler = bind_loop(AsyncStreamHandler, kwargs)
_AsyncStreamHandler = AsyncStreamHandler
self.add_handler(
_AsyncStreamHandler(
stream=sys.stdout,
Expand Down
3 changes: 1 addition & 2 deletions aiologger/loggers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
from typing import Dict, Iterable, Callable, Tuple, Any, Optional, Mapping

from aiologger import Logger
from aiologger.utils import create_task, loop_compat
from aiologger.utils import create_task
from aiologger.formatters.base import Formatter
from aiologger.formatters.json import ExtendedJsonFormatter
from aiologger.levels import LogLevel
from aiologger.logger import _Caller
from aiologger.records import ExtendedLogRecord


@loop_compat
class JsonLogger(Logger):
def __init__(
self,
Expand Down
22 changes: 0 additions & 22 deletions aiologger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,6 @@ def __init__(self, *args, **kwargs):

_F = TypeVar("_F", bound=Callable[..., object])

if sys.version_info >= (3, 10):

def loop_compat(v: _T) -> _T:
return v

def bind_loop(v: _F, kwargs: dict) -> _F:
return v


else:
loop_compat = _LoopCompat.decorate

def bind_loop(v: _F, kwargs: dict) -> _F:
"""
bind a loop kwarg, without letting mypy know about it
"""
try:
return cast(_F, functools.partial(v, loop=kwargs["loop"]))
except KeyError:
pass
return v


class classproperty:
def __init__(self, func):
Expand Down

0 comments on commit 0b6a6bd

Please sign in to comment.