Exemple #1
0
def transform(cls):
    """Pretend that any class inheriting from 'Dict' also inherits from 'dict'.
    Works around PyLint not knowing about operations on the 'Dict' class.
    https://github.com/PyCQA/pylint/issues/3129
    """
    for index, base in enumerate(cls.bases):
        if isinstance(base, Subscript):
            if isinstance(base.value, Name):
                if base.value.name == 'Dict':
                    cls.bases.append(Name('dict', parent=cls))
def _transform_assert_false_into_raise(assertion):
    if isinstance(assertion.test, Const) and assertion.test.value is False:
        out = Raise(lineno=assertion.lineno,
                    col_offset=assertion.col_offset,
                    parent=assertion.parent)
        exc = Call(parent=out)
        if assertion.fail:
            args = [assertion.fail]
            args[0].parent = exc
        else:
            args = []
        exc.postinit(Name("AssertionError", parent=exc), args)
        out.postinit(exc, None)
        return out