def for_enum(cls, enum): accepts = (str, int) if issubclass(enum, int) else (str, ) return cls(cls.ENUM, enum.__name__, getdoc(enum), accepts, members=[ EnumMember(name, str(member.value)) for name, member in enum.__members__.items() ])
def for_typed_dict(cls, typed_dict): items = [] required_keys = list(getattr(typed_dict, '__required_keys__', [])) optional_keys = list(getattr(typed_dict, '__optional_keys__', [])) for key, value in typed_dict.__annotations__.items(): typ = value.__name__ if isclass(value) else str(value) required = key in required_keys if required_keys or optional_keys else None items.append(TypedDictItem(key, typ, required)) return cls(cls.TYPED_DICT, typed_dict.__name__, getdoc(typed_dict), accepts=(str, ), items=items)
def from_name(cls, name): """Return langauge class based on given `name`. Name is matched both against the class name (language short name) and possible docstring (full language name). Matching is case-insensitive and hyphen (`-`) is ignored to support, for example, `PT-BR`. Raises `ValueError` if no matching langauge is found. """ normalized = name.lower().replace('-', '') for subcls in cls.__subclasses__(): if normalized in (subcls.__name__.lower(), getdoc(subcls).lower()): return subcls() raise ValueError(f"No language with name '{name}' found.")
def __init__(self, libcode, name, args, variables): if os.path.exists(name): name = os.path.splitext(os.path.basename(os.path.abspath(name)))[0] self.version = self._get_version(libcode) self.name = name self.orig_name = name # Stores original name also after copying self.positional_args = [] self.named_args = {} self._instance_cache = [] self._libinst = None if libcode is not None: self._doc = utils.getdoc(libcode) self.scope = self._get_scope(libcode) self._libcode = libcode self.init = self._create_init_handler(libcode) self.positional_args, self.named_args = self.init.arguments.resolve(args, variables)
def __init__(self, libcode, name, args, variables): if os.path.exists(name): name = os.path.splitext(os.path.basename(os.path.abspath(name)))[0] self.version = self._get_version(libcode) self.name = name self.orig_name = name # Stores original name also after copying self.positional_args = [] self.named_args = {} self._instance_cache = [] self._libinst = None if libcode is not None: self._doc = utils.getdoc(libcode) self.scope = self._get_scope(libcode) self._libcode = libcode self.init = self._create_init_handler(libcode) self.positional_args, self.named_args = self.init.arguments.resolve( args, variables)
def __init__(self, library, handler_name, handler_method): _RunnableHandler.__init__(self, library, handler_name, handler_method) self._doc = utils.getdoc(handler_method)
def __init__(self, library, handler_name, handler_method): _RunnableHandler.__init__(self, library, handler_name, handler_method, getdoc(handler_method))
def doc(self): if self._doc is None: self._doc = getdoc(self.get_instance()) return self._doc
def doc(self): return getdoc(self.converter) or getdoc(self.type)