inifile: add missing attributes (#10273)

And make many attributes read-only. The primary entry point to this module in `IniFile` (or its subclass
`AppIniFile`). Since the config file is read (from `filename`) and
parsed (using the `dialect`) in the `IniFile` constructor, modifying
attributes like `IniFile.filename` or `IniFile.dialect` after
construction is likely to cause problems.
This commit is contained in:
Jeff Dairiki
2023-06-07 15:00:49 -07:00
committed by GitHub
parent b0a3917145
commit 4849ddd74a
2 changed files with 41 additions and 10 deletions

View File

@@ -6,3 +6,18 @@ inifile.iter_from_file
inifile.iteritems
inifile.reraise
inifile.string_types
# Attributes that should be treated as read-only and thus are annotated
# with @property
inifile.Dialect.ns_sep
inifile.Dialect.kv_sep
inifile.Dialect.quotes
inifile.Dialect.true
inifile.Dialect.false
inifile.Dialect.comments
inifile.Dialect.allow_escaping
inifile.Dialect.linesep
inifile.IniData.dialect
inifile.IniFile.filename
inifile.IniFile.encoding
inifile.IniFile.is_new

View File

@@ -1,4 +1,4 @@
from _typeshed import StrOrBytesPath, StrPath, SupportsKeysAndGetItem
from _typeshed import StrPath, SupportsKeysAndGetItem
from collections.abc import Container, Iterable, Iterator, Mapping, MutableMapping, Sequence
from typing import TypeVar, overload
from typing_extensions import Literal, TypeAlias
@@ -16,14 +16,6 @@ _Token: TypeAlias = (
def get_app_dir(app_name: str, roaming: bool = ..., force_posix: bool = ...) -> str: ...
class Dialect:
ns_sep: str
kv_sep: str
quotes: Sequence[str]
true: Sequence[str]
false: Sequence[str]
comments: Container[str]
allow_escaping: bool
linesep: str | None
def __init__(
self,
ns_sep: str = ...,
@@ -35,6 +27,22 @@ class Dialect:
allow_escaping: bool = ...,
linesep: str | None = ...,
) -> None: ...
@property
def ns_sep(self) -> str: ...
@property
def kv_sep(self) -> str: ...
@property
def quotes(self) -> Sequence[str]: ...
@property
def true(self) -> Sequence[str]: ...
@property
def false(self) -> Sequence[str]: ...
@property
def comments(self) -> Container[str]: ...
@property
def allow_escaping(self) -> bool: ...
@property
def linesep(self) -> str | None: ...
def get_actual_linesep(self) -> str: ...
def get_strippable_lineseps(self) -> str: ...
def kv_serialize(self, key, val: str | None) -> str | None: ...
@@ -52,6 +60,8 @@ default_dialect: Dialect
class IniData(MutableMapping[str, str]):
def __init__(self, mapping: Mapping[str, str] | None = ..., dialect: Dialect | None = ...) -> None: ...
@property
def dialect(self) -> Dialect: ...
@property
def is_dirty(self) -> bool: ...
def get_updated_lines(self, line_iter: Iterable[_Token] | None = ...) -> list[_Token]: ...
def discard(self) -> None: ...
@@ -99,7 +109,13 @@ class IniData(MutableMapping[str, str]):
def __delitem__(self, name: str) -> None: ...
class IniFile(IniData):
def __init__(self, filename: StrOrBytesPath | int, encoding: str | None = ..., dialect: Dialect | None = ...) -> None: ...
def __init__(self, filename: StrPath, encoding: str | None = ..., dialect: Dialect | None = ...) -> None: ...
@property
def filename(self) -> str: ...
@property
def encoding(self) -> str | None: ...
@property
def is_new(self) -> bool: ...
def save(self, create_folder: bool = ...) -> None: ...
class AppIniFile(IniFile):