text
stringlengths 0
828
|
|---|
msg = ""No conversion finder provided to find a converter between parsed attribute '{patt}' of type "" \
|
""'{typ}' and expected type '{expt}'."".format(patt=str(parsed_att),
|
typ=get_pretty_type_str(type(parsed_att)),
|
expt=get_pretty_type_str(attribute_type))
|
else:
|
msg = ""No conversion chain found between parsed attribute '{patt}' of type '{typ}' and expected type "" \
|
""'{expt}' using conversion finder {conv}."".format(patt=parsed_att,
|
typ=get_pretty_type_str(type(parsed_att)),
|
expt=get_pretty_type_str(attribute_type),
|
conv=conversion_finder)
|
if errors is not None:
|
msg = msg + ' ' + str(errors)
|
return NoConverterFoundForObjectType(msg)"
|
505,"def get_all_conversion_chains_to_type(self, to_type: Type[Any])\
|
-> Tuple[List[Converter], List[Converter], List[Converter]]:
|
""""""
|
Utility method to find all converters to a given type
|
:param to_type:
|
:return:
|
""""""
|
return self.get_all_conversion_chains(to_type=to_type)"
|
506,"def get_all_conversion_chains_from_type(self, from_type: Type[Any]) \
|
-> Tuple[List[Converter], List[Converter], List[Converter]]:
|
""""""
|
Utility method to find all converters from a given type.
|
:param from_type:
|
:return:
|
""""""
|
return self.get_all_conversion_chains(from_type=from_type)"
|
507,"def get_all_conversion_chains(self, from_type: Type[Any] = JOKER, to_type: Type[Any] = JOKER)\
|
-> Tuple[List[Converter], List[Converter], List[Converter]]:
|
""""""
|
Utility method to find all converters or conversion chains matching the provided query.
|
:param from_type: a required type of input object, or JOKER for 'wildcard'(*) .
|
WARNING: ""from_type=AnyObject/object/Any"" means
|
""all converters able to source from anything"", which is different from ""from_type=JOKER"" which means ""all
|
converters whatever their source type"".
|
:param to_type: a required type of output object, or JOKER for 'wildcard'(*) .
|
WARNING: ""to_type=AnyObject/object/Any"" means ""all
|
converters able to produce any type of object"", which is different from ""to_type=JOKER"" which means ""all
|
converters whatever type they are able to produce"".
|
:return: a tuple of lists of matching converters, by type of *dest_type* match : generic, approximate, exact
|
""""""
|
pass"
|
508,"def find_and_convert(self, attr_name: str, attr_value: S, desired_attr_type: Type[T], logger: Logger,
|
options: Dict[str, Dict[str, Any]]) -> T:
|
""""""
|
Utility method to convert some value into the desired type. It relies on get_all_conversion_chains to find the
|
converters, and apply them in correct order
|
:return:
|
""""""
|
if robust_isinstance(attr_value, desired_attr_type) and not is_collection(desired_attr_type):
|
# value is already of the correct type
|
return attr_value
|
else:
|
# try to find conversion chains
|
generic, approx, exact = self.get_all_conversion_chains(type(attr_value), desired_attr_type)
|
all_chains = generic + approx + exact
|
if len(all_chains) > 0:
|
all_errors = dict()
|
for chain in reversed(all_chains):
|
try:
|
return chain.convert(desired_attr_type, attr_value, logger, options)
|
except Exception as e:
|
all_errors[chain] = e
|
raise AttrConversionException.create(attr_name, attr_value, desired_attr_type, all_errors)
|
else:
|
# did not find any conversion chain
|
raise NoConverterFoundForObjectType.create(self, attr_value, desired_attr_type)"
|
509,"def convert_collection_values_according_to_pep(coll_to_convert: Union[Dict, List, Set, Tuple],
|
desired_type: Type[T],
|
conversion_finder: 'ConversionFinder', logger: Logger, **kwargs) \
|
-> T:
|
""""""
|
Helper method to convert the values of a collection into the required (pep-declared) value type in desired_type.
|
If desired_type does not explicitly mention a type for its values, the collection will be returned as is, otherwise
|
a copy will be created and filled with conversions of the values, performed by the provided conversion_finder
|
:param coll_to_convert:
|
:param desired_type:
|
:param conversion_finder:
|
:param logger:
|
:param kwargs:
|
:return:
|
""""""
|
base_desired_type = get_base_generic_type(desired_type)
|
if issubclass(base_desired_type, Mapping): # or issubclass(base_desired_type, dict):
|
# get the base collection type if provided (this raises an error if key type is not str)
|
item_typ, _ = _extract_collection_base_type(desired_type, exception_if_none=False)
|
if item_typ is None:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.