|
28 | 28 | Dict, |
29 | 29 | Generic, |
30 | 30 | List, |
| 31 | + OrderedDict, |
31 | 32 | Sequence, |
32 | 33 | Tuple, |
33 | 34 | TypeVar, |
|
47 | 48 | T_ConfigParser = TypeVar("T_ConfigParser", bound="GitConfigParser") |
48 | 49 | T_OMD_value = TypeVar("T_OMD_value", str, bytes, int, float, bool, None) |
49 | 50 |
|
50 | | -if sys.version_info[:3] < (3, 7, 2): |
51 | | - # typing.Ordereddict not added until Python 3.7.2. |
52 | | - from collections import OrderedDict |
53 | | - |
54 | | - OrderedDict_OMD = OrderedDict |
55 | | -else: |
56 | | - from typing import OrderedDict |
57 | | - |
58 | | - OrderedDict_OMD = OrderedDict[str, List[T_OMD_value]] # type: ignore[assignment, misc] |
| 51 | +OrderedDict_OMD = OrderedDict[str, List[T_OMD_value]] |
59 | 52 |
|
60 | 53 | # ------------------------------------------------------------- |
61 | 54 |
|
@@ -259,7 +252,7 @@ def setlast(self, key: str, value: Any) -> None: |
259 | 252 |
|
260 | 253 | self.getall(key)[-1] = value |
261 | 254 |
|
262 | | - def get(self, key: str, default: Union[_T, None] = None) -> Union[_T, None]: |
| 255 | + def get(self, key: str, default: Union[_T, None] = None) -> Union[_T, None]: # type: ignore[override] |
263 | 256 | return super().get(self._key(key), [default])[-1] |
264 | 257 |
|
265 | 258 | def getall(self, key: str) -> List[_T]: |
@@ -381,7 +374,7 @@ def __init__( |
381 | 374 | Reference to repository to use if ``[includeIf]`` sections are found in |
382 | 375 | configuration files. |
383 | 376 | """ |
384 | | - cp.RawConfigParser.__init__(self, dict_type=_OMD, allow_no_value=True) |
| 377 | + cp.RawConfigParser.__init__(self, dict_type=cast(Any, _OMD), allow_no_value=True) |
385 | 378 | self._dict: Callable[..., _OMD] |
386 | 379 | self._defaults: _OMD |
387 | 380 | self._sections: _OMD |
@@ -458,7 +451,7 @@ def release(self) -> None: |
458 | 451 |
|
459 | 452 | try: |
460 | 453 | self.write() |
461 | | - except IOError: |
| 454 | + except OSError: |
462 | 455 | _logger.error("Exception during destruction of GitConfigParser", exc_info=True) |
463 | 456 | except ReferenceError: |
464 | 457 | # This happens in Python 3... and usually means that some state cannot be |
@@ -759,7 +752,7 @@ def read(self) -> None: # type: ignore[override] |
759 | 752 | with open(file_path, "rb") as fp: |
760 | 753 | file_ok = True |
761 | 754 | self._read(fp, fp.name) |
762 | | - except IOError: |
| 755 | + except OSError: |
763 | 756 | continue |
764 | 757 |
|
765 | 758 | # Read includes and append those that we didn't handle yet. We expect all |
@@ -909,7 +902,7 @@ def write(self) -> None: |
909 | 902 |
|
910 | 903 | def _assure_writable(self, method_name: str) -> None: |
911 | 904 | if self.read_only: |
912 | | - raise IOError("Cannot execute non-constant method %s.%s" % (self, method_name)) |
| 905 | + raise OSError(f"Cannot execute non-constant method {self}.{method_name}") |
913 | 906 |
|
914 | 907 | def add_section(self, section: "cp._SectionName") -> None: |
915 | 908 | """Assures added options will stay in order.""" |
|
0 commit comments