Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@property.setter incorrectly generated in stub files #29

Open
creatidy opened this issue Dec 24, 2024 · 0 comments
Open

@property.setter incorrectly generated in stub files #29

creatidy opened this issue Dec 24, 2024 · 0 comments

Comments

@creatidy
Copy link

Description:

The current implementation of @property.setter in QuantConnectStubsGenerator incorrectly generates the decorator as @property.setter instead of @<property_name>.setter. This causes PyLance and other Python tools to report a redeclaration error (reportRedeclaration) when a property and its setter share the same name.


Steps to Reproduce:

  1. Generate stubs using QuantConnectStubsGenerator.
  2. Define a property with both a getter and a setter in the codebase.
  3. Observe the generated output for the property and its setter.

Example of Incorrect Output:

@property
def time_in_force(self) -> QuantConnect.Orders.TimeInForce:
    ...

@property.setter
def time_in_force(self, value: QuantConnect.Orders.TimeInForce) -> None:
    ...

Expected Output:

The setter decorator should use the property name explicitly:

@property
def time_in_force(self) -> QuantConnect.Orders.TimeInForce:
    ...

@time_in_force.setter
def time_in_force(self, value: QuantConnect.Orders.TimeInForce) -> None:
    ...

Fix:

The issue can be fixed by updating the PropertyRenderer to use the correct setter decorator. Here's the proposed change:

diff --git a/QuantConnectStubsGenerator/Renderer/PropertyRenderer.cs b/QuantConnectStubsGenerator/Renderer/PropertyRenderer.cs
index fb017b5..6fc37be 100644
--- a/QuantConnectStubsGenerator/Renderer/PropertyRenderer.cs
+++ b/QuantConnectStubsGenerator/Renderer/PropertyRenderer.cs
@@ -110,7 +110,7 @@ namespace QuantConnectStubsGenerator.Renderer
             // render setter for mypy to be happy
             if (property.HasSetter)
             {
-                WriteLine("@property.setter");
+                WriteLine($"@{property.Name}.setter");

                 // Add the getter
                 WriteLine($"def {property.Name}(self, value: {property.Type.ToPythonString()}) -> None:");

Impact:

This bug affects compatibility with PyLance and other Python tooling, leading to false-positive errors during development.


Environment:

  • QuantConnect Stubs Generator version: generated from current master
  • Python version: 3.11.9

Additional Notes:

Please let me know if more details or a pull request are needed. Thank you for maintaining this great tool! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant