- Notifications
You must be signed in to change notification settings - Fork749
Closed
Description
Environment
- Pythonnet version: 2.5.2
- Python version: 3.7
- Operating System: Windows 10
- .NET Runtime: 4.8
Details
- Let's create a simple base class that exposes a property, then create a derived class that overrides the setter, but not the getter (that is supposed to be as it was defined in the base class)
namespacePythonNetTest{publicclassBaseClass{protectedstringname="noname";publicvirtualstringName{get=>name;set=>name=value;}}publicclassDerivedClass:BaseClass{publicoverridestringName{set=>base.Name=value.ToUpper();}}}
- Let's now use the above classes in Python
importclrclr.AddReference("PythonNetTest")fromPythonNetTestimportBaseClass,DerivedClassd=DerivedClass()b=BaseClass()b.Name='BaseClass Name'd.Name='DerivedClass Name'print(b.Name)# okprint(d.Name)# TypeError: property cannot be read
- Here the
print(d.Name)
will rise the exceptionTypeError: property cannot be read
. - As a workaround it is possible to use
print(d.GetType().BaseType.GetProperty('Name').GetValue(d))
instead, but it is not one would expect.