Title: Overloading based on an argument which can be str or None doesn't seem to work · Issue #3805 · python/mypy · GitHub
Open Graph Title: Overloading based on an argument which can be str or None doesn't seem to work · Issue #3805 · python/mypy
X Title: Overloading based on an argument which can be str or None doesn't seem to work · Issue #3805 · python/mypy
Description: 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.i...
Open Graph Description: 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 giv...
X Description: 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 giv...
Opengraph URL: https://github.com/python/mypy/issues/3805
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Overloading based on an argument which can be str or None doesn't seem to work","articleBody":"When digging in to an issue with the stubs for configparser in the stdlib (https://github.com/python/typeshed/pull/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).\r\n\r\nI have attempted to annotate this using overloading (because I believe that it's more precise than a union in this case):\r\n\r\n```py\r\n@overload\r\ndef items(self, section: str = ..., raw: bool = ..., vars: _section = ...) -> Iterable[Tuple[str, str]]: ...\r\n\r\n@overload\r\ndef items(self, section: None = ..., raw: bool = ..., vars: _section = ...) -> Iterable[Tuple[str, SectionProxy]]: ...\r\n```\r\n\r\nbut I hit the following errors running `./tests/mypy_test.py` in typeshed:\r\n\r\n```\r\nrunning mypy --python-version 3.6 --strict-optional # with 624 files\r\nstdlib/3/configparser.pyi:103: error: Signature of \"items\" incompatible with supertype \"Mapping\"\r\nstdlib/3/configparser.pyi:104: error: Overloaded function signatures 1 and 2 overlap with incompatible return types\r\n```\r\n\r\nThe first one is expected (and, in fact, is the reason that this annotation has a `#type: ignore` on it in typeshed currently).\r\n\r\nThe second one, however, I don't expect because (with `--strict-optional`) I don't think None and str should overlap.","author":{"url":"https://github.com/OddBloke","@type":"Person","name":"OddBloke"},"datePublished":"2017-08-07T02:05:25Z","url":"https://github.com/python/mypy/issues/3805"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9c444470-0f11-8ed3-f15d-1b2baf0e366e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DBA6:7F150:141ECE2:1A75EAF:6B000BFB |
| html-safe-nonce | 85df9f3b388aa8950311eec2515b401f443af2f1e06def8c119aace1bf95a1d0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQkE2OjdGMTUwOjE0MUVDRTI6MUE3NUVBRjo2QjAwMEJGQiIsInZpc2l0b3JfaWQiOiI3MjU3MTExOTcxNjA5MTg1Mjc1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ab2b5b9714509014eacdb7a4637557f55e4b5ae632ed5f810fd1ab0ca8190d99 |
| hovercard-subject-tag | issue:248289913 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/3805/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ca0c24b38816aa4026a1b148fa034e58ee50eb68cb0fa527c80bf5e2acc28034/python/mypy/issues/3805 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ca0c24b38816aa4026a1b148fa034e58ee50eb68cb0fa527c80bf5e2acc28034/python/mypy/issues/3805 |
| og:image:alt | 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 giv... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | OddBloke |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width