fix: make collections import compatible across Python versions (#419)
* Use collections.abc, fixes #418
* Python 2.7 compat fix
* Fix check
diff --git a/google/auth/jwt.py b/google/auth/jwt.py
index a30c575..361c456 100644
--- a/google/auth/jwt.py
+++ b/google/auth/jwt.py
@@ -40,7 +40,10 @@
"""
-import collections
+try:
+ from collections.abc import Mapping
+except ImportError: # Python 2.7 compatibility
+ from collections import Mapping
import copy
import datetime
import json
@@ -215,7 +218,7 @@
# If certs is specified as a dictionary of key IDs to certificates, then
# use the certificate identified by the key ID in the token header.
- if isinstance(certs, collections.Mapping):
+ if isinstance(certs, Mapping):
key_id = header.get("kid")
if key_id:
if key_id not in certs: