Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/pyforest/user_specific_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,24 @@ def _get_imports_from_user_settings(user_imports_path) -> list:


def _assign_imports_to_globals(import_statements: list, globals_) -> None:
symbols = [import_statement.split()[-1] for import_statement in import_statements]

for symbol, import_statement in zip(symbols, import_statements):
symbols = []; new_import_statements = []

for import_statement in import_statements:
def process(statement):
symbols.append(statement.split()[-1])
new_import_statements.append(statement)

if "," not in import_statement:
process(import_statement)
else:
Copy link
Author

@triper1022 triper1022 Jun 24, 2021

Choose a reason for hiding this comment

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

Thanks for reply!

My PR doesn't affect any original behaviors.

At first,
PR uses new line 70. to judge whether the import statement includes multiple imports.

if "," not in import_statement,
"from keras.layers import LSTM" still behaves as original code
of original line 63, which is similar with new line 63~68.

if "," is in import_statement,
like "from keras.layers import LSTM, Dropout, Dense",
it will become
"from keras.layers import LSTM"
"from keras.layers import Dropout"
"from keras.layers import Dense" with new line 73~78.

Then, the following behaviors are still the same as the original line 63, 65, 66.

multi_import_statement = import_statement.split(",")
splited_statement = multi_import_statement[0].split()
process(multi_import_statement[0])
for i in range(1, len(multi_import_statement)):
new_statement = splited_statement[:-1] + [multi_import_statement[i]]
process(" ".join(new_statement))

for symbol, import_statement in zip(symbols, new_import_statements):
exec(f"{symbol} = LazyImport('{import_statement}')", globals_)


Expand Down