Title: Does `field_specifier` support non-keyword arguments? · Issue #2170 · python/typing · GitHub
Open Graph Title: Does `field_specifier` support non-keyword arguments? · Issue #2170 · python/typing
X Title: Does `field_specifier` support non-keyword arguments? · Issue #2170 · python/typing
Description: I was reading through the specification of dataclass_transform and it doesn't really specify what field_specifiers looks like. It mostly just says: field_specifiers (tuple[Callable[..., Any], ...]) – Specifies a static list of supported ...
Open Graph Description: I was reading through the specification of dataclass_transform and it doesn't really specify what field_specifiers looks like. It mostly just says: field_specifiers (tuple[Callable[..., Any], ...])...
X Description: I was reading through the specification of dataclass_transform and it doesn't really specify what field_specifiers looks like. It mostly just says: field_specifiers (tuple[Callable[..., Any], ....
Opengraph URL: https://github.com/python/typing/issues/2170
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Does `field_specifier` support non-keyword arguments?","articleBody":"I was reading through the specification of `dataclass_transform` and it doesn't really specify what `field_specifiers` looks like. It mostly just says:\n\n> field_specifiers ([tuple](https://docs.python.org/3/library/stdtypes.html#tuple)[[Callable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[..., Any], ...]) – Specifies a static list of supported classes or functions that describe fields, similar to [dataclasses.field()](https://docs.python.org/3/library/dataclasses.html#dataclasses.field). Defaults to ().\n\nBut `dataclasses.field` takes keyword-only arguments, which leaves it a bit ambiguous about whether positional arguments are ok. For example:\n\n```python\nfrom typing import dataclass_transform, Any\n\ndef custom_field(default: object, *, init: bool = True) -> Any: ...\n\n@dataclass_transform(field_specifiers=(custom_field,))\ndef build(x): ...\n\n@build\nclass A:\n x: int = custom_field(default=0)\n\n@build\nclass B:\n x: int = custom_field(0)\n\nA()\nB()\n```\n\n[`pyrefly`](https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN2ZUDVAGMoqOHAD6DShjhheNADR0AgulKrKMAG4xUUGcxgAddOcwwwdEQFc4DWlMgwomABRWwqO1AaIdLjYAFYwIgyqAFSqrBABdHi4UHQAvHQAKpR2MACUdAC0AHzqmoGEFebmAAKCwmIS0rLyipQ0Hq7uUnDE4RCulHCpHvaOzp2Yyrm5ltaJdtCe%2BLnllRbo1dgL7uYNkuqI5nTHdPiBrPzpo040LhBunt6%2B-qkADDPrm9uYu%2BL7AEKHdAnU7ndCXWwOG53B4ed5VdA6fSGYy9DxqQhSKRxBhYj5IgxGJho-6Y7HoeJ4hFqDwff60kDKEB2BjQOAkciIEAAYjoAFVWVB4qQ6GA7OgIhBcOg4AjvKKlEIpOg7DRsDBKB4zpxwflinRHJQgSCdAw7JRgWBTCAAHKq9VGujAfAAX2t5kZIDIOjAUFIhBuUAovIACqQfX6DRgcARbNLIGxzUIpehCOZeQBlGAwOgACwYDGIcEQAHoS97rH7CLw2CWYOgS5hcCI4CWRPGIIm5KzpSWFZQ6KhdKhoKhsLA4%2BgE0me8DcMRZ%2BzzGQGLnpQV9IMU2k6NaAMyEACMACZ3egQC6maJWfoAGLQGAUNBYPBEMgXoA), [`pyright`](https://pyright-play.net/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoAmAhjEQMYA2RAztQPowhErXC4QA0UAginFyACmAN0FEKDRIIBQ0goOBQyAV2oxIdYEkEUCACnnAiyijABcUMACMAVoLIwuAKi6ok5qFbBgKUALxQACogyoIAlFAAtAB8PHwWAHRJsgACxKSUNPSMzKzselo6BHTUCPZIhSDUfnoqahqFuhxhYXIKnspIunoAHmGJydIpVp260pm0PGbSULNQPRao%2BAF16hCa2t2GxqZ%2BAAytQyNdBONUkwBC03PziyjLSqprG0V6B7JCouKSZXrcCXQ6G4YIDWp8xBJ4L8LgCgSh3KDZNw9K0LiigA), and [`mypy`](https://mypy-play.net/?mypy=latest&python=3.12&gist=6b7fa4d140b43ef67b8bb5a62f2388c6) all flag `B()` as an error while [`ty`](https://play.ty.dev/432daf76-d2e0-43ff-a1ce-4e5f30edc95e) accepts it without complaint.\n\nMy (uninformed) take is that this should be allowed -- `custom_field(default=0)` and `custom_field(0)` have the same runtime effect, so it feels like they should have the same type-checking effect too. This also matches how `pydantic` and `attrs` works (e.g. you can do `pydantic.Field(1)` and `attr.ib(0)`) -- today I suspect the type-checkers are special-casing this to make `pydantic` and `attrs` (since I've definitely used both without running into static type-checking errors about missing default values before).","author":{"url":"https://github.com/alanhdu","@type":"Person","name":"alanhdu"},"datePublished":"2026-02-11T00:46:18Z","url":"https://github.com/python/typing/issues/2170"}
| 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:521e664f-c8bf-eea1-8411-4744f79d2e86 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D7C6:1833B7:3A92D0:4FC0F0:6AFF7D6E |
| html-safe-nonce | e52da6b43f82c106b5af6d04bde1790ca33a0ef2121080d2784d7f59d357ed29 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEN0M2OjE4MzNCNzozQTkyRDA6NEZDMEYwOjZBRkY3RDZFIiwidmlzaXRvcl9pZCI6IjQ1MDA2NDcyOTQ0MTYxNTgwNjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f9de5f2bcbbd22824458ff244c002eef57a1ca65a048c719f8f971c2d966c60d |
| hovercard-subject-tag | issue:3924195089 |
| 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/typing/2170/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b07ce59d477ff44b022fcdd3bc16a22b1aa424116194848e36ace42d607d51fe/python/typing/issues/2170 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b07ce59d477ff44b022fcdd3bc16a22b1aa424116194848e36ace42d607d51fe/python/typing/issues/2170 |
| og:image:alt | I was reading through the specification of dataclass_transform and it doesn't really specify what field_specifiers looks like. It mostly just says: field_specifiers (tuple[Callable[..., Any], ...])... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alanhdu |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5a2047dbbde77e0ba2f8dfd78621e8a7313a105f7437ca693fcccd16cd137ee |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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 | 83e3dfa4de364d61589204ed35e53b2b7f77fba2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width