def test_union(self): assert_equal(type_repr(Union[int, float]), 'int | float') assert_equal(type_repr(Union[int, None, List[Any]]), 'int | None | List[Any]') if PY_VERSION >= (3, 10): assert_equal(type_repr(int | None | list[Any]), 'int | None | list[Any]')
def _get_type_docs(self, keywords, custom_converters): type_docs = {} for kw in keywords: for arg in kw.args: kw.type_docs[arg.name] = {} for typ in arg.types: type_doc = TypeDoc.for_type(typ, custom_converters) if type_doc: kw.type_docs[arg.name][type_repr(typ)] = type_doc.name type_docs.setdefault(type_doc, set()).add(kw.name) for type_doc, usages in type_docs.items(): type_doc.usages = sorted(usages, key=str.lower) return set(type_docs)
def test_generics(self): assert_equal(type_repr(list[Any]), 'list[Any]') assert_equal(type_repr(dict[int, None]), 'dict[int, None]')
def test_generics_from_typing(self): assert_equal(type_repr(List[Any]), 'List[Any]') assert_equal(type_repr(Dict[int, None]), 'Dict[int, None]')
def test_no_typing_prefix(self): assert_equal(type_repr(List), 'List')
def test_string(self): assert_equal(type_repr('MyType'), 'MyType')
def test_none(self): assert_equal(type_repr(None), 'None')
def test_class(self): class Foo: pass assert_equal(type_repr(Foo), 'Foo')
def types_reprs(self): return [type_repr(t) for t in self.types]