|
143 | 143 | between keys and values are surrounded by spaces.
|
144 | 144 | """
|
145 | 145 |
|
146 |
| -from collections.abc import MutableMapping |
| 146 | +# Do not import dataclasses; overhead is unacceptable (gh-117703) |
| 147 | + |
| 148 | +from collections.abc import Iterable, MutableMapping |
147 | 149 | from collections import ChainMap as _ChainMap
|
148 | 150 | import contextlib
|
149 |
| -from dataclasses import dataclass, field |
150 | 151 | import functools
|
151 | 152 | import io
|
152 | 153 | import itertools
|
153 | 154 | import os
|
154 | 155 | import re
|
155 | 156 | import sys
|
156 |
| -from typing import Iterable |
| 157 | +import types |
157 | 158 |
|
158 | 159 | __all__ = ("NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
|
159 | 160 | "NoOptionError", "InterpolationError", "InterpolationDepthError",
|
@@ -538,29 +539,26 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,
|
538 | 539 | "found: %r" % (rest,))
|
539 | 540 |
|
540 | 541 |
|
541 |
| -@dataclass |
542 | 542 | class _ReadState:
|
543 |
| - elements_added : set[str] = field(default_factory=set) |
| 543 | + elements_added : set[str] |
544 | 544 | cursect : dict[str, str] | None = None
|
545 | 545 | sectname : str | None = None
|
546 | 546 | optname : str | None = None
|
547 | 547 | lineno : int = 0
|
548 | 548 | indent_level : int = 0
|
549 |
| - errors : list[ParsingError] = field(default_factory=list) |
550 |
| - |
| 549 | + errors : list[ParsingError] |
551 | 550 |
|
552 |
| -@dataclass |
553 |
| -class _Prefixes: |
554 |
| - full : Iterable[str] |
555 |
| - inline : Iterable[str] |
| 551 | + def __init__(self): |
| 552 | + self.elements_added = set() |
| 553 | + self.errors = list() |
556 | 554 |
|
557 | 555 |
|
558 | 556 | class _Line(str):
|
559 | 557 |
|
560 | 558 | def __new__(cls, val, *args, **kwargs):
|
561 | 559 | return super().__new__(cls, val)
|
562 | 560 |
|
563 |
| - def __init__(self, val, prefixes: _Prefixes): |
| 561 | + def __init__(self, val, prefixes): |
564 | 562 | self.prefixes = prefixes
|
565 | 563 |
|
566 | 564 | @functools.cached_property
|
@@ -653,7 +651,7 @@ def __init__(self, defaults=None, dict_type=_default_dict,
|
653 | 651 | else:
|
654 | 652 | self._optcre = re.compile(self._OPT_TMPL.format(delim=d),
|
655 | 653 | re.VERBOSE)
|
656 |
| - self._prefixes = _Prefixes( |
| 654 | + self._prefixes = types.SimpleNamespace( |
657 | 655 | full=tuple(comment_prefixes or ()),
|
658 | 656 | inline=tuple(inline_comment_prefixes or ()),
|
659 | 657 | )
|
|
0 commit comments