Title: Idea: Use case for a VersionIterator? · Issue #223 · python-semver/python-semver · GitHub
Open Graph Title: Idea: Use case for a VersionIterator? · Issue #223 · python-semver/python-semver
X Title: Idea: Use case for a VersionIterator? · Issue #223 · python-semver/python-semver
Description: Situation For example, if we want to start from a certain version and get the next 3 versions we could do that: v = VersionInfo.parse("1.2.3-rc.3") for _ in range(3): print(v.next_version(part="prerelease")) This would work, but maybe we...
Open Graph Description: Situation For example, if we want to start from a certain version and get the next 3 versions we could do that: v = VersionInfo.parse("1.2.3-rc.3") for _ in range(3): print(v.next_version(part="pre...
X Description: Situation For example, if we want to start from a certain version and get the next 3 versions we could do that: v = VersionInfo.parse("1.2.3-rc.3") for _ in range(3): print(v.next_version...
Opengraph URL: https://github.com/python-semver/python-semver/issues/223
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Idea: Use case for a VersionIterator?","articleBody":"## Situation\r\n\r\nFor example, if we want to start from a certain version and get the next 3 versions we could do that:\r\n\r\n```python\r\nv = VersionInfo.parse(\"1.2.3-rc.3\")\r\nfor _ in range(3):\r\n print(v.next_version(part=\"prerelease\"))\r\n```\r\n\r\nThis would work, but maybe we could use the iterator protocol for that.\r\n\r\n## Proposed Solution\r\n\r\nThe solution is very rough, but that's on purpose. It's a minimal example to demonstrate the idea and not get distracted by other methods. So I know, this would need fine-tuning (add properties, protect from invalid datatypes etc.).\r\n\r\n```python\r\nclass VersionInfoIterator:\r\n \"\"\"Iterator over VersionInfo objects\"\"\"\r\n def __init__(self, version, part, steps=10):\r\n self.version = version\r\n self.part = part\r\n self._steps = steps\r\n\r\n def __iter__(self):\r\n return self\r\n\r\n def __repr__(self):\r\n cls = type(self)\r\n return \"{}(version={!r}, part={!r}, steps={})\".format(cls.__name__,\r\n self.version, self.part, self._steps)\r\n\r\n def __next__(self):\r\n if not self.steps:\r\n raise StopIteration\r\n self._steps -= 1\r\n self.version = self.version.next_version(self.part)\r\n return self.version\r\n```\r\n\r\nAn implementation could look like this:\r\n\r\n```python\r\nfrom semver import VersionInfo, VersionInfoIterator\r\n\u003e\u003e\u003e v = VersionInfo.parse(\"1.2.3-rc.3\")\r\n\u003e\u003e\u003e vit = VersionInfoIterator(v, \"prerelease\", steps=3)\r\n\u003e\u003e\u003e next(vit) \r\nVersionInfo(major=1, minor=2, patch=3, prerelease='rc.4', build=None)\r\n\u003e\u003e\u003e next(vit) \r\nVersionInfo(major=1, minor=2, patch=3, prerelease='rc.5', build=None)\r\n\u003e\u003e\u003e vit.part = \"minor\"\r\n\u003e\u003e\u003e next(vit) \r\nVersionInfo(major=1, minor=3, patch=0, prerelease=None, build=None)\r\n\u003e\u003e\u003e next(vit)\r\nTraceback (most recent call last)\r\n...\r\nStopIteration\r\n\r\n# or\r\n\r\n\u003e\u003e\u003e vit = VersionInfoIterator(v, \"prerelease\", steps=3)\r\n\u003e\u003e\u003e list(vit)\r\n[VersionInfo(major=1, minor=2, patch=3, prerelease='rc.4', build=None),\r\n VersionInfo(major=1, minor=2, patch=3, prerelease='rc.5', build=None),\r\n VersionInfo(major=1, minor=2, patch=3, prerelease='rc.6', build=None)]\r\n```\r\n\r\n## Questions\r\n\r\n* Would such an iterator be useful?\r\n* Is it necessary or is first example above enough when iterating?\r\n* If you think it could be useful, would you change something in `__init__`?\r\n\r\nActually, I'm not sure myself if this is something good or completely unnecessary. I just had this idea when working on issue #222. :wink: Also I thought, it would be helpful to document it, regardless if this will be accepted or not. \r\n\r\n@gsakkis, @scls19fr \r\nWhat do you think? I would like to hear your opinion. :wink: \r\n\r\n","author":{"url":"https://github.com/tomschr","@type":"Person","name":"tomschr"},"datePublished":"2020-02-28T09:32:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/223/python-semver/issues/223"}
| 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:f589cc1d-d1d8-ee63-a5f2-e3669e9c4968 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C1A4:66CFE:1E9721:2A20C9:696E6C3E |
| html-safe-nonce | d2ce8bef75d168802641d4ef690379528b77d2fafdc22b37ff3ff0d083858b2c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMUE0OjY2Q0ZFOjFFOTcyMToyQTIwQzk6Njk2RTZDM0UiLCJ2aXNpdG9yX2lkIjoiNzg5MzQzMzM0NTI0Mjk4MzQ4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 35caf5faa381268a94c49bde542e3c48c6f653323de229f0881185fb9bab2053 |
| hovercard-subject-tag | issue:572634889 |
| 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-semver/python-semver/223/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b870b3e3e35e04b9e5da96994921538409dd27d4f3630479c47c960b93ee8a64/python-semver/python-semver/issues/223 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b870b3e3e35e04b9e5da96994921538409dd27d4f3630479c47c960b93ee8a64/python-semver/python-semver/issues/223 |
| og:image:alt | Situation For example, if we want to start from a certain version and get the next 3 versions we could do that: v = VersionInfo.parse("1.2.3-rc.3") for _ in range(3): print(v.next_version(part="pre... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tomschr |
| hostname | github.com |
| expected-hostname | github.com |
| None | dd24262d9e4947a6c63df018b01e9a6da49caaf8259148a56a04b665d15d66b3 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-semver/python-semver git https://github.com/python-semver/python-semver.git |
| octolytics-dimension-user_id | 57228994 |
| octolytics-dimension-user_login | python-semver |
| octolytics-dimension-repository_id | 3375726 |
| octolytics-dimension-repository_nwo | python-semver/python-semver |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3375726 |
| octolytics-dimension-repository_network_root_nwo | python-semver/python-semver |
| 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 | 307ab96ec5f21762ff6c530a60b1ef6b1e74dd5a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width