55import inspect
66import logging
77import re
8- from typing import Any
8+ from typing import Any , Self
99import warnings
1010from uuid import UUID
1111
1212from bson .errors import InvalidId
1313from bson .objectid import ObjectId
1414from bson .son import SON
15- from typing_extensions import Self # For python 3.11 plus, can just use "from typing import Self"
1615
1716from opaque_keys import OpaqueKey , InvalidKeyError
1817from opaque_keys .edx .keys import AssetKey , CourseKey , DefinitionKey , \
@@ -412,8 +411,8 @@ def _from_deprecated_string(cls, serialized: str) -> Self:
412411
413412class LibraryLocator (BlockLocatorBase , CourseKey ):
414413 """
415- Locates a library. Libraries are XBlock structures with a 'library' block
416- at their root.
414+ Locates a legacy (v1) library. Legacy libraries are XBlock structures with a
415+ 'library' block at their root.
417416
418417 Libraries are treated analogously to courses for now. Once opaque keys are
419418 better supported, they will no longer have the 'run' property, and may no
@@ -1065,8 +1064,8 @@ def _from_deprecated_son(cls, id_dict, run):
10651064
10661065class LibraryUsageLocator (BlockUsageLocator ):
10671066 """
1068- Just like BlockUsageLocator, but this points to a block stored in a library,
1069- not a course .
1067+ Just like BlockUsageLocator, but this points to a block stored in a legacy
1068+ (v1) modulestore library .
10701069 """
10711070 CANONICAL_NAMESPACE = 'lib-block-v1'
10721071 KEY_FIELDS = ('library_key' , 'block_type' , 'block_id' )
@@ -1629,7 +1628,7 @@ class LibraryCollectionLocator(CheckFieldMixin, LibraryItemKey):
16291628 lib-collection:org:lib:collection-id
16301629 """
16311630 CANONICAL_NAMESPACE = 'lib-collection'
1632- KEY_FIELDS = ('library_key ' , 'collection_id' )
1631+ KEY_FIELDS = ('lib_key ' , 'collection_id' )
16331632 collection_id : str
16341633
16351634 __slots__ = KEY_FIELDS
@@ -1638,16 +1637,16 @@ class LibraryCollectionLocator(CheckFieldMixin, LibraryItemKey):
16381637 # Allow collection IDs to contian unicode characters
16391638 COLLECTION_ID_REGEXP = re .compile (r'^[\w\-.]+$' , flags = re .UNICODE )
16401639
1641- def __init__ (self , library_key : LibraryLocatorV2 , collection_id : str ):
1640+ def __init__ (self , lib_key : LibraryLocatorV2 , collection_id : str ):
16421641 """
16431642 Construct a CollectionLocator
16441643 """
1645- if not isinstance (library_key , LibraryLocatorV2 ):
1646- raise TypeError ("library_key must be a LibraryLocatorV2" )
1644+ if not isinstance (lib_key , LibraryLocatorV2 ):
1645+ raise TypeError ("lib_key must be a LibraryLocatorV2" )
16471646
16481647 self ._check_key_string_field ("collection_id" , collection_id , regexp = self .COLLECTION_ID_REGEXP )
16491648 super ().__init__ (
1650- library_key = library_key ,
1649+ lib_key = lib_key ,
16511650 collection_id = collection_id ,
16521651 )
16531652
@@ -1656,13 +1655,13 @@ def org(self) -> str | None: # pragma: no cover
16561655 """
16571656 The organization that this Collection belongs to.
16581657 """
1659- return self .library_key .org
1658+ return self .lib_key .org
16601659
16611660 def _to_string (self ) -> str :
16621661 """
16631662 Serialize this key as a string
16641663 """
1665- return ":" .join ((self .library_key .org , self .library_key .slug , self .collection_id ))
1664+ return ":" .join ((self .lib_key .org , self .lib_key .slug , self .collection_id ))
16661665
16671666 @classmethod
16681667 def _from_string (cls , serialized : str ) -> Self :
@@ -1671,14 +1670,14 @@ def _from_string(cls, serialized: str) -> Self:
16711670 """
16721671 try :
16731672 (org , lib_slug , collection_id ) = serialized .split (':' )
1674- library_key = LibraryLocatorV2 (org , lib_slug )
1675- return cls (library_key , collection_id )
1673+ lib_key = LibraryLocatorV2 (org , lib_slug )
1674+ return cls (lib_key , collection_id )
16761675 except (ValueError , TypeError ) as error :
16771676 raise InvalidKeyError (cls , serialized ) from error
16781677
16791678 @property
16801679 def context_key (self ) -> LibraryLocatorV2 :
1681- return self .library_key
1680+ return self .lib_key
16821681
16831682
16841683class LibraryContainerUsageLocator (LibraryUsageLocatorV2 ):
@@ -1694,7 +1693,7 @@ class LibraryContainerLocator(CheckFieldMixin, LibraryItemKey):
16941693 lct:org:lib:ct-type:ct-id
16951694 """
16961695 CANONICAL_NAMESPACE = 'lct' # "Library Container"
1697- KEY_FIELDS = ('library_key ' , 'container_type' , 'container_id' )
1696+ KEY_FIELDS = ('lib_key ' , 'container_type' , 'container_id' )
16981697 container_type : str
16991698 container_id : str
17001699
@@ -1704,17 +1703,17 @@ class LibraryContainerLocator(CheckFieldMixin, LibraryItemKey):
17041703 # Allow container IDs to contian unicode characters
17051704 CONTAINER_ID_REGEXP = re .compile (r'^[\w\-.]+$' , flags = re .UNICODE )
17061705
1707- def __init__ (self , library_key : LibraryLocatorV2 , container_type : str , container_id : str ):
1706+ def __init__ (self , lib_key : LibraryLocatorV2 , container_type : str , container_id : str ):
17081707 """
17091708 Construct a CollectionLocator
17101709 """
1711- if not isinstance (library_key , LibraryLocatorV2 ):
1712- raise TypeError ("library_key must be a LibraryLocatorV2" )
1710+ if not isinstance (lib_key , LibraryLocatorV2 ):
1711+ raise TypeError ("lib_key must be a LibraryLocatorV2" )
17131712
17141713 self ._check_key_string_field ("container_type" , container_type )
17151714 self ._check_key_string_field ("container_id" , container_id , regexp = self .CONTAINER_ID_REGEXP )
17161715 super ().__init__ (
1717- library_key = library_key ,
1716+ lib_key = lib_key ,
17181717 container_type = container_type ,
17191718 container_id = container_id ,
17201719 )
@@ -1724,11 +1723,11 @@ def org(self) -> str | None: # pragma: no cover
17241723 """
17251724 The organization that this Container belongs to.
17261725 """
1727- return self .library_key .org
1726+ return self .lib_key .org
17281727
17291728 @property
17301729 def context_key (self ) -> LibraryLocatorV2 :
1731- return self .library_key
1730+ return self .lib_key
17321731
17331732 @property
17341733 def lib_usage_key (self ) -> LibraryContainerUsageLocator :
@@ -1754,8 +1753,8 @@ def _to_string(self) -> str:
17541753 Serialize this key as a string
17551754 """
17561755 return ":" .join ((
1757- self .library_key .org ,
1758- self .library_key .slug ,
1756+ self .lib_key .org ,
1757+ self .lib_key .slug ,
17591758 self .container_type ,
17601759 self .container_id
17611760 ))
@@ -1767,7 +1766,7 @@ def _from_string(cls, serialized: str) -> Self:
17671766 """
17681767 try :
17691768 (org , lib_slug , container_type , container_id ) = serialized .split (':' )
1770- library_key = LibraryLocatorV2 (org , lib_slug )
1771- return cls (library_key , container_type , container_id )
1769+ lib_key = LibraryLocatorV2 (org , lib_slug )
1770+ return cls (lib_key , container_type , container_id )
17721771 except (ValueError , TypeError ) as error :
17731772 raise InvalidKeyError (cls , serialized ) from error
0 commit comments