pylance-release
pylance-release copied to clipboard
completeFunctionParens adds unnecessary parentheses for cached properties
Environment data
- Language Server version: 2022.4.2
- OS and version: darwin x64
- Python version (and distribution if applicable, e.g. Anaconda): 3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:43:32) [Clang 12.0.1 ]
- python.analysis.indexing: null
- python.analysis.typeCheckingMode: basic
Expected behaviour
Completions for class methods with functools @cached_property
decorators should not add parentheses, even when "python.analysis.completeFunctionParens": true
. The completions behave properly (i.e. do not add parentheses) for methods with the @property
decorator, so this would provide consistent, identical behaviour for @property
and @cached_property
.
Actual behaviour
When "python.analysis.completeFunctionParens": true
, parentheses are added to completions for class methods which have the a @cached_property
decorator. This will usually cause a TypeError if the parentheses are not manually removed.
Code Snippet / Additional information
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from functools import cached_property
class C:
@cached_property
def x_cached(self):
return 'x'
@property
def x_property(self):
return 'x'
c = C()
c.x_cached() # current incorrect completion for @cached_property - this completion will cause a TypeError when run
c.x_cached # suggested correct completion - this will run correctly and be consistent with @property
c.x_property # current correct completion for @property
This is another case where we should replace the internal call isPropertyClass(x)
with isMaybeDescriptor(x, false)
so we treat all descriptors (regardless of whether they're properties) the same.
Closing as this is behaving properly in our latest releases.
As a side note, the semantic highlighting is also correct now. x_cached
is now colored as a property
instead of as a function
.