@@ -57,6 +57,12 @@ class ApifyStorageClient(StorageClient):
5757 should be used when multiple consumers need to process requests from the same queue simultaneously.
5858 """
5959
60+ _LSP_ERROR_MSG = 'Expected "configuration" to be an instance of "apify.Configuration", but got {} instead.'
61+ """This class (intentionally) violates the Liskov Substitution Principle.
62+
63+ It requires a specialized `Configuration` instance compared to its parent class.
64+ """
65+
6066 def __init__ (self , * , request_queue_access : Literal ['single' , 'shared' ] = 'single' ) -> None :
6167 """Initialize a new instance.
6268
@@ -68,23 +74,6 @@ def __init__(self, *, request_queue_access: Literal['single', 'shared'] = 'singl
6874 """
6975 self ._request_queue_access = request_queue_access
7076
71- # This class breaches Liskov Substitution Principle. It requires specialized Configuration compared to its parent.
72- _lsp_violation_error_message_template = (
73- 'Expected "configuration" to be an instance of "apify.Configuration", but got {} instead.'
74- )
75-
76- @override
77- def get_storage_client_cache_key (self , configuration : CrawleeConfiguration ) -> Hashable :
78- if isinstance (configuration , ApifyConfiguration ):
79- # It is not supported to open exactly same queue with 'single' and 'shared' client at the same time.
80- # Whichever client variation gets used first, wins.
81- return super ().get_storage_client_cache_key (configuration ), hash_api_base_url_and_token (configuration )
82-
83- config_class = type (configuration )
84- raise TypeError (
85- self ._lsp_violation_error_message_template .format (f'{ config_class .__module__ } .{ config_class .__name__ } ' )
86- )
87-
8877 @override
8978 async def create_dataset_client (
9079 self ,
@@ -98,7 +87,7 @@ async def create_dataset_client(
9887 if isinstance (configuration , ApifyConfiguration ):
9988 return await ApifyDatasetClient .open (id = id , name = name , alias = alias , configuration = configuration )
10089
101- raise TypeError (self ._lsp_violation_error_message_template .format (type (configuration ).__name__ ))
90+ raise TypeError (self ._LSP_ERROR_MSG .format (type (configuration ).__name__ ))
10291
10392 @override
10493 async def create_kvs_client (
@@ -113,7 +102,7 @@ async def create_kvs_client(
113102 if isinstance (configuration , ApifyConfiguration ):
114103 return await ApifyKeyValueStoreClient .open (id = id , name = name , alias = alias , configuration = configuration )
115104
116- raise TypeError (self ._lsp_violation_error_message_template .format (type (configuration ).__name__ ))
105+ raise TypeError (self ._LSP_ERROR_MSG .format (type (configuration ).__name__ ))
117106
118107 @override
119108 async def create_rq_client (
@@ -130,4 +119,14 @@ async def create_rq_client(
130119 id = id , name = name , alias = alias , configuration = configuration , access = self ._request_queue_access
131120 )
132121
133- raise TypeError (self ._lsp_violation_error_message_template .format (type (configuration ).__name__ ))
122+ raise TypeError (self ._LSP_ERROR_MSG .format (type (configuration ).__name__ ))
123+
124+ @override
125+ def get_storage_client_cache_key (self , configuration : CrawleeConfiguration ) -> Hashable :
126+ if isinstance (configuration , ApifyConfiguration ):
127+ # It is not supported to open exactly same queue with 'single' and 'shared' client at the same time.
128+ # Whichever client variation gets used first, wins.
129+ return super ().get_storage_client_cache_key (configuration ), hash_api_base_url_and_token (configuration )
130+
131+ config_class = type (configuration )
132+ raise TypeError (self ._LSP_ERROR_MSG .format (f'{ config_class .__module__ } .{ config_class .__name__ } ' ))
0 commit comments