Title: Inconsistent behavior w.r.t missing builtins · Issue #14547 · python/mypy · GitHub
Open Graph Title: Inconsistent behavior w.r.t missing builtins · Issue #14547 · python/mypy
X Title: Inconsistent behavior w.r.t missing builtins · Issue #14547 · python/mypy
Description: Issue Some of the builtins fixtures are sparse to the point that they're missing even the declaration of dict, list, tuple etc. types. The austerity is justified by improved tests performance, and it's understood that specific tests can ...
Open Graph Description: Issue Some of the builtins fixtures are sparse to the point that they're missing even the declaration of dict, list, tuple etc. types. The austerity is justified by improved tests performance, and ...
X Description: Issue Some of the builtins fixtures are sparse to the point that they're missing even the declaration of dict, list, tuple etc. types. The austerity is justified by improved tests performance, ...
Opengraph URL: https://github.com/python/mypy/issues/14547
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent behavior w.r.t missing builtins","articleBody":"# Issue\r\n\r\nSome of the builtins fixtures are sparse to the point that they're missing even the declaration of `dict`, `list`, `tuple` etc. types. The austerity is justified by improved tests performance, and it's understood that specific tests can specify a broader fixture without slowing down other tests.\r\n\r\nHowever, some core features rely on the presence of those types, e.g.\r\n- functions' `**kwargs`\r\n- modules' `__annotations__`\r\n- `namedtuple`'s attributes like `_field_types`\r\n\r\nI've observed 3 different strategies used to handle the types absence:\r\n- **crash** (example: [`**kwargs` handling](https://github.com/python/mypy/blob/e778a58066f23982d5cbe1df5317d6540c5902fd/mypy/types.py#L3607))\r\n- **give up** (example: [`__annotations__` not being added](https://github.com/python/mypy/blob/bac9e77eaeb36c0535bc05cb1faf6eced25b8af1/mypy/semanal.py#L636-L639))\r\n- **fallback to `object`** (example: [`NamedTuple` attributes](https://github.com/python/mypy/blob/dcf910e05fdcff00b1fb9a8b9ca85f9a6667b946/mypy/semanal_namedtuple.py#L484-L486))\r\n\r\nI think we should recommend and, ideally, consolidate on one strategy.\r\n\r\n# Motivation\r\n\r\nCase in point: Recently while implementing #14526, I had to \"play\" a whack-a-mole with unrelated tests breaking. I've used `**kw` which required me to add `dict` to a number of builtins fixtures, which in turn caused `__annotations__` to materialize where they didn't before, and failed some other tests.\r\n\r\nI think ideally we shouldn't have this whack-a-mole, and tests should be less brittle.\r\n\r\n# Recommendation\r\n\r\nWhich strategy to adopt? While it's good practice to structure code to be more testable, I think it's normally discouraged to have code paths that are only due to testing. Since those builtins should universally exist in \"production\", I think **crash** should be our strategy.\r\n\r\nSince code typically relies only on the presence of those classes (not their methods), we can put in place a rule (validated by tests) that any builtins fixture must define a baseline of types, even if empty. This shouldn't affect performance greatly, and provide a comfortable baseline.","author":{"url":"https://github.com/ikonst","@type":"Person","name":"ikonst"},"datePublished":"2023-01-28T16:18:02Z","url":"https://github.com/python/mypy/issues/14547"}
| 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:90a5aacb-7cd1-18d6-fc08-877507513475 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A8E6:3FDF0C:5084F7:6BB2CF:6B002F13 |
| html-safe-nonce | 237445efae8f546c5e34b76adc13582f107e6cc43c2434c0b5900a92e0122ce9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOEU2OjNGREYwQzo1MDg0Rjc6NkJCMkNGOjZCMDAyRjEzIiwidmlzaXRvcl9pZCI6IjQ3NTkwMDc5NTk3MzA2MzA0MTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 040b83f0a69ff903180e7d776cfefb6b1767d199ea3a5659bab5b1aacd53de0e |
| hovercard-subject-tag | issue:1560917904 |
| 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/14547/issue_layout |
| twitter:image | https://opengraph.githubassets.com/51ec21d5e2bf41e42ba927a9a6d4e4804fd415c650bf2c5d79b8f4ada94526b3/python/mypy/issues/14547 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/51ec21d5e2bf41e42ba927a9a6d4e4804fd415c650bf2c5d79b8f4ada94526b3/python/mypy/issues/14547 |
| og:image:alt | Issue Some of the builtins fixtures are sparse to the point that they're missing even the declaration of dict, list, tuple etc. types. The austerity is justified by improved tests performance, and ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ikonst |
| 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