Skip to content

Python: Better allow import * to work with API graphs #14430

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

Merged
merged 3 commits into from
Oct 11, 2023

Conversation

RasmusWL
Copy link
Member

I'm curious to see what people think of this solution :D

Performance impact

I did some testing on a random DB I had locally. On this particular DB the change in number of LocalSourceNodes and API graph edges was insignificant:

  • local source nodes: 390,311 -> 390,411
  • API graph edge: 364,762 -> 366,994

However, that's not to say it couldn't impact things heavily on other DBs. We'll see what DCA says 👍

@RasmusWL RasmusWL requested a review from a team as a code owner October 10, 2023 15:09
Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand it correctly that all instances of an imported value will be considered local sources?

Copy link
Contributor

@tausbn tausbn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks good to me (but I do have one specific comment).

I feel like this is a fairly principled solution (our implementation of flow in the global scope is a bit weird), and I don't think it would add a lot of extra nodes in general.

@RasmusWL
Copy link
Member Author

Do I understand it correctly that all instances of an imported value will be considered local sources?

Yes, good point @yoff. In the example below, all three occurrences of Bar will be considered a LocalSourceNode 🤷

from foo import *

print(Bar)
print(Bar)
print(Bar)

@RasmusWL
Copy link
Member Author

rebased to drop the commit to use API::Node in the predicates, to preserve old git blame info

@tausbn
Copy link
Contributor

tausbn commented Oct 10, 2023

Do I understand it correctly that all instances of an imported value will be considered local sources?

Yes, good point @yoff. In the example below, all three occurrences of Bar will be considered a LocalSourceNode 🤷

from foo import *

print(Bar)
print(Bar)
print(Bar)

I think this is somewhat unavoidable due to how we do global flow. Right now, we have no way of knowing if the three instances of Bar are the same (imagine print(Bar); modify_Bar(); print(Bar), where the middle function changes the value of Bar), so this is the best we can do currently.

Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RasmusWL RasmusWL merged commit 68d00a8 into github:main Oct 11, 2023
@RasmusWL RasmusWL deleted the api-graph-import-star branch October 11, 2023 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants