Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-123339: fix out-of-bounds values ininspect.findsource#123347
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
picnixz commentedAug 26, 2024
I don't really know how I can test this. I'll need to think about tomorrow. |
picnixz commentedAug 27, 2024
I'm requesting a review from@gaogaotiantian since you were the author of#117025. |
gaogaotiantian commentedAug 27, 2024
Hmm, why does it give a line number that's out of range? Is there something we should fix deeper? |
picnixz commentedAug 27, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This happens on some classes in importcollections.abcimportinspectinspect.getsource(collections.abc.AsyncGenerator)# raises I believe that this might be because of file=inspect.getsourcefile(collections.abc.AsyncGenerator) but from_collections_abcimport*from_collections_abcimport__all__# noqa: F401from_collections_abcimport_CallableGenericAlias# noqa: F401 And in # This module has been renamed from collections.abc to _collections_abc to# speed up interpreter startup. Some of the types such as MutableMapping are# required early but collections module imports a lot of other modules.# See issue #19218__name__="collections.abc" I think the issue is just that ifisclass(object):ifhasattr(object,'__module__'):module=sys.modules.get(object.__module__) in |
gaogaotiantian commentedAug 27, 2024
Okay I guess that's the deeper issue I mentioned earlier. I'm not saying we should not protect the out of index issue in |
picnixz commentedAug 27, 2024
Yes, that's something I also wondered but since there's a similar check for code objects (which could be changed!), then I thought it was (for now) easier to protect it. I don't think this check can do worse than what we currently do but we definitely need to address the issue of getting the right file... |
gaogaotiantian commentedAug 28, 2024
Okay I took a look at the check for code object and realized that was done by me :). I thought about that and the check is inherited from some very very old code (20 years old I believe), where a regex was used to check the definition and it's possible that we missed something. However, with the current implementation, I don't believe that check was needed. It's also not exactly trivial to remove that because - well removing “useless” code could cause issues. And that's why I'm a bit hesitated to add the check - it might not be as easy to remove it. I'm not entirely convinced that adding this "sanity check" is just innocent, because it will introduce two different behaviors for the same root issue - like I mentioned above. For a relatively lower level library, I was hoping that we can provide a behavior that as consistent as possible (others might disagree with me). Now for this function, we should return the sources that we can retrieve and the line number - it's impossible for us to know if they match. I think we should remove the check for code object too to achieve a consistent behavior. However, I might be wrong. For this specific issue though, I believe locating the correct source file is the way to go, this PR is not a fix. @serhiy-storchaka has his experience with |
picnixz commentedAug 28, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I'll see what I can do. But, if people set |
picnixz commentedSep 3, 2024
Super-seeded by#123613 |
Uh oh!
There was an error while loading.Please reload this page.
collections.abcmodule is asked. #123339