Module xtelligent_serial.data_structs.struct_descriptor
Expand source code
from collections import namedtuple
from dataclasses import Field
from typing import Type, Iterable, Any
DescriptorInterface2 = namedtuple('DescriptorInterface', ['name', 'is_instance', 'get_fields'])
class DescriptorInterface:
'''Describes a family of classes/structs such as dataclass or attrs.'''
@property
def name(self) -> str:
'''Name of the family/API (dataclass, attrs)'''
raise NotImplementedError()
def is_instance(self, target: Any) -> bool:
'''Returns True if an instance is from that family. Note that the API
may not leverage inheritance for membership.'''
raise NotImplementedError()
def get_fields(self, t: Type) -> Iterable[Field]:
'''Returns the fields of a type in the family/API. The result is an Iterable
of dataclasses.Field instances.'''
raise NotImplementedError()
def is_instance_callback(target: Any) -> bool:
'''Returns true if the target is an instance of the structure family.'''
raise NotImplementedError()
def get_fields_callback(wanted_type: Type) -> Iterable[Field]:
'''Returns the fields for the type. Requires that each field is compatible
with dataclasses.Field.'''
raise NotImplementedError()
def describe_struct_family(name, is_instance: is_instance_callback, get_fields: get_fields_callback) -> DescriptorInterface:
return DescriptorInterface2(name, is_instance, get_fields)
Functions
def describe_struct_family(name, is_instance:
is_instance_callback() at 0x7f572f9fd5e0>, get_fields: get_fields_callback() at 0x7f572f9fd820>) ‑> DescriptorInterface -
Expand source code
def describe_struct_family(name, is_instance: is_instance_callback, get_fields: get_fields_callback) -> DescriptorInterface: return DescriptorInterface2(name, is_instance, get_fields)
def get_fields_callback(wanted_type: Type) ‑> Iterable[dataclasses.Field]
-
Returns the fields for the type. Requires that each field is compatible with dataclasses.Field.
Expand source code
def get_fields_callback(wanted_type: Type) -> Iterable[Field]: '''Returns the fields for the type. Requires that each field is compatible with dataclasses.Field.''' raise NotImplementedError()
def is_instance_callback(target: Any) ‑> bool
-
Returns true if the target is an instance of the structure family.
Expand source code
def is_instance_callback(target: Any) -> bool: '''Returns true if the target is an instance of the structure family.''' raise NotImplementedError()
Classes
class DescriptorInterface2 (name, is_instance, get_fields)
-
DescriptorInterface(name, is_instance, get_fields)
Expand source code
class DescriptorInterface: '''Describes a family of classes/structs such as dataclass or attrs.''' @property def name(self) -> str: '''Name of the family/API (dataclass, attrs)''' raise NotImplementedError() def is_instance(self, target: Any) -> bool: '''Returns True if an instance is from that family. Note that the API may not leverage inheritance for membership.''' raise NotImplementedError() def get_fields(self, t: Type) -> Iterable[Field]: '''Returns the fields of a type in the family/API. The result is an Iterable of dataclasses.Field instances.''' raise NotImplementedError()
Ancestors
- builtins.tuple
Instance variables
var get_fields
-
Alias for field number 2
var is_instance
-
Alias for field number 1
var name
-
Alias for field number 0
class DescriptorInterface
-
Describes a family of classes/structs such as dataclass or attrs.
Expand source code
class DescriptorInterface: '''Describes a family of classes/structs such as dataclass or attrs.''' @property def name(self) -> str: '''Name of the family/API (dataclass, attrs)''' raise NotImplementedError() def is_instance(self, target: Any) -> bool: '''Returns True if an instance is from that family. Note that the API may not leverage inheritance for membership.''' raise NotImplementedError() def get_fields(self, t: Type) -> Iterable[Field]: '''Returns the fields of a type in the family/API. The result is an Iterable of dataclasses.Field instances.''' raise NotImplementedError()
Instance variables
var name : str
-
Name of the family/API (dataclass, attrs)
Expand source code
@property def name(self) -> str: '''Name of the family/API (dataclass, attrs)''' raise NotImplementedError()
Methods
def get_fields(self, t: Type) ‑> Iterable[dataclasses.Field]
-
Returns the fields of a type in the family/API. The result is an Iterable of dataclasses.Field instances.
Expand source code
def get_fields(self, t: Type) -> Iterable[Field]: '''Returns the fields of a type in the family/API. The result is an Iterable of dataclasses.Field instances.''' raise NotImplementedError()
def is_instance(self, target: Any) ‑> bool
-
Returns True if an instance is from that family. Note that the API may not leverage inheritance for membership.
Expand source code
def is_instance(self, target: Any) -> bool: '''Returns True if an instance is from that family. Note that the API may not leverage inheritance for membership.''' raise NotImplementedError()