You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Overloading based on an argument which can be str or None doesn't seem to work #3805
When digging in to an issue with the stubs for configparser in the stdlib (python/typeshed#1527), I discovered that RawConfigParser.items() has two very different modes of operation. When it is given a section name (as a string, parser.items('name')), it will (with a little processing that shouldn't affect the types) return an iterable of tuples containing that sections keys and values (both of which are strings). When it is not given a section name (parser.items()), it instead returns an iterable of tuples containing the names and contents of the sections of the parser itself (the names are strings, and the contents are SectionProxy instances).
I have attempted to annotate this using overloading (because I believe that it's more precise than a union in this case):
I don't think it's related to #3295. The problem (with the example as written) is that both overloads can be called without arguments, so the error is correct. Note that the real function in fact does not work when called with None. Try using
Well, that seems extremely obvious now you've pointed it all out. :-p Thanks for taking the time!
I've updated the typeshed PR (and I'll consider filing some issues/PRs about improving the output of these warnings in the morning; I'll flatter myself by thinking I was only a couple of hints away from grokking this myself ;-).
Activity
OddBloke commentedon Aug 7, 2017
This is in the same realm as #3295, but as there's been a fair bit of discussion there, I didn't want to add to it without being sure.
Add comment explaining the status of RawConfigParser.items
gvanrossum commentedon Aug 7, 2017
I don't think it's related to #3295. The problem (with the example as written) is that both overloads can be called without arguments, so the error is correct. Note that the real function in fact does not work when called with
None. Try usingbut add back the other args.
Also note that using
AbstractSetmakes the argument-less signature compatible withMutableMapping.items()so no# type: ignoreis needed.OddBloke commentedon Aug 7, 2017
Well, that seems extremely obvious now you've pointed it all out. :-p Thanks for taking the time!
I've updated the typeshed PR (and I'll consider filing some issues/PRs about improving the output of these warnings in the morning; I'll flatter myself by thinking I was only a couple of hints away from grokking this myself ;-).
gvanrossum commentedon Aug 8, 2017
Don't feel bad! I end up having to reinvent this regularly myself when it appears in a new context.
Add comment explaining the status of RawConfigParser.items
Add comment explaining the status of RawConfigParser.items
Add comment explaining the status of RawConfigParser.items
Make configparser.RawConfigParser use SectionProxy where appropriate (#…