-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Tracking variable whereabouts in a plugin #9010
Comments
@Delgan I am linking you to this issue. If it comes to it, you will be able to explain runtime details much better 👍 |
Basically, what we need is a way to customize the returned type of a method based on introspection of the arguments. foo = logger.opt(lazy=True) # => foo is of type "LazyLogger"
bar = logger.opt(lazy=False) # => bar is of type "Logger" These types needs to be defined by the plugin, and later we need to be able to use them to decide whether |
I don't think that you need a plugin for this. Why not use literal types and and overloaded function to vary the return type of |
@JukkaL Sounds like a promising idea. I was not aware of literal types, thanks! What do you think @kornicameister? Would that solve the problem if we add this to the |
@JukkaL this might work. I guess loguru already exports typings so we can of course check it out. |
@JukkaL I have checked typing in loguru and indeed we can add @overload
def info(__self, __message: str, *args: Any, **kwargs: Any) -> None: ...
@overload
def info(__self, __message: Any) -> None: ... are quite accurate given dynamic nature of This sounds as some high level problem but if there's way to deal with that, I'd happy to know :D. |
@JukkaL Care to check this one out? kornicameister/loguru-mypy#7 ? |
FYI: It seems like it is sufficient to keep a state of what we want to track over in an instance of the That approach is being used in |
Can you explain this in more detail? Based on the description it's hard to say. |
@JukkaL it is actually not just description. I have just forgotten to link appropriate part of the plugin 😿 I just realized, that apart from a question if that is "the" way to implement that, there is just one question related to caching, but let's maybe stick to the original one for the time being. |
Hi! Is this still a problem for loguru-mypy, or can this issue now be closed? :) |
Please provide more information to help us understand the issue:
Code below should illustrate an expected behavior.
>=0.770
In short: with loguru you can use
Callable[[], Any]
for lazy loggers to avoid costly computations. But those have to be non-argument callables. Above you can find non-lazy loggers that will work just fine by doingstr(callable)
. In other words, to rephrase question from above, how can we:track a variable/object on which behalf a method was called?
This is quite vital because type checking cannot be done solely on a method call level because we need something from another call. There is
opt
method being called but having call details from it without anything to tie them to will not help too much.The text was updated successfully, but these errors were encountered: