`configparser.RawConfigParser` stub does not account for non-string options
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start with stdlib/configparser.pyi around line 133 and compare the RawConfigParser.set signature with the behavior shown in the issue. Run the provided script through mypy to reproduce the false positives, then verify that boolean, integer, and bytes values are accepted without errors while the existing get behavior remains covered.
Written by the indexing model from the issue text.
Description
The stub for configparser.RawConfigParser.set has its value argument typed as str | None (source) when it can accept lots of other types and is leading to a false positive in mypy for me.
Consider this valid script:
from configparser import RawConfigParser
cfg = RawConfigParser()
cfg.add_section("default")
cfg.set("default", "some_option1", True)
r1 = cfg.get("default", "some_option1")
print(r1, type(r1))
cfg.set("default", "some_option2", 1)
r2 = cfg.get("default", "some_option2")
print(r2, type(r2))
cfg.set("default", "some_option3", b"bytes")
r3 = cfg.get("default", "some_option3")
print(r3, type(r3))
It prints:
True <class 'bool'>
1 <class 'int'>
b'bytes' <class 'bytes'>
However, mypy flags this code for the reason described above:
test.py:6: error: Argument 3 to "set" of "RawConfigParser" has incompatible type "bool"; expected "Optional[str]"
test.py:11: error: Argument 3 to "set" of "RawConfigParser" has incompatible type "int"; expected "Optional[str]"
test.py:15: error: Argument 3 to "set" of "RawConfigParser" has incompatible type "bytes"; expected "Optional[str]"
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 73
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python/typeshed
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
project: infrastructure
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
stubs: improvement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100