deadcode 2.2.1__tar.gz → 2.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 (344) hide show
  1. {deadcode-2.2.1 → deadcode-2.3.0}/PKG-INFO +70 -24
  2. {deadcode-2.2.1 → deadcode-2.3.0}/README.md +69 -23
  3. deadcode-2.3.0/black/action/main.py +176 -0
  4. deadcode-2.3.0/black/docs/conf.py +218 -0
  5. deadcode-2.3.0/black/gallery/gallery.py +294 -0
  6. deadcode-2.3.0/black/profiling/dict_big.py +8001 -0
  7. deadcode-2.3.0/black/profiling/dict_huge.py +41440 -0
  8. deadcode-2.3.0/black/profiling/list_big.py +4000 -0
  9. deadcode-2.3.0/black/profiling/list_huge.py +22431 -0
  10. deadcode-2.3.0/black/profiling/mix_big.py +1002 -0
  11. deadcode-2.3.0/black/profiling/mix_huge.py +7692 -0
  12. deadcode-2.3.0/black/profiling/mix_small.py +102 -0
  13. deadcode-2.3.0/black/scripts/check_pre_commit_rev_in_example.py +54 -0
  14. deadcode-2.3.0/black/scripts/check_version_in_basics_example.py +48 -0
  15. deadcode-2.3.0/black/scripts/diff_shades_gha_helper.py +236 -0
  16. deadcode-2.3.0/black/scripts/fuzz.py +92 -0
  17. deadcode-2.3.0/black/scripts/generate_schema.py +74 -0
  18. deadcode-2.3.0/black/scripts/make_width_table.py +66 -0
  19. deadcode-2.3.0/black/scripts/migrate-black.py +96 -0
  20. deadcode-2.3.0/black/scripts/release.py +245 -0
  21. deadcode-2.3.0/black/scripts/release_tests.py +69 -0
  22. deadcode-2.3.0/black/src/black/__init__.py +1605 -0
  23. deadcode-2.3.0/black/src/black/__main__.py +3 -0
  24. deadcode-2.3.0/black/src/black/_width_table.py +478 -0
  25. deadcode-2.3.0/black/src/black/brackets.py +382 -0
  26. deadcode-2.3.0/black/src/black/cache.py +150 -0
  27. deadcode-2.3.0/black/src/black/comments.py +415 -0
  28. deadcode-2.3.0/black/src/black/concurrency.py +190 -0
  29. deadcode-2.3.0/black/src/black/const.py +4 -0
  30. deadcode-2.3.0/black/src/black/debug.py +54 -0
  31. deadcode-2.3.0/black/src/black/files.py +433 -0
  32. deadcode-2.3.0/black/src/black/handle_ipynb_magics.py +452 -0
  33. deadcode-2.3.0/black/src/black/linegen.py +1745 -0
  34. deadcode-2.3.0/black/src/black/lines.py +1073 -0
  35. deadcode-2.3.0/black/src/black/mode.py +265 -0
  36. deadcode-2.3.0/black/src/black/nodes.py +1007 -0
  37. deadcode-2.3.0/black/src/black/numerics.py +61 -0
  38. deadcode-2.3.0/black/src/black/output.py +122 -0
  39. deadcode-2.3.0/black/src/black/parsing.py +244 -0
  40. deadcode-2.3.0/black/src/black/ranges.py +521 -0
  41. deadcode-2.3.0/black/src/black/report.py +107 -0
  42. deadcode-2.3.0/black/src/black/rusty.py +28 -0
  43. deadcode-2.3.0/black/src/black/schema.py +20 -0
  44. deadcode-2.3.0/black/src/black/strings.py +325 -0
  45. deadcode-2.3.0/black/src/black/trans.py +2534 -0
  46. deadcode-2.3.0/black/src/blackd/__init__.py +259 -0
  47. deadcode-2.3.0/black/src/blackd/__main__.py +3 -0
  48. deadcode-2.3.0/black/src/blackd/middlewares.py +45 -0
  49. deadcode-2.3.0/black/src/blib2to3/__init__.py +1 -0
  50. deadcode-2.3.0/black/src/blib2to3/pgen2/__init__.py +4 -0
  51. deadcode-2.3.0/black/src/blib2to3/pgen2/conv.py +256 -0
  52. deadcode-2.3.0/black/src/blib2to3/pgen2/driver.py +316 -0
  53. deadcode-2.3.0/black/src/blib2to3/pgen2/grammar.py +227 -0
  54. deadcode-2.3.0/black/src/blib2to3/pgen2/literals.py +66 -0
  55. deadcode-2.3.0/black/src/blib2to3/pgen2/parse.py +411 -0
  56. deadcode-2.3.0/black/src/blib2to3/pgen2/pgen.py +428 -0
  57. deadcode-2.3.0/black/src/blib2to3/pgen2/token.py +88 -0
  58. deadcode-2.3.0/black/src/blib2to3/pgen2/tokenize.py +698 -0
  59. deadcode-2.3.0/black/src/blib2to3/pygram.py +200 -0
  60. deadcode-2.3.0/black/src/blib2to3/pytree.py +986 -0
  61. deadcode-2.3.0/black/tests/conftest.py +28 -0
  62. deadcode-2.3.0/black/tests/data/cases/allow_empty_first_line.py +166 -0
  63. deadcode-2.3.0/black/tests/data/cases/async_stmts.py +27 -0
  64. deadcode-2.3.0/black/tests/data/cases/attribute_access_on_number_literals.py +47 -0
  65. deadcode-2.3.0/black/tests/data/cases/beginning_backslash.py +12 -0
  66. deadcode-2.3.0/black/tests/data/cases/bracketmatch.py +15 -0
  67. deadcode-2.3.0/black/tests/data/cases/bytes_docstring.py +34 -0
  68. deadcode-2.3.0/black/tests/data/cases/class_blank_parentheses.py +59 -0
  69. deadcode-2.3.0/black/tests/data/cases/class_methods_new_line.py +270 -0
  70. deadcode-2.3.0/black/tests/data/cases/collections.py +174 -0
  71. deadcode-2.3.0/black/tests/data/cases/comment_after_escaped_newline.py +18 -0
  72. deadcode-2.3.0/black/tests/data/cases/comment_type_hint.py +3 -0
  73. deadcode-2.3.0/black/tests/data/cases/comments.py +96 -0
  74. deadcode-2.3.0/black/tests/data/cases/comments2.py +344 -0
  75. deadcode-2.3.0/black/tests/data/cases/comments3.py +48 -0
  76. deadcode-2.3.0/black/tests/data/cases/comments4.py +94 -0
  77. deadcode-2.3.0/black/tests/data/cases/comments5.py +70 -0
  78. deadcode-2.3.0/black/tests/data/cases/comments6.py +118 -0
  79. deadcode-2.3.0/black/tests/data/cases/comments8.py +15 -0
  80. deadcode-2.3.0/black/tests/data/cases/comments9.py +305 -0
  81. deadcode-2.3.0/black/tests/data/cases/comments_in_blocks.py +111 -0
  82. deadcode-2.3.0/black/tests/data/cases/comments_in_double_parens.py +113 -0
  83. deadcode-2.3.0/black/tests/data/cases/comments_non_breaking_space.py +44 -0
  84. deadcode-2.3.0/black/tests/data/cases/composition.py +181 -0
  85. deadcode-2.3.0/black/tests/data/cases/composition_no_trailing_comma.py +367 -0
  86. deadcode-2.3.0/black/tests/data/cases/conditional_expression.py +204 -0
  87. deadcode-2.3.0/black/tests/data/cases/context_managers_38.py +55 -0
  88. deadcode-2.3.0/black/tests/data/cases/context_managers_39.py +175 -0
  89. deadcode-2.3.0/black/tests/data/cases/context_managers_autodetect_310.py +36 -0
  90. deadcode-2.3.0/black/tests/data/cases/context_managers_autodetect_311.py +38 -0
  91. deadcode-2.3.0/black/tests/data/cases/context_managers_autodetect_38.py +46 -0
  92. deadcode-2.3.0/black/tests/data/cases/context_managers_autodetect_39.py +35 -0
  93. deadcode-2.3.0/black/tests/data/cases/docstring.py +457 -0
  94. deadcode-2.3.0/black/tests/data/cases/docstring_newline_preview.py +4 -0
  95. deadcode-2.3.0/black/tests/data/cases/docstring_no_extra_empty_line_before_eof.py +4 -0
  96. deadcode-2.3.0/black/tests/data/cases/docstring_no_string_normalization.py +250 -0
  97. deadcode-2.3.0/black/tests/data/cases/docstring_preview.py +104 -0
  98. deadcode-2.3.0/black/tests/data/cases/dummy_implementations.py +144 -0
  99. deadcode-2.3.0/black/tests/data/cases/empty_lines.py +187 -0
  100. deadcode-2.3.0/black/tests/data/cases/expression.py +630 -0
  101. deadcode-2.3.0/black/tests/data/cases/f_docstring.py +20 -0
  102. deadcode-2.3.0/black/tests/data/cases/fmtonoff.py +409 -0
  103. deadcode-2.3.0/black/tests/data/cases/fmtonoff2.py +40 -0
  104. deadcode-2.3.0/black/tests/data/cases/fmtonoff3.py +35 -0
  105. deadcode-2.3.0/black/tests/data/cases/fmtonoff4.py +36 -0
  106. deadcode-2.3.0/black/tests/data/cases/fmtonoff5.py +175 -0
  107. deadcode-2.3.0/black/tests/data/cases/fmtpass_imports.py +19 -0
  108. deadcode-2.3.0/black/tests/data/cases/fmtskip.py +3 -0
  109. deadcode-2.3.0/black/tests/data/cases/fmtskip2.py +20 -0
  110. deadcode-2.3.0/black/tests/data/cases/fmtskip3.py +20 -0
  111. deadcode-2.3.0/black/tests/data/cases/fmtskip4.py +13 -0
  112. deadcode-2.3.0/black/tests/data/cases/fmtskip5.py +22 -0
  113. deadcode-2.3.0/black/tests/data/cases/fmtskip6.py +13 -0
  114. deadcode-2.3.0/black/tests/data/cases/fmtskip7.py +11 -0
  115. deadcode-2.3.0/black/tests/data/cases/fmtskip8.py +62 -0
  116. deadcode-2.3.0/black/tests/data/cases/fmtskip9.py +9 -0
  117. deadcode-2.3.0/black/tests/data/cases/form_feeds.py +226 -0
  118. deadcode-2.3.0/black/tests/data/cases/fstring.py +25 -0
  119. deadcode-2.3.0/black/tests/data/cases/funcdef_return_type_trailing_comma.py +301 -0
  120. deadcode-2.3.0/black/tests/data/cases/function.py +244 -0
  121. deadcode-2.3.0/black/tests/data/cases/function2.py +121 -0
  122. deadcode-2.3.0/black/tests/data/cases/function_trailing_comma.py +178 -0
  123. deadcode-2.3.0/black/tests/data/cases/ignore_pyi.py +42 -0
  124. deadcode-2.3.0/black/tests/data/cases/import_spacing.py +118 -0
  125. deadcode-2.3.0/black/tests/data/cases/is_simple_lookup_for_doublestar_expression.py +14 -0
  126. deadcode-2.3.0/black/tests/data/cases/keep_newline_after_match.py +41 -0
  127. deadcode-2.3.0/black/tests/data/cases/line_ranges_basic.py +107 -0
  128. deadcode-2.3.0/black/tests/data/cases/line_ranges_diff_edge_case.py +28 -0
  129. deadcode-2.3.0/black/tests/data/cases/line_ranges_exceeding_end.py +36 -0
  130. deadcode-2.3.0/black/tests/data/cases/line_ranges_fmt_off.py +49 -0
  131. deadcode-2.3.0/black/tests/data/cases/line_ranges_fmt_off_decorator.py +47 -0
  132. deadcode-2.3.0/black/tests/data/cases/line_ranges_fmt_off_overlap.py +37 -0
  133. deadcode-2.3.0/black/tests/data/cases/line_ranges_imports.py +9 -0
  134. deadcode-2.3.0/black/tests/data/cases/line_ranges_indentation.py +27 -0
  135. deadcode-2.3.0/black/tests/data/cases/line_ranges_outside_source.py +7 -0
  136. deadcode-2.3.0/black/tests/data/cases/line_ranges_two_passes.py +27 -0
  137. deadcode-2.3.0/black/tests/data/cases/line_ranges_unwrapping.py +25 -0
  138. deadcode-2.3.0/black/tests/data/cases/linelength6.py +6 -0
  139. deadcode-2.3.0/black/tests/data/cases/long_strings_flag_disabled.py +296 -0
  140. deadcode-2.3.0/black/tests/data/cases/module_docstring_1.py +25 -0
  141. deadcode-2.3.0/black/tests/data/cases/module_docstring_2.py +70 -0
  142. deadcode-2.3.0/black/tests/data/cases/module_docstring_3.py +7 -0
  143. deadcode-2.3.0/black/tests/data/cases/module_docstring_4.py +8 -0
  144. deadcode-2.3.0/black/tests/data/cases/module_docstring_followed_by_class.py +10 -0
  145. deadcode-2.3.0/black/tests/data/cases/module_docstring_followed_by_function.py +10 -0
  146. deadcode-2.3.0/black/tests/data/cases/multiline_consecutive_open_parentheses_ignore.py +41 -0
  147. deadcode-2.3.0/black/tests/data/cases/nested_stub.py +69 -0
  148. deadcode-2.3.0/black/tests/data/cases/no_blank_line_before_docstring.py +66 -0
  149. deadcode-2.3.0/black/tests/data/cases/numeric_literals.py +39 -0
  150. deadcode-2.3.0/black/tests/data/cases/numeric_literals_skip_underscores.py +19 -0
  151. deadcode-2.3.0/black/tests/data/cases/one_element_subscript.py +36 -0
  152. deadcode-2.3.0/black/tests/data/cases/parenthesized_context_managers.py +46 -0
  153. deadcode-2.3.0/black/tests/data/cases/pattern_matching_complex.py +155 -0
  154. deadcode-2.3.0/black/tests/data/cases/pattern_matching_extras.py +102 -0
  155. deadcode-2.3.0/black/tests/data/cases/pattern_matching_generic.py +108 -0
  156. deadcode-2.3.0/black/tests/data/cases/pattern_matching_long.py +34 -0
  157. deadcode-2.3.0/black/tests/data/cases/pattern_matching_simple.py +93 -0
  158. deadcode-2.3.0/black/tests/data/cases/pattern_matching_style.py +92 -0
  159. deadcode-2.3.0/black/tests/data/cases/pattern_matching_trailing_comma.py +39 -0
  160. deadcode-2.3.0/black/tests/data/cases/pattern_matching_with_if_stmt.py +72 -0
  161. deadcode-2.3.0/black/tests/data/cases/pep604_union_types_line_breaks.py +188 -0
  162. deadcode-2.3.0/black/tests/data/cases/pep_570.py +45 -0
  163. deadcode-2.3.0/black/tests/data/cases/pep_572.py +48 -0
  164. deadcode-2.3.0/black/tests/data/cases/pep_572_do_not_remove_parens.py +26 -0
  165. deadcode-2.3.0/black/tests/data/cases/pep_572_py310.py +16 -0
  166. deadcode-2.3.0/black/tests/data/cases/pep_572_py39.py +8 -0
  167. deadcode-2.3.0/black/tests/data/cases/pep_572_remove_parens.py +142 -0
  168. deadcode-2.3.0/black/tests/data/cases/pep_572_slices.py +6 -0
  169. deadcode-2.3.0/black/tests/data/cases/pep_604.py +25 -0
  170. deadcode-2.3.0/black/tests/data/cases/pep_646.py +195 -0
  171. deadcode-2.3.0/black/tests/data/cases/pep_654.py +54 -0
  172. deadcode-2.3.0/black/tests/data/cases/pep_654_style.py +112 -0
  173. deadcode-2.3.0/black/tests/data/cases/percent_precedence.py +41 -0
  174. deadcode-2.3.0/black/tests/data/cases/power_op_newline.py +11 -0
  175. deadcode-2.3.0/black/tests/data/cases/power_op_spacing.py +149 -0
  176. deadcode-2.3.0/black/tests/data/cases/power_op_spacing_long.py +96 -0
  177. deadcode-2.3.0/black/tests/data/cases/prefer_rhs_split.py +106 -0
  178. deadcode-2.3.0/black/tests/data/cases/prefer_rhs_split_reformatted.py +38 -0
  179. deadcode-2.3.0/black/tests/data/cases/preview_cantfit.py +94 -0
  180. deadcode-2.3.0/black/tests/data/cases/preview_cantfit_string.py +18 -0
  181. deadcode-2.3.0/black/tests/data/cases/preview_comments7.py +309 -0
  182. deadcode-2.3.0/black/tests/data/cases/preview_format_unicode_escape_seq.py +34 -0
  183. deadcode-2.3.0/black/tests/data/cases/preview_hug_parens_with_braces_and_square_brackets.py +347 -0
  184. deadcode-2.3.0/black/tests/data/cases/preview_hug_parens_with_braces_and_square_brackets_no_ll1.py +106 -0
  185. deadcode-2.3.0/black/tests/data/cases/preview_long_dict_values.py +129 -0
  186. deadcode-2.3.0/black/tests/data/cases/preview_long_strings.py +928 -0
  187. deadcode-2.3.0/black/tests/data/cases/preview_long_strings__east_asian_width.py +26 -0
  188. deadcode-2.3.0/black/tests/data/cases/preview_long_strings__edge_case.py +141 -0
  189. deadcode-2.3.0/black/tests/data/cases/preview_long_strings__regression.py +1247 -0
  190. deadcode-2.3.0/black/tests/data/cases/preview_long_strings__type_annotations.py +60 -0
  191. deadcode-2.3.0/black/tests/data/cases/preview_multiline_strings.py +401 -0
  192. deadcode-2.3.0/black/tests/data/cases/preview_return_annotation_brackets_string.py +24 -0
  193. deadcode-2.3.0/black/tests/data/cases/py310_pep572.py +13 -0
  194. deadcode-2.3.0/black/tests/data/cases/python37.py +62 -0
  195. deadcode-2.3.0/black/tests/data/cases/python38.py +42 -0
  196. deadcode-2.3.0/black/tests/data/cases/python39.py +30 -0
  197. deadcode-2.3.0/black/tests/data/cases/raw_docstring.py +32 -0
  198. deadcode-2.3.0/black/tests/data/cases/raw_docstring_no_string_normalization.py +11 -0
  199. deadcode-2.3.0/black/tests/data/cases/remove_await_parens.py +195 -0
  200. deadcode-2.3.0/black/tests/data/cases/remove_except_parens.py +79 -0
  201. deadcode-2.3.0/black/tests/data/cases/remove_for_brackets.py +48 -0
  202. deadcode-2.3.0/black/tests/data/cases/remove_newline_after_code_block_open.py +212 -0
  203. deadcode-2.3.0/black/tests/data/cases/remove_parens.py +142 -0
  204. deadcode-2.3.0/black/tests/data/cases/remove_redundant_parens_in_case_guard.py +114 -0
  205. deadcode-2.3.0/black/tests/data/cases/remove_with_brackets.py +120 -0
  206. deadcode-2.3.0/black/tests/data/cases/return_annotation_brackets.py +219 -0
  207. deadcode-2.3.0/black/tests/data/cases/single_line_format_skip_with_multiple_comments.py +19 -0
  208. deadcode-2.3.0/black/tests/data/cases/skip_magic_trailing_comma.py +75 -0
  209. deadcode-2.3.0/black/tests/data/cases/slices.py +31 -0
  210. deadcode-2.3.0/black/tests/data/cases/split_delimiter_comments.py +51 -0
  211. deadcode-2.3.0/black/tests/data/cases/starred_for_target.py +28 -0
  212. deadcode-2.3.0/black/tests/data/cases/string_prefixes.py +45 -0
  213. deadcode-2.3.0/black/tests/data/cases/stub.py +152 -0
  214. deadcode-2.3.0/black/tests/data/cases/torture.py +91 -0
  215. deadcode-2.3.0/black/tests/data/cases/trailing_comma.py +55 -0
  216. deadcode-2.3.0/black/tests/data/cases/trailing_comma_optional_parens1.py +63 -0
  217. deadcode-2.3.0/black/tests/data/cases/trailing_comma_optional_parens2.py +12 -0
  218. deadcode-2.3.0/black/tests/data/cases/trailing_comma_optional_parens3.py +21 -0
  219. deadcode-2.3.0/black/tests/data/cases/trailing_commas_in_leading_parts.py +88 -0
  220. deadcode-2.3.0/black/tests/data/cases/tricky_unicode_symbols.py +9 -0
  221. deadcode-2.3.0/black/tests/data/cases/tupleassign.py +23 -0
  222. deadcode-2.3.0/black/tests/data/cases/type_aliases.py +30 -0
  223. deadcode-2.3.0/black/tests/data/cases/type_comment_syntax_error.py +11 -0
  224. deadcode-2.3.0/black/tests/data/cases/type_params.py +58 -0
  225. deadcode-2.3.0/black/tests/data/cases/typed_params_trailing_comma.py +24 -0
  226. deadcode-2.3.0/black/tests/data/cases/walrus_in_dict.py +9 -0
  227. deadcode-2.3.0/black/tests/data/cases/whitespace.py +6 -0
  228. deadcode-2.3.0/black/tests/data/ignore_subfolders_gitignore_tests/subdir/subdir/c.py +0 -0
  229. deadcode-2.3.0/black/tests/data/include_exclude_tests/b/.definitely_exclude/a.py +0 -0
  230. deadcode-2.3.0/black/tests/data/include_exclude_tests/b/dont_exclude/a.py +0 -0
  231. deadcode-2.3.0/black/tests/data/include_exclude_tests/b/exclude/a.py +0 -0
  232. deadcode-2.3.0/black/tests/data/invalid_gitignore_tests/a.py +0 -0
  233. deadcode-2.3.0/black/tests/data/invalid_nested_gitignore_tests/a/a.py +0 -0
  234. deadcode-2.3.0/black/tests/data/invalid_nested_gitignore_tests/a.py +0 -0
  235. deadcode-2.3.0/black/tests/data/line_ranges_formatted/basic.py +50 -0
  236. deadcode-2.3.0/black/tests/data/line_ranges_formatted/pattern_matching.py +25 -0
  237. deadcode-2.3.0/black/tests/data/miscellaneous/async_as_identifier.py +49 -0
  238. deadcode-2.3.0/black/tests/data/miscellaneous/blackd_diff.py +6 -0
  239. deadcode-2.3.0/black/tests/data/miscellaneous/debug_visitor.py +32 -0
  240. deadcode-2.3.0/black/tests/data/miscellaneous/decorators.py +182 -0
  241. deadcode-2.3.0/black/tests/data/miscellaneous/force_py36.py +16 -0
  242. deadcode-2.3.0/black/tests/data/miscellaneous/force_pyi.py +66 -0
  243. deadcode-2.3.0/black/tests/data/miscellaneous/invalid_header.py +2 -0
  244. deadcode-2.3.0/black/tests/data/miscellaneous/missing_final_newline.py +3 -0
  245. deadcode-2.3.0/black/tests/data/miscellaneous/pattern_matching_invalid.py +18 -0
  246. deadcode-2.3.0/black/tests/data/miscellaneous/python2_detection.py +90 -0
  247. deadcode-2.3.0/black/tests/data/miscellaneous/string_quotes.py +114 -0
  248. deadcode-2.3.0/black/tests/data/nested_gitignore_tests/root/a.py +1 -0
  249. deadcode-2.3.0/black/tests/data/nested_gitignore_tests/root/b.py +1 -0
  250. deadcode-2.3.0/black/tests/data/nested_gitignore_tests/root/c.py +1 -0
  251. deadcode-2.3.0/black/tests/data/nested_gitignore_tests/root/child/a.py +1 -0
  252. deadcode-2.3.0/black/tests/data/nested_gitignore_tests/root/child/b.py +1 -0
  253. deadcode-2.3.0/black/tests/data/nested_gitignore_tests/root/child/c.py +1 -0
  254. deadcode-2.3.0/black/tests/data/nested_gitignore_tests/x.py +0 -0
  255. deadcode-2.3.0/black/tests/optional.py +132 -0
  256. deadcode-2.3.0/black/tests/test_black.py +2980 -0
  257. deadcode-2.3.0/black/tests/test_blackd.py +248 -0
  258. deadcode-2.3.0/black/tests/test_docs.py +74 -0
  259. deadcode-2.3.0/black/tests/test_format.py +90 -0
  260. deadcode-2.3.0/black/tests/test_ipynb.py +517 -0
  261. deadcode-2.3.0/black/tests/test_no_ipynb.py +36 -0
  262. deadcode-2.3.0/black/tests/test_ranges.py +249 -0
  263. deadcode-2.3.0/black/tests/test_schema.py +17 -0
  264. deadcode-2.3.0/black/tests/test_trans.py +51 -0
  265. deadcode-2.3.0/black/tests/util.py +354 -0
  266. {deadcode-2.2.1 → deadcode-2.3.0}/call_arg_map_to_parameters_poc.py +3 -3
  267. deadcode-2.3.0/deadcode/__init__.py +0 -0
  268. deadcode-2.3.0/deadcode/actions/__init__.py +0 -0
  269. deadcode-2.2.1/deadcode/actions/fix_unused_code.py → deadcode-2.3.0/deadcode/actions/fix_or_show_unused_code.py +25 -4
  270. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/actions/parse_arguments.py +24 -6
  271. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/cli.py +5 -4
  272. deadcode-2.3.0/deadcode/constants.py +49 -0
  273. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/data_types.py +1 -0
  274. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/base.py +2 -2
  275. deadcode-2.3.0/deadcode/tests/cli_args/test_count.py +0 -0
  276. deadcode-2.3.0/deadcode/tests/cli_args/test_dry.py +318 -0
  277. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/cli_args/test_fix.py +5 -5
  278. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/cli_args/test_ignore_bodies_if_inherits_from.py +3 -3
  279. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/cli_args/test_ignore_definitions.py +1 -1
  280. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/cli_args/test_ignore_definitions_if_inherits_from.py +4 -4
  281. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/cli_args/test_ignore_names.py +3 -3
  282. deadcode-2.3.0/deadcode/tests/cli_args/test_ignore_names_in_files.py +0 -0
  283. deadcode-2.3.0/deadcode/tests/cli_args/test_no_color.py +0 -0
  284. deadcode-2.3.0/deadcode/tests/cli_args/test_parsing.py +113 -0
  285. deadcode-2.3.0/deadcode/tests/cli_args/test_quiet.py +0 -0
  286. deadcode-2.3.0/deadcode/tests/cli_args/test_verbose.py +0 -0
  287. deadcode-2.3.0/deadcode/tests/code_item/test_code_item.py +16 -0
  288. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/fix/test_assign.py +2 -2
  289. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/fix/test_class_def.py +4 -4
  290. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/fix/test_empty_files.py +2 -2
  291. deadcode-2.3.0/deadcode/tests/nested_scope/test_nested_scope.py +180 -0
  292. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/noqa/test_noqa_comments.py +28 -28
  293. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/test_deadcode.py +11 -11
  294. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/test_imports.py +3 -3
  295. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/test_output.py +6 -6
  296. deadcode-2.3.0/deadcode/tests/utils/test_add_colors_to_diff.py +38 -0
  297. deadcode-2.3.0/deadcode/utils/__init__.py +0 -0
  298. deadcode-2.3.0/deadcode/utils/add_colors_to_diff.py +10 -0
  299. deadcode-2.3.0/deadcode/utils/nested_scopes.py +83 -0
  300. deadcode-2.3.0/deadcode/visitor/__init__.py +0 -0
  301. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/visitor/code_item.py +12 -11
  302. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/visitor/dead_code_visitor.py +84 -156
  303. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/visitor/ignore.py +13 -13
  304. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/visitor/noqa.py +27 -14
  305. {deadcode-2.2.1 → deadcode-2.3.0}/pyproject.toml +6 -3
  306. deadcode-2.2.1/deadcode/constants.py +0 -49
  307. deadcode-2.2.1/deadcode/tests/cli_args/test_parsing.py +0 -66
  308. {deadcode-2.2.1 → deadcode-2.3.0}/.gitignore +0 -0
  309. {deadcode-2.2.1 → deadcode-2.3.0}/LICENSE +0 -0
  310. {deadcode-2.2.1/deadcode → deadcode-2.3.0/black/scripts}/__init__.py +0 -0
  311. {deadcode-2.2.1/deadcode/actions → deadcode-2.3.0/black/src/black/resources}/__init__.py +0 -0
  312. {deadcode-2.2.1/deadcode/utils → deadcode-2.3.0/black/tests}/__init__.py +0 -0
  313. /deadcode-2.2.1/deadcode/tests/cli_args/test_count.py → /deadcode-2.3.0/black/tests/data/gitignore_used_on_multiple_sources/dir1/a.py +0 -0
  314. /deadcode-2.2.1/deadcode/tests/cli_args/test_ignore_names_in_files.py → /deadcode-2.3.0/black/tests/data/gitignore_used_on_multiple_sources/dir1/b.py +0 -0
  315. /deadcode-2.2.1/deadcode/tests/cli_args/test_no_color.py → /deadcode-2.3.0/black/tests/data/gitignore_used_on_multiple_sources/dir2/a.py +0 -0
  316. /deadcode-2.2.1/deadcode/tests/cli_args/test_quiet.py → /deadcode-2.3.0/black/tests/data/gitignore_used_on_multiple_sources/dir2/b.py +0 -0
  317. /deadcode-2.2.1/deadcode/tests/cli_args/test_verbose.py → /deadcode-2.3.0/black/tests/data/ignore_subfolders_gitignore_tests/a.py +0 -0
  318. /deadcode-2.2.1/deadcode/visitor/__init__.py → /deadcode-2.3.0/black/tests/data/ignore_subfolders_gitignore_tests/subdir/b.py +0 -0
  319. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/actions/find_python_filenames.py +0 -0
  320. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/actions/find_unused_names.py +0 -0
  321. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/actions/get_unused_names_error_message.py +0 -0
  322. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/actions/merge_overlaping_file_parts.py +0 -0
  323. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/actions/parse_abstract_syntax_tree.py +0 -0
  324. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/actions/remove_file_parts_from_content.py +0 -0
  325. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/actions/test_find_python_filenames.py +0 -0
  326. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/actions/test_merge_overlaping_file_parts.py +0 -0
  327. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/cli_args/test_exclude.py +0 -0
  328. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/files/classes.py +0 -0
  329. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/files/functions.py +0 -0
  330. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/files/subdir/another_subdir/__init__.py +0 -0
  331. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/files/subdir/one_more_file.py +0 -0
  332. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/files/variables.py +0 -0
  333. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/fix/test_method_def.py +0 -0
  334. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/fix/test_scope.py +0 -0
  335. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/fix/test_unreachable_code.py +0 -0
  336. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/test_accurate_usage_detection.py +0 -0
  337. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/test_line_number_detection.py +0 -0
  338. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/test_variable_parsing_from_ast_dump.py +0 -0
  339. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/tests/utils/test_fix_indent.py +0 -0
  340. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/utils/fix_indent.py +0 -0
  341. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/utils/flatten_lists.py +0 -0
  342. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/utils/print_ast.py +0 -0
  343. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/visitor/lines.py +0 -0
  344. {deadcode-2.2.1 → deadcode-2.3.0}/deadcode/visitor/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: deadcode
3
- Version: 2.2.1
3
+ Version: 2.3.0
4
4
  Summary: Find and remove dead code.
5
5
  Project-URL: Homepage, https://github.com/albertas/deadcode
6
6
  Project-URL: Documentation, https://deadcode.readthedocs.io/
@@ -19,10 +19,16 @@ Requires-Python: >=3.8
19
19
  Requires-Dist: tomli==2.0.1
20
20
  Description-Content-Type: text/markdown
21
21
 
22
- # deadcode
23
- `deadcode` allows to detect and fix unused Python code. It implements `DCXXX`
24
- static code linting rules for detecting unused code such as
25
- variables, functions and classes.
22
+ [![Deadcode Logo](https://raw.githubusercontent.com/albertas/deadcode/main/docs/_static/deadcode-logo-readme.png)](https://deadcode.readthedocs.io/en/stable/)
23
+
24
+ <h2 align="center">Find and Fix Unused Python Code</h2>
25
+
26
+ <p align="center">
27
+ <a href="https://github.com/albertas/deadcode/blob/main/LICENSE"><img alt="License: AGPLv3" src="https://raw.githubusercontent.com/albertas/deadcode/main/docs/_static/AGPLv3-license.svg"></a>
28
+ <a href="https://pypi.org/project/deadcode/"><img alt="PyPI" src="https://img.shields.io/pypi/v/deadcode"></a>
29
+ <a href="https://pepy.tech/project/deadcode"><img alt="Downloads" src="https://static.pepy.tech/badge/deadcode"></a>
30
+ </p>
31
+
26
32
 
27
33
  ## Installation
28
34
  ```shell
@@ -30,11 +36,27 @@ pip install deadcode
30
36
  ```
31
37
 
32
38
  ## Usage
39
+ To see unused code findings:
33
40
  ```shell
34
41
  deadcode .
35
42
  ```
36
43
 
37
- Or with command line options:
44
+ To see suggested fixes for all files:
45
+ ```shell
46
+ deadcode . --fix --dry
47
+ ```
48
+
49
+ To see suggested fixes for only `foo.py` file:
50
+ ```shell
51
+ deadcode . --fix --dry foo.py
52
+ ```
53
+
54
+ To fix:
55
+ ```shell
56
+ deadcode . --fix
57
+ ```
58
+
59
+ Tune out some of the false positives, e.g.:
38
60
  ```
39
61
  deadcode . --exclude=venv,tests --ignore-names=BaseTestCase,*Mixin --ignore-names-in-files=migrations
40
62
  ```
@@ -52,6 +74,7 @@ ignore-names-in-files = ["migrations"]
52
74
  | Option&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Type | Meaning |
53
75
  |-------------------------------------------|------|----------------------------------------------------------------------|
54
76
  |`--fix` | - | Automatically remove detected unused code expressions from the code base. |
77
+ |`--dry` | - or list | Show changes which would be made in files. Shows changes for provided filenames or shows all changes if no filename is specified. |
55
78
  |`--exclude` | list | Filenames (or path expressions), which will be completely skipped without being analysed. |
56
79
  |`--ignore-names` | list | Removes provided list of names from the output. Regexp expressions to match multiple names can also be provided, e.g. `*Mixin` will match all classes ending with `Mixin`. |
57
80
  |`--ignore-names-in-files` | list | Ignores unused names in files, which filenames match provided path expressions. |
@@ -77,27 +100,26 @@ definition - whole class or function definition expression including its name an
77
100
  ## Rules
78
101
  | Code | Name | Message |
79
102
  |--------|--------------------|----------------|
80
- | DC001 | unused-variable | Variable `{name}` is never used
81
- | DC002 | unused-function | Function `{name}` is never used
82
- | DC003 | unused-class | Class `{name}` is never used
83
- | DC004 | unused-method | Method `{name}` is never used
84
- | DC005 | unused-attribute | Attribute `{name}` is never used
85
- | DC006 | unused-name | Name `{name}` is never used
86
- | DC007 | unused-import | Import `{name}` is never used
87
- | DC008 | unused-property | Property `{name}` is never used
88
- | DC009* | unreachable-code | Unreachable `else` block
89
- | DC011 | empty-file | Empty file
90
- | DC012* | commented-out-code | Commented out code
91
- | DC013* | ignore-expression | *This error code can ony be used in `# noqa: DC013` comments (no errors will be reported for expression which begins in current line)*
92
-
93
- `*` - are not yet implemented rules.
103
+ | DC01 | unused-variable | Variable `{name}` is never used
104
+ | DC02 | unused-function | Function `{name}` is never used
105
+ | DC03 | unused-class | Class `{name}` is never used
106
+ | DC04 | unused-method | Method `{name}` is never used
107
+ | DC05 | unused-attribute | Attribute `{name}` is never used
108
+ | DC06 | unused-name | Name `{name}` is never used
109
+ | DC07 | unused-import | Import `{name}` is never used
110
+ | DC08 | unused-property | Property `{name}` is never used
111
+ | DC09 | unreachable-if-block | Unreachable conditional statement block
112
+ | DC11 | empty-file | Empty Python file
113
+ | DC12 | commented-out-code | Commented out code
114
+ | DC13 | unreachable-code | Code after terminal statement, e.g. `return`, `raise`, `continue`, `break`
115
+ | DC | ignore-expression | Do not show any findings for an expression, which starts on current line (this code can only be used in `# noqa: DC` comments)
94
116
 
95
117
  ## Ignoring checks with noqa comments
96
118
  Inline `# noqa` comments can be used to ignore `deadcode` checks.
97
- E.g. unused `Foo` class wont be detected/fixed because `# noqa: DC003` comment is used:
119
+ E.g. unused `Foo` class wont be detected/fixed because `# noqa: DC03` comment is used:
98
120
 
99
121
  ```python
100
- class Foo: # noqa: DC003
122
+ class Foo: # noqa: DC03
101
123
  pass
102
124
  ```
103
125
 
@@ -127,10 +149,10 @@ code base is implemented in.
127
149
 
128
150
  ## Feature requests
129
151
  - [x] Replace `.*` with only `*` in regexp matching.
130
- - [x] Add unused class method detection DC004 check.
152
+ - [x] Add unused class method detection DC04 check.
131
153
  - [x] Add `--fix` option to automatically remove detected dead code occourencies
132
154
  - [x] Add a check for empty python files.
133
- - [x] Split error codes into DC001, DC002, DC003 for variables, functions, class.
155
+ - [x] Split error codes into DC01, DC02, DC03 for variables, functions, class.
134
156
  - [x] Should have different codes for ignoring name and ignoring whole definition (reserved DCxx0 - ignore name, DCxx1 - ignore definition).
135
157
  - [ ] Allow to disable each check separately using:
136
158
  - [ ] inline comment.
@@ -144,4 +166,28 @@ code base is implemented in.
144
166
  - [ ] --ignore-definitions-if-decorated-with
145
167
  - [ ] --ignore-names-if-inherits-from
146
168
  - [ ] --ignore-names-if-decorated-with
169
+ - [ ] --ignore-bodies-of
170
+ - [ ] --ignore-bodies-if-decorated-with
171
+ - [ ] --ignore-bodies-if-inherits-from
172
+ - [ ] --ignore-definitions
173
+ - [ ] --ignore-definitions-if-inherits-from
174
+ - [ ] --ignore-definitions-if-decorated-with
175
+ - Question: would it be possible to ignore only certain types of checks for a body, e.g. only variable attributes of TypedDict and still check usage of methods and properties?
176
+ - What expression would allow this type of precission?
147
177
  - [ ] Distinguish between definitions with same name, but different files.
178
+ - [ ] Repeated application of `deadcode` till the output stops changing.
179
+ - [ ] Unreachable code detection and fixing: this should only be scoped for if statements and only limited to primitive variables.
180
+ - [ ] `--fix --dry [filenames]` - only show whats about to change in the listed filenames.
181
+ - [ ] Benchmarking performance with larger projects (time, CPU and memory consumption) in order to optimize.
182
+ - [ ] `--fix` could accept a list of filenames as well (only those files would be changed, but the summary could would be full).
183
+ (This might be confusing, because filenames, which have to be considered are provided without any flag, --fix is expected to not accept arguments)
184
+ - [ ] pre-commit-hook.
185
+ - [ ] language server.
186
+ - [ ] Use only two digits for error codes instead of 3. Two is plenty and it simplifies usage a bit
187
+ - [ ] DC10: remove code after terminal statements like `raise`, `return`, `break`, `continue` and comes in the same scope.
188
+ - [ ] Add `ignore` and `per-file-ignores` command line and pyproject.toml options, which allows to skip some rules.
189
+ - [ ] Make sure that all rules are being skipped by `noqa` comment and all rules react to `noqa: rule_id` comments.
190
+ - [ ] Include package names into code item scope (dot-separated path), e.g. "package1.package2.module.class.method.variable".
191
+ - [ ] All options should be able to accept dot-separated path or a generic name, e.g. "marshmallow.Schema" vs "Schema",
192
+ documentation should cleary demonstrate the behaviour/example that "Schema" means "*.Schema".
193
+ - [ ] Redefinition of an existing name makes previous name unreachable, unless it is assigned somehow.
@@ -1,7 +1,13 @@
1
- # deadcode
2
- `deadcode` allows to detect and fix unused Python code. It implements `DCXXX`
3
- static code linting rules for detecting unused code such as
4
- variables, functions and classes.
1
+ [![Deadcode Logo](https://raw.githubusercontent.com/albertas/deadcode/main/docs/_static/deadcode-logo-readme.png)](https://deadcode.readthedocs.io/en/stable/)
2
+
3
+ <h2 align="center">Find and Fix Unused Python Code</h2>
4
+
5
+ <p align="center">
6
+ <a href="https://github.com/albertas/deadcode/blob/main/LICENSE"><img alt="License: AGPLv3" src="https://raw.githubusercontent.com/albertas/deadcode/main/docs/_static/AGPLv3-license.svg"></a>
7
+ <a href="https://pypi.org/project/deadcode/"><img alt="PyPI" src="https://img.shields.io/pypi/v/deadcode"></a>
8
+ <a href="https://pepy.tech/project/deadcode"><img alt="Downloads" src="https://static.pepy.tech/badge/deadcode"></a>
9
+ </p>
10
+
5
11
 
6
12
  ## Installation
7
13
  ```shell
@@ -9,11 +15,27 @@ pip install deadcode
9
15
  ```
10
16
 
11
17
  ## Usage
18
+ To see unused code findings:
12
19
  ```shell
13
20
  deadcode .
14
21
  ```
15
22
 
16
- Or with command line options:
23
+ To see suggested fixes for all files:
24
+ ```shell
25
+ deadcode . --fix --dry
26
+ ```
27
+
28
+ To see suggested fixes for only `foo.py` file:
29
+ ```shell
30
+ deadcode . --fix --dry foo.py
31
+ ```
32
+
33
+ To fix:
34
+ ```shell
35
+ deadcode . --fix
36
+ ```
37
+
38
+ Tune out some of the false positives, e.g.:
17
39
  ```
18
40
  deadcode . --exclude=venv,tests --ignore-names=BaseTestCase,*Mixin --ignore-names-in-files=migrations
19
41
  ```
@@ -31,6 +53,7 @@ ignore-names-in-files = ["migrations"]
31
53
  | Option&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Type | Meaning |
32
54
  |-------------------------------------------|------|----------------------------------------------------------------------|
33
55
  |`--fix` | - | Automatically remove detected unused code expressions from the code base. |
56
+ |`--dry` | - or list | Show changes which would be made in files. Shows changes for provided filenames or shows all changes if no filename is specified. |
34
57
  |`--exclude` | list | Filenames (or path expressions), which will be completely skipped without being analysed. |
35
58
  |`--ignore-names` | list | Removes provided list of names from the output. Regexp expressions to match multiple names can also be provided, e.g. `*Mixin` will match all classes ending with `Mixin`. |
36
59
  |`--ignore-names-in-files` | list | Ignores unused names in files, which filenames match provided path expressions. |
@@ -56,27 +79,26 @@ definition - whole class or function definition expression including its name an
56
79
  ## Rules
57
80
  | Code | Name | Message |
58
81
  |--------|--------------------|----------------|
59
- | DC001 | unused-variable | Variable `{name}` is never used
60
- | DC002 | unused-function | Function `{name}` is never used
61
- | DC003 | unused-class | Class `{name}` is never used
62
- | DC004 | unused-method | Method `{name}` is never used
63
- | DC005 | unused-attribute | Attribute `{name}` is never used
64
- | DC006 | unused-name | Name `{name}` is never used
65
- | DC007 | unused-import | Import `{name}` is never used
66
- | DC008 | unused-property | Property `{name}` is never used
67
- | DC009* | unreachable-code | Unreachable `else` block
68
- | DC011 | empty-file | Empty file
69
- | DC012* | commented-out-code | Commented out code
70
- | DC013* | ignore-expression | *This error code can ony be used in `# noqa: DC013` comments (no errors will be reported for expression which begins in current line)*
71
-
72
- `*` - are not yet implemented rules.
82
+ | DC01 | unused-variable | Variable `{name}` is never used
83
+ | DC02 | unused-function | Function `{name}` is never used
84
+ | DC03 | unused-class | Class `{name}` is never used
85
+ | DC04 | unused-method | Method `{name}` is never used
86
+ | DC05 | unused-attribute | Attribute `{name}` is never used
87
+ | DC06 | unused-name | Name `{name}` is never used
88
+ | DC07 | unused-import | Import `{name}` is never used
89
+ | DC08 | unused-property | Property `{name}` is never used
90
+ | DC09 | unreachable-if-block | Unreachable conditional statement block
91
+ | DC11 | empty-file | Empty Python file
92
+ | DC12 | commented-out-code | Commented out code
93
+ | DC13 | unreachable-code | Code after terminal statement, e.g. `return`, `raise`, `continue`, `break`
94
+ | DC | ignore-expression | Do not show any findings for an expression, which starts on current line (this code can only be used in `# noqa: DC` comments)
73
95
 
74
96
  ## Ignoring checks with noqa comments
75
97
  Inline `# noqa` comments can be used to ignore `deadcode` checks.
76
- E.g. unused `Foo` class wont be detected/fixed because `# noqa: DC003` comment is used:
98
+ E.g. unused `Foo` class wont be detected/fixed because `# noqa: DC03` comment is used:
77
99
 
78
100
  ```python
79
- class Foo: # noqa: DC003
101
+ class Foo: # noqa: DC03
80
102
  pass
81
103
  ```
82
104
 
@@ -106,10 +128,10 @@ code base is implemented in.
106
128
 
107
129
  ## Feature requests
108
130
  - [x] Replace `.*` with only `*` in regexp matching.
109
- - [x] Add unused class method detection DC004 check.
131
+ - [x] Add unused class method detection DC04 check.
110
132
  - [x] Add `--fix` option to automatically remove detected dead code occourencies
111
133
  - [x] Add a check for empty python files.
112
- - [x] Split error codes into DC001, DC002, DC003 for variables, functions, class.
134
+ - [x] Split error codes into DC01, DC02, DC03 for variables, functions, class.
113
135
  - [x] Should have different codes for ignoring name and ignoring whole definition (reserved DCxx0 - ignore name, DCxx1 - ignore definition).
114
136
  - [ ] Allow to disable each check separately using:
115
137
  - [ ] inline comment.
@@ -123,4 +145,28 @@ code base is implemented in.
123
145
  - [ ] --ignore-definitions-if-decorated-with
124
146
  - [ ] --ignore-names-if-inherits-from
125
147
  - [ ] --ignore-names-if-decorated-with
148
+ - [ ] --ignore-bodies-of
149
+ - [ ] --ignore-bodies-if-decorated-with
150
+ - [ ] --ignore-bodies-if-inherits-from
151
+ - [ ] --ignore-definitions
152
+ - [ ] --ignore-definitions-if-inherits-from
153
+ - [ ] --ignore-definitions-if-decorated-with
154
+ - Question: would it be possible to ignore only certain types of checks for a body, e.g. only variable attributes of TypedDict and still check usage of methods and properties?
155
+ - What expression would allow this type of precission?
126
156
  - [ ] Distinguish between definitions with same name, but different files.
157
+ - [ ] Repeated application of `deadcode` till the output stops changing.
158
+ - [ ] Unreachable code detection and fixing: this should only be scoped for if statements and only limited to primitive variables.
159
+ - [ ] `--fix --dry [filenames]` - only show whats about to change in the listed filenames.
160
+ - [ ] Benchmarking performance with larger projects (time, CPU and memory consumption) in order to optimize.
161
+ - [ ] `--fix` could accept a list of filenames as well (only those files would be changed, but the summary could would be full).
162
+ (This might be confusing, because filenames, which have to be considered are provided without any flag, --fix is expected to not accept arguments)
163
+ - [ ] pre-commit-hook.
164
+ - [ ] language server.
165
+ - [ ] Use only two digits for error codes instead of 3. Two is plenty and it simplifies usage a bit
166
+ - [ ] DC10: remove code after terminal statements like `raise`, `return`, `break`, `continue` and comes in the same scope.
167
+ - [ ] Add `ignore` and `per-file-ignores` command line and pyproject.toml options, which allows to skip some rules.
168
+ - [ ] Make sure that all rules are being skipped by `noqa` comment and all rules react to `noqa: rule_id` comments.
169
+ - [ ] Include package names into code item scope (dot-separated path), e.g. "package1.package2.module.class.method.variable".
170
+ - [ ] All options should be able to accept dot-separated path or a generic name, e.g. "marshmallow.Schema" vs "Schema",
171
+ documentation should cleary demonstrate the behaviour/example that "Schema" means "*.Schema".
172
+ - [ ] Redefinition of an existing name makes previous name unreachable, unless it is assigned somehow.
@@ -0,0 +1,176 @@
1
+ import os
2
+ import re
3
+ import shlex
4
+ import shutil
5
+ import sys
6
+ from pathlib import Path
7
+ from subprocess import PIPE, STDOUT, run
8
+ from typing import Union
9
+
10
+ ACTION_PATH = Path(os.environ["GITHUB_ACTION_PATH"])
11
+ ENV_PATH = ACTION_PATH / ".black-env"
12
+ ENV_BIN = ENV_PATH / ("Scripts" if sys.platform == "win32" else "bin")
13
+ OPTIONS = os.getenv("INPUT_OPTIONS", default="")
14
+ SRC = os.getenv("INPUT_SRC", default="")
15
+ JUPYTER = os.getenv("INPUT_JUPYTER") == "true"
16
+ BLACK_ARGS = os.getenv("INPUT_BLACK_ARGS", default="")
17
+ VERSION = os.getenv("INPUT_VERSION", default="")
18
+ USE_PYPROJECT = os.getenv("INPUT_USE_PYPROJECT") == "true"
19
+
20
+ BLACK_VERSION_RE = re.compile(r"^black([^A-Z0-9._-]+.*)$", re.IGNORECASE)
21
+ EXTRAS_RE = re.compile(r"\[.*\]")
22
+
23
+
24
+ def determine_version_specifier() -> str:
25
+ """Determine the version of Black to install.
26
+
27
+ The version can be specified either via the `with.version` input or via the
28
+ pyproject.toml file if `with.use_pyproject` is set to `true`.
29
+ """
30
+ if USE_PYPROJECT and VERSION:
31
+ print(
32
+ "::error::'with.version' and 'with.use_pyproject' inputs are "
33
+ "mutually exclusive.",
34
+ file=sys.stderr,
35
+ flush=True,
36
+ )
37
+ sys.exit(1)
38
+ if USE_PYPROJECT:
39
+ return read_version_specifier_from_pyproject()
40
+ elif VERSION and VERSION[0] in "0123456789":
41
+ return f"=={VERSION}"
42
+ else:
43
+ return VERSION
44
+
45
+
46
+ def read_version_specifier_from_pyproject() -> str:
47
+ if sys.version_info < (3, 11):
48
+ print(
49
+ "::error::'with.use_pyproject' input requires Python 3.11 or later.",
50
+ file=sys.stderr,
51
+ flush=True,
52
+ )
53
+ sys.exit(1)
54
+
55
+ import tomllib # type: ignore[import-not-found,unreachable]
56
+
57
+ try:
58
+ with Path("pyproject.toml").open("rb") as fp:
59
+ pyproject = tomllib.load(fp)
60
+ except FileNotFoundError:
61
+ print(
62
+ "::error::'with.use_pyproject' input requires a pyproject.toml file.",
63
+ file=sys.stderr,
64
+ flush=True,
65
+ )
66
+ sys.exit(1)
67
+
68
+ version = pyproject.get("tool", {}).get("black", {}).get("required-version")
69
+ if version is not None:
70
+ return f"=={version}"
71
+
72
+ arrays = [
73
+ pyproject.get("project", {}).get("dependencies"),
74
+ *pyproject.get("project", {}).get("optional-dependencies", {}).values(),
75
+ ]
76
+ for array in arrays:
77
+ version = find_black_version_in_array(array)
78
+ if version is not None:
79
+ break
80
+
81
+ if version is None:
82
+ print(
83
+ "::error::'black' dependency missing from pyproject.toml.",
84
+ file=sys.stderr,
85
+ flush=True,
86
+ )
87
+ sys.exit(1)
88
+
89
+ return version
90
+
91
+
92
+ def find_black_version_in_array(array: object) -> Union[str, None]:
93
+ if not isinstance(array, list):
94
+ return None
95
+ try:
96
+ for item in array:
97
+ # Rudimentary PEP 508 parsing.
98
+ item = item.split(";")[0]
99
+ item = EXTRAS_RE.sub("", item).strip()
100
+ if item == "black":
101
+ print(
102
+ "::error::Version specifier missing for 'black' dependency in "
103
+ "pyproject.toml.",
104
+ file=sys.stderr,
105
+ flush=True,
106
+ )
107
+ sys.exit(1)
108
+ elif m := BLACK_VERSION_RE.match(item):
109
+ return m.group(1).strip()
110
+ except TypeError:
111
+ pass
112
+
113
+ return None
114
+
115
+
116
+ run([sys.executable, "-m", "venv", str(ENV_PATH)], check=True)
117
+
118
+ version_specifier = determine_version_specifier()
119
+ if JUPYTER:
120
+ extra_deps = "[colorama,jupyter]"
121
+ else:
122
+ extra_deps = "[colorama]"
123
+ if version_specifier:
124
+ req = f"black{extra_deps}{version_specifier}"
125
+ else:
126
+ describe_name = ""
127
+ with open(ACTION_PATH / ".git_archival.txt", encoding="utf-8") as fp:
128
+ for line in fp:
129
+ if line.startswith("describe-name: "):
130
+ describe_name = line[len("describe-name: ") :].rstrip()
131
+ break
132
+ if not describe_name:
133
+ print("::error::Failed to detect action version.", file=sys.stderr, flush=True)
134
+ sys.exit(1)
135
+ # expected format is one of:
136
+ # - 23.1.0
137
+ # - 23.1.0-51-g448bba7
138
+ if describe_name.count("-") < 2:
139
+ # the action's commit matches a tag exactly, install exact version from PyPI
140
+ req = f"black{extra_deps}=={describe_name}"
141
+ else:
142
+ # the action's commit does not match any tag, install from the local git repo
143
+ req = f".{extra_deps}"
144
+ print(f"Installing {req}...", flush=True)
145
+ pip_proc = run(
146
+ [str(ENV_BIN / "python"), "-m", "pip", "install", req],
147
+ stdout=PIPE,
148
+ stderr=STDOUT,
149
+ encoding="utf-8",
150
+ cwd=ACTION_PATH,
151
+ )
152
+ if pip_proc.returncode:
153
+ print(pip_proc.stdout)
154
+ print("::error::Failed to install Black.", file=sys.stderr, flush=True)
155
+ sys.exit(pip_proc.returncode)
156
+
157
+
158
+ base_cmd = [str(ENV_BIN / "black")]
159
+ if BLACK_ARGS:
160
+ # TODO: remove after a while since this is deprecated in favour of SRC + OPTIONS.
161
+ proc = run(
162
+ [*base_cmd, *shlex.split(BLACK_ARGS)],
163
+ stdout=PIPE,
164
+ stderr=STDOUT,
165
+ encoding="utf-8",
166
+ )
167
+ else:
168
+ proc = run(
169
+ [*base_cmd, *shlex.split(OPTIONS), *shlex.split(SRC)],
170
+ stdout=PIPE,
171
+ stderr=STDOUT,
172
+ encoding="utf-8",
173
+ )
174
+ shutil.rmtree(ENV_PATH, ignore_errors=True)
175
+ print(proc.stdout)
176
+ sys.exit(proc.returncode)