Commit Graph

96 Commits

Author SHA1 Message Date
Jason R. Coombs 9c93b7402b
gh-117348: restore import time performance of configparser (#117703)
Reduces import time by over 50% (10431µs vs 4350µs on Apple M3 Pro).
2024-04-14 11:10:09 +00:00
Jason R. Coombs 019143fecb
gh-117348: Refactored RawConfigParser._read for similicity and comprehensibility (#117372)
* Extract method for _read_inner, reducing complexity and indentation by 1.

* Extract method for _raise_all and yield ParseErrors from _read_inner.

Reduces complexity by 1 and reduces touch points for handling errors in _read_inner.

* Prefer iterators to splat expansion and literal indexing.

* Extract method for _strip_comments. Reduces complexity by 7.

* Model the file lines in a class to encapsulate the comment status and cleaned value.

* Encapsulate the read state as a dataclass

* Extract _handle_continuation_line and _handle_rest methods. Reduces complexity by 8.

* Reindent

* At least for now, collect errors in the ReadState

* Check for missing section header separately.

* Extract methods for _handle_header and _handle_option. Reduces complexity by 6.

* Remove unreachable code. Reduces complexity by 4.

* Remove unreachable branch

* Handle error condition early. Reduces complexity by 1.

* Add blurb

* Move _raise_all to ParsingError, as its behavior is most closely related to the exception class and not the reader.

* Split _strip* into separate methods.

* Refactor _strip_full to compute the strip just once and use 'not any' to determine the factor.

* Replace use of 'sys.maxsize' with direct computation of the stripped value.

* Extract has_comments as a dynamic property.

* Implement clean as a cached property.

* Model comment prefixes in the RawConfigParser within a prefixes namespace.

* Use a regular expression to search for the first match.

Avoids mutating variables and tricky logic and over-computing all of the starts when only the first is relevant.
2024-03-29 16:06:09 -04:00
Pedro Lacerda 54f7e14500
gh-66449: configparser: Add support for unnamed sections (#117273)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
2024-03-29 15:05:00 +00:00
David Röthlisberger b1bc37597f
gh-116957: configparser: Do post-process values after DuplicateOptionError (GH-116958)
If you catch DuplicateOptionError / DuplicateSectionError when reading a
config file (the intention is to skip invalid config files) and then
attempt to use the ConfigParser instance, any values it *had* read
successfully so far, were stored as a list instead of string! Later
`get` calls would raise "AttributeError: 'list' object has no attribute
'find'" from somewhere deep in the interpolation code.
2024-03-19 11:59:08 +02:00
Prince Roshan e800265aa1
gh-107625: configparser: Raise error if a missing value is continued (GH-107651)
Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
2024-03-06 14:05:54 +00:00
litlighilit 845e593c4e
Fix typo in configparser module docstring (#105652)
"zc.buildbot" -> "zc.buildout"
2023-06-11 15:06:42 +01:00
Victor Stinner 94d5f9827d
gh-105407: Remove unused imports in the stdlib (#105411) 2023-06-06 21:13:24 +00:00
Hugo van Kemenade 3f9c60f51e
gh-104886: Remove deprecated configparser.LegacyInterpolation (#104887)
Co-authored-by: Victor Stinner <vstinner@python.org>
2023-05-26 06:06:32 +00:00
Nikita Sobolev 199507b81a
gh-100520: Fix `rst` markup in `configparser` docstrings (#100524) 2022-12-26 17:08:49 +05:30
Gregory P. Smith 296e4efebb
gh-89336: Remove configparser APIs that were deprecated for 3.12 (#92503)
https://github.com/python/cpython/issue/89336: Remove configparser 3.12 deprecations.

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2022-06-21 14:31:25 -07:00
Hugo van Kemenade 75280944e5
bpo-46607: Add DeprecationWarning for LegacyInterpolation, deprecated in docs since 3.2 (GH-30927) 2022-04-05 08:15:11 -07:00
Brian Faherty fc115c9bde
bpo-41086: Add exception for uninstantiated interpolation (configparser) (GH-21062)
* Add exception for uninstantiated interpolation (configparser)

The current feedback when users try to pass an uninstantiated
interpolation into a ConfigParser is an error message that does not help
users solve the problem. This current error of `TypeError: before_set()
missing 1 required positional argument: 'value'` does not display until
the parser is used, which usually results in the assumption that
instantiation of the parser was done correctly. The new exception of
InterpolationTypeError, will be raised on the line where the
ConfigParser is instantiated. This will result in users see the line
that has the error in their backtrace for faster debugging.

There have been a number of bugs created in the issue tracker, which
could have been addressed by:
https://bugs.python.org/issue26831 and https://bugs.python.org/issue26469

* 📜🤖 Added by blurb_it.

* Replace custom Error with TypeError

Per feedback from @iritkatriel, the custom InterpolationTypeError has
been dropped in favour of a TypeError with a custom message, and the
unittests have been expanded.

* More verbose message

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2022-02-17 13:17:43 +01:00
Hugo van Kemenade e8659b47de
bpo-45173: Keep configparser deprecations until Python 3.12 (GH-30952)
* Revert "bpo-45173 Remove configparser deprecations"

This reverts commit df2284bc41.

* bpo-45173: Note these configparser deprecations will be removed in 3.12
2022-02-02 08:59:39 -08:00
Hugo van Kemenade 1fc41ae870
bpo-45173 Remove configparser deprecations (GH-28292)
In the configparser module, these have been deprecated since Python 3.2:

* the SafeConfigParser class,
* the filename property of the ParsingError class,
* the readfp method of the ConfigParser class,
2021-09-13 19:12:36 +02:00
jsnklln 2924bb1a56
bpo-38741: Definition of multiple ']' in header configparser (GH-17129)
Co-authored-by: Jason Killen <jason.killen@windsorcircle.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2021-07-13 15:54:06 +02:00
Jürgen Gmach 02ee819126
bpo-41963: document that ConfigParser strips off comments (GH-26197)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Laura Gutierrez Funderburk <58710704+lgfunderburk@users.noreply.github.com>
2021-05-18 18:11:23 +02:00
Inada Naoki 4827483f47
bpo-43510: Implement PEP 597 opt-in EncodingWarning. (GH-19481)
See [PEP 597](https://www.python.org/dev/peps/pep-0597/).

* Add `-X warn_default_encoding` and `PYTHONWARNDEFAULTENCODING`.
* Add EncodingWarning
* Add io.text_encoding()
* open(), TextIOWrapper() emits EncodingWarning when encoding is omitted and warn_default_encoding is enabled.
* _pyio.TextIOWrapper() uses UTF-8 as fallback default encoding used when failed to import locale module. (used during building Python)
* bz2, configparser, gzip, lzma, pathlib, tempfile modules use io.text_encoding().
* What's new entry
2021-03-29 12:28:14 +09:00
Woko 45d75faa72 fix typo in configparser doc (GH-12154) 2019-03-03 18:23:19 -08:00
Zackery Spytz e45473e3ca bpo-27351: Fix ConfigParser.read() documentation and docstring (GH-8123)
Switch "list" with "iterable" to match with the implementation.
2018-09-29 10:15:55 -06:00
Cheryl Sabella 33cd058f21 bpo-32108: Don't clear configparser values if key is assigned to itself (GH-7588) 2018-06-12 13:37:51 -07:00
Łukasz Langa 214f18e49f
bpo-33802: Do not interpolate in ConfigParser while reading defaults (GH-7524)
This solves a regression in logging config due to changes in BPO-23835.
2018-06-08 04:02:48 -07:00
John Reese 3a5b0d8988 bpo-33504: Migrate configparser from OrderedDict to dict. (#6819)
With 3.7+, dictionary are ordered by design.  Configparser still uses
collections.OrderedDict, which is unnecessary.  This updates the module
to use the standard dict implementation by default, and changes the
docs and tests to match.
2018-06-05 16:31:33 -07:00
Chris Bradbury 1d4a733cce bpo-33251: Prevent ConfigParser.items returning items present in vars. (#6446)
* bpo-33251: ConfigParser.items no longer returns items present in vars.

Documentation for `ConfigParser.items()` states:
'Items present in vars no longer appear in the result.'

This fix aligns behaviour to that specified in the documentation.
2018-04-23 12:16:17 -07:00
Vincent Michel e314853d57 bpo-31307: Make ConfigParser.read() accept bytes objects (GH-3420) 2017-11-02 15:47:04 +03:00
Łukasz Langa a5fab17fc1 bpo-23835: Restore legacy defaults= behavior for RawConfigParser (#3191)
The fix for bpo-23835 fixed ConfigParser behavior in defaults= handling.
Unfortunately, it caused a backwards compatibility regression with
RawConfigParser objects which allow for non-string values.

This commit restores the legacy behavior for RawConfigParser only.
2017-08-24 09:43:53 -07:00
James Tocknell 44e6ad8734 bpo-23835: Enforce that configparser defaults are strings (#2558)
* Enforce that configparser defaults are strings
* Update test_configparser.py
2017-08-21 15:46:30 -07:00
Serhiy Storchaka 5affd23e6f bpo-29762: More use "raise from None". (#569)
This hides unwanted implementation details from tracebacks.
2017-04-05 09:37:24 +03:00
David Ellis 85b8d01c91 bpo-29623: Make PathLike objects work with ConfigParser.read() (#242) 2017-03-03 20:14:27 +03:00
Łukasz Langa 47a9a4beda Fixes #24142: [configparser] always join multiline values to not leave the parser in an invalid state 2016-11-26 14:00:39 -08:00
Robert Collins f7a92673ab Issue #21159: Improve message in configparser.InterpolationMissingOptionError.
Patch from Łukasz Langa.
2015-08-14 11:47:41 +12:00
Robert Collins ac37ba0742 Issue #21159: Improve message in configparser.InterpolationMissingOptionError.
Patch from Łukasz Langa.
2015-08-14 11:11:35 +12:00
Łukasz Langa dfdd2f7ef8 Closes #18159: ConfigParser getters not available on SectionProxy 2014-09-15 02:08:41 -07:00
Łukasz Langa 949053bff2 Fix #19546: onfigparser exceptions expose implementation details. Patch by Claudiu Popa. 2014-09-04 01:36:33 -07:00
Serhiy Storchaka a26b3f183d Issue #20363. Fixed BytesWarning triggerred by test suite.
Patch by Berker Peksag.
2014-02-06 22:52:23 +02:00
Serhiy Storchaka bc27a050a7 Issue #20363. Fixed BytesWarning triggerred by test suite.
Patch by Berker Peksag.
2014-02-06 22:49:45 +02:00
Serhiy Storchaka ab0ac27d24 Issue #20315: Removed support for backward compatibility with early 2.x versions.
Removed backward compatibility alias curses.window.nooutrefresh which should
be removed in 2.3.
2014-01-20 21:35:06 +02:00
Serhiy Storchaka 7e52705ee3 Issue #20315: Removed support for backward compatibility with early 2.x versions. 2014-01-20 21:29:31 +02:00
Łukasz Langa 82276964c8 Merged fix for issue #18260 from 3.3 2013-06-23 19:12:12 +02:00
Łukasz Langa f9b4eb4d04 Fixed issue #18260: configparser TypeError on source name specified as bytes 2013-06-23 19:10:25 +02:00
Łukasz Langa f3d8fb142d fix character index in ExtendedInterpolation's exception message 2013-04-24 01:25:55 +02:00
Łukasz Langa fa608186b4 fix character index in ExtendedInterpolation's exception message 2013-04-24 01:25:18 +02:00
Łukasz Langa 6e410a2cdb Merged section order preservation fix when using `__setitem__` (issue #16820) 2013-01-01 22:36:33 +01:00
Łukasz Langa a821f82f66 configparser: preserve section order when using `__setitem__` (issue #16820) 2013-01-01 22:33:19 +01:00
Łukasz Langa 8d518970ce Merged `parser['DEFAULT'].__setitem__` fix (issue #16820) from 3.3. 2012-12-31 13:57:21 +01:00
Łukasz Langa 0210194d48 Fixes `__setitem__` on parser['DEFAULT'] reported in issue #16820. 2012-12-31 13:55:11 +01:00
Łukasz Langa 1dce0003a6 Merged `parser.clean()` fix (issue #16820) from 3.2 through 3.3. 2012-12-31 03:43:37 +01:00
Łukasz Langa 0dc5ab41f0 Merged `parser.clean()` fix (issue #16820) from 3.2. 2012-12-31 03:41:54 +01:00
Łukasz Langa 3a8479a583 Fixes `parser.clean()` reported in issue #16820. 2012-12-31 03:38:39 +01:00
Łukasz Langa 641bb66070 Merged fix for #15803 from 3.2 through 3.3 2012-12-31 02:26:11 +01:00
Łukasz Langa 97eefc105e Merged fix for #15803 from 3.2 2012-12-31 02:25:28 +01:00