mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-09 21:04:17 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -2,34 +2,32 @@
|
|||
(C) Ronny Pfannschmidt, Holger Krekel -- MIT licensed
|
||||
"""
|
||||
from __future__ import annotations
|
||||
from typing import (
|
||||
Callable,
|
||||
Iterator,
|
||||
Mapping,
|
||||
Optional,
|
||||
Tuple,
|
||||
TypeVar,
|
||||
Union,
|
||||
TYPE_CHECKING,
|
||||
NoReturn,
|
||||
NamedTuple,
|
||||
overload,
|
||||
cast,
|
||||
)
|
||||
|
||||
import os
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Iterator
|
||||
from typing import Mapping
|
||||
from typing import NamedTuple
|
||||
from typing import NoReturn
|
||||
from typing import Optional
|
||||
from typing import overload
|
||||
from typing import Tuple
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TypeVar
|
||||
from typing import Union
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Final
|
||||
from typing import Final
|
||||
|
||||
__all__ = ["IniConfig", "ParseError", "COMMENTCHARS", "iscommentline"]
|
||||
__all__ = ['IniConfig', 'ParseError', 'COMMENTCHARS', 'iscommentline']
|
||||
|
||||
from .exceptions import ParseError
|
||||
from . import _parse
|
||||
from ._parse import COMMENTCHARS, iscommentline
|
||||
|
||||
_D = TypeVar("_D")
|
||||
_T = TypeVar("_T")
|
||||
_D = TypeVar('_D')
|
||||
_T = TypeVar('_T')
|
||||
|
||||
|
||||
class SectionWrapper:
|
||||
|
|
@ -110,7 +108,7 @@ class IniConfig:
|
|||
self,
|
||||
path: str | os.PathLike[str],
|
||||
data: str | None = None,
|
||||
encoding: str = "utf-8",
|
||||
encoding: str = 'utf-8',
|
||||
) -> None:
|
||||
self.path = os.fspath(path)
|
||||
if data is None:
|
||||
|
|
@ -125,17 +123,17 @@ class IniConfig:
|
|||
|
||||
for lineno, section, name, value in tokens:
|
||||
if section is None:
|
||||
raise ParseError(self.path, lineno, "no section header defined")
|
||||
raise ParseError(self.path, lineno, 'no section header defined')
|
||||
self._sources[section, name] = lineno
|
||||
if name is None:
|
||||
if section in self.sections:
|
||||
raise ParseError(
|
||||
self.path, lineno, f"duplicate section {section!r}"
|
||||
self.path, lineno, f'duplicate section {section!r}',
|
||||
)
|
||||
sections_data[section] = {}
|
||||
else:
|
||||
if name in self.sections[section]:
|
||||
raise ParseError(self.path, lineno, f"duplicate name {name!r}")
|
||||
raise ParseError(self.path, lineno, f'duplicate name {name!r}')
|
||||
assert value is not None
|
||||
sections_data[section][name] = value
|
||||
|
||||
|
|
@ -172,7 +170,7 @@ class IniConfig:
|
|||
|
||||
@overload
|
||||
def get(
|
||||
self, section: str, name: str, default: _D, convert: None = None
|
||||
self, section: str, name: str, default: _D, convert: None = None,
|
||||
) -> str | _D:
|
||||
...
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
from __future__ import annotations
|
||||
from .exceptions import ParseError
|
||||
|
||||
from typing import NamedTuple
|
||||
|
||||
from .exceptions import ParseError
|
||||
|
||||
COMMENTCHARS = "#;"
|
||||
|
||||
COMMENTCHARS = '#;'
|
||||
|
||||
|
||||
class _ParsedLine(NamedTuple):
|
||||
|
|
@ -25,19 +26,19 @@ def parse_lines(path: str, line_iter: list[str]) -> list[_ParsedLine]:
|
|||
# new section
|
||||
elif name is not None and data is None:
|
||||
if not name:
|
||||
raise ParseError(path, lineno, "empty section name")
|
||||
raise ParseError(path, lineno, 'empty section name')
|
||||
section = name
|
||||
result.append(_ParsedLine(lineno, section, None, None))
|
||||
# continuation
|
||||
elif name is None and data is not None:
|
||||
if not result:
|
||||
raise ParseError(path, lineno, "unexpected value continuation")
|
||||
raise ParseError(path, lineno, 'unexpected value continuation')
|
||||
last = result.pop()
|
||||
if last.name is None:
|
||||
raise ParseError(path, lineno, "unexpected value continuation")
|
||||
raise ParseError(path, lineno, 'unexpected value continuation')
|
||||
|
||||
if last.value:
|
||||
last = last._replace(value=f"{last.value}\n{data}")
|
||||
last = last._replace(value=f'{last.value}\n{data}')
|
||||
else:
|
||||
last = last._replace(value=data)
|
||||
result.append(last)
|
||||
|
|
@ -47,30 +48,30 @@ def parse_lines(path: str, line_iter: list[str]) -> list[_ParsedLine]:
|
|||
def _parseline(path: str, line: str, lineno: int) -> tuple[str | None, str | None]:
|
||||
# blank lines
|
||||
if iscommentline(line):
|
||||
line = ""
|
||||
line = ''
|
||||
else:
|
||||
line = line.rstrip()
|
||||
if not line:
|
||||
return None, None
|
||||
# section
|
||||
if line[0] == "[":
|
||||
if line[0] == '[':
|
||||
realline = line
|
||||
for c in COMMENTCHARS:
|
||||
line = line.split(c)[0].rstrip()
|
||||
if line[-1] == "]":
|
||||
if line[-1] == ']':
|
||||
return line[1:-1], None
|
||||
return None, realline.strip()
|
||||
# value
|
||||
elif not line[0].isspace():
|
||||
try:
|
||||
name, value = line.split("=", 1)
|
||||
if ":" in name:
|
||||
name, value = line.split('=', 1)
|
||||
if ':' in name:
|
||||
raise ValueError()
|
||||
except ValueError:
|
||||
try:
|
||||
name, value = line.split(":", 1)
|
||||
name, value = line.split(':', 1)
|
||||
except ValueError:
|
||||
raise ParseError(path, lineno, "unexpected line: %r" % line)
|
||||
raise ParseError(path, lineno, 'unexpected line: %r' % line)
|
||||
return name.strip(), value.strip()
|
||||
# continuation
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# file generated by setuptools_scm
|
||||
# don't change, don't track in version control
|
||||
from __future__ import annotations
|
||||
__version__ = version = '2.0.0'
|
||||
__version_tuple__ = version_tuple = (2, 0, 0)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Final
|
||||
from typing import Final
|
||||
|
||||
|
||||
class ParseError(Exception):
|
||||
|
|
@ -17,4 +18,4 @@ class ParseError(Exception):
|
|||
self.msg = msg
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.path}:{self.lineno + 1}: {self.msg}"
|
||||
return f'{self.path}:{self.lineno + 1}: {self.msg}'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue