How to use the typeguard.qualified_name function in typeguard

To help you get started, we’ve selected a few typeguard examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebookincubator / TestSlide / testslide / lib.py View on Github external
def get_qualified_name(self):
        return typeguard.qualified_name(self._spec_class)
github agronholm / typeguard / tests / test_typeguard.py View on Github external
def test_qualified_name(inputval, expected):
    assert qualified_name(inputval) == expected
github facebookincubator / TestSlide / testslide / lib.py View on Github external
def _validate_argument_type(expected_type, name: str, value) -> None:
    if "~" in str(expected_type):
        # this means that we have a TypeVar type, and those require
        # checking all the types of all the params as a whole, but we
        # don't have a good way of getting right now
        # TODO: #165
        return

    original_check_type = typeguard.check_type
    original_qualified_name = typeguard.qualified_name

    def wrapped_qualified_name(obj):
        """Needed to be able to show the useful qualified name for mock specs"""
        if isinstance(obj, WrappedMock):
            return obj.get_qualified_name()

        return original_qualified_name(obj)

    def wrapped_check_type(
        argname,
        inner_value,
        inner_expected_type,
        *args,
        globals: Optional[Dict[str, Any]] = None,
        locals: Optional[Dict[str, Any]] = None,
        **kwargs,
github cenobites / flask-jsonrpc / flask_jsonrpc / site.py View on Github external
resp_view = view_func(**params)
            else:
                raise InvalidParamsError(
                    data={
                        'message': 'Parameter structures are by-position '
                        '(tuple, set, list) or by-name (dict): {0}'.format(params)
                    }
                )

            # TODO: Improve the checker to return type
            view_fun_annotations = get_type_hints(view_func)
            view_fun_return = view_fun_annotations.pop('return', None)
            if resp_view is not None and view_fun_return is None:
                raise TypeError(
                    'return type of {} must be a type; got {} instead'.format(
                        qualified_name(resp_view), qualified_name(view_fun_return)
                    )
                )
        except TypeError as e:
            current_app.logger.error('invalid type checked for: %s', view_func.__name__)
            current_app.logger.exception(e)
            raise InvalidParamsError(data={'message': str(e)})

        return self.make_response(req_json, resp_view)