Skip to content

Add opt-in semantic version equality for trailing zeros (1.0 == 1.0.0)#495

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-version-comparison-issue
Draft

Add opt-in semantic version equality for trailing zeros (1.0 == 1.0.0)#495
Copilot wants to merge 5 commits intomainfrom
copilot/fix-version-comparison-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 18, 2025

What does this PR do?

Adds an opt-in semantic_equality parameter to enable semantic version comparison where trailing zeros are considered equivalent (e.g., "1.0" equals "1.0.0"). By default, the behavior remains unchanged for backward compatibility.

from awesomeversion import AwesomeVersion, AwesomeVersionStrategy

# Default behavior (backward compatible) - strict string comparison
AwesomeVersion("1.0") == AwesomeVersion("1.0.0")  # False

# Opt-in to semantic equality
AwesomeVersion("1.0", semantic_equality=True) == AwesomeVersion("1.0.0", semantic_equality=True)  # True

# Still False - modifiers matter even with semantic_equality
AwesomeVersion("1.0.0", semantic_equality=True) == AwesomeVersion("1.0.0-beta", semantic_equality=True)  # False

# Still False - special containers use string comparison
AwesomeVersion("beta") == AwesomeVersion("stable")  # False

# Different versions remain distinct
AwesomeVersion("1.0", semantic_equality=True) != AwesomeVersion("1.0.1", semantic_equality=True)  # True

Key Features:

  • Backward compatible: Default behavior unchanged (semantic_equality=False)
  • Opt-in: Set semantic_equality=True to enable trailing zeros equality
  • Preserves modifiers: Versions with different modifiers remain unequal
  • Special containers: Continue using string comparison

Type of change (pick one)

  • 🐛 Bug fix
  • ✨ New feature
  • 🔨 Code improvement or refactor
  • 📦 Dependency update
  • 💥 Breaking change

Related issues or links

Fixes #491

Checklist

  • I tested my changes locally
  • All tests pass
  • No commented-out code left
  • Code is formatted (run script/lint)
  • Added or updated tests if needed
Original prompt

This section details on the original issue you should resolve

<issue_title>Versioning comparison</issue_title>
<issue_description>### The problem

A version "1.0" is not considered equivalent to "1.0.0".

@ludeeus : They are not equal so technically correct, but their meaning is the same.

Operating system

Debian

Python version

3.11

Problem-relevant code

>>> from awesomeversion import AwesomeVersion, AwesomeVersionStrategy
>>> version = AwesomeVersion("1.6.1", ensure_strategy=AwesomeVersionStrategy.PEP440)
>>> version2 = AwesomeVersion("1.6.1", ensure_strategy=AwesomeVersionStrategy.SIMPLEVER)
>>> version == version2
True

>>> version = AwesomeVersion("1.0", ensure_strategy=AwesomeVersionStrategy.SIMPLEVER)
>>> version2 = AwesomeVersion("1.0.0", ensure_strategy=AwesomeVersionStrategy.SIMPLEVER)
>>> version == version2
False
>>> version > version2
False
>>> version < version2
False

Traceback/Error logs

Additional information

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: ludeeus <15093472+ludeeus@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Nov 18, 2025

Deploying awesomeversion with  Cloudflare Pages  Cloudflare Pages

Latest commit: 41c3a94
Status: ✅  Deploy successful!
Preview URL: https://fd8eb5d3.awesomeversion.pages.dev
Branch Preview URL: https://copilot-fix-version-comparis.awesomeversion.pages.dev

View logs

Co-authored-by: ludeeus <15093472+ludeeus@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix version comparison logic for AwesomeVersion Fix semantic version equality for trailing zeros (1.0 == 1.0.0) Nov 18, 2025
Copilot AI requested a review from ludeeus November 18, 2025 05:57
Co-authored-by: ludeeus <15093472+ludeeus@users.noreply.github.com>
Copilot AI requested a review from ludeeus November 19, 2025 08:43
"""Check if equals to."""
compareto = self._ensure_awesome_version(compareto)
return self.string == compareto.string

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot make this new logic be opt-in by setting a kwarg to true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the semantic equality logic opt-in in commit 41c3a94. Added a semantic_equality kwarg that defaults to False for backward compatibility. Users must explicitly set semantic_equality=True to enable the trailing zeros equality behavior (e.g., AwesomeVersion("1.0", semantic_equality=True)).

Co-authored-by: ludeeus <15093472+ludeeus@users.noreply.github.com>
Copilot AI changed the title Fix semantic version equality for trailing zeros (1.0 == 1.0.0) Add opt-in semantic version equality for trailing zeros (1.0 == 1.0.0) Nov 19, 2025
Copilot AI requested a review from ludeeus November 19, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Versioning comparison

2 participants