Skip to content

Commit d63aed2

Browse files
authored
Upgrade pylint to latest version (#41)
pylint 2.9.2 -> 2.15.9 in preparation for pylint 3.x
1 parent 5e46092 commit d63aed2

10 files changed

Lines changed: 26 additions & 105 deletions

opencage/geocoder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(self, reset_time, reset_to):
6262

6363
def __unicode__(self):
6464
"""Convert exception to a string."""
65-
return "Your rate limit has expired. It will reset to {0} on {1}".format(self.reset_to, self.reset_time.isoformat())
65+
return f"Your rate limit has expired. It will reset to {self.reset_to} on {self.reset_time.isoformat()}"
6666

6767
__str__ = __unicode__
6868

@@ -235,7 +235,7 @@ def _opencage_request(self, params):
235235
if self.session:
236236
response = self.session.get(self.url, params=params)
237237
else:
238-
response = requests.get(self.url, params=params)
238+
response = requests.get(self.url, params=params) # pylint: disable=missing-timeout
239239

240240
try:
241241
response_json = response.json()
@@ -248,7 +248,7 @@ def _opencage_request(self, params):
248248
if response.status_code == 403:
249249
raise ForbiddenError()
250250

251-
if (response.status_code == 402 or response.status_code == 429):
251+
if response.status_code in (402, 429):
252252
# Rate limit exceeded
253253
reset_time = datetime.utcfromtimestamp(response_json['rate']['reset'])
254254
raise RateLimitExceededError(reset_to=int(response_json['rate']['limit']), reset_time=reset_time)
@@ -274,7 +274,7 @@ async def _opencage_async_request(self, params):
274274
if response.status == 403:
275275
raise ForbiddenError()
276276

277-
if (response.status == 402 or response.status == 429):
277+
if response.status in (402, 429):
278278
# Rate limit exceeded
279279
print(response_json)
280280
reset_time = datetime.utcfromtimestamp(response_json['rate']['reset'])
@@ -306,7 +306,7 @@ def _query_for_reverse_geocoding(lat, lng):
306306
# have to do some stupid f/Decimal/str stuff to (a) ensure we get as much
307307
# decimal places as the user already specified and (b) to ensure we don't
308308
# get e-5 stuff
309-
return "{0:f},{1:f}".format(Decimal(str(lat)), Decimal(str(lng)))
309+
return f"{Decimal(str(lat)):f},{Decimal(str(lng)):f}"
310310

311311

312312
def float_if_float(float_string):

pylintrc

Lines changed: 7 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -54,92 +54,13 @@ confidence=
5454
# --enable=similarities". If you want to run only the classes checker, but have
5555
# no Warning level messages displayed, use"--disable=all --enable=classes
5656
# --disable=W"
57-
disable=print-statement,
58-
parameter-unpacking,
59-
unpacking-in-except,
60-
old-raise-syntax,
61-
backtick,
62-
long-suffix,
63-
old-ne-operator,
64-
old-octal-literal,
65-
import-star-module-level,
66-
non-ascii-bytes-literal,
67-
invalid-unicode-literal,
68-
raw-checker-failed,
69-
bad-inline-option,
70-
locally-disabled,
71-
locally-enabled,
72-
file-ignored,
73-
suppressed-message,
74-
useless-suppression,
75-
deprecated-pragma,
76-
apply-builtin,
77-
basestring-builtin,
78-
buffer-builtin,
79-
cmp-builtin,
80-
coerce-builtin,
81-
execfile-builtin,
82-
file-builtin,
83-
long-builtin,
84-
raw_input-builtin,
85-
reduce-builtin,
86-
standarderror-builtin,
87-
unicode-builtin,
88-
xrange-builtin,
89-
coerce-method,
90-
delslice-method,
91-
getslice-method,
92-
setslice-method,
93-
no-absolute-import,
94-
old-division,
95-
dict-iter-method,
96-
dict-view-method,
97-
next-method-called,
98-
metaclass-assignment,
99-
indexing-exception,
100-
raising-string,
101-
reload-builtin,
102-
oct-method,
103-
hex-method,
104-
nonzero-method,
105-
cmp-method,
106-
input-builtin,
107-
round-builtin,
108-
intern-builtin,
109-
unichr-builtin,
110-
map-builtin-not-iterating,
111-
zip-builtin-not-iterating,
112-
range-builtin-not-iterating,
113-
filter-builtin-not-iterating,
114-
using-cmp-argument,
115-
eq-without-hash,
116-
div-method,
117-
idiv-method,
118-
rdiv-method,
119-
exception-message-attribute,
120-
invalid-str-codec,
121-
sys-max-int,
122-
bad-python3-import,
123-
deprecated-string-function,
124-
deprecated-str-translate-call,
125-
deprecated-itertools-function,
126-
deprecated-types-field,
127-
next-method-defined,
128-
dict-items-not-iterating,
129-
dict-keys-not-iterating,
130-
dict-values-not-iterating,
131-
deprecated-operator-function,
132-
deprecated-urllib-function,
133-
xreadlines-attribute,
134-
deprecated-sys-function,
135-
exception-escape,
136-
comprehension-escape,
137-
no-else-return,
138-
missing-docstring,
139-
invalid-name,
140-
protected-access,
141-
unpacking-non-sequence,
142-
R0801
57+
disable=unrecognized-option,
58+
invalid-name,
59+
missing-function-docstring,
60+
no-else-return,
61+
missing-module-docstring,
62+
protected-access,
63+
duplicate-code
14364

14465
# Enable the message, report, category or checker with the given id(s). You can
14566
# either give multiple identifier separated by comma (,) or put this option

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# try for travis
2323
try:
24-
with open(os.path.join(SOURCE_DIR, 'README.md')) as f:
24+
with open(os.path.join(SOURCE_DIR, 'README.md'), encoding="utf-8") as f:
2525
long_description = f.read()
2626
except FileNotFoundError:
2727
long_description = ""

test/test_all.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_gb_postcode():
1919
httpretty.register_uri(
2020
httpretty.GET,
2121
geocoder.url,
22-
body=Path('test/fixtures/uk_postcode.json').read_text()
22+
body=Path('test/fixtures/uk_postcode.json').read_text(encoding="utf-8")
2323
)
2424

2525
results = geocoder.geocode("EC1M 5RF")
@@ -31,7 +31,7 @@ def test_australia():
3131
httpretty.register_uri(
3232
httpretty.GET,
3333
geocoder.url,
34-
body=Path('test/fixtures/mudgee_australia.json').read_text()
34+
body=Path('test/fixtures/mudgee_australia.json').read_text(encoding="utf-8")
3535
)
3636

3737
results = geocoder.geocode("Mudgee, Australia")
@@ -43,7 +43,7 @@ def testMunster():
4343
httpretty.register_uri(
4444
httpretty.GET,
4545
geocoder.url,
46-
body=Path('test/fixtures/muenster.json').read_text()
46+
body=Path('test/fixtures/muenster.json').read_text(encoding="utf-8")
4747
)
4848

4949
results = geocoder.geocode("Münster")
@@ -54,7 +54,7 @@ def testDonostia():
5454
httpretty.register_uri(
5555
httpretty.GET,
5656
geocoder.url,
57-
body=Path('test/fixtures/donostia.json').read_text()
57+
body=Path('test/fixtures/donostia.json').read_text(encoding="utf-8")
5858

5959
)
6060

test/test_error_blocked.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_api_key_blocked():
1515
httpretty.register_uri(
1616
httpretty.GET,
1717
geocoder.url,
18-
body=Path('test/fixtures/403_apikey_disabled.json').read_text(),
18+
body=Path('test/fixtures/403_apikey_disabled.json').read_text(encoding="utf-8"),
1919
status=403,
2020
)
2121

test/test_error_invalid_input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def test_must_be_unicode_string():
2626

2727
with pytest.raises(InvalidInputError) as excinfo:
2828
geocoder.geocode(utf8_string)
29-
assert str(excinfo.value) == "Input must be a unicode string, not {0!r}".format(utf8_string)
29+
assert str(excinfo.value) == f"Input must be a unicode string, not {utf8_string!r}"
3030
assert excinfo.value.bad_value == utf8_string
3131

3232
with pytest.raises(InvalidInputError) as excinfo:
3333
geocoder.geocode(latin1_string)
34-
assert str(excinfo.value) == "Input must be a unicode string, not {0!r}".format(latin1_string)
34+
assert str(excinfo.value) == f"Input must be a unicode string, not {latin1_string!r}"
3535
assert excinfo.value.bad_value == latin1_string

test/test_error_not_authorized.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_api_key_not_authorized():
1414
httpretty.register_uri(
1515
httpretty.GET,
1616
geocoder.url,
17-
body=Path('test/fixtures/401_not_authorized.json').read_text(),
17+
body=Path('test/fixtures/401_not_authorized.json').read_text(encoding="utf-8"),
1818
status=401,
1919
)
2020

test/test_error_ratelimit_exceeded.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_no_rate_limit():
1515
httpretty.register_uri(
1616
httpretty.GET,
1717
geocoder.url,
18-
body=Path('test/fixtures/no_ratelimit.json').read_text()
18+
body=Path('test/fixtures/no_ratelimit.json').read_text(encoding="utf-8")
1919
)
2020
# shouldn't raise an exception
2121
geocoder.geocode("whatever")
@@ -27,7 +27,7 @@ def test_rate_limit_exceeded():
2727
httpretty.register_uri(
2828
httpretty.GET,
2929
geocoder.url,
30-
body=Path('test/fixtures/402_rate_limit_exceeded.json').read_text(),
30+
body=Path('test/fixtures/402_rate_limit_exceeded.json').read_text(encoding="utf-8"),
3131
status=402,
3232
adding_headers={'X-RateLimit-Limit': '2500', 'X-RateLimit-Remaining': '0', 'X-RateLimit-Reset': '1402185600'},
3333
)

test/test_session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_success():
1616
httpretty.register_uri(
1717
httpretty.GET,
1818
geocoder.url,
19-
body=Path('test/fixtures/uk_postcode.json').read_text()
19+
body=Path('test/fixtures/uk_postcode.json').read_text(encoding="utf-8")
2020
)
2121

2222
results = geocoder.geocode("EC1M 5RF")
@@ -28,7 +28,7 @@ def test_failure():
2828
httpretty.register_uri(
2929
httpretty.GET,
3030
geocoder.url,
31-
body=Path('test/fixtures/401_not_authorized.json').read_text(),
31+
body=Path('test/fixtures/401_not_authorized.json').read_text(encoding="utf-8"),
3232
status=401,
3333
)
3434

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ commands = pytest test
1212
usedevelop = True
1313
deps =
1414
httpretty
15-
pylint==2.9.1
15+
pylint==2.15.9
1616
pytest
1717
commands = pylint opencage examples/demo.py setup.py test

0 commit comments

Comments
 (0)