Title: Simple type checks in ctor called inside function not errroring · Issue #8531 · python/mypy · GitHub
Open Graph Title: Simple type checks in ctor called inside function not errroring · Issue #8531 · python/mypy
X Title: Simple type checks in ctor called inside function not errroring · Issue #8531 · python/mypy
Description: I'm new to using type hints in Python and stumbled upon a case where I expected mypy to error but it did not. I narrowed it down and it seems that a check in ctor is not checked when called inside a function. Example not triggering type ...
Open Graph Description: I'm new to using type hints in Python and stumbled upon a case where I expected mypy to error but it did not. I narrowed it down and it seems that a check in ctor is not checked when called inside ...
X Description: I'm new to using type hints in Python and stumbled upon a case where I expected mypy to error but it did not. I narrowed it down and it seems that a check in ctor is not checked when called ins...
Opengraph URL: https://github.com/python/mypy/issues/8531
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Simple type checks in ctor called inside function not errroring","articleBody":"I'm new to using type hints in Python and stumbled upon a case where I expected mypy to error but it did not. I narrowed it down and it seems that a check in ctor is not checked when called inside a function.\r\n\r\n#### Example not triggering type error:\r\n\r\n```\r\n#!/usr/bin/env python3\r\n\r\nclass TestClass:\r\n def __init__(self,\r\n verbose: bool):\r\n pass\r\n\r\ndef main():\r\n bla = TestClass(\"Foo\")\r\n\r\nmain()\r\n```\r\nIt doesn't error as expected:\r\n```\r\nmypy script.py\r\nSuccess: no issues found in 1 source file\r\n```\r\nWith `--script` it works\r\n```\r\nmypy --strict script.py\r\nscript.py:10: error: Function is missing a return type annotation\r\nscript.py:10: note: Use \"-> None\" if function does not return a value\r\nscript.py:11: error: Argument 1 to \"TestClass\" has incompatible type \"str\"; expected \"bool\"\r\nscript.py:14: error: Call to untyped function \"main\" in typed context\r\nFound 3 errors in 1 file (checked 1 source file)\r\n```\r\n\r\n#### Example correctly triggering type error:\r\n\r\n```\r\n#!/usr/bin/env python3\r\n\r\nclass TestClass:\r\n def __init__(self,\r\n verbose: bool):\r\n pass\r\n\r\nbla = TestClass(\"Foo\")\r\n```\r\nIt triggers the error as it probably should:\r\n```\r\nmypy script.py \r\nscript.py:10: error: Argument 1 to \"TestClass\" has incompatible type \"str\"; expected \"bool\"\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\nAnd also with `--strict` it - of course - works:\r\n```\r\nmypy --strict script.py\r\nscript.py:8: error: Argument 1 to \"TestClass\" has incompatible type \"str\"; expected \"bool\"\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\n#### Versions\r\n```\r\nmypy --version\r\nmypy 0.770\r\n```\r\n\r\n```\r\npython --version\r\nPython 3.8.2\r\n```\r\n\r\nWith `--strict` it works:","author":{"url":"https://github.com/julianoes","@type":"Person","name":"julianoes"},"datePublished":"2020-03-13T08:48:48Z","url":"https://github.com/python/mypy/issues/8531"}
| 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:c2486e53-c327-b5b2-1c82-1c0f94eba989 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 998A:609A0:2BA4A3A:38FCD82:6B000A54 |
| html-safe-nonce | 33bf16313c77b12faa1380bcce161424664da831466614685ee1682cfebd0f9f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OThBOjYwOUEwOjJCQTRBM0E6MzhGQ0Q4Mjo2QjAwMEE1NCIsInZpc2l0b3JfaWQiOiIyNjUwMzc3ODk1ODU1MjYyMjkyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c463fb965a76b68af81c1ab14d6db77dee78f55d33a7b30d3eac103fc921c613 |
| hovercard-subject-tag | issue:580455499 |
| 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/8531/issue_layout |
| twitter:image | https://opengraph.githubassets.com/40456b3d1018d70f96c33b6a042615d29b439ee968eca4300247bc560a818734/python/mypy/issues/8531 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/40456b3d1018d70f96c33b6a042615d29b439ee968eca4300247bc560a818734/python/mypy/issues/8531 |
| og:image:alt | I'm new to using type hints in Python and stumbled upon a case where I expected mypy to error but it did not. I narrowed it down and it seems that a check in ctor is not checked when called inside ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | julianoes |
| 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