Example #1
0
 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]')
Example #2
0
 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)
Example #3
0
 def test_generics(self):
     assert_equal(type_repr(list[Any]), 'list[Any]')
     assert_equal(type_repr(dict[int, None]), 'dict[int, None]')
Example #4
0
 def test_generics_from_typing(self):
     assert_equal(type_repr(List[Any]), 'List[Any]')
     assert_equal(type_repr(Dict[int, None]), 'Dict[int, None]')
Example #5
0
 def test_no_typing_prefix(self):
     assert_equal(type_repr(List), 'List')
Example #6
0
 def test_string(self):
     assert_equal(type_repr('MyType'), 'MyType')
Example #7
0
 def test_none(self):
     assert_equal(type_repr(None), 'None')
Example #8
0
    def test_class(self):
        class Foo:
            pass

        assert_equal(type_repr(Foo), 'Foo')
Example #9
0
 def types_reprs(self):
     return [type_repr(t) for t in self.types]