Skip to content

CG-9706: Support imp.is_dynamic #149

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 5 commits into from
Jan 28, 2025
Merged

Conversation

tawsifkamal
Copy link
Contributor

Motivation

  • Checks if the import is dynamic by checking if it's in the body of a function, method, if statement, etc
  • Supports TSImport and PyImport

Copy link

linear bot commented Jan 28, 2025

CG-9706 Support `import.is_dynamic`

  • Would be great to be able to say an import is top-level or not
  • Same for JS - not have to mess with the edge cases here

See implementation here: https://www.codegen.sh/codemod/4897/code/22013/playground/diff

Make sure to update the docs! ("Imports and Exports")

This should enable us to detect this import in python:

if TYPE_CHECKING:
  from codegen import Codebase

def my_function():
  from codegen import MyFunction

Bonus: support JS! (what does this look like?)

@tawsifkamal tawsifkamal reopened this Jan 28, 2025
@tawsifkamal tawsifkamal merged commit 86189ed into develop Jan 28, 2025
9 of 14 checks passed
@tawsifkamal tawsifkamal deleted the tawsif-import-is-dynamic branch January 28, 2025 21:29
jayhack pushed a commit that referenced this pull request Feb 9, 2025
# Motivation
<!-- Why is this change necessary? -->
- Checks if the import is dynamic by checking if it's in the body of a
function, method, if statement, etc
- Supports TSImport and PyImport

---------

Co-authored-by: codegen-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants