text stringlengths 0 828 |
|---|
1623,"def get_applicable_options(self, options: Dict[str, Dict[str, Any]]): |
"""""" |
Returns the options that are applicable to this particular converter, from the full map of options. |
It first uses 'get_id_for_options()' to know the id of this parser, and then simply extracts the contents of |
the options corresponding to this id, or returns an empty dict(). |
:param options: a dictionary converter_id > options |
:return: |
"""""" |
return get_options_for_id(options, self.get_id_for_options())" |
1624,"def _convert(self, desired_type: Type[T], source_obj: S, logger: Logger, options: Dict[str, Dict[str, Any]]) -> T: |
"""""" |
Implementing classes should implement this method to perform the conversion itself |
:param desired_type: the destination type of the conversion |
:param source_obj: the source object that should be converter |
:param logger: a logger to use if any is available, or None |
:param options: additional options map. Implementing classes may use 'self.get_applicable_options()' to get the |
options that are of interest for this converter. |
:return: |
"""""" |
pass" |
1625,"def create_not_able_to_convert(source: S, converter: Converter, desired_type: Type[T]): |
"""""" |
Helper method provided because we actually can't put that in the constructor, it creates a bug in Nose tests |
ERROR: type should be string, got " https://github.com/nose-devs/nose/issues/725" |
:param source: |
:param converter: |
:param desired_type: |
:return: |
"""""" |
base_msg = 'Converter ' + str(converter) + ' is not able to ingest source value \'' + str(source) + '\''\ |
' of type \'' + get_pretty_type_str(type(source)) + '\' and/or convert it to type \'' \ |
+ get_pretty_type_str(desired_type) + '\'.' |
base_msg += ' This can happen in a chain when the previous step in the chain is generic and actually produced '\ |
' an output of the wrong type/content' |
return ConversionException(base_msg)" |
1626,"def create(converter_func: ConversionMethod, caught: Exception): |
"""""" |
Helper method provided because we actually can't put that in the constructor, it creates a bug in Nose tests |
ERROR: type should be string, got " https://github.com/nose-devs/nose/issues/725" |
:param converter_func: |
:param caught: |
:return: |
"""""" |
msg = 'Caught TypeError while calling conversion function \'' + str(converter_func.__name__) + '\'. ' \ |
'Note that the conversion function signature should be \'' + conversion_method_example_signature_str \ |
+ '\' (unpacked options mode - default) or ' + multioptions_conversion_method_example_signature_str \ |
+ ' (unpack_options = False).' \ |
+ 'Caught error message is : ' + caught.__class__.__name__ + ' : ' + str(caught) |
return CaughtTypeError(msg).with_traceback(caught.__traceback__)" |
1627,"def _convert(self, desired_type: Type[T], source_obj: S, logger: Logger, options: Dict[str, Dict[str, Any]]) -> T: |
"""""" |
Delegates to the user-provided method. Passes the appropriate part of the options according to the |
function name. |
:param desired_type: |
:param source_obj: |
:param logger: |
:param options: |
:return: |
"""""" |
try: |
if self.unpack_options: |
opts = self.get_applicable_options(options) |
if self.function_args is not None: |
return self.conversion_method(desired_type, source_obj, logger, **self.function_args, **opts) |
else: |
return self.conversion_method(desired_type, source_obj, logger, **opts) |
else: |
if self.function_args is not None: |
return self.conversion_method(desired_type, source_obj, logger, options, **self.function_args) |
else: |
return self.conversion_method(desired_type, source_obj, logger, options) |
except TypeError as e: |
raise CaughtTypeError.create(self.conversion_method, e)" |
1628,"def is_able_to_convert_detailed(self, strict: bool, from_type: Type[Any], to_type: Type[Any]): |
"""""" |
Overrides the parent method to delegate left check to the first (left) converter of the chain and right check |
to the last (right) converter of the chain. This includes custom checking if they have any... |
see Converter.is_able_to_convert for details |
:param strict: |
:param from_type: |
:param to_type: |
:return: |
"""""" |
# check if first and last converters are happy |
if not self._converters_list[0].is_able_to_convert(strict, from_type=from_type, to_type=JOKER): |
return False, None, None |
elif not self._converters_list[-1].is_able_to_convert(strict, from_type=JOKER, to_type=to_type): |
return False, None, None |
else: |
# behave as usual. This is probably useless but lets be sure. |
return super(ConversionChain, self).is_able_to_convert_detailed(strict, from_type, to_type)" |
1629,"def remove_first(self, inplace: bool = False): |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.