Title: Possible regression when narrowing using isinstance · Issue #16462 · python/mypy · GitHub
Open Graph Title: Possible regression when narrowing using isinstance · Issue #16462 · python/mypy
X Title: Possible regression when narrowing using isinstance · Issue #16462 · python/mypy
Description: Bug Report Type narrowing using isinstance with 1.7 behaves differently from 1.6 for seemingly valid code. To Reproduce import typing class A: def write(self) -> str: return "A" # succeeds def eq1(self, other: typing.Any) -> bool: if oth...
Open Graph Description: Bug Report Type narrowing using isinstance with 1.7 behaves differently from 1.6 for seemingly valid code. To Reproduce import typing class A: def write(self) -> str: return "A" # succeeds def eq1(...
X Description: Bug Report Type narrowing using isinstance with 1.7 behaves differently from 1.6 for seemingly valid code. To Reproduce import typing class A: def write(self) -> str: return "A" # succ...
Opengraph URL: https://github.com/python/mypy/issues/16462
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Possible regression when narrowing using isinstance","articleBody":"**Bug Report**\r\n\r\nType narrowing using `isinstance` with 1.7 behaves differently from 1.6 for seemingly valid code.\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nimport typing\r\n\r\nclass A:\r\n def write(self) -> str:\r\n return \"A\"\r\n\r\n # succeeds\r\n def eq1(self, other: typing.Any) -> bool:\r\n if other:\r\n if isinstance(other, self.__class__):\r\n return self.write() == other.write()\r\n return False\r\n\r\n # fails\r\n def eq2(self, other: typing.Any) -> bool:\r\n if other and isinstance(other, self.__class__):\r\n return self.write() == other.write()\r\n return False\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nThe `eq1` and `eq2` should both be valid code. `eq2` fails under 1.7 but succeeded under 1.6.\r\n\r\n**Actual Behavior**\r\n\r\n```\r\nfile.py:15: error: Returning Any from function declared to return \"bool\" [no-any-return]\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\n**Your Environment**\r\n\r\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\r\n\r\n- Mypy version used: 1.7.0\r\n- Mypy command-line flags:\r\n- Mypy configuration options from `mypy.ini` (and other config files):\r\n\r\n```\r\n# Global options:\r\n\r\n[mypy]\r\nignore_missing_imports = True\r\nfollow_imports = silent\r\nstrict = True\r\n```\r\n\r\n- Python version used:\r\n\r\nPython 3.12 macos-arm64\r\n\r\n\u003c!-- You can freely edit this text, please remove all the lines you believe are unnecessary. -->\r\n","author":{"url":"https://github.com/cmeyer","@type":"Person","name":"cmeyer"},"datePublished":"2023-11-11T18:13:43Z","url":"https://github.com/python/mypy/issues/16462"}
| 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:e4e84663-37e9-f674-30a3-cf70a6580a94 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9044:11BB24:20F53EE:2CB1681:6B001CF7 |
| html-safe-nonce | b13880f410108ce617aa58e7ebb282a7621b9b95851077372ef1d5a27b00c522 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDQ0OjExQkIyNDoyMEY1M0VFOjJDQjE2ODE6NkIwMDFDRjciLCJ2aXNpdG9yX2lkIjoiMjUyMzc0NDI5NDEyMDk4Nzg5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 26182851cb8fdd7e867821ccfc81aecb5c7b69a63d4141803d5ea8a3ffa90db7 |
| hovercard-subject-tag | issue:1989066524 |
| 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/16462/issue_layout |
| twitter:image | https://opengraph.githubassets.com/934789c67911dcc9e3ad1c8f8b7b4e15532c936f6ca94486da688b332cf8e3dd/python/mypy/issues/16462 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/934789c67911dcc9e3ad1c8f8b7b4e15532c936f6ca94486da688b332cf8e3dd/python/mypy/issues/16462 |
| og:image:alt | Bug Report Type narrowing using isinstance with 1.7 behaves differently from 1.6 for seemingly valid code. To Reproduce import typing class A: def write(self) -> str: return "A" # succeeds def eq1(... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cmeyer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width