Title: list is not equivalent to typing.List under combination of generics and futures · Issue #6130 · pydantic/pydantic · GitHub
Open Graph Title: list is not equivalent to typing.List under combination of generics and futures · Issue #6130 · pydantic/pydantic
X Title: list is not equivalent to typing.List under combination of generics and futures · Issue #6130 · pydantic/pydantic
Description: Initial Checks I have searched GitHub for a duplicate issue and I'm sure this is something new I have searched Google & StackOverflow for a solution and couldn't find anything I have read and followed the docs and still think this is a b...
Open Graph Description: Initial Checks I have searched GitHub for a duplicate issue and I'm sure this is something new I have searched Google & StackOverflow for a solution and couldn't find anything I have read and follo...
X Description: Initial Checks I have searched GitHub for a duplicate issue and I'm sure this is something new I have searched Google & StackOverflow for a solution and couldn't find anything I have re...
Opengraph URL: https://github.com/pydantic/pydantic/issues/6130
X: @github
Domain: redirect.github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"list is not equivalent to typing.List under combination of generics and futures","articleBody":"### Initial Checks\n\n- [X] I have searched GitHub for a duplicate issue and I'm sure this is something new\n- [X] I have searched Google & StackOverflow for a solution and couldn't find anything\n- [X] I have read and followed [the docs](https://docs.pydantic.dev) and still think this is a bug\n- [X] I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like [FastAPI](https://fastapi.tiangolo.com) or [mypy](https://mypy.readthedocs.io/en/stable))\n\n\n### Description\n\nThis is a strange one - under the below conditions, exchanging `typing.List` for the more modern `list` produces the below error. I can't reproduce in a simpler example than this - it looks to me like a bug in pydantic:\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"pydantic/validators.py\", line 751, in pydantic.validators.find_validators\r\nTypeError: issubclass() arg 1 must be a class\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n File \"{path_to_test}/test.py\", line 11, in \u003cmodule>\r\n outer = Outer[\"Inner\"]\r\n File \"{path_to_pydantic}/pydantic/generics.py\", line 163, in __class_getitem__\r\n _prepare_model_fields(created_model, fields, instance_type_hints, typevars_map)\r\n File \"{path_to_pydantic}/pydantic/generics.py\", line 389, in _prepare_model_fields\r\n field.prepare()\r\n File \"pydantic/fields.py\", line 552, in pydantic.fields.ModelField.prepare\r\n File \"pydantic/fields.py\", line 758, in pydantic.fields.ModelField._type_analysis\r\n File \"pydantic/fields.py\", line 808, in pydantic.fields.ModelField._create_sub_type\r\n File \"pydantic/fields.py\", line 436, in pydantic.fields.ModelField.__init__\r\n File \"pydantic/fields.py\", line 557, in pydantic.fields.ModelField.prepare\r\n File \"pydantic/fields.py\", line 831, in pydantic.fields.ModelField.populate_validators\r\n File \"pydantic/validators.py\", line 760, in find_validators\r\nRuntimeError: error checking inheritance of 'Inner' (type: str)\r\n```\r\n\r\nI've also displayed the minimal example below - thanks!\n\n### Example Code\n\n```Python\nfrom typing import Generic, List, TypeVar\r\n\r\nfrom pydantic import BaseModel\r\nfrom pydantic.generics import GenericModel\r\n\r\nChangingType = TypeVar(\"ChangingType\")\r\n\r\nclass Outer(GenericModel, Generic[ChangingType]):\r\n fields_: list[ChangingType] # Swapping list -> List on this line fixes the bug\r\n\r\nouter = Outer[\"Inner\"]\r\nclass Inner(BaseModel):\r\n new: list[outer]\r\n\r\nouter.update_forward_refs()\r\nInner.update_forward_refs()\r\n\r\nout = Inner.parse_obj({\"new\": [{\"fields_\": []}]})\r\n\r\nprint(out)\n```\n\n\n### Python, Pydantic & OS Version\n\n```Text\npydantic version: 1.10.9\r\npydantic compiled: True\r\ninstall path: /{package location}/.venv/lib64/python3.10/site-packages/pydantic\r\npython version: 3.10.10 (main, Feb 8 2023, 00:00:00) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)]\r\nplatform: Linux-5.10.16.3-microsoft-standard-WSL2-x86_64-with-glibc2.35\r\noptional deps. installed: ['typing-extensions']\n```\n\n\n### Affected Components\n\n- [ ] [Compatibility between releases](https://docs.pydantic.dev/changelog/)\n- [ ] [Data validation/parsing](https://docs.pydantic.dev/usage/models/#basic-model-usage)\n- [ ] [Data serialization](https://docs.pydantic.dev/usage/exporting_models/) - `.dict()` and `.json()`\n- [ ] [JSON Schema](https://docs.pydantic.dev/usage/schema/)\n- [ ] [Dataclasses](https://docs.pydantic.dev/usage/dataclasses/)\n- [ ] [Model Config](https://docs.pydantic.dev/usage/model_config/)\n- [x] [Field Types](https://docs.pydantic.dev/usage/types/) - adding or changing a particular data type\n- [ ] [Function validation decorator](https://docs.pydantic.dev/usage/validation_decorator/)\n- [X] [Generic Models](https://docs.pydantic.dev/usage/models/#generic-models)\n- [ ] [Other Model behaviour](https://docs.pydantic.dev/usage/models/) - `construct()`, pickling, private attributes, ORM mode\n- [ ] [Plugins](https://docs.pydantic.dev/) and integration with other tools - mypy, FastAPI, python-devtools, Hypothesis, VS Code, PyCharm, etc.","author":{"url":"https://github.com/mark-todd","@type":"Person","name":"mark-todd"},"datePublished":"2023-06-14T10:26:47Z","url":"https://github.com/pydantic/pydantic/issues/6130"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| 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:4141fae4-1e42-3987-b7e6-b909f6e6a508 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E0E:3B2C08:343077:469F27:6AEDB266 |
| html-safe-nonce | 12c7558a1f9d0dc2e7bb3b2d2719c1bb17b37364594c4409e0cf984a4871dbe1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTBFOjNCMkMwODozNDMwNzc6NDY5RjI3OjZBRURCMjY2IiwidmlzaXRvcl9pZCI6IjU4NzkxMjI4NTkxNTY5NDM0NjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8710ca0ef4db325665b55599eeaa2ee652994e3a88656f36c2c40a62f8b2846b |
| hovercard-subject-tag | issue:1756563021 |
| 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/pydantic/pydantic/6130/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b8a1ba6c11be72b39ac0d8ab45c7010d37c9001edea769eb8460ff0b222bc872/pydantic/pydantic/issues/6130 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b8a1ba6c11be72b39ac0d8ab45c7010d37c9001edea769eb8460ff0b222bc872/pydantic/pydantic/issues/6130 |
| og:image:alt | Initial Checks I have searched GitHub for a duplicate issue and I'm sure this is something new I have searched Google & StackOverflow for a solution and couldn't find anything I have read and follo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mark-todd |
| hostname | github.com |
| expected-hostname | github.com |
| None | e40242599af5e7da0f281843dec7492c322688d4a48caeea85f9fb8e41c8ea53 |
| turbo-cache-control | no-preview |
| go-import | github.com/pydantic/pydantic git https://github.com/pydantic/pydantic.git |
| octolytics-dimension-user_id | 110818415 |
| octolytics-dimension-user_login | pydantic |
| octolytics-dimension-repository_id | 90194616 |
| octolytics-dimension-repository_nwo | pydantic/pydantic |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 90194616 |
| octolytics-dimension-repository_network_root_nwo | pydantic/pydantic |
| 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 | 89cbf2bb52a24fc179bf5925abba0ba574b262ce |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width