wexample-filestate-python 9.1.4__tar.gz → 9.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/PKG-INFO +3 -3
  2. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/README.md +1 -1
  3. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/pyproject.toml +2 -2
  4. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/config_value/python_config_value.py +1 -2
  5. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/file/python_test_stub_file.py +1 -3
  6. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/abstract_python_file_content_option.py +12 -0
  7. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/fstringify_option.py +3 -1
  8. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/relocate_imports_option.py +3 -1
  9. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/python_attrs_utils.py +1 -3
  10. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/python_blank_lines_utils.py +5 -1
  11. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/python_class_attributes_utils.py +3 -1
  12. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/python_class_docstring_utils.py +1 -1
  13. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/python_class_methods_utils.py +1 -0
  14. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/python_constants_utils.py +3 -1
  15. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/python_functions_utils.py +6 -10
  16. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/python_main_guard_utils.py +5 -1
  17. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/python_module_metadata_utils.py +1 -2
  18. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/tests/.gitkeep +0 -0
  19. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/tests/helper/__init__.py +0 -0
  20. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/tests/helper/test_package.py +0 -0
  21. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/tests/helper/test_toml.py +0 -0
  22. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/tests/unit/__init__.py +0 -0
  23. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/tests/unit/helper/__init__.py +0 -0
  24. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/tests/unit/helper/test_package.py +0 -0
  25. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/tests/unit/helper/test_toml.py +0 -0
  26. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/tests/unit/utils/__init__.py +0 -0
  27. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/tests/unit/utils/test_python_iterable_utils.py +0 -0
  28. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/__init__.py +0 -0
  29. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/common/__init__.py +0 -0
  30. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/common/pipy_gateway.py +0 -0
  31. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/config_option/__init__.py +0 -0
  32. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/config_option/mixin/__init__.py +0 -0
  33. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/config_option/mixin/with_stdout_wrapping_mixin.py +0 -0
  34. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/config_value/__init__.py +0 -0
  35. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/const/__init__.py +0 -0
  36. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/const/name_pattern.py +0 -0
  37. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/const/path.py +0 -0
  38. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/const/python_file.py +0 -0
  39. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/event/__init__.py +0 -0
  40. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/event/src/__init__.py +0 -0
  41. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/event/src/wexample_event/__init__.py +0 -0
  42. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/file/__init__.py +0 -0
  43. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/file/python_file.py +0 -0
  44. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/helper/__init__.py +0 -0
  45. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/helper/package.py +0 -0
  46. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/helper/python/__init__.py +0 -0
  47. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/helper/toml.py +0 -0
  48. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/__init__.py +0 -0
  49. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/__init__.py +0 -0
  50. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/add_future_annotations_option.py +0 -0
  51. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/add_return_types_option.py +0 -0
  52. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/class_name_matches_file_name_option.py +0 -0
  53. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/fix_attrs_option.py +0 -0
  54. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/fix_blank_lines_option.py +0 -0
  55. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/format_option.py +0 -0
  56. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/modernize_typing_option.py +0 -0
  57. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/order_class_attributes_option.py +0 -0
  58. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/order_class_docstring_option.py +0 -0
  59. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/order_class_methods_option.py +0 -0
  60. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/order_constants_option.py +0 -0
  61. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/order_iterable_items_option.py +0 -0
  62. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/order_main_guard_option.py +0 -0
  63. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/order_module_docstring_option.py +0 -0
  64. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/order_module_functions_option.py +0 -0
  65. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/order_module_metadata_option.py +0 -0
  66. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/order_type_checking_block_option.py +0 -0
  67. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/remove_unused_option.py +0 -0
  68. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/sort_imports_option.py +0 -0
  69. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python/unquote_annotations_option.py +0 -0
  70. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/option/python_option.py +0 -0
  71. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/options_provider/__init__.py +0 -0
  72. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/options_provider/python_options_provider.py +0 -0
  73. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/py.typed +0 -0
  74. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/__init__.py +0 -0
  75. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/cst_cache.py +0 -0
  76. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/python_docstring_utils.py +0 -0
  77. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/python_iterable_utils.py +0 -0
  78. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/python_type_checking_utils.py +0 -0
  79. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/relocate_imports/__init__.py +0 -0
  80. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/relocate_imports/python_import_rewriter.py +0 -0
  81. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/relocate_imports/python_localize_runtime_imports.py +0 -0
  82. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/relocate_imports/python_parser_import_index.py +0 -0
  83. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/relocate_imports/python_runtime_symbol_collector.py +0 -0
  84. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/src/wexample_filestate_python/utils/relocate_imports/python_usage_collector.py +0 -0
  85. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/tests/tests/__init__.py +0 -0
  86. {wexample_filestate_python-9.1.4 → wexample_filestate_python-9.3.0}/tests/wexample_tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wexample-filestate-python
3
- Version: 9.1.4
3
+ Version: 9.3.0
4
4
  Summary: Extends wexample-filestate with Python file options: format, sort imports, modernize typing, and reorder class members.
5
5
  Author-Email: weeger <contact@wexample.com>
6
6
  License: MIT
@@ -20,7 +20,7 @@ Requires-Dist: packaging
20
20
  Requires-Dist: ruff
21
21
  Requires-Dist: tomli
22
22
  Requires-Dist: wexample-api>=6.8.0
23
- Requires-Dist: wexample-filestate>=17.5.2
23
+ Requires-Dist: wexample-filestate>=18.0.0
24
24
  Provides-Extra: dev
25
25
  Requires-Dist: pytest; extra == "dev"
26
26
  Requires-Dist: pytest-cov; extra == "dev"
@@ -28,7 +28,7 @@ Description-Content-Type: text/markdown
28
28
 
29
29
  # filestate_python
30
30
 
31
- Version: 9.1.4
31
+ Version: 9.3.0
32
32
 
33
33
  Extends wexample-filestate with Python file options: format, sort imports, modernize typing, and reorder class members.
34
34
 
@@ -1,6 +1,6 @@
1
1
  # filestate_python
2
2
 
3
- Version: 9.1.4
3
+ Version: 9.3.0
4
4
 
5
5
  Extends wexample-filestate with Python file options: format, sort imports, modernize typing, and reorder class members.
6
6
 
@@ -6,7 +6,7 @@ build-backend = "pdm.backend"
6
6
 
7
7
  [project]
8
8
  name = "wexample-filestate-python"
9
- version = "9.1.4"
9
+ version = "9.3.0"
10
10
  description = "Extends wexample-filestate with Python file options: format, sort imports, modernize typing, and reorder class members."
11
11
  authors = [
12
12
  { name = "weeger", email = "contact@wexample.com" },
@@ -29,7 +29,7 @@ dependencies = [
29
29
  "ruff",
30
30
  "tomli",
31
31
  "wexample-api>=6.8.0",
32
- "wexample-filestate>=17.5.2",
32
+ "wexample-filestate>=18.0.0",
33
33
  ]
34
34
 
35
35
  [project.readme]
@@ -205,6 +205,5 @@ class PythonConfigValue(ConfigValue):
205
205
  if _OPTION_NAME_TO_ATTR is None:
206
206
  _OPTION_NAME_TO_ATTR = _build_option_name_to_attr()
207
207
  return {
208
- name: getattr(self, attr)
209
- for name, attr in _OPTION_NAME_TO_ATTR.items()
208
+ name: getattr(self, attr) for name, attr in _OPTION_NAME_TO_ATTR.items()
210
209
  }
@@ -75,9 +75,7 @@ def _render_stub(primary_module_name: str, module) -> str:
75
75
  # No public surface — emit a placeholder so the file is valid pytest
76
76
  # and the human knows the stub generator ran but found nothing.
77
77
  lines.append(f"# Auto-generated stub for {primary_module_name}.py.")
78
- lines.append(
79
- "# No public functions/classes detected — add tests manually."
80
- )
78
+ lines.append("# No public functions/classes detected — add tests manually.")
81
79
  lines.append("")
82
80
 
83
81
  return "\n".join(lines)
@@ -1,14 +1,26 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from typing import TYPE_CHECKING
4
+
3
5
  from wexample_filestate.option.abstract_file_content_option import (
4
6
  AbstractFileContentOption,
5
7
  )
6
8
  from wexample_helpers.decorator.base_class import base_class
7
9
 
10
+ if TYPE_CHECKING:
11
+ from wexample_filestate.enum.natures import Nature
12
+
8
13
 
9
14
  @base_class
10
15
  class AbstractPythonFileContentOption(AbstractFileContentOption):
11
16
  """Base class for Python file content transformation options."""
12
17
 
18
+ @classmethod
19
+ def get_nature(cls) -> Nature:
20
+ """It rewrites source code: run at push, not at publication."""
21
+ from wexample_filestate.enum.natures import Nature
22
+
23
+ return Nature.CODE
24
+
13
25
  def applicable_on_empty_content_file(self) -> bool:
14
26
  return False
@@ -26,4 +26,6 @@ class FstringifyOption(WithStdoutWrappingMixin, AbstractPythonFileContentOption)
26
26
 
27
27
  src = target.get_local_file().read()
28
28
  state = State(aggressive=False, multiline=False, len_limit=120)
29
- return self._execute_and_wrap_stdout(lambda: fstringify_code(src, state=state)).content
29
+ return self._execute_and_wrap_stdout(
30
+ lambda: fstringify_code(src, state=state)
31
+ ).content
@@ -87,7 +87,9 @@ class RelocateImportsOption(AbstractPythonFileContentOption):
87
87
  runtime_used_anywhere: set[str] = rsc.runtime_used_anywhere
88
88
 
89
89
  # Resolve categories
90
- runtime_local_all: set[str] = {n for s in functions_needing_local.values() for n in s}
90
+ runtime_local_all: set[str] = {
91
+ n for s in functions_needing_local.values() for n in s
92
+ }
91
93
  # class_level has priority over runtime_local: if a name is class-level, we do NOT local-import it
92
94
  runtime_local_final: set[str] = {
93
95
  n for n in runtime_local_all if n not in class_level_names
@@ -82,9 +82,7 @@ class _AttrsKwOnlyFixer(cst.CSTTransformer):
82
82
 
83
83
  elif isinstance(updated_node.decorator, (cst.Name, cst.Attribute)):
84
84
  # Bare decorator (no parens) — wrap it in a Call with kw_only=True
85
- kw_only_arg = cst.Arg(
86
- keyword=cst.Name("kw_only"), value=cst.Name("True")
87
- )
85
+ kw_only_arg = cst.Arg(keyword=cst.Name("kw_only"), value=cst.Name("True"))
88
86
  new_call = cst.Call(func=updated_node.decorator, args=[kw_only_arg])
89
87
  return updated_node.with_changes(decorator=new_call)
90
88
 
@@ -196,7 +196,11 @@ def _is_dataclass(class_node: cst.ClassDef) -> bool:
196
196
  dec = decorator.decorator
197
197
  if isinstance(dec, cst.Name) and dec.value == "dataclass":
198
198
  return True
199
- if isinstance(dec, cst.Call) and isinstance(dec.func, cst.Name) and dec.func.value == "dataclass":
199
+ if (
200
+ isinstance(dec, cst.Call)
201
+ and isinstance(dec.func, cst.Name)
202
+ and dec.func.value == "dataclass"
203
+ ):
200
204
  return True
201
205
  return False
202
206
 
@@ -34,7 +34,9 @@ def find_attribute_blocks_in_class(
34
34
  Returns list of (start_index, end_index_exclusive, nodes)
35
35
  where indices refer to classdef.body.body positions.
36
36
  """
37
- body_list = classdef.body.body # already an indexable sequence (tuple); no copy needed
37
+ body_list = (
38
+ classdef.body.body
39
+ ) # already an indexable sequence (tuple); no copy needed
38
40
  n = len(body_list)
39
41
  blocks: list[tuple[int, int, list[cst.CSTNode]]] = []
40
42
  i = 0
@@ -58,7 +58,7 @@ def move_class_docstring_to_top(classdef: cst.ClassDef) -> cst.ClassDef:
58
58
  normalized = normalize_docstring_quotes_stmt(doc).with_changes(leading_lines=[])
59
59
 
60
60
  body_seq = classdef.body.body
61
- body_list = [normalized, *body_seq[:idx], *body_seq[idx + 1:]]
61
+ body_list = [normalized, *body_seq[:idx], *body_seq[idx + 1 :]]
62
62
  new_suite = classdef.body.with_changes(body=body_list)
63
63
  return classdef.with_changes(body=new_suite)
64
64
 
@@ -188,6 +188,7 @@ def _is_dunder(name: str) -> bool:
188
188
  def _is_private(name: str) -> bool:
189
189
  return name.startswith("_") and not (name.startswith("__") and name.endswith("__"))
190
190
 
191
+
191
192
  # Hoisted sort-key; avoids creating a new lambda/closure object on every
192
193
  # call to _sort_by_visibility and reorder_class_methods.
193
194
  def _KEY_BY_NAME(m: dict) -> tuple:
@@ -221,7 +221,9 @@ def sort_constants_block(
221
221
  cleaned_leadings.append(cleaned)
222
222
 
223
223
  # Pre-build O(1) id-keyed lookup: node object id → original index in pairs
224
- node_to_original_index: dict[int, int] = {id(n): i for i, (_, n) in enumerate(pairs)}
224
+ node_to_original_index: dict[int, int] = {
225
+ id(n): i for i, (_, n) in enumerate(pairs)
226
+ }
225
227
 
226
228
  for idx, (_, node) in enumerate(sorted_pairs):
227
229
  original_index = node_to_original_index.get(id(node))
@@ -102,9 +102,7 @@ def reorder_module_functions(module: cst.Module) -> cst.Module:
102
102
 
103
103
  # Remove all function nodes from body
104
104
  remove_indices: set[int] = {
105
- i
106
- for idx, g in groups_with_idx
107
- for i in range(idx, idx + len(g.nodes))
105
+ i for idx, g in groups_with_idx for i in range(idx, idx + len(g.nodes))
108
106
  }
109
107
 
110
108
  new_body: list[cst.CSTNode] = []
@@ -112,7 +110,7 @@ def reorder_module_functions(module: cst.Module) -> cst.Module:
112
110
  if idx in remove_indices:
113
111
  continue
114
112
  new_body.append(node)
115
-
113
+
116
114
  # Determine insertion index using an anchor strategy:
117
115
  # - Find the index of the FIRST function definition in the original module
118
116
  # - Reinsert the whole (sorted) functions block at that original position
@@ -154,7 +152,9 @@ def reorder_module_functions(module: cst.Module) -> cst.Module:
154
152
  for g in sorted_groups:
155
153
  # First node keeps its original leading_lines (no-op with_changes avoided)
156
154
  rebuilt_functions.append(g.nodes[0])
157
- rebuilt_functions.extend(fn.with_changes(leading_lines=[]) for fn in g.nodes[1:])
155
+ rebuilt_functions.extend(
156
+ fn.with_changes(leading_lines=[]) for fn in g.nodes[1:]
157
+ )
158
158
 
159
159
  # Insert functions as a contiguous block
160
160
  new_body[insert_at:insert_at] = rebuilt_functions
@@ -186,11 +186,7 @@ def _is_main_guard(node: cst.CSTNode) -> bool:
186
186
  if isinstance(test, cst.Comparison):
187
187
  left = test.left
188
188
  comps = test.comparisons
189
- if (
190
- len(comps) == 1
191
- and isinstance(left, cst.Name)
192
- and left.value == "__name__"
193
- ):
189
+ if len(comps) == 1 and isinstance(left, cst.Name) and left.value == "__name__":
194
190
  comp = comps[0]
195
191
  # operator should be ==
196
192
  if isinstance(comp.operator, cst.Equal):
@@ -16,7 +16,11 @@ def is_main_guard_at_end(module: cst.Module) -> bool:
16
16
  # Consider "at the end" if it's the last non-empty node (ignoring trailing blank lines)
17
17
  # Find last non-empty node index
18
18
  last_non_empty = next(
19
- (i for i in range(len(module.body) - 1, -1, -1) if not isinstance(module.body[i], cst.EmptyLine)),
19
+ (
20
+ i
21
+ for i in range(len(module.body) - 1, -1, -1)
22
+ if not isinstance(module.body[i], cst.EmptyLine)
23
+ ),
20
24
  -1,
21
25
  )
22
26
  return last_index == last_non_empty
@@ -52,8 +52,7 @@ def group_and_sort_module_metadata(module: cst.Module) -> cst.Module:
52
52
 
53
53
  # Build moved list directly from found; names are already known, no re-parse needed
54
54
  moved: list[tuple[str, cst.SimpleStatementLine]] = [
55
- (name, stmt.with_changes(leading_lines=[]))
56
- for _, stmt, name in found
55
+ (name, stmt.with_changes(leading_lines=[])) for _, stmt, name in found
57
56
  ]
58
57
  moved.sort(key=lambda t: t[0].lower())
59
58