René's URL Explorer Experiment


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

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@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-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d9e9f1a2-3e59-dc00-c53d-10d4dc274d9d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA6A4:3204C8:3409B1E:44F9B41:6B003D28
html-safe-noncee551d457b02b92608f14ce59bb437144314bfcea54b741c9e247ab8d7f151c49
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNkE0OjMyMDRDODozNDA5QjFFOjQ0RjlCNDE6NkIwMDNEMjgiLCJ2aXNpdG9yX2lkIjoiNjg5MjQxNTA2Mjg3MTM5MTUyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac5a1ee5c58bd164f9df8401ea633ee80234d3bfb933ee8c1092d71d2b309455f5
hovercard-subject-tagissue:1599042830
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/typing/1355/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d0dd3eca4345c43bbf21a21aeaf7a0f95f960b6528cff7f0708ce5b6dbebad3e/python/typing/issues/1355
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d0dd3eca4345c43bbf21a21aeaf7a0f95f960b6528cff7f0708ce5b6dbebad3e/python/typing/issues/1355
og:image:altI'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:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameerictraut
hostnamegithub.com
expected-hostnamegithub.com
None7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0
turbo-cache-controlno-preview
go-importgithub.com/python/typing git https://github.com/python/typing.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id24604008
octolytics-dimension-repository_nwopython/typing
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24604008
octolytics-dimension-repository_network_root_nwopython/typing
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef3f3a43ca095cdea3abbb394112e971f9fdb94fa
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/typing/issues/1355#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftyping%2Fissues%2F1355
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftyping%2Fissues%2F1355
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Ftyping
Reloadhttps://github.com/python/typing/issues/1355
Reloadhttps://github.com/python/typing/issues/1355
Reloadhttps://github.com/python/typing/issues/1355
pythonhttps://github.com/python
typinghttps://github.com/python/typing
Codehttps://github.com/python/typing
Issues206 (206)https://github.com/python/typing/issues
Pull requests27 (27)https://github.com/python/typing/pulls
Discussionshttps://github.com/python/typing/discussions
Actionshttps://github.com/python/typing/actions
Security and qualityhttps://github.com/python/typing/security
Insightshttps://github.com/python/typing/insights
https://github.com/python/typing
New issuehttps://github.com/login?return_to=https://github.com/python/typing/issues/1355
New issuehttps://github.com/login?return_to=https://github.com/python/typing/issues/1355
Assuming self or cls parameter is positional-onlyhttps://github.com/python/typing/issues/1355#top
topic: otherOther topics not coveredhttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20other%22
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Feb 24, 2023https://github.com/python/typing/issues/1355#issue-1599042830
pyright bug reporthttps://github.com/microsoft/pyright/issues/4685
PEP 570https://peps.python.org/pep-0570/
PEP 544https://peps.python.org/pep-0544/
@AlexWaygoodhttps://github.com/AlexWaygood
erictrauthttps://github.com/erictraut
topic: otherOther topics not coveredhttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20other%22
on Feb 24, 2023https://github.com/python/typing/issues/1355#event-8604227481
https://github.com/AlexWaygood
AlexWaygoodhttps://github.com/AlexWaygood
on Feb 24, 2023https://github.com/python/typing/issues/1355#issuecomment-1444177327
@erictrauthttps://github.com/erictraut
https://github.com/hmc-cs-mdrissi
hmc-cs-mdrissihttps://github.com/hmc-cs-mdrissi
on Feb 24, 2023https://github.com/python/typing/issues/1355#issuecomment-1444338672
https://github.com/NeilGirdhar
NeilGirdharhttps://github.com/NeilGirdhar
on Feb 25, 2023https://github.com/python/typing/issues/1355#issuecomment-1444997685
https://github.com/hmc-cs-mdrissi
hmc-cs-mdrissihttps://github.com/hmc-cs-mdrissi
on Feb 25, 2023https://github.com/python/typing/issues/1355#issuecomment-1445000192
https://github.com/NeilGirdhar
NeilGirdharhttps://github.com/NeilGirdhar
on Feb 25, 2023https://github.com/python/typing/issues/1355#issuecomment-1445006971
https://github.com/TeamSpen210
TeamSpen210https://github.com/TeamSpen210
on Feb 25, 2023https://github.com/python/typing/issues/1355#issuecomment-1445038238
literally wrap them in classmethodhttps://github.com/python/cpython/blob/22b8d77b98a5944e688be0927b8139c49d4a7257/Objects/typeobject.c#L3089
it uses staticmethod()https://github.com/python/cpython/blob/22b8d77b98a5944e688be0927b8139c49d4a7257/Objects/typeobject.c#L3239
explicitly passedhttps://github.com/python/cpython/blob/22b8d77b98a5944e688be0927b8139c49d4a7257/Objects/typeobject.c#L8438
https://github.com/AlexWaygood
AlexWaygoodhttps://github.com/AlexWaygood
on Feb 25, 2023https://github.com/python/typing/issues/1355#issuecomment-1445039975
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Feb 25, 2023https://github.com/python/typing/issues/1355#issuecomment-1445174900
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/typing/issues/1355
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/typing/issues/1355
topic: otherOther topics not coveredhttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20other%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.