Skip to content

Commit

Permalink
Minor comment/docstring/test id adjustments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachaa-Thanasius committed Sep 8, 2024
1 parent 02d413e commit d736a36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/defer_imports/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def instrument(self, mode: str = "exec") -> _tp.Any:
return ast.fix_missing_locations(self.visit(to_visit))

def _visit_scope(self, node: ast.AST) -> ast.AST:
"""Track Python scope changes. Used to determine if defer_imports.until_use usage is valid."""
"""Track Python scope changes. Used to determine if defer_imports.until_use usage is global."""

self.scope_depth += 1
try:
Expand Down Expand Up @@ -199,8 +199,9 @@ def _substitute_import_keys(self, import_nodes: list[ast.stmt]) -> list[ast.stmt

@staticmethod
def check_With_for_defer_usage(node: ast.With) -> bool:
"""Only accept "with defer_imports.until_use"."""

return len(node.items) == 1 and (
# Allow "with defer_imports.until_use".
isinstance(node.items[0].context_expr, ast.Attribute)
and isinstance(node.items[0].context_expr.value, ast.Name)
and node.items[0].context_expr.value.id == "defer_imports"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_deferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def temp_cache_module(name: str, module: ModuleType):
from defer_imports._core import DeferredImportKey as @DeferredImportKey, DeferredImportProxy as @DeferredImportProxy
del @DeferredImportKey, @DeferredImportProxy
''',
id="Inserts statements after module docstring",
id="inserts statements after module docstring",
),
pytest.param(
"""from __future__ import annotations""",
Expand Down Expand Up @@ -91,7 +91,7 @@ def temp_cache_module(name: str, module: ModuleType):
import inspect
del @DeferredImportKey, @DeferredImportProxy
""",
id="does nothing if used at same time as another context manager",
id="does nothing if used with another context manager",
),
pytest.param(
"""\
Expand Down Expand Up @@ -140,7 +140,7 @@ def temp_cache_module(name: str, module: ModuleType):
del @temp_proxy, @local_ns
del @DeferredImportKey, @DeferredImportProxy
""",
id="mixed import 1",
id="mixed import",
),
pytest.param(
"""\
Expand All @@ -162,7 +162,7 @@ def temp_cache_module(name: str, module: ModuleType):
del @temp_proxy, @local_ns
del @DeferredImportKey, @DeferredImportProxy
""",
id="relative import 1",
id="relative import",
),
],
)
Expand Down

0 comments on commit d736a36

Please sign in to comment.