|
20 | 20 | )
|
21 | 21 | from mypy.stubutil import walk_packages, remove_misplaced_type_comments, common_dir_prefix
|
22 | 22 | from mypy.stubgenc import (
|
23 |
| - generate_c_type_stub, infer_method_sig, generate_c_function_stub, generate_c_property_stub |
| 23 | + generate_c_type_stub, infer_method_sig, generate_c_function_stub, generate_c_property_stub, |
| 24 | + is_c_property_readonly |
24 | 25 | )
|
25 | 26 | from mypy.stubdoc import (
|
26 | 27 | parse_signature, parse_all_signatures, build_signature, find_unique_signatures,
|
@@ -868,9 +869,34 @@ def get_attribute(self) -> None:
|
868 | 869 | pass
|
869 | 870 | attribute = property(get_attribute, doc="")
|
870 | 871 |
|
871 |
| - output: List[str] = [] |
872 |
| - generate_c_property_stub('attribute', TestClass.attribute, [], [], output, readonly=True) |
873 |
| - assert_equal(output, ['@property', 'def attribute(self) -> str: ...']) |
| 872 | + readwrite_properties: List[str] = [] |
| 873 | + readonly_properties: List[str] = [] |
| 874 | + generate_c_property_stub('attribute', TestClass.attribute, [], |
| 875 | + readwrite_properties, readonly_properties, |
| 876 | + is_c_property_readonly(TestClass.attribute)) |
| 877 | + assert_equal(readwrite_properties, []) |
| 878 | + assert_equal(readonly_properties, ['@property', 'def attribute(self) -> str: ...']) |
| 879 | + |
| 880 | + def test_generate_c_property_with_rw_property(self) -> None: |
| 881 | + class TestClass: |
| 882 | + def __init__(self) -> None: |
| 883 | + self._attribute = 0 |
| 884 | + |
| 885 | + @property |
| 886 | + def attribute(self) -> int: |
| 887 | + return self._attribute |
| 888 | + |
| 889 | + @attribute.setter |
| 890 | + def attribute(self, value: int) -> None: |
| 891 | + self._attribute = value |
| 892 | + |
| 893 | + readwrite_properties: List[str] = [] |
| 894 | + readonly_properties: List[str] = [] |
| 895 | + generate_c_property_stub("attribute", type(TestClass.attribute), [], |
| 896 | + readwrite_properties, readonly_properties, |
| 897 | + is_c_property_readonly(TestClass.attribute)) |
| 898 | + assert_equal(readwrite_properties, ['attribute: Any']) |
| 899 | + assert_equal(readonly_properties, []) |
874 | 900 |
|
875 | 901 | def test_generate_c_type_with_single_arg_generic(self) -> None:
|
876 | 902 | class TestClass:
|
|
0 commit comments