Fix typing related to iniconfig

iniconfig now has typing stubs which reveal a couple issues.
This commit is contained in:
Ran Benita 2020-10-17 18:18:24 +03:00
parent 0a258f534f
commit e5e47c1097
3 changed files with 8 additions and 5 deletions

View File

@ -54,6 +54,8 @@ repos:
- id: mypy - id: mypy
files: ^(src/|testing/) files: ^(src/|testing/)
args: [] args: []
additional_dependencies:
- iniconfig>=1.1.0
- repo: local - repo: local
hooks: hooks:
- id: rst - id: rst

View File

@ -27,7 +27,7 @@ def _parse_ini_config(path: Path) -> iniconfig.IniConfig:
Raise UsageError if the file cannot be parsed. Raise UsageError if the file cannot be parsed.
""" """
try: try:
return iniconfig.IniConfig(path) return iniconfig.IniConfig(str(path))
except iniconfig.ParseError as exc: except iniconfig.ParseError as exc:
raise UsageError(str(exc)) from exc raise UsageError(str(exc)) from exc

View File

@ -32,6 +32,7 @@ from weakref import WeakKeyDictionary
import attr import attr
import py import py
from iniconfig import IniConfig from iniconfig import IniConfig
from iniconfig import SectionWrapper
import pytest import pytest
from _pytest import timing from _pytest import timing
@ -785,10 +786,10 @@ class Pytester:
"""Write a tox.ini file with 'source' as contents.""" """Write a tox.ini file with 'source' as contents."""
return self.makefile(".ini", tox=source) return self.makefile(".ini", tox=source)
def getinicfg(self, source: str) -> IniConfig: def getinicfg(self, source: str) -> SectionWrapper:
"""Return the pytest section from the tox.ini config file.""" """Return the pytest section from the tox.ini config file."""
p = self.makeini(source) p = self.makeini(source)
return IniConfig(p)["pytest"] return IniConfig(str(p))["pytest"]
def makepyprojecttoml(self, source: str) -> Path: def makepyprojecttoml(self, source: str) -> Path:
"""Write a pyproject.toml file with 'source' as contents. """Write a pyproject.toml file with 'source' as contents.
@ -1541,9 +1542,9 @@ class Testdir:
"""See :meth:`Pytester.makeini`.""" """See :meth:`Pytester.makeini`."""
return py.path.local(str(self._pytester.makeini(source))) return py.path.local(str(self._pytester.makeini(source)))
def getinicfg(self, source) -> py.path.local: def getinicfg(self, source: str) -> SectionWrapper:
"""See :meth:`Pytester.getinicfg`.""" """See :meth:`Pytester.getinicfg`."""
return py.path.local(str(self._pytester.getinicfg(source))) return self._pytester.getinicfg(source)
def makepyprojecttoml(self, source) -> py.path.local: def makepyprojecttoml(self, source) -> py.path.local:
"""See :meth:`Pytester.makepyprojecttoml`.""" """See :meth:`Pytester.makepyprojecttoml`."""