Skip to content

Commit 5c858b3

Browse files
committed
Instead of type annotating in __init__, uncomment the type annotations on the class member variables.
1 parent bdba112 commit 5c858b3

File tree

2 files changed

+45
-25
lines changed

2 files changed

+45
-25
lines changed

ipfshttpclient/filescanner.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ class Matcher(ty.Generic[ty.AnyStr], metaclass=abc.ABCMeta):
3535
should be included in some file scanning/adding operation"""
3636
__slots__ = ("is_binary",)
3737

38+
is_binary: bool
39+
3840
def __init__(self, is_binary: bool = False) -> None:
39-
self.is_binary: bool = is_binary
41+
self.is_binary = is_binary
4042

4143
@abc.abstractmethod
4244
def should_descend(self, path: ty.AnyStr) -> bool:
@@ -127,6 +129,12 @@ class emulates. If your are accustomed the globing on real Unix shells
127129
"""
128130
__slots__ = ("period_special", "_sep", "_pat", "_dir_only")
129131

132+
period_special: bool
133+
134+
_sep: ty.AnyStr
135+
_pat: "ty.List[ty.Optional[re_pattern_t[ty.AnyStr]]]"
136+
_dir_only: bool
137+
130138
def __init__(self, pat: ty.AnyStr, *, period_special: bool = True):
131139
"""
132140
Arguments
@@ -140,9 +148,9 @@ def __init__(self, pat: ty.AnyStr, *, period_special: bool = True):
140148
"""
141149
super().__init__(isinstance(pat, bytes))
142150

143-
self.period_special: bool = period_special
151+
self.period_special = period_special
144152

145-
self._sep: ty.AnyStr = utils.maybe_fsencode(os.path.sep, pat)
153+
self._sep = utils.maybe_fsencode(os.path.sep, pat)
146154
dblstar = utils.maybe_fsencode("**", pat)
147155
dot = utils.maybe_fsencode(".", pat)
148156
pat_ndot = utils.maybe_fsencode(r"(?![.])", pat)
@@ -160,9 +168,9 @@ def __init__(self, pat: ty.AnyStr, *, period_special: bool = True):
160168
# (TBH, I find it hard to see how that is useful, but everybody does it
161169
# and it keeps things consistent overall – something to only match files
162170
# would be nice however.)
163-
self._dir_only: bool = pat.endswith(self._sep)
171+
self._dir_only = pat.endswith(self._sep)
164172

165-
self._pat: ty.List[ty.Optional[re_pattern_t[ty.AnyStr]]] = []
173+
self._pat = []
166174
for label in pat.split(self._sep):
167175
# Skip over useless path components
168176
if len(label) < 1 or label == dot:
@@ -187,8 +195,7 @@ def __init__(self, pat: ty.AnyStr, *, period_special: bool = True):
187195
if period_special and not label.startswith(dot):
188196
re_expr = pat_ndot + re_expr
189197
self._pat.append(re.compile(re_expr))
190-
191-
198+
192199
def should_descend(self, path: ty.AnyStr) -> bool:
193200
for idx, label in enumerate(path.split(self._sep)):
194201
# Always descend into any directory below a recursive pattern as we
@@ -292,8 +299,10 @@ class ReMatcher(Matcher[ty.AnyStr], ty.Generic[ty.AnyStr]):
292299
"""
293300
__slots__ = ("_pat",)
294301

302+
_pat: "re_pattern_t[ty.AnyStr]"
303+
295304
def __init__(self, pat: ty.Union[ty.AnyStr, "re_pattern_t[ty.AnyStr]"]):
296-
self._pat: "re_pattern_t[ty.AnyStr]" = re.compile(pat)
305+
self._pat = re.compile(pat)
297306

298307
super().__init__(not (self._pat.flags & re.UNICODE))
299308

@@ -309,11 +318,13 @@ class MetaMatcher(Matcher[ty.AnyStr], ty.Generic[ty.AnyStr]):
309318
"""Match files and directories by delegating to other matchers"""
310319
__slots__ = ("_children",)
311320

321+
_children: ty.List[Matcher[ty.AnyStr]]
322+
312323
def __init__(self, children: ty.List[Matcher[ty.AnyStr]]):
313324
assert len(children) > 0
314325
super().__init__(children[0].is_binary)
315326

316-
self._children: ty.List[Matcher[ty.AnyStr]] = children
327+
self._children = children
317328

318329
def should_descend(self, path: ty.AnyStr) -> bool:
319330
return any(m.should_descend(path) for m in self._children)
@@ -332,10 +343,12 @@ class NoRecusionAdapterMatcher(Matcher[ty.AnyStr], ty.Generic[ty.AnyStr]):
332343
"""
333344
__slots__ = ("_child",)
334345

346+
_child: Matcher[ty.AnyStr]
347+
335348
def __init__(self, child: Matcher[ty.AnyStr]):
336349
super().__init__(child.is_binary)
337350

338-
self._child: Matcher[ty.AnyStr] = child
351+
self._child = child
339352

340353
def should_descend(self, path: ty.AnyStr) -> bool:
341354
return False
@@ -423,6 +436,9 @@ class FSNodeType(enum.Enum):
423436
class walk(ty.Generator[FSNodeEntry, ty.Any, None], ty.Generic[ty.AnyStr]):
424437
__slots__ = ("_generator", "_close_fd")
425438

439+
_generator: ty.Generator[FSNodeEntry, None, None]
440+
_close_fd: ty.Optional[int]
441+
426442
def __init__(
427443
self,
428444
directory: ty.Union[ty.AnyStr, utils.PathLike[ty.AnyStr], int],
@@ -465,7 +481,7 @@ def __init__(
465481
:class:`NoRecusionAdapterMatcher` and hence prevent the scanner from
466482
doing any recursion.
467483
"""
468-
self._close_fd: ty.Optional[int] = None
484+
self._close_fd = None
469485

470486
# Create matcher object
471487
matcher = matcher_from_spec( # type: ignore[type-var]
@@ -480,7 +496,7 @@ def __init__(
480496
raise NotImplementedError("Passing a file descriptor as directory is "
481497
"not supported on this platform")
482498

483-
self._generator: ty.Generator[FSNodeEntry, None, None] = self._walk(
499+
self._generator = self._walk(
484500
directory,
485501
None,
486502
matcher, # type: ignore[arg-type]
@@ -678,6 +694,6 @@ def _walk(
678694

679695

680696
if HAVE_FWALK: # pragma: no cover
681-
supports_fd = frozenset({walk}) # type: ty.FrozenSet[ty.Callable[..., ty.Any]]
697+
supports_fd: ty.FrozenSet[ty.Callable[..., ty.Any]] = frozenset({walk})
682698
else: # pragma: no cover
683699
supports_fd = frozenset()

ipfshttpclient/multipart.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,12 @@ class StreamBase(metaclass=abc.ABCMeta):
122122
The maximum size that any single file chunk may have in bytes
123123
"""
124124
__slots__ = ("chunk_size", "name", "_boundary", "_headers")
125-
#chunk_size: int
126-
#name: str
127-
#_boundry: str
128-
#_headers: ty.Dict[str, str]
125+
126+
chunk_size: int
127+
name: str
128+
129+
_boundry: str
130+
_headers: ty.Dict[str, str]
129131

130132
def __init__(self, name: str, chunk_size: int = default_chunk_size) -> None:
131133
self.chunk_size = chunk_size
@@ -371,9 +373,10 @@ class DirectoryStream(StreamBase, StreamFileMixin, ty.Generic[ty.AnyStr]):
371373
shells allow one to disable this behaviour
372374
"""
373375
__slots__ = ("abspath", "follow_symlinks", "scanner")
374-
#abspath: ty.Optional[ty.AnyStr]
375-
#follow_symlinks: bool
376-
#scanner: filescanner.walk[ty.AnyStr]
376+
377+
abspath: ty.Optional[ty.AnyStr]
378+
follow_symlinks: bool
379+
scanner: filescanner.walk[ty.AnyStr]
377380

378381
def __init__(self, directory: ty.Union[ty.AnyStr, utils.PathLike[ty.AnyStr], int], *,
379382
chunk_size: int = default_chunk_size,
@@ -387,7 +390,7 @@ def __init__(self, directory: ty.Union[ty.AnyStr, utils.PathLike[ty.AnyStr], int
387390
directory = utils.convert_path(directory)
388391

389392
# Create file scanner from parameters
390-
self.scanner: filescanner.walk[ty.AnyStr] = filescanner.walk(
393+
self.scanner = filescanner.walk(
391394
directory,
392395
patterns,
393396
follow_symlinks=follow_symlinks,
@@ -396,13 +399,13 @@ def __init__(self, directory: ty.Union[ty.AnyStr, utils.PathLike[ty.AnyStr], int
396399
)
397400

398401
# Figure out the absolute path of the directory added
399-
self.abspath = None # type: ty.Optional[ty.AnyStr]
402+
self.abspath = None
400403
if not isinstance(directory, int):
401404
self.abspath = os.path.abspath(utils.convert_path(directory))
402405

403406
# Figure out basename of the containing directory
404407
# (normpath is an acceptable approximation here)
405-
basename = "_" # type: ty.Union[str, bytes]
408+
basename = "_"
406409
if not isinstance(directory, int):
407410
basename = os.fsdecode(os.path.basename(os.path.normpath(directory)))
408411
super().__init__(os.fsdecode(basename), chunk_size=chunk_size)
@@ -462,14 +465,15 @@ class BytesFileStream(FilesStream):
462465
The maximum size of a single data chunk
463466
"""
464467
__slots__ = ("data",)
465-
#data: ty.Iterable[bytes]
468+
469+
data: ty.Iterable[bytes]
466470

467471
def __init__(self, data: ty.Union[bytes, gen_bytes_t], name: str = "bytes", *,
468472
chunk_size: int = default_chunk_size) -> None:
469473
super().__init__([], name=name, chunk_size=chunk_size)
470474

471475
if not isinstance(data, bytes):
472-
self.data = data # type: ty.Iterable[bytes]
476+
self.data = data
473477
else:
474478
self.data = (data,)
475479

0 commit comments

Comments
 (0)