Skip to content

Commit

Permalink
Accept numbers (int,float) for loguru calls (kornicameister#79)
Browse files Browse the repository at this point in the history
* Accept numbers (int,float) for loguru calls

Partially: kornicameister#49
  • Loading branch information
kornicameister authored Jan 3, 2021
1 parent 89f76ad commit c176016
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 10 additions & 3 deletions loguru_mypy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from mypy.nodes import (
CallExpr,
Expression,
FloatExpr,
FuncDef,
IntExpr,
LambdaExpr,
MemberExpr,
NameExpr,
Expand Down Expand Up @@ -96,9 +98,14 @@ def _loguru_logger_call_handler(
log_msg_expr = ctx.args[0][0]
logger_opts = loggers.get(ctx.type) or DEFAULT_OPTS

assert isinstance(log_msg_expr, StrExpr), type(log_msg_expr)

_check_str_format_call(log_msg_expr, ctx)
if isinstance(log_msg_expr, StrExpr):
_check_str_format_call(log_msg_expr, ctx)
elif isinstance(log_msg_expr, (IntExpr, FloatExpr)):
# nothing to be done, this is valid log
# and callee is not expected to provide anything useful over here
return ctx.default_return_type
else:
raise TypeError(f'No idea (yet) how to handle {type(log_msg_expr)}')

if logger_opts.lazy:
# collect call args/kwargs
Expand Down
9 changes: 9 additions & 0 deletions typesafety/test_issue_49.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- case: numbers
main: |
from loguru import logger
logger.info(123)
logger.debug(123.3)
logger.trace(1)
logger.error(.3)

0 comments on commit c176016

Please sign in to comment.