Skip to content

Commit

Permalink
Merge branch 'cpython'
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Aug 18, 2024
2 parents a090089 + ef8f595 commit 8443b29
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
37 changes: 18 additions & 19 deletions backports/configparser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,18 @@

from __future__ import annotations

from collections.abc import MutableMapping
# Do not import dataclasses; overhead is unacceptable (gh-117703)

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

__all__ = (
"NoSectionError",
Expand Down Expand Up @@ -578,28 +579,25 @@ def _interpolate_some( # noqa: C901
)


@dataclass
class _ReadState:
elements_added: set[str] = field(default_factory=set)
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)

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]

@dataclass
class _Prefixes:
full: Iterable[str]
inline: Iterable[str]
def __init__(self):
self.elements_added = set()
self.errors = list()


class _Line(str):
def __new__(cls, val, *args, **kwargs):
return super().__new__(cls, val)

def __init__(self, val, prefixes: _Prefixes):
def __init__(self, val, prefixes):
self.prefixes = prefixes

@functools.cached_property
Expand Down Expand Up @@ -705,8 +703,9 @@ def __init__(
if allow_no_value:
self._optcre = re.compile(self._OPT_NV_TMPL.format(delim=d), re.VERBOSE)
else:
self._optcre = re.compile(self._OPT_TMPL.format(delim=d), re.VERBOSE)
self._prefixes = _Prefixes(
self._optcre = re.compile(self._OPT_TMPL.format(delim=d),
re.VERBOSE)
self._prefixes = types.SimpleNamespace(
full=tuple(comment_prefixes or ()),
inline=tuple(inline_comment_prefixes or ()),
)
Expand Down
5 changes: 2 additions & 3 deletions tests/test_configparser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import collections
import io
import os
import pathlib
import textwrap
import unittest

Expand Down Expand Up @@ -777,12 +776,12 @@ def test_read_returns_file_list(self):
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
# check when we pass only a Path object:
cf = self.newconfig()
parsed_files = cf.read(pathlib.Path(file1), encoding="utf-8")
parsed_files = cf.read(os_helper.FakePath(file1), encoding="utf-8")
self.assertEqual(parsed_files, [file1])
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
# check when we passed both a filename and a Path object:
cf = self.newconfig()
parsed_files = cf.read([pathlib.Path(file1), file1], encoding="utf-8")
parsed_files = cf.read([os_helper.FakePath(file1), file1], encoding="utf-8")
self.assertEqual(parsed_files, [file1, file1])
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
# check when we pass only missing files:
Expand Down

0 comments on commit 8443b29

Please sign in to comment.