Title: Assuming `self` or `cls` parameter is positional-only · Issue #1355 · python/typing · GitHub
Open Graph Title: Assuming `self` or `cls` parameter is positional-only · Issue #1355 · python/typing
X Title: Assuming `self` or `cls` parameter is positional-only · Issue #1355 · python/typing
Description: I'm interested in guidance from the typing community relating to a question that came up in a recent pyright bug report. The issue has to do with the self parameter in an instance method and the cls parameter in a class method — whether ...
Open Graph Description: I'm interested in guidance from the typing community relating to a question that came up in a recent pyright bug report. The issue has to do with the self parameter in an instance method and the cl...
X Description: I'm interested in guidance from the typing community relating to a question that came up in a recent pyright bug report. The issue has to do with the self parameter in an instance method and th...
Opengraph URL: https://github.com/python/typing/issues/1355
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Assuming `self` or `cls` parameter is positional-only","articleBody":"I'm interested in guidance from the typing community relating to a question that came up in a recent [pyright bug report](https://github.com/microsoft/pyright/issues/4685).\r\n\r\nThe issue has to do with the `self` parameter in an instance method and the `cls` parameter in a class method — whether a type checker should assume that they are implicitly positional-only parameters. In particular, the discussion was about method declarations within a protocol class. \r\n\r\n[PEP 570](https://peps.python.org/pep-0570/) makes a reference to this topic in its introductory section:\r\n\r\n> One special case of this situation is the `self` parameter for class methods: it is undesirable that a caller can bind by keyword to the name `self` when calling the method from the class.\r\n\r\nBut PEP 570 doesn't provide any specific guidance about `self` or `cls` in its specification section. [PEP 544](https://peps.python.org/pep-0544/) (which introduced protocols) is also silent on the topic.\r\n\r\nPyright currently assumes that `self` and `cls` are _not_ positional-only parameters (unless explicitly followed by a `/` parameter marker or named with double underscores). This assumption affects protocol matching — and more generally, subtype compatibility evaluation for callables.\r\n\r\n@AlexWaygood is proposing that the first parameter of instance and class methods should always be considered position-only parameters.\r\n\r\nThis raises some questions in my mind:\r\n1. Is this a safe assumption? Does anyone know of a situation where `self` or `cls` are used as keyword arguments?\r\n2. Does this apply only to protocol methods, or does it apply generally to methods in any class?\r\n3. Should it be considered a type checker error if someone attempts to use a keyword argument to target the first parameter of an instance or class method? It works at runtime.\r\n```python\r\nclass Foo:\r\n def bar(self): pass\r\n\r\nFoo.bar(self=Foo())\r\n```\r\n5. Does the `cls` exemption apply only to explicit class methods, or does it also apply to `__new__` and `__init_subclass__`?","author":{"url":"https://github.com/erictraut","@type":"Person","name":"erictraut"},"datePublished":"2023-02-24T17:34:25Z","url":"https://github.com/python/typing/issues/1355"}
| 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:d9e9f1a2-3e59-dc00-c53d-10d4dc274d9d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A6A4:3204C8:3409B1E:44F9B41:6B003D28 |
| html-safe-nonce | e551d457b02b92608f14ce59bb437144314bfcea54b741c9e247ab8d7f151c49 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNkE0OjMyMDRDODozNDA5QjFFOjQ0RjlCNDE6NkIwMDNEMjgiLCJ2aXNpdG9yX2lkIjoiNjg5MjQxNTA2Mjg3MTM5MTUyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5a1ee5c58bd164f9df8401ea633ee80234d3bfb933ee8c1092d71d2b309455f5 |
| hovercard-subject-tag | issue:1599042830 |
| 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/1355/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d0dd3eca4345c43bbf21a21aeaf7a0f95f960b6528cff7f0708ce5b6dbebad3e/python/typing/issues/1355 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d0dd3eca4345c43bbf21a21aeaf7a0f95f960b6528cff7f0708ce5b6dbebad3e/python/typing/issues/1355 |
| og:image:alt | I'm interested in guidance from the typing community relating to a question that came up in a recent pyright bug report. The issue has to do with the self parameter in an instance method and the cl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | erictraut |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width