botostubs icon indicating copy to clipboard operation
botostubs copied to clipboard

botostubs showing details for get_paginator, but not actual api call

Open tekdj7 opened this issue 5 years ago • 7 comments
trafficstars

botostubs type hinting, hover for get_paginator works fine. hover over "list_policies" doesn't work. autocomplete where "list_policies" doesn't work. It be nice if botostubs can be updated to handle things, when we have to use pagination.

` import boto3 import botostubs org_client = boto3.client("organizations") # type: botostubs.Organizations

def get_policies(filter): paginator = org_client.get_paginator("list_policies") policies = [] for page in paginator.paginate(Filter=filter): policies.extend(page.get("Policies")) return policies `

tekdj7 avatar Jul 10 '20 06:07 tekdj7

Hello Julio, botostubs does support paginators. You have to declare the type hint just like client classes. Try this:

paginator = org_client.get_paginator("list_policies") # type: botostubs.Organizations.ListPoliciesPaginator

jeshan avatar Jul 14 '20 15:07 jeshan

Let me know if I misunderstood your question

jeshan avatar Jul 14 '20 15:07 jeshan

Will test that out. However, I would prefer it would figure that out automatically, without me having to add separate type hints everywhere I use paginators. For instance, when doing calls without paginating, I don't have to add separate type hints, just having the main type hint when I declare the client, is sufficient.

tekdj7 avatar Jul 14 '20 16:07 tekdj7

org_client = boto3.client("organizations") # type: botostubs.Organizations org_info = org_client.describe_organization().get("Organization")

Example where it works nicely (without paginators), without me adding type hints to each API call

tekdj7 avatar Jul 14 '20 16:07 tekdj7

it be great, if botostubs handled that automatically, whenever it saw "get_paginator" being used. Other reason why its helpful, is so that its easy to comment out botostubs when no longer needed, or being deployed as a solution. Only have to comment the import line and the type hints in the client lines. If I have to add this for paginators separately, that is more lines to add comments too.

On another note, put in another ticket I think, to see if there is a method to use botostubs, without having to add type hints at all to each line, instead import botostubs, and then all works. that would be sweet. I primarily use Visual Studio Code, fyi.

tekdj7 avatar Jul 14 '20 16:07 tekdj7

I would prefer it would figure that out automatically

Yeah but I only included type hints that will work in many IDEs. Such feature that you're describing needs expertise on IDE-specific plugin dev which I don't have.

its easy to comment out botostubs when no longer needed

Instead of commenting it, I suggest you write it like this:

try:
  import botostubs
except:
  pass

If I have to add this for paginators separately, that is more lines to add comments too

If you're using the type hints as comments, then you don't need to comment them, right?

jeshan avatar Jul 14 '20 20:07 jeshan

try/except worked out great. errors I was still getting was my linters, and doing try/except got rid of those errors too.

I was thinking something like function overloads, similar to boto3-stubs (https://pypi.org/project/boto3-stubs/), and it doesn't require any IDE extensions to make it work. Or using pylance that just got released by microsoft visual studio code, where you can point at stubs in a directory, and it dynamically reads it. Just thoughts.

thanks for the help. much appreciated.

tekdj7 avatar Jul 14 '20 22:07 tekdj7