Title: arg-type error when inheriting from NamedTuple · Issue #11160 · python/mypy · GitHub
Open Graph Title: arg-type error when inheriting from NamedTuple · Issue #11160 · python/mypy
X Title: arg-type error when inheriting from NamedTuple · Issue #11160 · python/mypy
Description: Bug Report mypy does not identify NamedTuple as a base type when passing objects from a subclass in function calls. However, everything works as expected when using a custom base class. To Reproduce (Write your steps here:) from typing i...
Open Graph Description: Bug Report mypy does not identify NamedTuple as a base type when passing objects from a subclass in function calls. However, everything works as expected when using a custom base class. To Reproduc...
X Description: Bug Report mypy does not identify NamedTuple as a base type when passing objects from a subclass in function calls. However, everything works as expected when using a custom base class. To Reproduc...
Opengraph URL: https://github.com/python/mypy/issues/11160
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"arg-type error when inheriting from NamedTuple","articleBody":"\u003c!--\r\n If you're new to mypy and you're not sure whether what you're experiencing is a mypy bug, please see the \"Question and Help\" form\r\n instead.\r\n-->\r\n\r\n**Bug Report**\r\n\r\n\u003c!--\r\nNote: If the problem you are reporting is about a specific library function, then the typeshed tracker is better suited\r\nfor this report: https://github.com/python/typeshed/issues\r\n-->\r\n\r\n`mypy` does not identify `NamedTuple` as a base type when passing objects from a subclass in function calls.\r\nHowever, everything works as expected when using a custom base class.\r\n\r\n**To Reproduce**\r\n\r\n(Write your steps here:)\r\n\r\n```python\r\nfrom typing import NamedTuple\r\n\r\n\r\nclass Base:\r\n def __repr__(self):\r\n return \"Base\"\r\n\r\n\r\nclass Foo(Base):\r\n def __repr__(self):\r\n return \"Foo\"\r\n\r\n\r\nclass Bar(NamedTuple):\r\n name: str = \"Bar\"\r\n\r\n\r\ndef print_base(obj: Base) -> None:\r\n print(obj)\r\n\r\n\r\ndef print_namedtuple(obj: NamedTuple) -> None:\r\n print(obj._asdict())\r\n\r\n\r\nprint_base(Foo())\r\nprint_namedtuple(Bar())\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nNo error.\r\n\r\n**Actual Behavior**\r\n\r\n```tmp\\test.py:27:18: error: Argument 1 to \"print_namedtuple\" has incompatible type \"Bar\"; expected \"NamedTuple\" [arg-type]```\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: 0.910\r\n- Mypy command-line flags: NA\r\n- Mypy configuration options from `mypy.ini` (and other config files): \r\n`pyproject.toml`:\r\n```toml\r\n[tool.mypy]\r\nexclude = \"build|doc|tests\"\r\nshow_column_numbers = true\r\nshow_error_codes = true\r\nstrict = false\r\nwarn_return_any = true\r\nwarn_unused_configs = true\r\n\r\n[[tool.mypy.overrides]]\r\nmodule = [\"numpy\", \"setuptools\"]\r\nignore_missing_imports = true\r\n\r\n```\r\n- Python version used: miniconda environment, python 3.9.7\r\n- Operating system and version: Windows 10\r\n\r\n\u003c!--\r\nYou can freely edit this text, please remove all the lines\r\nyou believe are unnecessary.\r\n-->\r\n","author":{"url":"https://github.com/lgiraldi","@type":"Person","name":"lgiraldi"},"datePublished":"2021-09-21T15:25:55Z","url":"https://github.com/python/mypy/issues/11160"}
| 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:5abd9e5c-5251-4dc9-72d4-8ddf8558d850 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B5EE:3A7693:2383783:3030F19:6B002A6C |
| html-safe-nonce | acdc71dc097164124d6738f4453db0415bd45634224ea3bfe7c7cf1d7cac1a3f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNUVFOjNBNzY5MzoyMzgzNzgzOjMwMzBGMTk6NkIwMDJBNkMiLCJ2aXNpdG9yX2lkIjoiOTY0NTkxNjUyOTQzNDQwNDkyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e5cfc50783f852e9881163a13693d6d7193ed38679f869b3d6878bd7b8f68c0e |
| hovercard-subject-tag | issue:1002709279 |
| 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/11160/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ecb6aba31fd6477aeff20b8dc361296b6216cb3f93bfb86953d179b816cf7205/python/mypy/issues/11160 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ecb6aba31fd6477aeff20b8dc361296b6216cb3f93bfb86953d179b816cf7205/python/mypy/issues/11160 |
| og:image:alt | Bug Report mypy does not identify NamedTuple as a base type when passing objects from a subclass in function calls. However, everything works as expected when using a custom base class. To Reproduc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lgiraldi |
| 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