Tinkoff / invest-python

Tinkoff Invest Python gRPC client
https://tinkoff.github.io/invest-python/
Apache License 2.0
317 stars 89 forks source link

Code Completion in PyCharm #51

Closed BatmanDZ closed 2 years ago

BatmanDZ commented 2 years ago

Что случилось?

Не работает автозаполнение кода в PyCharm в области редактирования. Инвалидами и реиндексация кэша не помогает. В run time в консоли PyCharm все работает

Воспроизведение

import tinkoff.invest as invest

with invest.Client(TOKEN) as client: client.

Tinkoff Invest Version

0.2.0-beta23

Python Version

3.9

OS

Mac OS

Логи

No response

irusland commented 2 years ago

Можно попробовать добавить

client: Services = client
client.
irusland commented 2 years ago

@daxartio это известный ишью https://youtrack.jetbrains.com/issue/PY-36444

Но можно починить это примерно заменив:


@contextmanager
def Client(
    token: str,
    *,
    sandbox_token: Optional[str] = None,
    options: Optional[ChannelArgumentType] = None,
    app_name: Optional[str] = None,
) -> Generator[Services, None, None]:
    with create_channel(options=options) as channel:
        yield Services(
            channel, token=token, sandbox_token=sandbox_token, app_name=app_name
        )

на


class Client:
    def __init__(
        self,
        token: str,
        *,
        sandbox_token: Optional[str] = None,
        options: Optional[ChannelArgumentType] = None,
        app_name: Optional[str] = None,
    ):
        self.token = token
        self.sandbox_token = sandbox_token
        self.options = options
        self.app_name = app_name
        self.channel = create_channel(options=self.options)

    def __enter__(self) -> Services:
        channel = self.channel.__enter__()
        return Services(
            channel, token=self.token, sandbox_token=self.sandbox_token, app_name=self.app_name
        )

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.channel.__exit__(exc_type, exc_val, exc_tb)

делаем?

irusland commented 2 years ago

И хинты появятся

Screenshot 2022-05-01 at 16 00 59
irusland commented 2 years ago

FIx https://github.com/Tinkoff/invest-python/pull/57