Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ matrix:
- SETUPTOOLS=setuptools PIP=pip
dist: xenial
sudo: true
install:
- pip install mypy
- make typecheck
- python: "3.6"
install:
- pip install mypy
- make typecheck
env:
- SETUPTOOLS=setuptools PIP=pip
- python: "3.5"
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.4.11] - Unreleased

### Fixed

- Fixed tests leaving tmp files
- Fixed typing issues
- Fixed link namespace returning bytes

## [2.4.10] - 2019-07-29

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion fs/_fscompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from os import fspath
except ImportError:

def fspath(path):
def fspath(path): # type: ignore
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy complains about redefinition

"""Return the path representation of a path-like object.
If str or bytes is passed in, it is returned unchanged. Otherwise the
Expand Down
2 changes: 1 addition & 1 deletion fs/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version, used in module and setup.py.
"""
__version__ = "2.4.10"
__version__ = "2.4.11a0"
13 changes: 7 additions & 6 deletions fs/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@
from . import wildcard


_PATTERN_CACHE = LRUCache(
1000
) # type: LRUCache[Tuple[Text, bool], Tuple[int, bool, Pattern]]

GlobMatch = namedtuple('GlobMatch', ["path", "info"])
GlobMatch = namedtuple("GlobMatch", ["path", "info"])
Counts = namedtuple("Counts", ["files", "directories", "data"])
LineCounts = namedtuple("LineCounts", ["lines", "non_blank"])

if False: # typing.TYPE_CHECKING
from typing import Iterator, List, Optional, Tuple
from typing import Iterator, List, Optional, Pattern, Text, Tuple
from .base import FS
from .info import Info


_PATTERN_CACHE = LRUCache(
1000
) # type: LRUCache[Tuple[Text, bool], Tuple[int, bool, Pattern]]


def _translate_glob(pattern, case_sensitive=True):
levels = 0
recursive = False
Expand Down
3 changes: 2 additions & 1 deletion fs/memoryfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ def _get_dir_entry(self, dir_path):

def close(self):
# type: () -> None
self.root = None
if not self._closed:
del self.root
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mypy complains when assigning None, rather than modify the type of root just del it.

return super(MemoryFS, self).close()

def getinfo(self, path, namespaces=None):
Expand Down
1 change: 1 addition & 0 deletions fs/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __contains__(self, character):
# type: (object) -> bool
"""Check if a mode contains a given character.
"""
assert isinstance(character, Text)
return character in self._mode

def to_platform(self):
Expand Down
4 changes: 2 additions & 2 deletions fs/opener/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __repr__(self):
return "<fs-registry {!r}>".format(self.protocols)

def install(self, opener):
# type: (Union[Type[Opener], Opener, Callable[[], Opener]]) -> None
# type: (Union[Type[Opener], Opener, Callable[[], Opener]]) -> Opener
"""Install an opener.

Arguments:
Expand All @@ -76,7 +76,7 @@ class ArchiveOpener(Opener):
assert _opener.protocols, "must list one or more protocols"
for protocol in _opener.protocols:
self._protocols[protocol] = _opener
return opener
return _opener

@property
def protocols(self):
Expand Down
14 changes: 6 additions & 8 deletions fs/osfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
try:
from scandir import scandir # type: ignore
except ImportError: # pragma: no cover
scandir = None # pragma: no cover
scandir = None # type: ignore # pragma: no cover

try:
from os import sendfile
except ImportError:
try:
from sendfile import sendfile # type: ignore
except ImportError:
sendfile = None # pragma: no cover
sendfile = None # type: ignore # pragma: no cover

from . import errors
from .errors import FileExists
Expand Down Expand Up @@ -186,7 +186,7 @@ def __str__(self):
return fmt.format(_class_name.lower(), self.root_path)

def _to_sys_path(self, path):
# type: (Text) -> Text
# type: (Text) -> bytes
"""Convert a FS path to a path on the OS.
"""
sys_path = fsencode(
Expand Down Expand Up @@ -266,13 +266,11 @@ def _gettarget(self, sys_path):
if hasattr(os, "readlink"):
try:
if _WINDOWS_PLATFORM: # pragma: no cover
target = os.readlink(sys_path)
return os.readlink(sys_path)
else:
target = os.readlink(fsencode(sys_path))
return fsdecode(os.readlink(fsencode(sys_path)))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link target was returned as bytes. A genuine bug uncovered by Mypy. Thanks, Mypy.

except OSError:
pass
else:
return target
return None

def _make_link_info(self, sys_path):
Expand Down Expand Up @@ -484,7 +482,7 @@ def _scandir(self, path, namespaces=None):
self._root_path, path.lstrip("/").replace("/", os.sep)
)
else:
sys_path = self._to_sys_path(_path)
sys_path = self._to_sys_path(_path) # type: ignore
with convert_os_errors("scandir", path, directory=True):
for dir_entry in scandir(sys_path):
info = {
Expand Down