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

Make library compatible with type checking and auto-completion #695

Open
g3or3 opened this issue Aug 30, 2022 · 4 comments
Open

Make library compatible with type checking and auto-completion #695

g3or3 opened this issue Aug 30, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@g3or3
Copy link

g3or3 commented Aug 30, 2022

I noticed there are types available as part of the google ads client and I was wondering what the intended application is for them?

from google.ads.googleads.v11.services.types

I've tried using them to enforce type checking with mypy, e.g:

from google.ads.googleads.v11.services.types.customizer_attribute_service import CustomizerAttributeOperation

operations: List[CustomizerAttributeOperation] = [1, 2, 'banana'] # no error

However this is not raised as an error with mypy. Besides auto-completion is there something I'm missing as an intended benefit? Also, is there a way to make this work with mypy to enforce type checking?

Thank you!

@g3or3 g3or3 added the question Further information is requested label Aug 30, 2022
@g3or3 g3or3 changed the title googleads.vXX.servicices.types suggested use googleads.vXX.services.types suggested use Aug 30, 2022
@BenRKarl BenRKarl self-assigned this Sep 1, 2022
@BenRKarl
Copy link
Contributor

BenRKarl commented Sep 1, 2022

Hi @g3or3 thanks for the question - those are the types that are required by the adjacent service classes. Most of the operation, request, and response classes are defined there.

It's a bit complicated to ensure that the library is compatible with mypy type checking. All of the API-specific code (i.e. anything under the v* directories here) is generated, so to alter the structure of that portion of the library would require a huge amount of work that would affect other libraries at Google that rely on the code generator.

That said, I'll mark this as a feature request and see if we can make the library structure compatible with type checking/auto-completion in the future.

@g3or3
Copy link
Author

g3or3 commented Sep 1, 2022

Thank you for the insight! Looking forward to this.

@BenRKarl BenRKarl added enhancement New feature or request and removed question Further information is requested labels Sep 26, 2022
@BenRKarl BenRKarl removed their assignment Sep 26, 2022
@BenRKarl BenRKarl changed the title googleads.vXX.services.types suggested use Make library compatible with type checking and auto-completion Sep 26, 2022
@iRod3s
Copy link

iRod3s commented May 4, 2023

This would be much appreciated. The way my team is handing this problem is using https://github.com/henribru/google-ads-stubs to improve our development velocity, but an officially supported solution would be great

@henribru
Copy link

@g3or3 The reason Mypy doesn't complain about your code is that this package doesn't declare itself as supporting typechecking using a py.typed file. In the absence of this marker, Mypy treats anything imported from the package as Any, regardless of whether the package has type annotations. As far as I'm aware there's no way to force Mypy to look at the annotations in this case. Anyone who'd rather not use google-ads-stubs might have more luck with Pyright, I think the useLibraryCodeForTypes setting allows this. Though note that only the services in this package have actual type annotations, not the protobuff classes like CustomizerAttributeOperation. You should be able to get some basic typechecking for those using https://pypi.org/project/proto-plus-stubs/ (disclaimer: also my package).

It would be great not having to maintain google-ads-stubs anymore, so if I can help move this along in the future I'd be happy to, e.g. by upstreaming any work.

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

No branches or pull requests

4 participants