-
Notifications
You must be signed in to change notification settings - Fork 20
feat!: rename LibraryCollectionLocator.collection_id to collection_code #434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1625,30 +1625,30 @@ def html_id(self) -> str: | |
| class LibraryCollectionLocator(CheckFieldMixin, CollectionKey): | ||
| """ | ||
| When serialized, these keys look like: | ||
| lib-collection:org:lib:collection-id | ||
| lib-collection:{org_code}:{library_code}:{collection_code} | ||
| """ | ||
| CANONICAL_NAMESPACE = 'lib-collection' | ||
| KEY_FIELDS = ('lib_key', 'collection_id') | ||
| KEY_FIELDS = ('lib_key', 'collection_code') | ||
| lib_key: LibraryLocatorV2 | ||
| collection_id: str | ||
| collection_code: str | ||
|
|
||
| __slots__ = KEY_FIELDS | ||
| CHECKED_INIT = False | ||
|
|
||
| # Allow collection IDs to contian unicode characters | ||
| COLLECTION_ID_REGEXP = re.compile(r'^[\w\-.]+$', flags=re.UNICODE) | ||
| COLLECTION_CODE_REGEXP = re.compile(r'^[\w\-.]+$', flags=re.UNICODE) | ||
|
|
||
| def __init__(self, lib_key: LibraryLocatorV2, collection_id: str): | ||
| def __init__(self, lib_key: LibraryLocatorV2, collection_code: str): | ||
| """ | ||
| Construct a CollectionLocator | ||
| """ | ||
| if not isinstance(lib_key, LibraryLocatorV2): | ||
| raise TypeError("lib_key must be a LibraryLocatorV2") | ||
|
|
||
| self._check_key_string_field("collection_id", collection_id, regexp=self.COLLECTION_ID_REGEXP) | ||
| self._check_key_string_field("collection_code", collection_code, regexp=self.COLLECTION_CODE_REGEXP) | ||
| super().__init__( | ||
| lib_key=lib_key, | ||
| collection_id=collection_id, | ||
| collection_code=collection_code, | ||
| ) | ||
|
|
||
| @property | ||
|
|
@@ -1658,6 +1658,13 @@ def org(self) -> str | None: # pragma: no cover | |
| """ | ||
| return self.lib_key.org | ||
|
|
||
| @property | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea. i'll do that when I open the broader renaming PR |
||
| def collection_id(self) -> str: | ||
| """ | ||
| Backcompat alias for collection_code | ||
| """ | ||
| return self.collection_code | ||
|
|
||
| def _to_string(self) -> str: | ||
| """ | ||
| Serialize this key as a string | ||
|
|
@@ -1670,9 +1677,9 @@ def _from_string(cls, serialized: str) -> Self: | |
| Instantiate this key from a serialized string | ||
| """ | ||
| try: | ||
| (org, lib_slug, collection_id) = serialized.split(':') | ||
| lib_key = LibraryLocatorV2(org, lib_slug) | ||
| return cls(lib_key, collection_id) | ||
| (org, library_code, collection_code) = serialized.split(':') | ||
| lib_key = LibraryLocatorV2(org, library_code) | ||
| return cls(lib_key, collection_code) | ||
| except (ValueError, TypeError) as error: | ||
| raise InvalidKeyError(cls, serialized) from error | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we make the constructor accept a backwards compatible
kwarg, so this isn't a breaking change? Because it's difficult, or because we want to force a change sooner and avoid having an inconsistent state for a long time?