def test_infer_prop_type_from_docstring(self) -> None: assert_equal(infer_prop_type_from_docstring('str: A string.'), 'str') assert_equal(infer_prop_type_from_docstring('Optional[int]: An int.'), 'Optional[int]') assert_equal( infer_prop_type_from_docstring('Tuple[int, int]: A tuple.'), 'Tuple[int, int]') assert_equal(infer_prop_type_from_docstring('\nstr: A string.'), None)
def infer_prop_type(docstr: Optional[str]) -> Optional[str]: """Infer property type from docstring or docstring signature.""" if docstr is not None: inferred = infer_ret_type_sig_from_anon_docstring(docstr) if not inferred: inferred = infer_prop_type_from_docstring(docstr) return inferred else: return None
def generate_c_property_stub(name: str, obj: object, output: List[str], readonly: bool) -> None: """Generate property stub using introspection of 'obj'. Try to infer type from docstring, append resulting lines to 'output'. """ docstr = getattr(obj, '__doc__', None) inferred = infer_prop_type_from_docstring(docstr) if not inferred: inferred = 'Any' output.append('@property') output.append('def {}(self) -> {}: ...'.format(name, inferred)) if not readonly: output.append('@{}.setter'.format(name)) output.append('def {}(self, val: {}) -> None: ...'.format(name, inferred))
def generate_c_property_stub(name: str, obj: object, output: List[str], readonly: bool) -> None: """Generate property stub using introspection of 'obj'. Try to infer type from docstring, append resulting lines to 'output'. """ docstr = getattr(obj, '__doc__', None) inferred = infer_prop_type_from_docstring(docstr) if not inferred: inferred = 'Any' output.append('@property') output.append('def {}(self) -> {}: ...'.format(name, inferred)) if not readonly: output.append('@{}.setter'.format(name)) output.append('def {}(self, val: {}) -> None: ...'.format(name, inferred))
def test_infer_prop_type_from_docstring(self) -> None: assert_equal(infer_prop_type_from_docstring('str: A string.'), 'str') assert_equal(infer_prop_type_from_docstring('Optional[int]: An int.'), 'Optional[int]') assert_equal(infer_prop_type_from_docstring('Tuple[int, int]: A tuple.'), 'Tuple[int, int]') assert_equal(infer_prop_type_from_docstring('\nstr: A string.'), None)