This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: configparser: before_get() method of class Interpolation has positional 'parser' parameter that is not used.
Type: Stage: resolved
Components: Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: rprosser, wolma
Priority: normal Keywords:

Created on 2016-11-25 10:55 by rprosser, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Repositories containing patches
https://hg.python.org/cpython/file/3.5/Lib/configparser.py
https://hg.python.org/cpython/file/3.5/Lib/configparser.py
Messages (5)
msg281697 - (view) Author: Richard Prosser (rprosser) Date: 2016-11-25 10:55
From https://hg.python.org/cpython/file/3.5/Lib/configparser.py (for example):

358class Interpolation:
359    """Dummy interpolation that passes the value through with no changes."""
360
361    def before_get(self, parser, section, option, value, defaults):
362        return value

but a typical invocation misses out the 'parser' parameter:

796            return self._interpolation.before_get(self, section, option, value,
797                                                  d)

As far as I can see, this is not a keyword-only parameter, yet PyCharm seems to treat it as one. So maybe this is some new behaviour that I don't understand yet but there seems to be a fault here, IMO.

I am using Python 3.5.2 on Windows 7, after using the 'futurize' tool on some legacy 2.7 code that extended self._interpolate (which no longer exists in 3+).
msg281701 - (view) Author: Wolfgang Maier (wolma) * Date: 2016-11-25 11:21
Ah, that's kind of confusing at first!

the 'self' in the method calls (like on line 796) refers to the ConfigParser instance and will be bound to the parser parameter. The first parameter, the 'self' in the interpolation method definition, is not provided as usual because the method is called on an _interpolation instance. => Nothing special here except the names of the arguments
msg281705 - (view) Author: Richard Prosser (rprosser) Date: 2016-11-25 12:27
Thanks for the prompt reply. I still don't fully understand yet but there aren't any errors reported so I presume that it is OK.

There is another related matter however: PyCharm (2016.2.3) indicates that a get() method signature does not match that of the Mapping class one ...

557
558class RawConfigParser(MutableMapping):

761
762    def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET):


There are other similar cases I believe.

So I am not sure what to make of that, either.
msg281711 - (view) Author: Richard Prosser (rprosser) Date: 2016-11-25 12:46
Ah. Something like self._interpolation.before_get(self, section, option, value, d) could be better written as self._interpolation.before_get(parser=self, ...) - but that would require keyword arguments to be used throughout.

I still don't grock the apparent 'get()' signature mis-match however.
msg281715 - (view) Author: Wolfgang Maier (wolma) * Date: 2016-11-25 13:21
> Ah. Something like self._interpolation.before_get(self, section, option, value, d) could be better written as self._interpolation.before_get(parser=self, ...)

Yep, that's roughly what I was trying to explain.

> I still don't grock the apparent 'get()' signature mis-match however.

There is not much special here either. RawConfigParser inherits from MutableMapping, which in turn inherits from Mapping, which defines a get method, which RawConfigParser overwrites. The overwritten and the overwriting method *do* have different parameters, but I don't see why that matters.

In general, this does not look like a topic for the Python bug tracker (you are not reporting a bug, but you try to understand how correctly working code does its job), but rather for news:comp.lang.python or a PyCharm mailing list.
History
Date User Action Args
2022-04-11 14:58:40adminsetgithub: 72987
2016-11-25 16:19:41r.david.murraysetstatus: open -> closed
resolution: not a bug
stage: resolved
2016-11-25 13:21:33wolmasetmessages: + msg281715
2016-11-25 12:46:39rprossersetmessages: + msg281711
2016-11-25 12:27:50rprossersethgrepos: + hgrepo363
messages: + msg281705
2016-11-25 11:21:59wolmasetnosy: + wolma
type: compile error ->
messages: + msg281701
2016-11-25 10:55:51rprossercreate