René's URL Explorer Experiment


Title: Rethinking __init__ of VersionInfo class? · Issue #303 · python-semver/python-semver · GitHub

Open Graph Title: Rethinking __init__ of VersionInfo class? · Issue #303 · python-semver/python-semver

X Title: Rethinking __init__ of VersionInfo class? · Issue #303 · python-semver/python-semver

Description: Situation Originally posted by @tomschr in #258 (comment) From the above discussion, I thought it would be worth to decouple the compare discussion from the initializer discussion. Both are somewhat related, but can live independently. W...

Open Graph Description: Situation Originally posted by @tomschr in #258 (comment) From the above discussion, I thought it would be worth to decouple the compare discussion from the initializer discussion. Both are somewha...

X Description: Situation Originally posted by @tomschr in #258 (comment) From the above discussion, I thought it would be worth to decouple the compare discussion from the initializer discussion. Both are somewha...

Opengraph URL: https://github.com/python-semver/python-semver/issues/303

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Rethinking __init__ of VersionInfo class?","articleBody":"# Situation\r\n\r\n_Originally posted by @tomschr in https://github.com/python-semver/python-semver/issues/258#issuecomment-652482631_\r\n\r\nFrom the above discussion, I thought it would be worth to decouple the `compare` discussion from the initializer discussion. Both are somewhat related, but can live independently. \r\n\r\nWith a more \"advanced\" initializer/constructor we get the following benefits:\r\n\r\n* more \"pythonic\": it's one, obvious way to get an instance.\r\n* avoids the longer function call `Version.parse(...)`.\r\n* more readable\r\n\r\nWith such an (overloaded?) initializer, we could cover the following use cases:\r\n\r\n```python\r\n\u003e\u003e\u003e from semver import Version\r\n\u003e\u003e\u003e Version(1)\r\nVersion(major=1, minor=0, patch=0, prerelease=None, build=None)\r\n\u003e\u003e\u003e Version(1, \"4\", b\"5\")\r\nVersion(major=1, minor=4, patch=5, prerelease=None, build=None)\r\n\u003e\u003e\u003e Version(1, patch=2)\r\nVersion(major=1, minor=0, patch=2, prerelease=None, build=None)\r\n\u003e\u003e\u003e Version(\"1.2.3\")\r\nVersion(major=1, minor=2, patch=3, prerelease=None, build=None)\r\n\u003e\u003e\u003e Version(b\"1.2.3\")\r\nVersion(major=1, minor=2, patch=3, prerelease=None, build=None)\r\n\u003e\u003e\u003e v = Version(b\"2.3.4\")\r\n\u003e\u003e\u003e Version(v)\r\nVersion(major=2, minor=3, patch=4, prerelease=None, build=None)\r\n\u003e\u003e\u003e t = (1, 2, 3)\r\n\u003e\u003e\u003e Version(*t)                                             \r\nVersion(major=1, minor=2, patch=3, prerelease=None, build=None)\r\n\u003e\u003e\u003e d = {'major': 3, 'minor': 4, 'patch': 5,  'prerelease': 'pre.2', 'build': 'build.4'}\r\n\u003e\u003e\u003e Version(**d)\r\nVersion(major=3, minor=4, patch=5, prerelease='pre.2', build='build.4')\r\n```\r\n\r\n# Discussions and Possible Solutions\r\n\r\nTo implement a somewhat more advanced constructor/initializer, we have these options:\r\n\r\n1. Program it manually with `isinstance` and if...else constructs\r\n1. Use the [`typing.overload`](https://docs.python.org/3.6/library/typing.html#typing.overload) function (suggested by @tlaferriere)\r\n1. Use [`functools.singledispatch`](https://docs.python.org/3.6/library/functools.html#functools.singledispatch)\r\n\r\nHowever, all three comes at a cost or an issue:\r\n\r\n1. Maybe not impossible, but the code would look probably ugly.\r\n1. \"The `@overload` decorator is purely for type hints, you can only specify one function body and it has to distinguish the different types using isinstance.` (_Originally posted by @tlaferriere in https://github.com/python-semver/python-semver/issues/258#issuecomment-650648949_)\r\n1. Is not possible with an `__init__` method. The `singledispatch` works only for _functions_(!), *not* methods. For methods we would need [`functools.singledispatchmethod`](https://docs.python.org/3.8/library/functools.html#functools.singledispatchmethod) which is only available from Python \u003e= 3.8.\r\n\r\n----\r\n\r\nAnother idea goes into a completely different direction. Maybe we shouldn't change the `Version` class much, but offer a much shorter variant: `semver.v`.\r\n\r\n```python\r\nfrom functools import singledispatch\r\n\r\n# ...\r\n@singledispatch\r\ndef ver(major, minor=0, patch=0, prerelease=None, build=None) -\u003e \"Version\":\r\n    return Version(major, minor, patch, prerelease, build)\r\n    \r\n@ver.register(bytes)\r\n@ver.register(str)\r\ndef _(ver: str) -\u003e \"Version\":\r\n    if isinstance(ver, bytes):\r\n       ver = str(ver, \"utf-8\")\r\n    if \".\" in ver:\r\n        return Version.parse(ver)\r\n    return Version(int(ver))\r\n\r\n@ver.register(Version)\r\ndef _(ver: \"Version\") -\u003e \"Version\":\r\n    return ver\r\n```\r\n\r\nWhich means, we could just use `semver.v` as a much shorter variant:\r\n\r\n```python\r\n\u003e\u003e\u003e import semver\r\n\u003e\u003e\u003e semver.v(\"1.2.3\")\r\nVersion(major=1, minor=2, patch=3, prerelease=None, build=None)\r\n```\r\n\r\nOne drawback could be that `v` is quite short. Maybe too short? Especially if you import it with `from semver import v` it could be easily overwritten by other, local variables.\r\nThat could be a bit avoided to use capital `V` or `ver`. Or we use the much longer name `semver.version`.\r\n\r\nThoughts? Any other ideas? Would that be worth the effort?\r\n\r\n@tlaferriere @gsakkis @ppkt ","author":{"url":"https://github.com/tomschr","@type":"Person","name":"tomschr"},"datePublished":"2020-10-26T19:22:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/303/python-semver/issues/303"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:b476bab4-f14d-afc6-1afa-07afaa3bca8f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB972:3EB92C:1FF5E28:2A3BD8A:696EF3DB
html-safe-nonce2b96bea5def40588d65b750b75a3fea9e01ec2ecae270186dcc94308a8078d23
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTcyOjNFQjkyQzoxRkY1RTI4OjJBM0JEOEE6Njk2RUYzREIiLCJ2aXNpdG9yX2lkIjoiMjA2Mzc1OTcxNzY2OTIwNDk1NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacc180b2373fe01384eae99e66efab73ae363d975d105a5f68c54c58be4dfddeb4
hovercard-subject-tagissue:729840307
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-semver/python-semver/303/issue_layout
twitter:imagehttps://opengraph.githubassets.com/a0c466c57c510183db0691182cbb7251dd09d5a3f9cafae37566b924846ac8d7/python-semver/python-semver/issues/303
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/a0c466c57c510183db0691182cbb7251dd09d5a3f9cafae37566b924846ac8d7/python-semver/python-semver/issues/303
og:image:altSituation Originally posted by @tomschr in #258 (comment) From the above discussion, I thought it would be worth to decouple the compare discussion from the initializer discussion. Both are somewha...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametomschr
hostnamegithub.com
expected-hostnamegithub.com
Noneb278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee
turbo-cache-controlno-preview
go-importgithub.com/python-semver/python-semver git https://github.com/python-semver/python-semver.git
octolytics-dimension-user_id57228994
octolytics-dimension-user_loginpython-semver
octolytics-dimension-repository_id3375726
octolytics-dimension-repository_nwopython-semver/python-semver
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id3375726
octolytics-dimension-repository_network_root_nwopython-semver/python-semver
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
release39aed5006635ab6f45e6b77d23e73b08a00272a3
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/python-semver/python-semver/issues/303#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-semver%2Fpython-semver%2Fissues%2F303
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-semver%2Fpython-semver%2Fissues%2F303
Sign up https://patch-diff.githubusercontent.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-semver%2Fpython-semver
Reloadhttps://patch-diff.githubusercontent.com/python-semver/python-semver/issues/303
Reloadhttps://patch-diff.githubusercontent.com/python-semver/python-semver/issues/303
Reloadhttps://patch-diff.githubusercontent.com/python-semver/python-semver/issues/303
python-semver https://patch-diff.githubusercontent.com/python-semver
python-semverhttps://patch-diff.githubusercontent.com/python-semver/python-semver
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-semver%2Fpython-semver
Fork 96 https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-semver%2Fpython-semver
Star 514 https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-semver%2Fpython-semver
Code https://patch-diff.githubusercontent.com/python-semver/python-semver
Issues 12 https://patch-diff.githubusercontent.com/python-semver/python-semver/issues
Pull requests 3 https://patch-diff.githubusercontent.com/python-semver/python-semver/pulls
Discussions https://patch-diff.githubusercontent.com/python-semver/python-semver/discussions
Actions https://patch-diff.githubusercontent.com/python-semver/python-semver/actions
Projects 0 https://patch-diff.githubusercontent.com/python-semver/python-semver/projects
Security Uh oh! There was an error while loading. Please reload this page. https://patch-diff.githubusercontent.com/python-semver/python-semver/security
Please reload this pagehttps://patch-diff.githubusercontent.com/python-semver/python-semver/issues/303
Insights https://patch-diff.githubusercontent.com/python-semver/python-semver/pulse
Code https://patch-diff.githubusercontent.com/python-semver/python-semver
Issues https://patch-diff.githubusercontent.com/python-semver/python-semver/issues
Pull requests https://patch-diff.githubusercontent.com/python-semver/python-semver/pulls
Discussions https://patch-diff.githubusercontent.com/python-semver/python-semver/discussions
Actions https://patch-diff.githubusercontent.com/python-semver/python-semver/actions
Projects https://patch-diff.githubusercontent.com/python-semver/python-semver/projects
Security https://patch-diff.githubusercontent.com/python-semver/python-semver/security
Insights https://patch-diff.githubusercontent.com/python-semver/python-semver/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/python-semver/python-semver/issues/303
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/python-semver/python-semver/issues/303
#317https://github.com/python-semver/python-semver/pull/317
Rethinking __init__ of VersionInfo class?https://patch-diff.githubusercontent.com/python-semver/python-semver/issues/303#top
#317https://github.com/python-semver/python-semver/pull/317
DesignIdeas, suggestions, musings about design questionshttps://github.com/python-semver/python-semver/issues?q=state%3Aopen%20label%3A%22Design%22
EnhancementNot a bug, but increases or improves in value, quality, desirability, or attractivenesshttps://github.com/python-semver/python-semver/issues?q=state%3Aopen%20label%3A%22Enhancement%22
QuestionUnclear or open issue subject for debatehttps://github.com/python-semver/python-semver/issues?q=state%3Aopen%20label%3A%22Question%22
Release_3.x.yOnly for the major release 3https://github.com/python-semver/python-semver/issues?q=state%3Aopen%20label%3A%22Release_3.x.y%22
https://github.com/tomschr
https://github.com/tomschr
tomschrhttps://github.com/tomschr
on Oct 26, 2020https://github.com/python-semver/python-semver/issues/303#issue-729840307
@tomschrhttps://github.com/tomschr
#258 (comment)https://github.com/python-semver/python-semver/issues/258#issuecomment-652482631
typing.overloadhttps://docs.python.org/3.6/library/typing.html#typing.overload
@tlaferrierehttps://github.com/tlaferriere
functools.singledispatchhttps://docs.python.org/3.6/library/functools.html#functools.singledispatch
@tlaferrierehttps://github.com/tlaferriere
Consider keeping compare module level function #258 (comment)https://github.com/python-semver/python-semver/issues/258#issuecomment-650648949
functools.singledispatchmethodhttps://docs.python.org/3.8/library/functools.html#functools.singledispatchmethod
@tlaferrierehttps://github.com/tlaferriere
@gsakkishttps://github.com/gsakkis
@ppkthttps://github.com/ppkt
DesignIdeas, suggestions, musings about design questionshttps://github.com/python-semver/python-semver/issues?q=state%3Aopen%20label%3A%22Design%22
EnhancementNot a bug, but increases or improves in value, quality, desirability, or attractivenesshttps://github.com/python-semver/python-semver/issues?q=state%3Aopen%20label%3A%22Enhancement%22
QuestionUnclear or open issue subject for debatehttps://github.com/python-semver/python-semver/issues?q=state%3Aopen%20label%3A%22Question%22
Release_3.x.yOnly for the major release 3https://github.com/python-semver/python-semver/issues?q=state%3Aopen%20label%3A%22Release_3.x.y%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.