Python setter not recognized (property has no attribute setter)

Hi,

I am having an issue defining setter for an attribute. When I try to define a setter for an attribute using @property.setter, an error is shown when the project is build stating that the property has no attribute setter.

Copilot claims the following…

It seems you are encountering a common mistake when defining setters for properties in Python. Make sure that the property decorator is applied to the getter method first, and then you use the @property_name.setter decorator to define the setter. If the property is defined correctly, it should look something like this:

class MyClass:
    def __init__(self):
        self._attribute = None

    @property
    def attribute(self):
        return self._attribute

    @attribute.setter
    def attribute(self, value):
        self._attribute = value

Make sure the names are consistent, especially with the setter decorator, as typos or mismatched names can lead to the error “property has no attribute setter.”

Here is the code I am currently using:

@attribute(OpenTap.Display(Name=“ForumStep”, Description=“ForumStep Description”, Group=“Demo”))
@attribute(OpenTap.AllowAnyChild())
class ForumStep(TestStep):

_Number = property(Int32, 1) \
    .add_attribute(OpenTap.Display(Name="Number", Description="Size of the cell", Group="Cell Settings", Order=1))
def __init__(self) -> None:
    super().__init__()
@property
def Number(self)-> int:
    return self.Number
@Number.setter
def Number(self, value)-> None:
    self._Number = value

When I delete the setter only I am getting this message ‘object is not a type’ and when deleting setter and getter methods it works fine. I am wondering if the property returned from the getter is a .net object instead of python .

Check your imports—are you inadvertently importing every name from the opentap module? For example:

from opentap import *

When you use a wildcard import like this, the @property decorator will bind to a CLR property rather than a native Python one. As a best practice, avoid wildcard imports
(from module import *) to prevent namespace pollution and make your code clearer and more maintainable.