[issue35954] Incoherent type conversion in configparser

2019-06-09 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

> IMO we should at most clarify in the docs.

This makes sense, I will update my PR tomorrow.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35954] Incoherent type conversion in configparser

2019-06-07 Thread Tal Einat


Tal Einat  added the comment:

This is indeed inconsistent, but it's a minor issue that has been this way for 
a long time and is easily worked around. IMO changing it would create more 
problems than leaving it as-is.

IMO we should at most clarify in the docs.

--
nosy: +taleinat
versions: +Python 3.9 -Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35954] Incoherent type conversion in configparser

2019-02-19 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

Other methods validate explicitly their arguments with _validate_value_types 
for example.

Here it raises KeyError which does not seem to be the appropriate exception. 
ConfigParser implementing the mapping protocol it seems weird to me to have

>>> a = 123
>>> config[a] = {}
>>> config[a]
KeyError: 123

I would have prefered a TypeError to be raised on __setitem__ but this is now 
documented behavior.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35954] Incoherent type conversion in configparser

2019-02-18 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Other methods do not convert key to string too.

What is a use case for having a non-string section name?

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35954] Incoherent type conversion in configparser

2019-02-18 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

> Btw: The name "read_dict" [1] as well as its docstring say exactly the 
> opposite of what it does. It acts as a "save_dict". Maybe that can be fixed 
> on the go ...


The name `read_dict` is correct, it reads from the dict given as parameter and 
changing the name would break existing code.

I opened a new PR with the change to convert keys to strings in __getitem__, I 
did not wrap `key = str(key)` in a try-except as it's not done in read_dict(). 
This way both __getitem__ and read_dict() will fail the same way.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35954] Incoherent type conversion in configparser

2019-02-18 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
keywords: +patch
pull_requests: +11943
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35954] Incoherent type conversion in configparser

2019-02-10 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
nosy: +remi.lapeyre

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35954] Incoherent type conversion in configparser

2019-02-10 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +lukasz.langa

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35954] Incoherent type conversion in configparser

2019-02-10 Thread Adeokkuw


Adeokkuw  added the comment:

Btw: The name "read_dict" [1] as well as its docstring say exactly the opposite 
of what it does. It acts as a "save_dict". Maybe that can be fixed on the go ...

The docstring

""" [...]
All types held in the dictionary are converted to strings during
reading, including section names, option names and keys. [...]
"""

actually implies what is my proposal here: Convert arguments to str during 
lookup as well.

```
def __getitem__(self, key):
if key != self.default_section and not self.has_section(key):
raise KeyError(key)
return self._proxies[key]
```

to

```
def __getitem__(self, key):

try: key = str(key)
except (WhateverError, IsRelevantHereError): raise KeyError(key)

if key != self.default_section and not self.has_section(key):
raise KeyError(key)
return self._proxies[key]
```

[1] https://github.com/python/cpython/blob/3.7/Lib/configparser.py

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35954] Incoherent type conversion in configparser

2019-02-10 Thread Adeokkuw


New submission from Adeokkuw :

configparser interface implicitly converts all objects to str (read_dict [sic] 
on line 724 of "3.7/Lib/configparser.py") while saving but not while lookup 
(__getitem__ on line 956).

MWE:

```
config = configparser.ConfigParser()
config[123] = {}
print(config[123])
```
~> KeyError: 123

--
components: Library (Lib)
messages: 335150
nosy: Adeokkuw
priority: normal
severity: normal
status: open
title: Incoherent type conversion in configparser
type: behavior
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com