You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
inspect.getsource (findsource) not working as expected when duplicate class is used #106727
changed the title [-]`inspect.getsource` not working as expected when duplicate class is used[/-][+]`inspect.getsource` (`findsource`) not working as expected when duplicate class is used[/+]on Jul 13, 2023
The method has already been changed from regex to ast. I can work on the PR if you are okay with it. If you want to fix this yourself, the code piece is at the similar place, just switched to an ast based searching.
The method has already been changed from regex to ast. I can work on the PR if you are okay with it. If you want to fix this yourself, the code piece is at the similar place, just switched to an ast based searching.
Yes by look at what was done in #10307 I meant improve this ast based search.
We could probably need some heuristics to figure out which class it should be.
I wonder if this is possible depending of the condition evaluated.
Oh sorry I did not look at the PR thoroughly. I saw the word "regex" and thought it was improving the regex method.
classes do not have useful compile time information with it as far as I know which makes this tricky - that's why I said we probably need some heuristics. I doubt if we can make this work:
ifruntime_cond:
classA:
passelse:
classA:
pass
They are indistinguishable. We can, however, try to figure out which class it is by some "guessing" like reading their methods. Let me know if this is out of your comfortable zone and you'd like me to work on it, I'm kind of familiar with the area. Otherwise, let me know if you have any question about the implementation.
I'll try to take a look, I'm not that familiar with ast but I'll try to come up with something (this is a good opportunity to learn more about it), we will then be able to work on this together if I encounter any blocking points
Actually while I see how this could be implemented, I don't really see which attributes should be used to guess the right class. @gaogaotiantian if you have something in mind I'll be pleased to see a PR
Activity
[-]`inspect.getsource` not working as expected when duplicate class is used[/-][+]`inspect.getsource` (`findsource`) not working as expected when duplicate class is used[/+]gaogaotiantian commentedon Jul 13, 2023
The method has already been changed from regex to ast. I can work on the PR if you are okay with it. If you want to fix this yourself, the code piece is at the similar place, just switched to an
astbased searching.gaogaotiantian commentedon Jul 13, 2023
Just BTW, the last class may not be the one you need.
We could probably need some heuristics to figure out which class it should be.
Viicos commentedon Jul 14, 2023
Yes by look at what was done in #10307 I meant improve this ast based search.
I wonder if this is possible depending of the condition evaluated.
gaogaotiantian commentedon Jul 14, 2023
Oh sorry I did not look at the PR thoroughly. I saw the word "regex" and thought it was improving the regex method.
classes do not have useful compile time information with it as far as I know which makes this tricky - that's why I said we probably need some heuristics. I doubt if we can make this work:
They are indistinguishable. We can, however, try to figure out which class it is by some "guessing" like reading their methods. Let me know if this is out of your comfortable zone and you'd like me to work on it, I'm kind of familiar with the area. Otherwise, let me know if you have any question about the implementation.
Viicos commentedon Jul 15, 2023
I'll try to take a look, I'm not that familiar with
astbut I'll try to come up with something (this is a good opportunity to learn more about it), we will then be able to work on this together if I encounter any blocking pointsViicos commentedon Jul 16, 2023
Actually while I see how this could be implemented, I don't really see which attributes should be used to guess the right class. @gaogaotiantian if you have something in mind I'll be pleased to see a PR
gaogaotiantian commentedon Jul 16, 2023
No worries, I'll work on it, it can be a bit tricky.
Viicos commentedon Jul 16, 2023
Yeah I was first thinking maybe use the values from
__dict__, but we have to make sure not to include attributes set by a potential metaclassgh-106727: Make `inspect.getsource` smarter for class for same name d…
gh-106727: Add `__module__` check for `inspect.getsource(cls)` (#106968)
pythongh-106727: Add `__module__` check for `inspect.getsource(cls)` (p…