-
Notifications
You must be signed in to change notification settings - Fork 245
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
(Python): @jsii.python.classproperty not working as intended with type checking #3633
Comments
In some scenarios, the `@classproperty` decorator would not yield something that python type checkers would consider as a property. This attempts to add additional type hints to help type checkers discover that the returned object is a property descriptor. Fixes #3633
In some scenarios, the `@classproperty` decorator would not yield something that python type checkers would consider as a property. This attempts to add additional type hints to help type checkers discover that the returned object is a property descriptor. Fixes #3633
Okay this is weird as I have definitely been validating that and it did not cause any issues with my setup, where it was considered all good (we actually run Would you be able to try and replace the |
@RomainMuller assuming I did this right (replaced the file in my |
This feels like the type checker you're using might be incorrectly handling property descriptors... can you tell more about what the setup/tooling is? |
This is Pyright with default settings. Pyright version is 1.1.264 if that helps. |
Okay... I've tried running PyRight on the jsii runtime for Python... it definitely found some issues that |
I found the cause of the issue to be that the |
It'd be awesome if pyright were included in the test suite. It's the type checker used in Pylance, VS Code's Python language server. |
@gshpychka yep... I'm actually adding |
I think I might have hit a bug in |
The `jsii.python` submodule was not re-exported in `__init__.py`, which made type resolves not manage to access the. `@classproperty` decorator and default to treating it as `Any`. This adds some missing type annotations, runs `pyright` on the runtime library and tests thereof (as `mypy` did not identify this problem), and adds the missing export declaration. Fixes #3633 --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
|
Reopening as I can confirm this still doesn't work as expected with PyCharm:
PyCharm thinks that It stops complaining. VSCode though doesn't seem to exhibit this issue: |
Describe the bug
Static properties in the generated Python code are not correctly interpreted by the type checking system. They're recognized as class methods, and require casting.
Consider the following example snippet:
Expected Behavior
pyright does not report any issues
Current Behavior
Type checker interprets the type of the property as a callable method
Reproduction Steps
Use any static property and enable type checking.
Possible Solution
No response
Additional Information/Context
No response
SDK version used
1.61.0
Environment details (OS name and version, etc.)
Linux
The text was updated successfully, but these errors were encountered: