def test_should_refinement_nested_dict(self):
     self.assertEqual(
         TypeBrick(
             kind="Union",
             indexes=[
                 TypeBrick(kind="Optional",
                           indexes=[TypeBrick(kind="Dict", indexes=[])])
             ],
         ),
         typehint_parser.parse_typehint("Union[Optional[dict]]"),
     )
 def test_should_fix_incorrect_type(self):
     self.assertEqual(
         TypeBrick(
             kind="Dict",
             indexes=[
                 TypeBrick(kind="str", indexes=[]),
                 TypeBrick(kind="float", indexes=[]),
             ],
         ),
         typehint_parser.parse_typehint("dict[str -> float]"),
     )
 def test_should_parse_dict(self):
     self.assertEqual(
         TypeBrick(
             kind="Dict",
             indexes=[
                 TypeBrick(kind="str", indexes=[]),
                 TypeBrick(kind="str", indexes=[]),
             ],
         ),
         typehint_parser.parse_typehint("Dict[str, str]"),
     )
 def test_should_parse_deprecated_union_style(self):
     self.assertEqual(
         TypeBrick(
             kind="Iterator",
             indexes=[
                 TypeBrick(
                     kind="Union",
                     indexes=[
                         TypeBrick(kind="Dict", indexes=[]),
                         TypeBrick(kind="Set", indexes=[]),
                     ],
                 )
             ],
         ),
         typehint_parser.parse_typehint("iterator[dict|set]"),
     )
    def _consume_field(self) -> Tuple[str, TypeBrick, List[SectionBrick]]:
        line = next(self._line_iter)

        before, _, after = self._partition_field_on_colon(line)
        _name, _type, _desc = before, "", after

        match = _TYPED_ARG_REGEX.match(before)
        if match:
            _name = match.group(1)
            _type = match.group(2)

        _type_element = typehint_parser.parse_typehint(_type)
        indent = self._get_indent(line) + 1
        _descs = [_desc] + self._dedent(self._consume_indented_block(indent))
        _sections = [SectionBrick("Text", self._join_sentences(_descs))]
        return _name, _type_element, _sections
    def _consume_returns_section(self) -> List[FieldBrick]:
        lines = self._dedent(self._consume_to_next_section())
        if lines:
            before, colon, after = self._partition_field_on_colon(lines[0])
            _name, _type, _desc = "", "", lines

            if colon:
                if after:
                    _desc = [after] + lines[1:]
                else:
                    _desc = lines[1:]

                _type = before

            _sections = [SectionBrick("Text", self._join_sentences(_desc))]
            _type_element = typehint_parser.parse_typehint(
                _type) if _type else None
            return [FieldBrick(_name, _type_element, _sections)]
        return []
 def test_should_refinement_dict(self):
     self.assertEqual(TypeBrick(kind="Dict", indexes=[]),
                      typehint_parser.parse_typehint("dict"))
 def test_real_cases(self, exptected_result, input_text):
     self.assertEqual(exptected_result,
                      typehint_parser.parse_typehint(input_text))
 def test_should_parse_list(self):
     self.assertEqual(
         TypeBrick(kind="List", indexes=[TypeBrick(kind="str",
                                                   indexes=[])]),
         typehint_parser.parse_typehint("List[str]"),
     )
 def test_should_parse_class(self):
     self.assertEqual(
         TypeBrick(kind="airflow_munchkin.typehint_parser", indexes=[]),
         typehint_parser.parse_typehint("airflow_munchkin.typehint_parser"),
     )
 def test_should_parse_primitives(self):
     self.assertEqual(TypeBrick(kind="str", indexes=[]),
                      typehint_parser.parse_typehint("str"))