Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

botostubs showing details for get_paginator, but not actual api call #10

Open
tekdj7 opened this issue Jul 10, 2020 · 7 comments
Open

Comments

@tekdj7
Copy link

tekdj7 commented Jul 10, 2020

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
`

@jeshan
Copy link
Owner

jeshan commented Jul 14, 2020

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
Copy link
Owner

jeshan commented Jul 14, 2020

Let me know if I misunderstood your question

@tekdj7
Copy link
Author

tekdj7 commented Jul 14, 2020

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
Copy link
Author

tekdj7 commented Jul 14, 2020

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
Copy link
Author

tekdj7 commented Jul 14, 2020

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.

@jeshan
Copy link
Owner

jeshan commented Jul 14, 2020

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?

@tekdj7
Copy link
Author

tekdj7 commented Jul 14, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants