-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Support attribute references of positional/keyword arguments with string formatting #42
Comments
Issue-Label Bot is automatically applying the label Links: app homepage, dashboard and code for this bot. |
(IMHO this is more a bug since it's flagging valid syntax) |
HI @ThibaultLemaire . I am deeply sorry but I don't think there will be much time for me to take a look. Actually I don't have time even to finish PR that is already here and another code sits in my desk. Dang, it was even 7 days already since reporting this issue. If you have an idea how to fix that PR are welcome ;) PS. It actually looks ok, so I think you're right and that's a bug. If you don't mind dropping |
I'll take a look at the code and see what I can do. It should be the opportunity to see how a mypy plugin is made, maybe I'll learn a trick or two to enhance mypy checks (I'm thinking mainly of type-checking pymongo/motor queries, as that's something I've been meaning to do for a long time). I've updated the description with |
Okay, so it looks like you've got some custom code there to support loguru's syntax, but mypy already has the capability to type class Foo:
bar = "baz"
foo = Foo()
'The bar is "{0.bar}"'.format(foo) # typechecks
'The bar is "{0.bar}"'.format("not foo") # error: "str" has no attribute "bar"
'The bar is "{my_foo.bar}"'.format(my_foo=foo) # typechecks
'The bar is "{my_foo.bar}"'.format(my_foo="not foo") # error: "str" has no attribute "bar" So I wonder if we could leverage mypy directly to typecheck something like logger.debug('The bar is "{my_foo.bar}"', my_foo=foo) as if it was written like this logger.debug('The bar is "{my_foo.bar}"'.format(my_foo=foo)) |
Progress reportAfter wiring up a debugger to mypy I was able to analyse the way it checks calls to
Where that last Now all I need is a way to call that method with all the necessary arguments as mypy is a very tightly coupled mess. Hopefully though, the |
Progress reportSo after further investigation, Now, I've been able to create a I'll have to trace and debug mypy with the loguru plugin to see exactly what's going wrong. |
There we go, I've got some sprout of working code, continuing technical discussion over at PR #43 |
Hey @kornicameister when do you think this will be released? I'd like to use it at work. |
@ThibaultLemaire I will release it with 0.0.3 but there are some build errors.I think I have introduced some time ago. |
Ah that's too bad, don't worry though, this is low priority for me. |
Not for me ;-) |
Thank you very much, I added loguru-mypy to our project on a feature branch and confirmed it's working in the scenario that initally prompted me to open this issue. 👍 However, I'm hitting two new scenarii where the plugin fails to correctly validate the code 🙁 The first, I had anticipated when working on my PR: from loguru import logger
logger.configure(
handlers=[
dict(
sink=sys.stderr,
format="Site {extra[site]} broadcasting: {message}",
backtrace=False,
diagnose=False,
),
],
extra={"site": "unknown"},
)
site = 19
scp = 682
# We're passing the `site` number for local formatting of this message, but we're also passing the `scp` number as `extra` for the formatter of the handler.
logger.warning("SCP-{} containment breach detected", scp, site=site)
# error: Not all arguments converted during string formatting
# But this is easily circumvented:
logger.bind(site=site).warning("SCP-{} containment breach detected", scp) The workaround isn't too bad, and fixing the issue - I think - would prove a tad more complicated than my previous PR (see #48 ). But the second issue is a real blocker: essentially it's the 3rd exemple of #49 as reported by @Delgan from loguru import logger
foo = "bar"
logger.info(foo) # error: INTERNAL ERROR So I think I'm going to start working on fix for that, as I think it shouldn't be too complicated. |
The text was updated successfully, but these errors were encountered: