Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.
This repository was archived by the owner on Aug 30, 2026. It is now read-only.

Incorrect type hints in collection() #289

Closed

Description

@mbrancato

Environment details

  • OS type and version: MacOS
  • Python version: Python 3.7.7
  • google-cloud-firestore version: 2.0.2

At some point recently the type hints for for Client().collection() methods were changed, and they do not reflect examples or the docs. I'm getting type hint warnings.

def collection(self, *collection_path: Tuple[str]) -> CollectionReference:

Should the type hint be changed to simply str ? All the comments and docs show these:

client.collection('top')
client.collection('mydocs/doc/subcol')
client.collection('mydocs', 'doc', 'subcol')

None of these are Tuple[str]. The argument *collection_path will produce a tuple when called, but it is called with strings.

Activity

  1. added
    help wantedWe'd love to have community involvement on this issue.
    and removed
    triage meI really want to be triaged.
    on Jan 11, 2021
  2. added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    and removed
    triage meI really want to be triaged.
    on Jan 12, 2021
  3. tseaver commented on Feb 2, 2021

    @tseaver
    Contributor

    Per the implementation, the collection_path argument can be either a single, slash-delimited path string, or a Tuple[str]. See the _path_helper function, which also has an incorrect typespec for its argument.

  4. tseaver commented on Feb 2, 2021

    @tseaver
    Contributor

    A correction: the leading asterisk (*collection_path) means that the value received by the function will always be a tuple, and we require that the elements of the tuple be strings. The caller may pass a single string, e.g. client.collection("mydocs/doc/subcol"), which will be split on the slashes, exactly as if the caller had passed client.collection("mydocs", "doc", "subcol"). That example is from the docstring of Client.collection.

  5. tseaver commented on Feb 2, 2021

    @tseaver
    Contributor

    OK, looking at PEP 484, it appears that *args should be typed as the type of one element.

  6. added 2 commits that reference this issue on Feb 2, 2021
    21e4526
    ebe2b3e
  7. added a commit that references this issue on Feb 4, 2021
    15b579f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/python-firestore API.help wantedWe'd love to have community involvement on this issue.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions