Title: mypy infers conditional expression of Dict[str, object] to be object instead of union · Issue #7835 · python/mypy · GitHub
Open Graph Title: mypy infers conditional expression of Dict[str, object] to be object instead of union · Issue #7835 · python/mypy
X Title: mypy infers conditional expression of Dict[str, object] to be object instead of union · Issue #7835 · python/mypy
Description: Are you reporting a bug, or opening a feature request? Bug Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. from typing import Dict from dataclasses import dataclass @dataclass class F...
Open Graph Description: Are you reporting a bug, or opening a feature request? Bug Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. from typing import Dict from datacla...
X Description: Are you reporting a bug, or opening a feature request? Bug Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. from typing import Dict from datacla...
Opengraph URL: https://github.com/python/mypy/issues/7835
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mypy infers conditional expression of Dict[str, object] to be object instead of union","articleBody":"* Are you reporting a bug, or opening a feature request?\r\n\r\nBug\r\n* Please insert below the code you are checking with mypy,\r\n or a mock-up repro if the source is private. \r\n```python3\r\nfrom typing import Dict\r\nfrom dataclasses import dataclass\r\n\r\n\r\n@dataclass\r\nclass Foo:\r\n bar: bool\r\n\r\n\r\n@dataclass\r\nclass Bar:\r\n baz: bool\r\n\r\n\r\nfoo_registry: Dict[str, Foo] = {}\r\nbar_registry: Dict[str, Bar] = {}\r\n\r\nuse_foo = True\r\n\r\nregistry = foo_registry if use_foo else bar_registry\r\nregistry.get('asdfsdf')\r\n```\r\n* What is the actual behavior/output?\r\n\r\nOn the last line, mypy infers that `registry` has the type `object`\r\n```\r\nerror: \"object\" has no attribute \"get\"\r\n```\r\n\r\n* What is the behavior/output you expect?\r\n\r\nmypy infers that the type of `registry` to be `Union[Dict[str, Foo], Dict[str, Bar]]` but it looks like this behavior may have been undone by https://github.com/python/mypy/pull/5095 ?\r\n\r\n* What are the versions of mypy and Python you are using?\r\n\r\nmypy 0.740 and Python 3.7.2\r\n\r\nDo you see the same issue after installing mypy from Git master?\r\n\r\nI ran into other issues doing this, but I am on the latest release.\r\n\r\n* What are the mypy flags you are using? (For example --strict-optional)\r\n\r\nI'm using `--strict --warn-unreachable` though this occurs with no flags at all.\r\n\r\nThanks for reading.","author":{"url":"https://github.com/scascketta","@type":"Person","name":"scascketta"},"datePublished":"2019-10-31T16:38:17Z","url":"https://github.com/python/mypy/issues/7835"}
| 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:9ee7e852-9a0c-6089-d180-fe6f362b26ec |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C310:102136:50CD24:6BDADF:6B002FFE |
| html-safe-nonce | e43daf91ff72c5c31e490802b0a14a6bb9b7eafbc35fdc6daa0a529e01419ca0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzEwOjEwMjEzNjo1MENEMjQ6NkJEQURGOjZCMDAyRkZFIiwidmlzaXRvcl9pZCI6IjgzMDg3NDYxNDI5NDI3NjkxNTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ea339804120b3c596acfcaa1372c47359d0bcee1e62f6cfa618e99392c168764 |
| hovercard-subject-tag | issue:515579579 |
| 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/7835/issue_layout |
| twitter:image | https://opengraph.githubassets.com/657d92471c7d8f447b7d4d3e08ddebcc69643ad1612645bff233b3d4661b9ee7/python/mypy/issues/7835 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/657d92471c7d8f447b7d4d3e08ddebcc69643ad1612645bff233b3d4661b9ee7/python/mypy/issues/7835 |
| og:image:alt | Are you reporting a bug, or opening a feature request? Bug Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. from typing import Dict from datacla... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | scascketta |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width