Skip to content

Commit

Permalink
Remove redundant Python 2 code
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored and Asif Saif Uddin committed Mar 21, 2021
1 parent 16e77b1 commit f57bc48
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 24 deletions.
10 changes: 1 addition & 9 deletions geojson/geometry.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import sys
from decimal import Decimal
from numbers import Number

from geojson.base import GeoJSON


if sys.version_info[0] == 3:
# Python 3.x has no long type
_JSON_compliant_types = (float, int, Decimal)
else:
_JSON_compliant_types = (float, int, Decimal, long) # noqa


class Geometry(GeoJSON):
"""
Represents an abstract base class for a WGS84 geometry.
Expand Down Expand Up @@ -50,7 +42,7 @@ def clean_coordinates(cls, coords, precision):
new_coords.append(cls.clean_coordinates(coord, precision))
elif isinstance(coord, Geometry):
new_coords.append(coord['coordinates'])
elif isinstance(coord, _JSON_compliant_types):
elif isinstance(coord, (float, int, Decimal)):
new_coords.append(round(coord, precision))
else:
raise ValueError("%r is not a JSON compliant number" % coord)
Expand Down
5 changes: 1 addition & 4 deletions geojson/mapping.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
try:
from collections.abc import MutableMapping
except ImportError:
from collections import MutableMapping
from collections.abc import MutableMapping

try:
import simplejson as json
Expand Down
2 changes: 0 additions & 2 deletions geojson/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ def coords(obj):
# Handle recursive case first
if 'features' in obj: # FeatureCollection
for f in obj['features']:
# For Python 2 compatibility
# See https://www.reddit.com/r/learnpython/comments/4rc15s/yield_from_and_python_27/ # noqa: E501
yield from coords(f)
elif 'geometry' in obj: # Feature
yield from coords(obj['geometry'])
Expand Down
6 changes: 1 addition & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import io
from setuptools import setup
import sys
import re
Expand All @@ -19,10 +18,7 @@

def test_suite():
import doctest
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest

suite = unittest.TestLoader().discover("tests")
suite.addTest(doctest.DocFileSuite("README.rst"))
Expand Down
5 changes: 1 addition & 4 deletions tests/test_features.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
from io import StringIO
import unittest

import geojson
Expand Down

0 comments on commit f57bc48

Please sign in to comment.