text stringlengths 0 828 |
|---|
# resolve forward references |
typ = resolve_forward_ref(typ) |
if not is_valid_pep484_type_hint(typ): |
raise InvalidPEP484TypeHint.create_for_object_attributes(item_type, attr_name, typ) |
return typ" |
1049,"def get_constructor_attributes_types(item_type) -> Dict[str, Tuple[Type[Any], bool]]: |
"""""" |
Utility method to return a dictionary of attribute name > attribute type from the constructor of a given type |
It supports PEP484 and 'attrs' declaration, see https://github.com/python-attrs/attrs. |
:param item_type: |
:return: a dictionary containing for each attr name, a tuple (type, is_mandatory) |
"""""" |
res = dict() |
try: |
# -- Try to read an 'attr' declaration and to extract types and optionality |
from parsyfiles.plugins_optional.support_for_attrs import get_attrs_declarations |
decls = get_attrs_declarations(item_type) |
# check that types are correct |
for attr_name, v in decls.items(): |
typ, is_optional = v |
# -- Get and check that the attribute type is PEP484 compliant |
typ = get_validated_attribute_type_info(typ, item_type, attr_name) |
# -- optional = attrs'Optional validator was used, or a default value was set, or type is pep484 Optional |
is_optional = is_optional or is_pep484_nonable(typ) |
# -- store both info in result dict |
res[attr_name] = (typ, not is_optional) |
return res |
except: # ImportError or NotAnAttrsClassError but we obviously cant import the latter. |
pass # do not specify a type and use 'pass' so as to reset the exception context |
# -- Fallback to PEP484 |
# first get the signature of the class constructor |
s = _get_constructor_signature(item_type) |
# then extract the type and optionality of each attribute and raise errors if needed |
for attr_name in s.parameters.keys(): |
# skip the 'self' attribute |
if attr_name != 'self': |
# -- Get and check that the attribute type is PEP484 compliant |
typ = get_validated_attribute_type_info(s.parameters[attr_name].annotation, item_type, attr_name) |
# -- is the attribute mandatory ? |
is_mandatory = (s.parameters[attr_name].default is Parameter.empty) and not is_pep484_nonable(typ) |
# -- store both info in result dict |
res[attr_name] = (typ, is_mandatory) |
return res" |
1050,"def create_for_collection_items(item_type, hint): |
"""""" |
Helper method for collection items |
:param item_type: |
:return: |
"""""" |
# this leads to infinite loops |
# try: |
# prt_type = get_pretty_type_str(item_type) |
# except: |
# prt_type = str(item_type) |
return TypeInformationRequiredError(""Cannot parse object of type {t} as a collection: this type has no valid "" |
""PEP484 type hint about its contents: found {h}. Please use a standard "" |
""PEP484 declaration such as Dict[str, Foo] or List[Foo]"" |
"""".format(t=str(item_type), h=hint))" |
1051,"def create_for_object_attributes(item_type, faulty_attribute_name: str, hint): |
"""""" |
Helper method for constructor attributes |
:param item_type: |
:return: |
"""""" |
# this leads to infinite loops |
# try: |
# prt_type = get_pretty_type_str(item_type) |
# except: |
# prt_type = str(item_type) |
return TypeInformationRequiredError(""Cannot create instances of type {t}: constructor attribute '{a}' has an"" |
"" invalid PEP484 type hint: {h}."".format(t=str(item_type), |
a=faulty_attribute_name, h=hint))" |
1052,"def bounding_box_from_annotation(source=None, padding=None, **kwargs): |
""""""bounding_box_from_annotation(source, padding, **kwargs) -> bounding_box |
Creates a bounding box from the given parameters, which are, in general, annotations read using :py:func:`bob.ip.facedetect.read_annotation_file`. |
Different kinds of annotations are supported, given by the ``source`` keyword: |
* ``direct`` : bounding boxes are directly specified by keyword arguments ``topleft`` and ``bottomright`` |
* ``eyes`` : the left and right eyes are specified by keyword arguments ``leye`` and ``reye`` |
* ``left-profile`` : the left eye and the mouth are specified by keyword arguments ``eye`` and ``mouth`` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.