-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
add type hints #42
Merged
Merged
add type hints #42
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
854a4d6
add type hints
jicruz96 407e516
[nit] standardize imports
jicruz96 d491cf3
use ContinentCode type for Country.continentcode
jicruz96 01e8341
fix mypy errors by loosening type restrictions of helper functions
jicruz96 d0cc123
add typing overloads for geonamescache.mappers.country
jicruz96 89ae766
explicitly type country field types
jicruz96 ff92eb4
[nit] use explicit types for country overload
jicruz96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
# -*- coding: utf-8 -*- | ||
from typing import List | ||
|
||
from typing_extensions import Literal, NotRequired, TypedDict | ||
|
||
GeoNameIdStr = str | ||
ISOStr = str | ||
ContinentCode = Literal['AF', 'AN', 'AS', 'EU', 'NA', 'OC', 'SA'] | ||
USStateCode = Literal[ | ||
'AK', | ||
'AL', | ||
'AR', | ||
'AZ', | ||
'CA', | ||
'CO', | ||
'CT', | ||
'DC', | ||
'DE', | ||
'FL', | ||
'GA', | ||
'HI', | ||
'IA', | ||
'ID', | ||
'IL', | ||
'IN', | ||
'KS', | ||
'KY', | ||
'LA', | ||
'MA', | ||
'MD', | ||
'ME', | ||
'MI', | ||
'MN', | ||
'MO', | ||
'MS', | ||
'MT', | ||
'NC', | ||
'ND', | ||
'NE', | ||
'NH', | ||
'NJ', | ||
'NM', | ||
'NV', | ||
'NY', | ||
'OH', | ||
'OK', | ||
'OR', | ||
'PA', | ||
'RI', | ||
'SC', | ||
'SD', | ||
'TN', | ||
'TX', | ||
'UT', | ||
'VA', | ||
'VT', | ||
'WA', | ||
'WI', | ||
'WV', | ||
'WY', | ||
] | ||
USStateName = Literal[ | ||
'Alaska', | ||
'Alabama', | ||
'Arkansas', | ||
'Arizona', | ||
'California', | ||
'Colorado', | ||
'Connecticut', | ||
'District of Columbia', | ||
'Delaware', | ||
'Florida', | ||
'Georgia', | ||
'Hawaii', | ||
'Iowa', | ||
'Idaho', | ||
'Illinois', | ||
'Indiana', | ||
'Kansas', | ||
'Kentucky', | ||
'Louisiana', | ||
'Massachusetts', | ||
'Maryland', | ||
'Maine', | ||
'Michigan', | ||
'Minnesota', | ||
'Missouri', | ||
'Mississippi', | ||
'Montana', | ||
'North Carolina', | ||
'North Dakota', | ||
'Nebraska', | ||
'New Hampshire', | ||
'New Jersey', | ||
'New Mexico', | ||
'Nevada', | ||
'New York', | ||
'Ohio', | ||
'Oklahoma', | ||
'Oregon', | ||
'Pennsylvania', | ||
'Rhode Island', | ||
'South Carolina', | ||
'South Dakota', | ||
'Tennessee', | ||
'Texas', | ||
'Utah', | ||
'Virginia', | ||
'Vermont', | ||
'Washington', | ||
'Wisconsin', | ||
'West Virginia', | ||
'Wyoming', | ||
] | ||
CitySearchAttribute = Literal['alternatenames', 'admin1code', 'countrycode', 'name', 'timezone'] | ||
|
||
|
||
class TimeZone(TypedDict): | ||
dstOffset: int | ||
gmtOffset: int | ||
timeZoneId: str | ||
|
||
|
||
class BBox(TypedDict): | ||
accuracyLevel: int | ||
east: float | ||
north: float | ||
south: float | ||
west: float | ||
|
||
|
||
class ContinentAlternateName(TypedDict): | ||
lang: str | ||
name: str | ||
isPreferredName: NotRequired[bool] | ||
isShortName: NotRequired[bool] | ||
isColloquial: NotRequired[bool] | ||
|
||
|
||
class Continent(TypedDict): | ||
alternateNames: List[ContinentAlternateName] | ||
adminName1: str | ||
adminName2: str | ||
adminName3: str | ||
adminName4: str | ||
adminName5: str | ||
asciiName: str | ||
continentCode: ContinentCode | ||
fclName: str | ||
fcodeName: str | ||
astergdem: int | ||
bbox: BBox | ||
geonameId: int | ||
fcl: str | ||
fcode: str | ||
lat: str | ||
lng: str | ||
name: str | ||
population: int | ||
timezone: TimeZone | ||
toponymName: str | ||
srtm3: int | ||
wikipediaURL: str | ||
cc2: NotRequired[str] | ||
|
||
|
||
class City(TypedDict): | ||
alternatenames: List[str] | ||
admin1code: str | ||
countrycode: str | ||
geonameid: int | ||
latitude: float | ||
longitude: float | ||
name: str | ||
population: int | ||
timezone: str | ||
|
||
|
||
class Country(TypedDict): | ||
areakm2: int | ||
capital: str | ||
continentcode: ContinentCode | ||
currencycode: str | ||
currencyname: str | ||
iso: str | ||
isonumeric: int | ||
iso3: str | ||
fips: str | ||
geonameid: int | ||
languages: str | ||
name: str | ||
neighbours: str | ||
phone: str | ||
population: int | ||
postalcoderegex: str | ||
tld: str | ||
|
||
|
||
class USState(TypedDict): | ||
code: USStateCode | ||
fips: str | ||
geonameid: int | ||
name: USStateName | ||
|
||
|
||
class USCounty(TypedDict): | ||
fips: str | ||
name: str | ||
state: USStateCode |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ ipython | |
ipdb | ||
pytest | ||
twine | ||
typing-extensions | ||
wheel |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,5 @@ | |
], | ||
test_suite='tests', | ||
tests_require=['pytest'], | ||
install_requires=["typing-extensions"] | ||
) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend this be treated as a patch, as the underlying functionality hasn't changed, although a minor update would make sense too given the addition of a dependency.