Skip to content

Commit

Permalink
Replace dataclass with SimpleNamespace.
Browse files Browse the repository at this point in the history
Reduces import time by over 50% (10431µs vs 4350µs on Apple M3 Pro).
  • Loading branch information
jaraco committed Apr 10, 2024
1 parent 8091be3 commit 727e4ed
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@
between keys and values are surrounded by spaces.
"""

# Do not import dataclasses; overhead is unacceptable.

from collections.abc import Iterable, MutableMapping
from collections import ChainMap as _ChainMap
import contextlib
from dataclasses import dataclass, field
import functools
import io
import itertools
import os
import re
import sys
import types

__all__ = ("NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
"NoOptionError", "InterpolationError", "InterpolationDepthError",
Expand Down Expand Up @@ -537,19 +539,21 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,
"found: %r" % (rest,))


@dataclass
class _ReadState:
elements_added : set[str] = field(default_factory=set)
class _ReadState(types.SimpleNamespace):
elements_added : set[str]
cursect : dict[str, str] | None = None
sectname : str | None = None
optname : str | None = None
lineno : int = 0
indent_level : int = 0
errors : list[ParsingError] = field(default_factory=list)
errors : list[ParsingError]

def __init__(self):
self.elements_added = set()
self.errors = list()


@dataclass
class _Prefixes:
class _Prefixes(types.SimpleNamespace):
full : Iterable[str]
inline : Iterable[str]

Expand Down

0 comments on commit 727e4ed

Please sign in to comment.