Skip to content

Commit

Permalink
implement review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Dec 19, 2022
1 parent 10583b8 commit 0253ff1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ repos:
- id: setup-cfg-fmt
args: [--include-version-classifiers]
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 22.12.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.991'
hooks:
- id: mypy
args: []
additional_dependencies:
- "pytest==7.2.0"
- "pytest==7.2.0"
- "tomli"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ build-backend = "setuptools.build_meta"
[tool.setuptools_scm]

[tool.mypy]
strict = true
strict = true
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ url = https://github.com/RonnyPfannschmidt/iniconfig
author = Ronny Pfannschmidt, Holger Krekel
author_email = pensource@ronnypfannschmidt.de, holger.krekel@gmail.com
license = MIT
license_file = LICENSE
license_files = LICENSE
platforms = unix, linux, osx, cygwin, win32
classifiers =
Development Status :: 4 - Beta
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup
from setuptools import setup # type: ignore[import]

# Ensures that setuptools_scm is installed, so wheels get proper versions
import setuptools_scm # noqa
import setuptools_scm # type: ignore[import]


def local_scheme(version: object) -> str:
Expand Down
22 changes: 14 additions & 8 deletions src/iniconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
cast,
)

import os

if TYPE_CHECKING:
from typing_extensions import Final
Expand All @@ -35,7 +36,7 @@ class SectionWrapper:
config: Final[IniConfig]
name: Final[str]

def __init__(self, config: IniConfig, name: str):
def __init__(self, config: IniConfig, name: str) -> None:
self.config = config
self.name = name

Expand All @@ -57,7 +58,7 @@ def __iter__(self) -> Iterator[str]:
section: Mapping[str, str] = self.config.sections.get(self.name, {})

def lineof(key: str) -> int:
return self.config.lineof(self.name, key) # type: ignore
return self.config.lineof(self.name, key) # type: ignore[return-value]

yield from sorted(section, key=lineof)

Expand All @@ -71,30 +72,35 @@ class IniConfig:
sections: Final[Mapping[str, Mapping[str, str]]]

def __init__(
self, path: str, data: str | None = None, encoding: str = "utf-8"
self,
path: str | os.PathLike[str],
data: str | None = None,
encoding: str = "utf-8",
) -> None:
self.path = str(path) # convenience
self.path = os.fspath(path)
if data is None:
with open(self.path, encoding=encoding) as fp:
data = fp.read()

tokens = _parse.parse_lines(path, data.splitlines(True))
tokens = _parse.parse_lines(self.path, data.splitlines(True))

self._sources = {}
sections_data: dict[str, dict[str, str]]
self.sections = sections_data = {}

for lineno, section, name, value in tokens:
if section is None:
raise ParseError(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(path, lineno, f"duplicate section {section!r}")
raise ParseError(
self.path, lineno, f"duplicate section {section!r}"
)
sections_data[section] = {}
else:
if name in self.sections[section]:
raise ParseError(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

Expand Down
4 changes: 2 additions & 2 deletions src/iniconfig/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class ParseError(Exception):
lineno: Final[int]
msg: Final[str]

def __init__(self, path: str, lineno: int, msg: str):
Exception.__init__(self, path, lineno, msg)
def __init__(self, path: str, lineno: int, msg: str) -> None:
super().__init__(path, lineno, msg)
self.path = path
self.lineno = lineno
self.msg = msg
Expand Down

0 comments on commit 0253ff1

Please sign in to comment.