Skip to content

Annotate get_us_counties() - #50

Open
cweider wants to merge 1 commit into
yaph:masterfrom
cweider:annotate-get-us-counties
Open

cweider wants to merge 1 commit into
yaph:masterfrom
cweider:annotate-get-us-counties

Conversation

@cweider

@cweider cweider commented Sep 18, 2026 •

Copy link
Copy Markdown

8bd6642 (#42 - "add type hints") added type hints to all of the methods of GeonamesCache except for get_us_counties(). There's no discussion of the method in the pull request and no indication in the code that the absense of type annotation is important.

It is likely that it was omitted, because it was the one usage of _load_data() that was incompatible with the type that it specified (list vs. dict). The specification of dict by that method is not necessary. Specifying an unbound TypeVar will accomodate the usage by get_us_counties().

Being an annotation, the change will have no runtime affect and only a minimal effect for those consumers using a static type checker: the unusual consumer that attempts to del a key or assigns a value with an incompatible type will receive errors from their type checker. Additions to the dictionary will be permitted, since USCountry is not closed.

As adding the annotation will remove the need for a cast by consumers, it's a worthwhile amendment to the interface.

8bd6642 (yaph#42 - "add type hints") added type hints all of the methods
of `GeonamesCache` except for `get_us_counties()`. There's no
discussion of the method in the pull request and no indication in
the code that the absense of type annotations is important.

It is likely that it was omitted, because it was the one usage of
`_load_data()` that was incompatible with the type that _it_
specified (`list` vs. `dict`). The specification of `dict` by that
method is not necessary. Specifying an unbound `TypeVar` will
accomodate the usage by `get_us_counties()`.

Being an annotation, the change will have no runtime affect and
only a minimal effect for those consumers using a static type
checker: the unusual consumer that attempts to `del` a key or
assigns a value with an incompatible type will receive errors
from their type checker. Additions to the dictionary will be
permitted, since `USCountry` is not `closed`.

As adding the annotation will remove the need for a `cast` by
consumers, it's a worthwhile amendment to the interface.
Comment thread geonamescache/__init__.py
)

TDict = TypeVar('TDict', bound=Mapping[str, Any])
TData = TypeVar('TData')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to underscore these (and get_dataset_by_key() as well), but that has an API effect and can get done at some later date.

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

Successfully merging this pull request may close these issues.

1 participant