-
-
Notifications
You must be signed in to change notification settings - Fork 215
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
Logger detected as abstract method by ABC #229
Comments
Alright, I have a workaround, but it's not pretty: import abc
import structlog
class classproperty:
def __init__(self, f):
self.f = f
def __get__(self, obj, owner):
return self.f(owner)
_foo_log = structlog.get_logger()
class Foo(abc.ABC):
@classproperty
def log(cls):
return _foo_log
Foo.log # works
Foo().log # also works (getter only I won't be trying to look for the reason this is happening since I found this workaround. But this is probably something that should be fixed (not sure if it's a structlog or abc bug though). |
I think it's being confused by the fact, that our generic BoundLogger will propagate any call, so the introspection fails. This is what IPython introspects out of a BoundLoggerLazyProxy, although it's not callable at all and partial is used only within the actual BoundLogger:
Is there any chance you could move the get_logger into the module and then |
That's exactly what I had initially. But because of #126 (specifically the logger being picklable, and I'm using multiprocessing on some cases, which needs pickable instances), and because I prefer using the latest release (and the fix for #126 isn't released yet, though I tested the master branch and it works for me) I moved to the class from the instance when migrating these loggers to structlog (I'm slowly migrating to structlog). But also, I have a large number of these instances. I haven't measured, so this is just speculation, but I worry that having the loggers on the instances might have a significant memory footprint. So that's another reason for moving to the class. |
I think I've fixed it in master; please report back if the problem isn't solved. But I still think you shouldn't do it and I've made everything in structlog pickleable in the last release. :) |
Took me a while to touch back on this. But I can confirm it is working for me. Thanks. |
I recently stumbled with this. Makes no sense to me, but seems quite easy to reproduce:
I have no idea why Python detects
log
as an abstract method, but this is clearly wrong. I'm still looking for a workaround.The text was updated successfully, but these errors were encountered: