From bb18da769cbc8b4b31a5b3d3e61363ad323a0672 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 24 Oct 2019 12:08:08 -0700 Subject: [PATCH] PYTHON-2001 Fix Python 3.8 SyntaxWarning: "is not" with a literal (#425) Fixes this warning from Python 3.8: bson/json_util.py:702: SyntaxWarning: "is not" with a literal. Did you mean "!="? if doc['$minKey'] is not 1: bson/json_util.py:711: SyntaxWarning: "is not" with a literal. Did you mean "!="? if doc['$maxKey'] is not 1: --- bson/json_util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bson/json_util.py b/bson/json_util.py index 86c5c41c9..35bdc3070 100644 --- a/bson/json_util.py +++ b/bson/json_util.py @@ -699,7 +699,7 @@ def _parse_canonical_decimal128(doc): def _parse_canonical_minkey(doc): """Decode a JSON MinKey to bson.min_key.MinKey.""" - if doc['$minKey'] is not 1: + if type(doc['$minKey']) is not int or doc['$minKey'] != 1: raise TypeError('$minKey value must be 1: %s' % (doc,)) if len(doc) != 1: raise TypeError('Bad $minKey, extra field(s): %s' % (doc,)) @@ -708,7 +708,7 @@ def _parse_canonical_minkey(doc): def _parse_canonical_maxkey(doc): """Decode a JSON MaxKey to bson.max_key.MaxKey.""" - if doc['$maxKey'] is not 1: + if type(doc['$maxKey']) is not int or doc['$maxKey'] != 1: raise TypeError('$maxKey value must be 1: %s', (doc,)) if len(doc) != 1: raise TypeError('Bad $minKey, extra field(s): %s' % (doc,))