Pycharm autofill suggestions for dynamically built objects

已回答

Hello

I'm building objects dynamically using settattr() from a known set of allowed attribute names. I would like PyCharm to suggest me those attribute names. Is there a way to achieve that?

I tried using __slots__ in my classes, but PyCharm didn't use them for suggestions.

0

Hi Michal! There's a similar ticket in our tracker: PY-20062 feel free to vote for it. Meanwhile only way to achieve this right now I can think of is to create a stub file (.pyi) for your script and specify all possible attributes there. Something like this:

# sample.py
class Foo:
pass
# sample.pyi
class Foo:
a = ...
b = ...
0
Avatar
Permanently deleted user

Works like a charm! Exactly what I needed. Thanks

0

请先登录再写评论。