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

Dictionary support not reflected in type annotations #1380

Closed
PicardParis opened this issue Jul 29, 2022 · 4 comments · Fixed by #1464 or #1473
Closed

Dictionary support not reflected in type annotations #1380

PicardParis opened this issue Jul 29, 2022 · 4 comments · Fixed by #1464 or #1473
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@PicardParis
Copy link
Contributor

Issue

  • This is a follow-up to #986 (closed). Retesting the recent google-cloud-documentai==1.5.0 version, the issue is still present.
  • This code is valid:
    import google.cloud.documentai_v1 as documentai
    
    client_options = dict(api_endpoint="eu-documentai.googleapis.com")
    client = documentai.DocumentProcessorServiceClient(client_options=client_options)
    
  • But it triggers the following type checker warning:
    Argument of type "dict[str, str]" cannot be assigned to parameter "client_options" of type "ClientOptions | None" in function "__init__"
    Type "dict[str, str]" cannot be assigned to type "ClientOptions | None"
    "dict[str, str]" is incompatible with "ClientOptions"
    
  • If you check the source, client_options can be a dict, yet its declaration says otherwise:
    def __init__(
        ...
        client_options: Optional[client_options_lib.ClientOptions] = None,
        ...
    ) -> None:
        ...
        if isinstance(client_options, dict):
            client_options = client_options_lib.from_dict(client_options)

Expected

def __init__(
    ...
    client_options: Union[client_options_lib.ClientOptions, dict, None] = None,
    ...
) -> None:
    ...
@atulep
Copy link
Contributor

atulep commented Aug 15, 2022

@PicardParis

Yup, your code looks good. Feel free to open a PR. Otherwise, my team will triage this issue and resolve it, but may take longer.

@PicardParis
Copy link
Contributor Author

Hi, I thought the library was auto-generated from protobufs. Please confirm that it's not and I'll make a PR.

@vam-google
Copy link
Contributor

@PicardParis The library is generated, so the change should be done not in the lib, but in gapic-generator-python (i.e. this repository) instead. The changes are most likely to happen in one of the template files (*.py.j2 files). I would look into changing somethign here: https://github.com/googleapis/gapic-generator-python/blob/main/gapic/templates/%25namespace/%25name_%25version/%25sub/services/%25service/client.py.j2#L279

@vam-google vam-google added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p3 Desirable enhancement or fix. May not be included in next release. labels Aug 26, 2022
@PicardParis
Copy link
Contributor Author

@atulep @vam-google

  • Thanks for the explanation & pointer
  • I made the tentative PR#1431

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
3 participants