@@ -161,6 +161,10 @@ class UnsupportedArrayError(ValueError):
161
161
pass
162
162
163
163
164
+ class ForeignObjectError (ValueError ):
165
+ pass
166
+
167
+
164
168
# {{{ mapper base class
165
169
166
170
ResultT = TypeVar ("ResultT" )
@@ -199,13 +203,6 @@ def handle_unsupported_array(self, expr: MappedT,
199
203
raise UnsupportedArrayError (
200
204
f"{ type (self ).__name__ } cannot handle expressions of type { type (expr )} " )
201
205
202
- def map_foreign (self , expr : Any , * args : P .args , ** kwargs : P .kwargs ) -> Any :
203
- """Mapper method that is invoked for an object of class for which a
204
- mapper method does not exist in this mapper.
205
- """
206
- raise ValueError (
207
- f"{ type (self ).__name__ } encountered invalid foreign object: { expr !r} " )
208
-
209
206
def rec (self , expr : ArrayOrNames , * args : P .args , ** kwargs : P .kwargs ) -> ResultT :
210
207
"""Call the mapper method of *expr* and return the result."""
211
208
method : Callable [..., Any ] | None
@@ -223,7 +220,9 @@ def rec(self, expr: ArrayOrNames, *args: P.args, **kwargs: P.kwargs) -> ResultT:
223
220
else :
224
221
return self .handle_unsupported_array (expr , * args , ** kwargs )
225
222
else :
226
- return cast ("ResultT" , self .map_foreign (expr , * args , ** kwargs ))
223
+ raise ForeignObjectError (
224
+ f"{ type (self ).__name__ } encountered invalid foreign "
225
+ f"object: { expr !r} " ) from None
227
226
228
227
assert method is not None
229
228
return cast ("ResultT" , method (expr , * args , ** kwargs ))
@@ -237,7 +236,8 @@ def rec_function_definition(
237
236
try :
238
237
method = self .map_function_definition # type: ignore[attr-defined]
239
238
except AttributeError :
240
- return cast ("FunctionResultT" , self .map_foreign (expr , * args , ** kwargs ))
239
+ raise ValueError (
240
+ f"{ type (self ).__name__ } lacks a mapper method for functions." ) from None
241
241
242
242
assert method is not None
243
243
return cast ("FunctionResultT" , method (expr , * args , ** kwargs ))
0 commit comments