Python static property autocomplete list not working in PyCharm
I'm using PyCharm Community Edition 2024.2.4. Autocomplete function lists appear correctly except in the case where I have a static property returning an object instance.
The static property syntax comes from this post: @staticmethod with @property
class staticproperty(property):
def __get__(self, owner_self, owner_cls):
return self.fget()
class _ScorecardClass(object):
_average = 0
@property
def average_score(self) -> float:
return self._average
@average_score.setter
def average_score(self, value):
self._average = value
class MainClass(object):
@staticmethod
def _get_scorecard():
return _ExternalDataProvider._get_scorecard()
@staticproperty
def Scorecard() -> _ScorecardClass:
r"""Returns the scorecard."""
return MainClass._get_scorecard()
In calling code, I can access the Scorecard object via its static property as follows:
MainClass.ScoreCard
However, the average_score property is not shown in the popup function list for ScoreCard. If I enter the function name manually, the code runs correctly.
average = MainClass.ScoreCard.average_score
I have the various code-completion options enabled in PyCharm. It seems to work fine for instance properties, but not statics. The auto-complete list displays correctly in VS Code. I have tried Python 3.9 and 3.12 and it's the same in both cases.
If I do:
sc: _ScorecardClass
The sc variable shows the various properties of _ScorecardClass in its autocomplete list, complete with docstring when the property is highlighted.
请先登录再写评论。
Don't all answer at once guys!
Please try upgrading IDE to the latest version, disabling all non-bundled plugins (**Settings | Plugins**, click the cog icon -> Disable All Downloaded Plugins) and check if the problem persists.
If the problem remains unresolved, we would like to investigate it properly. Please create an issue on YouTrack (https://youtrack.jetbrains.com/newIssue) regarding this problem. Attach relevant logs (Help | Collect Logs and Diagnostic Data), screenshots, precise steps for reproducing the issue and a runnable code/project sample if needed.
For urgent inquiries, please use Help | Contact Support in the IDE.