def default_type_hints(self): fn_type_hints = IOTypeHints.from_callable(self.expand) if fn_type_hints is not None: fn_type_hints = fn_type_hints.strip_pcoll() # Prefer class decorator type hints for backwards compatibility. return get_type_hints(self.__class__).with_defaults(fn_type_hints)
def callable_ptransform_factory(*args, **kwargs): res = _PTransformFnPTransform(fn, *args, **kwargs) if ptransform_fn_typehints_enabled: # Apply type hints applied before or after the ptransform_fn decorator, # falling back on PTransform defaults. # If the @with_{input,output}_types decorator comes before ptransform_fn, # the type hints get applied to this function. If it comes after they will # get applied to fn, and @wraps will copy the _type_hints attribute to # this function. type_hints = get_type_hints(callable_ptransform_factory) res._set_type_hints(type_hints.with_defaults(res.get_type_hints())) _LOGGER.debug('type hints for %s: %s', res.default_label(), res.get_type_hints()) return res
def wrapper(*args, **kwargs): hints = get_type_hints(f) if hints.input_types: input_hints = getcallargs_forhints( f, *hints.input_types[0], **hints.input_types[1]) inputs = inspect.getcallargs(f, *args, **kwargs) for var, hint in input_hints.items(): value = inputs[var] new_value = check_or_interleave(hint, value, var) if new_value is not value: if var in kwargs: kwargs[var] = new_value else: args = list(args) for ix, pvar in enumerate(inspect.getargspec(f).args): if pvar == var: args[ix] = new_value break else: raise NotImplementedError('Iterable in nested argument %s' % var) res = f(*args, **kwargs) return check_or_interleave(hints.simple_output_type('typecheck'), res, None)
def wrapper(*args, **kwargs): hints = get_type_hints(f) if hints.input_types: # pylint: disable=too-many-nested-blocks input_hints = getcallargs_forhints( f, *hints.input_types[0], **hints.input_types[1]) inputs = inspect.getcallargs(f, *args, **kwargs) for var, hint in input_hints.items(): value = inputs[var] new_value = check_or_interleave(hint, value, var) if new_value is not value: if var in kwargs: kwargs[var] = new_value else: args = list(args) for ix, pvar in enumerate(getfullargspec(f).args): if pvar == var: args[ix] = new_value break else: raise NotImplementedError('Iterable in nested argument %s' % var) res = f(*args, **kwargs) return check_or_interleave(hints.simple_output_type('typecheck'), res, None)
def wrapper(*args, **kwargs): hints = get_type_hints(f) if hints.input_types: # pylint: disable=too-many-nested-blocks input_hints = getcallargs_forhints( f, *hints.input_types[0], **hints.input_types[1]) inputs = get_signature(f).bind(*args, **kwargs).arguments for var, hint in input_hints.items(): value = inputs[var] new_value = check_or_interleave(hint, value, var) if new_value is not value: if var in kwargs: kwargs[var] = new_value else: args = list(args) for ix, pvar in enumerate(get_signature(f).parameters): if pvar == var: args[ix] = new_value break else: raise NotImplementedError('Iterable in nested argument %s' % var) res = f(*args, **kwargs) return check_or_interleave(hints.simple_output_type('typecheck'), res, None)