Skip to content

Commit 29a9e64

Browse files
darguetawillmcgugan
authored andcommitted
Add flake8 linting (#351)
* Remove unused imports, fix line lengths * Fix JSON exception catching * Add linting tools * More linting * Fix broken/extra imports, long lines, unused variables * Fix hasattr/getattr confusion * Remove unused loop variables, fix comprehensions * Update CHANGELOG * Move tool configs to setup.cfg with the rest
1 parent 6f89b81 commit 29a9e64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+227
-159
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ matrix:
1818
- name: "Type checking"
1919
python: "3.7"
2020
env: TOXENV=typecheck
21+
- name: 'Lint'
22+
python: '3.7'
23+
env: TOXENV=lint
2124

2225
before_install:
2326
- pip install -U tox tox-travis

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2323
- Fixed abstract class import from `collections` which would break on Python 3.8
2424
- Fixed incorrect imports of `mock` on Python 3
2525
- Removed some unused imports and unused `requirements.txt` file
26-
- Added mypy checks to Travis
26+
- Added mypy checks to Travis. Closes [#332](https://github.com/PyFilesystem/pyfilesystem2/issues/332).
2727
- Fixed missing `errno.ENOTSUP` on PyPy. Closes [#338](https://github.com/PyFilesystem/pyfilesystem2/issues/338).
28+
- Fixed bug in a decorator that would trigger an `AttributeError` when a class
29+
was created that implemented a deprecated method and had no docstring of its
30+
own.
2831

2932
### Changed
3033

3134
- Entire test suite has been migrated to [pytest](https://docs.pytest.org/en/latest/). Closes [#327](https://github.com/PyFilesystem/pyfilesystem2/issues/327).
35+
- Style checking is now enforced using `flake8`; this involved some code cleanup
36+
such as removing unused imports.
3237

3338
## [2.4.10] - 2019-07-29
3439

fs/_bulk.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
from __future__ import unicode_literals
88

99
import threading
10+
import typing
1011

1112
from six.moves.queue import Queue
1213

1314
from .copy import copy_file_internal
1415
from .errors import BulkCopyFailed
1516
from .tools import copy_file_data
1617

17-
if False: # typing.TYPE_CHECKING
18+
if typing.TYPE_CHECKING:
1819
from .base import FS
1920
from types import TracebackType
20-
from typing import IO, Iterator, List, Optional, Mapping, Text, Type, Union
21+
from typing import IO, List, Optional, Text, Type
2122

2223

2324
class _Worker(threading.Thread):
@@ -96,7 +97,7 @@ def start(self):
9697
def stop(self):
9798
"""Stop the workers (will block until they are finished)."""
9899
if self.running and self.num_workers:
99-
for worker in self.workers:
100+
for _worker in self.workers:
100101
self.queue.put(None)
101102
for worker in self.workers:
102103
worker.join()

fs/_fscompat.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
import six
42

53
try:

fs/_repr.py

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

66
import typing
77

8-
if False: # typing.TYPE_CHECKING
8+
if typing.TYPE_CHECKING:
99
from typing import Text, Tuple
1010

1111

fs/_typing.py

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

1313
if _PY.major == 3 and _PY.minor == 5 and _PY.micro in (0, 1):
1414

15-
def overload(func): # pragma: no cover
15+
def overload(func): # pragma: no cover # noqa: F811
1616
return func
1717

1818

fs/_url_tools.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import re
22
import six
33
import platform
4+
import typing
45

5-
if False: # typing.TYPE_CHECKING
6-
from typing import Text, Union, BinaryIO
6+
if typing.TYPE_CHECKING:
7+
from typing import Text
78

89
_WINDOWS_PLATFORM = platform.system() == "Windows"
910

fs/appfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from ._repr import make_repr
1616
from appdirs import AppDirs
1717

18-
if False: # typing.TYPE_CHECKING
18+
if typing.TYPE_CHECKING:
1919
from typing import Optional, Text
2020

2121

fs/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from .time import datetime_to_epoch
2929
from .walk import Walker
3030

31-
if False: # typing.TYPE_CHECKING
31+
if typing.TYPE_CHECKING:
3232
from datetime import datetime
3333
from threading import RLock
3434
from typing import (
@@ -84,7 +84,7 @@ def _method(*args, **kwargs):
8484
""".format(
8585
method.__name__
8686
)
87-
if getattr(_method, "__doc__"):
87+
if hasattr(_method, "__doc__"):
8888
_method.__doc__ += deprecated_msg
8989

9090
return _method
@@ -1624,7 +1624,8 @@ def hash(self, path, name):
16241624
16251625
Arguments:
16261626
path(str): A path on the filesystem.
1627-
name(str): One of the algorithms supported by the hashlib module, e.g. `"md5"`
1627+
name(str):
1628+
One of the algorithms supported by the hashlib module, e.g. `"md5"`
16281629
16291630
Returns:
16301631
str: The hex digest of the hash.

fs/compress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
from .errors import NoSysPath, MissingInfoNamespace
2323
from .walk import Walker
2424

25-
if False: # typing.TYPE_CHECKING
26-
from typing import BinaryIO, Optional, Text, Tuple, Type, Union
25+
if typing.TYPE_CHECKING:
26+
from typing import BinaryIO, Optional, Text, Tuple, Union
2727
from .base import FS
2828

2929
ZipTime = Tuple[int, int, int, int, int, int]

0 commit comments

Comments
 (0)