Skip to content

Commit

Permalink
allow both importing static and strict
Browse files Browse the repository at this point in the history
Summary:
In the next commit, we separate strict analysis from static
compilation. Since this is the case, some users may expect static
compilation to also perform strict analysis (in the case where someone
just calls `import __static__` without `from __strict__ import
allow_side_effects`).

This commit provides a forwards-compatible way to make this codemod
before both strict analysis is decoupled.

Reviewed By: DinoV

Differential Revision: D49736501

fbshipit-source-id: ef7fc1029829ff0a91a39263fc948957671f4373
  • Loading branch information
pilleye authored and facebook-github-bot committed Oct 18, 2023
1 parent 0672d94 commit 422eda0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 32 deletions.
9 changes: 4 additions & 5 deletions StrictModules/Compiler/abstract_module_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,11 @@ std::pair<ModuleKind, ShouldAnalyze> getModuleKindFromStmts(
if (modKind == std::nullopt) {
modKind = tempModKind;
goto loop_continue;
} else if (modKind == ModuleKind::kStrict) {
modKind = tempModKind;
goto loop_continue;
} else {
modInfo->setFlagError(
stmt->lineno,
stmt->col_offset,
"strict flag must be at top of module");
return {ModuleKind::kNonStrict, should_analyze};
goto loop_continue;
}
}
}
Expand Down
27 changes: 0 additions & 27 deletions StrictModules/Tests/comparison_tests/interpreter_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9826,33 +9826,6 @@ x = 1
x
---
---
test_flag_after_two_doc
---
'''First docstring.'''
'''Second "docstring."'''
import __strict__
x = 1
---
---
3 0 BadStrictFlagException strict flag must be at top of module
---
test_flag_after_import
---
import foo
import __strict__
---
---
2 0 BadStrictFlagException strict flag must be at top of module
---
test_duplicate_flag
---
import __strict__
import foo
import __strict__
---
---
3 0 BadStrictFlagException strict flag must be at top of module
---
test_flag_with_imports
---
import __strict__, foo
Expand Down

0 comments on commit 422eda0

Please sign in to comment.