77It doesn't recognise the "styles" dir anywhere (on the root, under "docs", under "_static"...).
88Not even changing ``html_static_path`` on ``conf.py`` worked.
99"""
10+ from __future__ import annotations
11+
1012import sys
1113from collections import defaultdict
1214from importlib import import_module
1315from pathlib import Path
1416from subprocess import check_output # nosec
1517from textwrap import dedent , indent
16- from typing import Optional , Dict , List , Set , Tuple , Union
1718
1819import attr
1920import click
@@ -55,15 +56,16 @@ class FileType:
5556
5657 text : str
5758 url : str
58- check : Union [ bool , int ]
59- autofix : Union [ bool , int ]
59+ check : bool | int
60+ autofix : bool | int
6061
6162 def __post_init__ (self ):
6263 """Warn about text that might render incorrectly."""
6364 if "`" in self .text :
64- raise RuntimeError (f"Remove all backticks from the text: { self .text } " )
65+ msg = f"Remove all backticks from the text: { self .text } "
66+ raise RuntimeError (msg )
6567
66- def __lt__ (self , other : " FileType" ) -> bool :
68+ def __lt__ (self , other : FileType ) -> bool :
6769 """Sort instances.
6870
6971 From the `docs <https://docs.python.org/3/howto/sorting.html#odd-and-ends>`_:
@@ -103,12 +105,12 @@ def autofix_str(self) -> str:
103105 return self ._pretty ("autofix" )
104106
105107 @property
106- def row (self ) -> Tuple [str , str , str ]:
108+ def row (self ) -> tuple [str , str , str ]:
107109 """Tuple for a table row."""
108110 return self .text_with_url , self .check_str , self .autofix_str
109111
110112
111- IMPLEMENTED_FILE_TYPES : Set [FileType ] = {
113+ IMPLEMENTED_FILE_TYPES : set [FileType ] = {
112114 FileType ("Any INI file" , f"{ READ_THE_DOCS_URL } plugins.html#ini-files" , True , True ),
113115 FileType ("Any JSON file" , f"{ READ_THE_DOCS_URL } plugins.html#json-files" , True , True ),
114116 FileType ("Any plain text file" , f"{ READ_THE_DOCS_URL } plugins.html#text-files" , True , False ),
@@ -118,7 +120,7 @@ def row(self) -> Tuple[str, str, str]:
118120 FileType (PYLINTRC , f"{ READ_THE_DOCS_URL } plugins.html#ini-files" , True , True ),
119121 FileType (SETUP_CFG , f"{ READ_THE_DOCS_URL } plugins.html#ini-files" , True , True ),
120122}
121- PLANNED_FILE_TYPES : Set [FileType ] = {
123+ PLANNED_FILE_TYPES : set [FileType ] = {
122124 FileType ("Any Markdown file" , "" , 280 , 0 ),
123125 FileType ("Any Terraform file" , "" , 318 , 0 ),
124126 FileType (".dockerignore" , "" , 8 , 8 ),
@@ -145,7 +147,7 @@ def __init__(self, filename: str) -> None:
145147 self .divider_end = RST_DIVIDER_END
146148 self .divider_from_here = RST_DIVIDER_FROM_HERE
147149
148- def write (self , lines : List [str ], divider : Optional [ str ] = None ) -> int :
150+ def write (self , lines : list [str ], divider : str | None = None ) -> int :
149151 """Write content to the file."""
150152 old_content = self .file .read_text ()
151153 if divider :
@@ -193,7 +195,6 @@ def write_plugins() -> int:
193195 ):
194196 header = plugin_class .filename
195197 if not header :
196- # module_name = file_class.__module__
197198 module = import_module (plugin_class .__module__ )
198199 header = (module .__doc__ or "" ).strip (" ." )
199200
@@ -234,7 +235,7 @@ def write_cli() -> int:
234235 parts .append (command )
235236 parts .append ("--help" )
236237 print (" " .join (parts ))
237- output = check_output (parts ).decode ().strip () # nosec
238+ output = check_output (parts ).decode ().strip () # noqa: S603
238239 blocks .append (
239240 clean_template .format (
240241 anchor = anchor , header = header , dashes = "-" * len (header ), long = dedent (long ), help = indent (output , " " )
@@ -252,20 +253,20 @@ def write_config() -> int:
252253 return DocFile ("configuration.rst" ).write (blocks , divider = "config-file" )
253254
254255
255- def rst_table (header : Tuple [str , ...], rows : List [ Tuple [str , ...]]) -> List [str ]:
256+ def rst_table (header : tuple [str , ...], rows : list [ tuple [str , ...]]) -> list [str ]:
256257 """Create a ReST table from header and rows."""
257258 blocks = [".. list-table::\n :header-rows: 1\n " ]
258259 num_columns = len (header )
259- for row in [header ] + rows :
260+ for row in [header , * rows ] :
260261 template = ("*" + " - {}\n " * num_columns ).rstrip ()
261262 blocks .append (indent (template .format (* row ), " " ))
262263 return blocks
263264
264265
265- def write_readme (file_types : Set [FileType ], divider : str ) -> int :
266+ def write_readme (file_types : set [FileType ], divider : str ) -> int :
266267 """Write the README."""
267268 # TODO: chore: quickstart.rst has some parts of README.rst as a copy/paste/change
268- rows : List [ Tuple [str , ...]] = []
269+ rows : list [ tuple [str , ...]] = []
269270 for file_type in sorted (file_types ):
270271 rows .append (file_type .row )
271272
@@ -281,9 +282,9 @@ class StyleLibraryRow: # pylint: disable=too-few-public-methods
281282 name : str
282283
283284
284- def _build_library (gitref : bool = True ) -> List [str ]:
285+ def _build_library (gitref : bool = True ) -> list [str ]:
285286 # pylint: disable=no-member
286- library : Dict [str , List [ Tuple ]] = defaultdict (list )
287+ library : dict [str , list [ tuple ]] = defaultdict (list )
287288 pre , post = (":gitref:" , "" ) if gitref else ("" , "_" )
288289 for path in sorted (builtin_styles ()): # type: Path
289290 style = BuiltinStyle .from_path (path )
0 commit comments