Skip to content

Commit

Permalink
Remove many deprecated pylint options (#329)
Browse files Browse the repository at this point in the history
These were mostly useful for the python2->python3 transition. Fix new issues with the code 
that were caught by the new config.
  • Loading branch information
hmaarrfk authored Feb 18, 2024
1 parent 77c78a2 commit 1204d76
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 103 deletions.
38 changes: 1 addition & 37 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,attribute-defined-outside-init,similarities,bad-continuation,,import-error
disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,deprecated-pragma,attribute-defined-outside-init,similarities,,import-error

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down Expand Up @@ -111,12 +111,6 @@ max-line-length=100
# Maximum number of lines in a module
max-module-lines=2000

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,dict-separator

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
Expand Down Expand Up @@ -196,46 +190,28 @@ spelling-store-unknown-words=no

[BASIC]

# Naming hint for argument names
argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Regular expression matching correct argument names
argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Naming hint for attribute names
attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Regular expression matching correct attribute names
attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata

# Naming hint for class attribute names
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$

# Regular expression matching correct class attribute names
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$

# Naming hint for class names
class-name-hint=[A-Z_][a-zA-Z0-9]+$

# Regular expression matching correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$

# Naming hint for constant names
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$

# Regular expression matching correct constant names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$

# Minimum line length for functions/classes that require docstrings, shorter
# ones are exempt.
docstring-min-length=-1

# Naming hint for function names
function-name-hint=(([a-z][a-z0-9_]{2,50})|(_[a-z0-9_]*))$

# Regular expression matching correct function names
function-rgx=(([a-z][a-z0-9_]{2,50})|(_[a-z0-9_]*))$

Expand All @@ -245,21 +221,12 @@ good-names=i,j,k,w,e,s,n,x,y,z,cv,ax
# Include a hint for the correct naming format with invalid-name
include-naming-hint=no

# Naming hint for inline iteration names
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$

# Regular expression matching correct inline iteration names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$

# Naming hint for method names
method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Regular expression matching correct method names
method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Naming hint for module names
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

# Regular expression matching correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

Expand All @@ -275,9 +242,6 @@ no-docstring-rgx=^_
# to this list to register other decorators that produce valid properties.
property-classes=abc.abstractproperty

# Naming hint for variable names
variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Regular expression matching correct variable names
variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

Expand Down
2 changes: 1 addition & 1 deletion env/requirements-style.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Style checks
black
flake8
pylint==2.4.*
pylint>=2.4
pathspec
3 changes: 1 addition & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ dependencies:
- pathspec
- black>=20.8b1
- flake8
- pip:
- pylint==2.4.*
- pylint>=2.4
6 changes: 3 additions & 3 deletions pooch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,10 @@ def __init__(
self.path = path
self.base_url = base_url
if registry is None:
registry = dict()
registry = {}
self.registry = registry
if urls is None:
urls = dict()
urls = {}
self.urls = dict(urls)
self.retry_if_failed = retry_if_failed
self.allow_updates = allow_updates
Expand Down Expand Up @@ -647,7 +647,7 @@ def load_registry(self, fname):
fin = fname
else:
# It's a file path
fin = stack.enter_context(open(fname))
fin = stack.enter_context(open(fname, encoding="utf-8"))

for linenum, line in enumerate(fin):
if isinstance(line, bytes):
Expand Down
31 changes: 21 additions & 10 deletions pooch/downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def __init__(self, progressbar=False, chunk_size=1024, **kwargs):
if self.progressbar is True and tqdm is None:
raise ValueError("Missing package 'tqdm' required for progress bars.")

def __call__(self, url, output_file, pooch, check_only=False):
def __call__(
self, url, output_file, pooch, check_only=False
): # pylint: disable=R0914
"""
Download the given URL over HTTP to the given output file.
Expand Down Expand Up @@ -195,17 +197,21 @@ def __call__(self, url, output_file, pooch, check_only=False):
import requests # pylint: disable=C0415

if check_only:
response = requests.head(url, allow_redirects=True)
timeout = self.kwargs.get("timeout", 5)
response = requests.head(url, timeout=timeout, allow_redirects=True)
available = bool(response.status_code == 200)
return available

kwargs = self.kwargs.copy()
timeout = kwargs.pop("timeout", 5)
kwargs.setdefault("stream", True)
ispath = not hasattr(output_file, "write")
if ispath:
# pylint: disable=consider-using-with
output_file = open(output_file, "w+b")
# pylint: enable=consider-using-with
try:
response = requests.get(url, **kwargs)
response = requests.get(url, timeout=timeout, **kwargs)
response.raise_for_status()
content = response.iter_content(chunk_size=self.chunk_size)
total = int(response.headers.get("content-length", 0))
Expand Down Expand Up @@ -344,7 +350,9 @@ def __call__(self, url, output_file, pooch, check_only=False):

ispath = not hasattr(output_file, "write")
if ispath:
# pylint: disable=consider-using-with
output_file = open(output_file, "w+b")
# pylint: enable=consider-using-with
try:
ftp.login(user=self.username, passwd=self.password, acct=self.account)
command = f"RETR {parsed_url['path']}"
Expand Down Expand Up @@ -632,7 +640,7 @@ def doi_to_url(doi):
import requests # pylint: disable=C0415

# Use doi.org to resolve the DOI to the repository website.
response = requests.get(f"https://doi.org/{doi}")
response = requests.get(f"https://doi.org/{doi}", timeout=5)
url = response.url
if 400 <= response.status_code < 600:
raise ValueError(
Expand Down Expand Up @@ -791,7 +799,8 @@ def api_response(self):

article_id = self.archive_url.split("/")[-1]
self._api_response = requests.get(
f"{self.base_api_url}/{article_id}"
f"{self.base_api_url}/{article_id}",
timeout=5,
).json()

return self._api_response
Expand All @@ -817,9 +826,9 @@ def api_version(self):
str
"""
if self._api_version is None:
if all(["key" in file for file in self.api_response["files"]]):
if all("key" in file for file in self.api_response["files"]):
self._api_version = "legacy"
elif all(["filename" in file for file in self.api_response["files"]]):
elif all("filename" in file for file in self.api_response["files"]):
self._api_version = "new"
else:
raise ValueError(
Expand Down Expand Up @@ -956,7 +965,8 @@ def api_response(self):

# Use the figshare API to find the article ID from the DOI
article = requests.get(
f"https://api.figshare.com/v2/articles?doi={self.doi}"
f"https://api.figshare.com/v2/articles?doi={self.doi}",
timeout=5,
).json()[0]
article_id = article["id"]
# Parse desired version from the doi
Expand All @@ -983,7 +993,7 @@ def api_response(self):
f"{article_id}/versions/{version}"
)
# Make the request and return the files in the figshare repository
response = requests.get(api_url)
response = requests.get(api_url, timeout=5)
response.raise_for_status()
self._api_response = response.json()["files"]

Expand Down Expand Up @@ -1076,7 +1086,8 @@ def _get_api_response(cls, doi, archive_url):
parsed = parse_url(archive_url)
response = requests.get(
f"{parsed['protocol']}://{parsed['netloc']}/api/datasets/"
f":persistentId?persistentId=doi:{doi}"
f":persistentId?persistentId=doi:{doi}",
timeout=5,
)
return response

Expand Down
2 changes: 1 addition & 1 deletion pooch/hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def make_registry(directory, output, recursive=True):

hashes = [file_hash(str(directory / fname)) for fname in files]

with open(output, "w") as outfile:
with open(output, "w", encoding="utf-8") as outfile:
for fname, fhash in zip(files, hashes):
# Only use Unix separators for the registry so that we don't go
# insane dealing with file paths.
Expand Down
10 changes: 5 additions & 5 deletions pooch/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def test_pooch_update():
# Create a dummy version of tiny-data.txt that is different from the
# one in the remote storage
true_path = str(path / "tiny-data.txt")
with open(true_path, "w") as fin:
with open(true_path, "w", encoding="utf-8") as fin:
fin.write("different data")
# Setup a pooch in a temp dir
pup = Pooch(path=path, base_url=BASEURL, registry=REGISTRY)
Expand All @@ -344,7 +344,7 @@ def test_pooch_update_disallowed():
# Create a dummy version of tiny-data.txt that is different from the
# one in the remote storage
true_path = str(path / "tiny-data.txt")
with open(true_path, "w") as fin:
with open(true_path, "w", encoding="utf-8") as fin:
fin.write("different data")
# Setup a pooch in a temp dir
pup = Pooch(
Expand All @@ -367,7 +367,7 @@ def test_pooch_update_disallowed_environment():
# Create a dummy version of tiny-data.txt that is different from
# the one in the remote storage
true_path = str(path / "tiny-data.txt")
with open(true_path, "w") as fin:
with open(true_path, "w", encoding="utf-8") as fin:
fin.write("different data")
# Setup a pooch in a temp dir
pup = create(
Expand Down Expand Up @@ -454,7 +454,7 @@ def test_pooch_load_registry_fileobj():

# Text mode
pup = Pooch(path="", base_url="")
with open(path) as fin:
with open(path, "r", encoding="utf-8") as fin:
pup.load_registry(fin)
assert pup.registry == REGISTRY
assert pup.registry_files.sort() == list(REGISTRY).sort()
Expand Down Expand Up @@ -604,7 +604,7 @@ def test_download_action():
assert verb == "Updating"

with temporary_file() as tmp:
with open(tmp, "w") as output:
with open(tmp, "w", encoding="utf-8") as output:
output.write("some data")
action, verb = download_action(Path(tmp), known_hash=file_hash(tmp))
assert action == "fetch"
Expand Down
52 changes: 26 additions & 26 deletions pooch/tests/test_downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,13 @@ class TestZenodoAPISupport:
)
file_checksum = "2942bfabb3d05332b66eb128e0842cff"

legacy_api_response = dict(
created="2021-20-19T08:00:00.000000+00:00",
modified="2021-20-19T08:00:00.000000+00:00",
id=article_id,
doi=doi,
doi_url=doi_url,
files=[
legacy_api_response = {
"created": "2021-20-19T08:00:00.000000+00:00",
"modified": "2021-20-19T08:00:00.000000+00:00",
"id": article_id,
"doi": doi,
"doi_url": doi_url,
"files": [
{
"id": "513d7033-93a2-4eeb-821c-2fb0bbab0012",
"key": file_name,
Expand All @@ -417,15 +417,15 @@ class TestZenodoAPISupport:
},
}
],
)

new_api_response = dict(
created="2021-20-19T08:00:00.000000+00:00",
modified="2021-20-19T08:00:00.000000+00:00",
id=article_id,
doi=doi,
doi_url=doi_url,
files=[
}

new_api_response = {
"created": "2021-20-19T08:00:00.000000+00:00",
"modified": "2021-20-19T08:00:00.000000+00:00",
"id": article_id,
"doi": doi,
"doi_url": doi_url,
"files": [
{
"id": "513d7033-93a2-4eeb-821c-2fb0bbab0012",
"filename": file_name,
Expand All @@ -435,15 +435,15 @@ class TestZenodoAPISupport:
},
}
],
)

invalid_api_response = dict(
created="2021-20-19T08:00:00.000000+00:00",
modified="2021-20-19T08:00:00.000000+00:00",
id=article_id,
doi=doi,
doi_url=doi_url,
files=[
}

invalid_api_response = {
"created": "2021-20-19T08:00:00.000000+00:00",
"modified": "2021-20-19T08:00:00.000000+00:00",
"id": article_id,
"doi": doi,
"doi_url": doi_url,
"files": [
{
"id": "513d7033-93a2-4eeb-821c-2fb0bbab0012",
"filename": file_name,
Expand All @@ -461,7 +461,7 @@ class TestZenodoAPISupport:
},
},
],
)
}

@pytest.mark.parametrize(
"api_version, api_response",
Expand Down
Loading

0 comments on commit 1204d76

Please sign in to comment.