Skip to content

Commit 84719be

Browse files
authored
typing fixes (#334)
* typing fixes * changelog * install mypy in travis * removed mypy * add typecheck to travis * second attempt * add typecheck to matrix * safer close * ignore type error * handle double close
1 parent 7d7539a commit 84719be

File tree

9 files changed

+34
-19
lines changed

9 files changed

+34
-19
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ matrix:
1111
- SETUPTOOLS=setuptools PIP=pip
1212
dist: xenial
1313
sudo: true
14+
install:
15+
- pip install mypy
16+
- make typecheck
1417
- python: "3.6"
18+
install:
19+
- pip install mypy
20+
- make typecheck
1521
env:
1622
- SETUPTOOLS=setuptools PIP=pip
1723
- python: "3.5"

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [2.4.11] - Unreleased
9+
10+
### Fixed
11+
12+
- Fixed tests leaving tmp files
13+
- Fixed typing issues
14+
- Fixed link namespace returning bytes
15+
816
## [2.4.10] - 2019-07-29
917

1018
### Fixed

fs/_fscompat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from os import fspath
1212
except ImportError:
1313

14-
def fspath(path):
14+
def fspath(path): # type: ignore
1515
"""Return the path representation of a path-like object.
1616
1717
If str or bytes is passed in, it is returned unchanged. Otherwise the

fs/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Version, used in module and setup.py.
22
"""
3-
__version__ = "2.4.10"
3+
__version__ = "2.4.11a0"

fs/glob.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010
from . import wildcard
1111

1212

13-
_PATTERN_CACHE = LRUCache(
14-
1000
15-
) # type: LRUCache[Tuple[Text, bool], Tuple[int, bool, Pattern]]
16-
17-
GlobMatch = namedtuple('GlobMatch', ["path", "info"])
13+
GlobMatch = namedtuple("GlobMatch", ["path", "info"])
1814
Counts = namedtuple("Counts", ["files", "directories", "data"])
1915
LineCounts = namedtuple("LineCounts", ["lines", "non_blank"])
2016

2117
if False: # typing.TYPE_CHECKING
22-
from typing import Iterator, List, Optional, Tuple
18+
from typing import Iterator, List, Optional, Pattern, Text, Tuple
2319
from .base import FS
2420
from .info import Info
2521

2622

23+
_PATTERN_CACHE = LRUCache(
24+
1000
25+
) # type: LRUCache[Tuple[Text, bool], Tuple[int, bool, Pattern]]
26+
27+
2728
def _translate_glob(pattern, case_sensitive=True):
2829
levels = 0
2930
recursive = False

fs/memoryfs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ def _get_dir_entry(self, dir_path):
342342

343343
def close(self):
344344
# type: () -> None
345-
self.root = None
345+
if not self._closed:
346+
del self.root
346347
return super(MemoryFS, self).close()
347348

348349
def getinfo(self, path, namespaces=None):

fs/mode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __contains__(self, character):
6767
# type: (object) -> bool
6868
"""Check if a mode contains a given character.
6969
"""
70+
assert isinstance(character, Text)
7071
return character in self._mode
7172

7273
def to_platform(self):

fs/opener/registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __repr__(self):
5757
return "<fs-registry {!r}>".format(self.protocols)
5858

5959
def install(self, opener):
60-
# type: (Union[Type[Opener], Opener, Callable[[], Opener]]) -> None
60+
# type: (Union[Type[Opener], Opener, Callable[[], Opener]]) -> Opener
6161
"""Install an opener.
6262
6363
Arguments:
@@ -76,7 +76,7 @@ class ArchiveOpener(Opener):
7676
assert _opener.protocols, "must list one or more protocols"
7777
for protocol in _opener.protocols:
7878
self._protocols[protocol] = _opener
79-
return opener
79+
return _opener
8080

8181
@property
8282
def protocols(self):

fs/osfs.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
try:
2929
from scandir import scandir # type: ignore
3030
except ImportError: # pragma: no cover
31-
scandir = None # pragma: no cover
31+
scandir = None # type: ignore # pragma: no cover
3232

3333
try:
3434
from os import sendfile
3535
except ImportError:
3636
try:
3737
from sendfile import sendfile # type: ignore
3838
except ImportError:
39-
sendfile = None # pragma: no cover
39+
sendfile = None # type: ignore # pragma: no cover
4040

4141
from . import errors
4242
from .errors import FileExists
@@ -186,7 +186,7 @@ def __str__(self):
186186
return fmt.format(_class_name.lower(), self.root_path)
187187

188188
def _to_sys_path(self, path):
189-
# type: (Text) -> Text
189+
# type: (Text) -> bytes
190190
"""Convert a FS path to a path on the OS.
191191
"""
192192
sys_path = fsencode(
@@ -266,13 +266,11 @@ def _gettarget(self, sys_path):
266266
if hasattr(os, "readlink"):
267267
try:
268268
if _WINDOWS_PLATFORM: # pragma: no cover
269-
target = os.readlink(sys_path)
269+
return os.readlink(sys_path)
270270
else:
271-
target = os.readlink(fsencode(sys_path))
271+
return fsdecode(os.readlink(fsencode(sys_path)))
272272
except OSError:
273273
pass
274-
else:
275-
return target
276274
return None
277275

278276
def _make_link_info(self, sys_path):
@@ -484,7 +482,7 @@ def _scandir(self, path, namespaces=None):
484482
self._root_path, path.lstrip("/").replace("/", os.sep)
485483
)
486484
else:
487-
sys_path = self._to_sys_path(_path)
485+
sys_path = self._to_sys_path(_path) # type: ignore
488486
with convert_os_errors("scandir", path, directory=True):
489487
for dir_entry in scandir(sys_path):
490488
info = {

0 commit comments

Comments
 (0)