Skip to content

Commit

Permalink
add deprecation warning for alt_id, id, reference, and scope (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoehnelt authored Sep 20, 2019
1 parent e10f05d commit cdf75c7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ All notable changes to this project will be documented in this file.

## [Unreleased]
### Changed
- deprecation warning for place fields: `alt_id`, `id`, `reference`, and `scope`. Read more about this at https://developers.google.com/maps/deprecations.

## [v3.1.2]
### Added
### Removed
- Tests for distribution tar as part of CI

## [v3.1.2]
### Added
Expand Down
23 changes: 18 additions & 5 deletions googlemaps/places.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#

"""Performs requests to the Google Places API."""
import warnings

from googlemaps import convert

Expand All @@ -35,13 +36,13 @@
"geometry/viewport/southwest/lat",
"geometry/viewport/southwest/lng",
"icon",
"id",
"id", # deprecated: https://developers.google.com/maps/deprecations
"name",
"permanently_closed",
"photos",
"place_id",
"plus_code",
"scope",
"scope", # deprecated: https://developers.google.com/maps/deprecations
"types",
]
)
Expand All @@ -60,7 +61,7 @@
[
"address_component",
"adr_address",
"alt_id",
"alt_id", # deprecated: https://developers.google.com/maps/deprecations
"formatted_address",
"geometry",
"geometry/location",
Expand All @@ -74,13 +75,13 @@
"geometry/viewport/southwest/lat",
"geometry/viewport/southwest/lng",
"icon",
"id",
"id", # deprecated: https://developers.google.com/maps/deprecations
"name",
"permanently_closed",
"photo",
"place_id",
"plus_code",
"scope",
"scope", # deprecated: https://developers.google.com/maps/deprecations
"type",
"url",
"utc_offset",
Expand All @@ -102,6 +103,11 @@
^ PLACES_DETAIL_FIELDS_ATMOSPHERE
)

DEPRECATED_FIELDS = {"alt_id", "id", "reference", "scope"}
DEPRECATED_FIELDS_MESSAGE = (
"Fields, %s, are deprecated. "
"Read more at https://developers.google.com/maps/deprecations."
)

def find_place(
client, input, input_type, fields=None, location_bias=None, language=None
Expand Down Expand Up @@ -147,6 +153,13 @@ def find_place(
)

if fields:
deprecated_fields = set(fields) & DEPRECATED_FIELDS
if deprecated_fields:
warnings.warn(
DEPRECATED_FIELDS_MESSAGE % str(list(deprecated_fields)),
DeprecationWarning
)

invalid_fields = set(fields) - PLACES_FIND_FIELDS
if invalid_fields:
raise ValueError(
Expand Down

0 comments on commit cdf75c7

Please sign in to comment.