perf: use _get_spec_version in more places in Specifier
#1005
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Inspired by @henryiii comment #999 (comment)
_get_spec_versionis an internal one element cache inSpecifierto save having to re-parse the version thatSpecifieris based on, we can use it in two extra places:_canonical_specwhen version is not a wild card, however a wild card will always fail to be turned into aVersionobject bycanonicalize_version, so we can short-circuit and immediately return the wild card string.prereleasesproperty, again when version is not a wild card, however wild cards cannot imply prereleases, e.g.1.0a1.*is not a valid version, so we can skip checking if wild cards imply prereleases and immediately returnFalse.Also I have added a new
TestSpecifierInternalthat validates that the underlying cache element_spec_versionis initially set and doesn't change, as it is not trivial to deduce that from all the places it is used. Let me know if this is over the top, I can remove it.