Fix incorrect type hints for timeout and language params in Nominatim and Photon#601
Open
nuglifeleoji wants to merge 1 commit into
Open
Fix incorrect type hints for timeout and language params in Nominatim and Photon#601nuglifeleoji wants to merge 1 commit into
nuglifeleoji wants to merge 1 commit into
Conversation
… Photon
Static type checkers (Pylance, mypy) reported incorrect type errors when
calling geocode/reverse with standard argument types:
- timeout: Pylance inferred the type as `geopy.geocoders.base.object` (the
custom sentinel class created via type('object', ...)), making `int`
values appear incompatible. (geopy#590)
- language: Pylance inferred the type as `bool` from the `False` default,
making string values like `'de'` appear incompatible. (geopy#593, geopy#594)
Fix both issues in Nominatim and Photon geocoders by:
- Adding `Optional[Union[int, float]]` type annotation for `timeout`
- Adding `Optional[str]` type annotation for `language`
- Changing the `language` default from `False` to `None` (both are falsy
so `if language:` checks are unaffected, but `None` communicates the
"not set" intent more clearly to type checkers)
Closes geopy#590, geopy#593, geopy#594
Made-with: Cursor
|
感谢您的来信,我会尽快查阅并回复!
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem (fixes #590, #593, #594)
Static type checkers (Pylance, mypy) report spurious errors for standard usage of
geocode()andreverse()in the Nominatim and Photon geocoders.Issue 1 –
timeoutparameter (#590)DEFAULT_SENTINELis created viatype('object', (object,), ...)(), giving it the class name'object'. Pylance treats this asgeopy.geocoders.base.object(notbuiltins.object), so any integer or float is seen as incompatible.Issue 2 –
languageparameter (#593, #594)language=Falsecauses Pylance to infer the parameter type asbool.Fix
Add explicit type annotations to
geocode()andreverse()in Nominatim and Photon:timeout: Optional[Union[int, float]] = DEFAULT_SENTINELlanguage: Optional[str] = None(default changed fromFalsetoNone;both are falsy so all
if language:checks are unaffected)The fix uses
typing.Optional/typing.Unionfor Python 3.7 compatibility.Made with Cursor