René's URL Explorer Experiment


Title: Classmethod doesn't pass generic type · Issue #616 · python/typing · GitHub

Open Graph Title: Classmethod doesn't pass generic type · Issue #616 · python/typing

X Title: Classmethod doesn't pass generic type · Issue #616 · python/typing

Description: This may be related to #123. PEP 484, says the type is assumed to be Type[type(cls(...))]. classmethod says a class method receives the class as implicit first argument. I'd assume that Obj[int] is it's own class, different from Obj. How...

Open Graph Description: This may be related to #123. PEP 484, says the type is assumed to be Type[type(cls(...))]. classmethod says a class method receives the class as implicit first argument. I'd assume that Obj[int] is...

X Description: This may be related to #123. PEP 484, says the type is assumed to be Type[type(cls(...))]. classmethod says a class method receives the class as implicit first argument. I'd assume that Obj[int...

Opengraph URL: https://github.com/python/typing/issues/616

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Classmethod doesn't pass generic type","articleBody":" - This may be related to #123.\r\n - [PEP 484, says the type is assumed to be `Type[type(cls(...))]`][0].\r\n - [`classmethod` says a class method receives the class as implicit first argument][1].\r\n\r\nI'd assume that `Obj[int]` is it's own class, different from `Obj`. However `classmethod` doesn't work this way. This means that I can't use `Obj[int].from_str()` to make an `Obj[int]`, much like I can use `Obj.from_str()` to make an `Obj`. This can be seen in the following example.\r\n\r\n```\r\nfrom typing import Generic, TypeVar, Type\r\n\r\nT = TypeVar('T')\r\n\r\n\r\nclass Obj(Generic[T]):\r\n    value: T\r\n\r\n    def __init__(self, value: T):\r\n        self.value = value\r\n\r\n    def __str__(self):\r\n        name = getattr(self, '__orig_class__', type(self).__name__)\r\n        return f'{name}(value={self.value!r})'\r\n\r\n    @classmethod\r\n    def from_str(cls, value: str):\r\n        fn = getattr(cls, '__args__', [str])[0]\r\n        return cls(fn(value))\r\n\r\n\r\ndef from_str(cls: Type[Obj[T]], value) -> Obj[T]:\r\n    fn = getattr(cls, '__args__', [str])[0]\r\n    return cls(fn(value))\r\n\r\n\r\nif __name__ == '__main__':\r\n    # untyped\r\n    print(Obj.from_str('1'))\r\n    print(from_str(Obj, '1'))\r\n\r\n    # typed\r\n    print(Obj[int].from_str('1'))\r\n    print(from_str(Obj[int], '1'))\r\n```\r\n\r\nWhich outputs:\r\n\r\n```\r\nObj(value='1')\r\nObj(value='1')\r\nObj(value='1')\r\n__main__.Obj[int](value=1)\r\n```\r\n\r\nIt seems like `classmethod` and typing agree that it shouldn't be passed the generic type. However I think passing the type as well to be better than having to make all `classmethods` outside the class to support the generic type. It also doesn't look like it'd destroy current code as `cls` seems to work the same way whether it's typed or not.\r\n\r\n  [0]: https://www.python.org/dev/peps/pep-0484/#annotating-instance-and-class-methods\r\n  [1]: https://docs.python.org/3/library/functions.html#classmethod","author":{"url":"https://github.com/Peilonrayz","@type":"Person","name":"Peilonrayz"},"datePublished":"2019-02-22T15:48:27Z","url":"https://github.com/python/typing/issues/616"}

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:0a384c96-6883-4c85-cebd-317f6c4feaaf
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9AA2:1BAA33:219E553:2CAC93B:6B004A96
html-safe-nonce7e9c3cd373795d59d57922a01fe3f3f12688809796997ba98845df9a2a1a31ef
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QUEyOjFCQUEzMzoyMTlFNTUzOjJDQUM5M0I6NkIwMDRBOTYiLCJ2aXNpdG9yX2lkIjoiNDgyOTgwNTU0Njc3OTYzNDE0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacd186809c4a7c37e9f8b33a9a870bfaa4fd16d472ea5505810ced98b1c57962c9
hovercard-subject-tagissue:413462516
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/616/issue_layout
twitter:imagehttps://opengraph.githubassets.com/30ae056344175b59d6f6e0ae4ade08293864a623fb1bef9d3a8cd839a8c1d52d/python/typing/issues/616
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/30ae056344175b59d6f6e0ae4ade08293864a623fb1bef9d3a8cd839a8c1d52d/python/typing/issues/616
og:image:altThis may be related to #123. PEP 484, says the type is assumed to be Type[type(cls(...))]. classmethod says a class method receives the class as implicit first argument. I'd assume that Obj[int] is...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamePeilonrayz
hostnamegithub.com
expected-hostnamegithub.com
Nonef9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b
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
releaseb27c5dde30676028abd5c5fc53ce5c9b625f8281
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/typing/issues/616#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftyping%2Fissues%2F616
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%2F616
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/616
Reloadhttps://github.com/python/typing/issues/616
Reloadhttps://github.com/python/typing/issues/616
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/616
New issuehttps://github.com/login?return_to=https://github.com/python/typing/issues/616
Classmethod doesn't pass generic typehttps://github.com/python/typing/issues/616#top
https://github.com/Peilonrayz
Peilonrayzhttps://github.com/Peilonrayz
on Feb 22, 2019https://github.com/python/typing/issues/616#issue-413462516
Type of first argument of class methods should not be 'type' #123https://github.com/python/typing/issues/123
PEP 484, says the type is assumed to be Type[type(cls(...))]https://www.python.org/dev/peps/pep-0484/#annotating-instance-and-class-methods
classmethod says a class method receives the class as implicit first argumenthttps://docs.python.org/3/library/functions.html#classmethod
https://github.com/ilevkivskyi
ilevkivskyihttps://github.com/ilevkivskyi
on Feb 24, 2019https://github.com/python/typing/issues/616#issuecomment-466800870
https://github.com/Peilonrayz
Peilonrayzhttps://github.com/Peilonrayz
on Feb 24, 2019https://github.com/python/typing/issues/616#issuecomment-466803542
@ilevkivskyihttps://github.com/ilevkivskyi
https://github.com/ilevkivskyi
ilevkivskyihttps://github.com/ilevkivskyi
on Jun 20, 2019https://github.com/python/typing/issues/616#issuecomment-503943187
#629https://github.com/python/typing/issues/629
ilevkivskyihttps://github.com/ilevkivskyi
completedhttps://github.com/python/typing/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jun 20, 2019https://github.com/python/typing/issues/616#event-2426721385
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/typing/issues/616
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/typing/issues/616
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.