@@ -35,8 +35,10 @@ class Matcher(ty.Generic[ty.AnyStr], metaclass=abc.ABCMeta):
35
35
should be included in some file scanning/adding operation"""
36
36
__slots__ = ("is_binary" ,)
37
37
38
+ is_binary : bool
39
+
38
40
def __init__ (self , is_binary : bool = False ) -> None :
39
- self .is_binary : bool = is_binary
41
+ self .is_binary = is_binary
40
42
41
43
@abc .abstractmethod
42
44
def should_descend (self , path : ty .AnyStr ) -> bool :
@@ -127,6 +129,12 @@ class emulates. If your are accustomed the globing on real Unix shells
127
129
"""
128
130
__slots__ = ("period_special" , "_sep" , "_pat" , "_dir_only" )
129
131
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
+
130
138
def __init__ (self , pat : ty .AnyStr , * , period_special : bool = True ):
131
139
"""
132
140
Arguments
@@ -140,9 +148,9 @@ def __init__(self, pat: ty.AnyStr, *, period_special: bool = True):
140
148
"""
141
149
super ().__init__ (isinstance (pat , bytes ))
142
150
143
- self .period_special : bool = period_special
151
+ self .period_special = period_special
144
152
145
- self ._sep : ty . AnyStr = utils .maybe_fsencode (os .path .sep , pat )
153
+ self ._sep = utils .maybe_fsencode (os .path .sep , pat )
146
154
dblstar = utils .maybe_fsencode ("**" , pat )
147
155
dot = utils .maybe_fsencode ("." , pat )
148
156
pat_ndot = utils .maybe_fsencode (r"(?![.])" , pat )
@@ -160,9 +168,9 @@ def __init__(self, pat: ty.AnyStr, *, period_special: bool = True):
160
168
# (TBH, I find it hard to see how that is useful, but everybody does it
161
169
# and it keeps things consistent overall – something to only match files
162
170
# would be nice however.)
163
- self ._dir_only : bool = pat .endswith (self ._sep )
171
+ self ._dir_only = pat .endswith (self ._sep )
164
172
165
- self ._pat : ty . List [ ty . Optional [ re_pattern_t [ ty . AnyStr ]]] = []
173
+ self ._pat = []
166
174
for label in pat .split (self ._sep ):
167
175
# Skip over useless path components
168
176
if len (label ) < 1 or label == dot :
@@ -187,8 +195,7 @@ def __init__(self, pat: ty.AnyStr, *, period_special: bool = True):
187
195
if period_special and not label .startswith (dot ):
188
196
re_expr = pat_ndot + re_expr
189
197
self ._pat .append (re .compile (re_expr ))
190
-
191
-
198
+
192
199
def should_descend (self , path : ty .AnyStr ) -> bool :
193
200
for idx , label in enumerate (path .split (self ._sep )):
194
201
# Always descend into any directory below a recursive pattern as we
@@ -292,8 +299,10 @@ class ReMatcher(Matcher[ty.AnyStr], ty.Generic[ty.AnyStr]):
292
299
"""
293
300
__slots__ = ("_pat" ,)
294
301
302
+ _pat : "re_pattern_t[ty.AnyStr]"
303
+
295
304
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 )
297
306
298
307
super ().__init__ (not (self ._pat .flags & re .UNICODE ))
299
308
@@ -309,11 +318,13 @@ class MetaMatcher(Matcher[ty.AnyStr], ty.Generic[ty.AnyStr]):
309
318
"""Match files and directories by delegating to other matchers"""
310
319
__slots__ = ("_children" ,)
311
320
321
+ _children : ty .List [Matcher [ty .AnyStr ]]
322
+
312
323
def __init__ (self , children : ty .List [Matcher [ty .AnyStr ]]):
313
324
assert len (children ) > 0
314
325
super ().__init__ (children [0 ].is_binary )
315
326
316
- self ._children : ty . List [ Matcher [ ty . AnyStr ]] = children
327
+ self ._children = children
317
328
318
329
def should_descend (self , path : ty .AnyStr ) -> bool :
319
330
return any (m .should_descend (path ) for m in self ._children )
@@ -332,10 +343,12 @@ class NoRecusionAdapterMatcher(Matcher[ty.AnyStr], ty.Generic[ty.AnyStr]):
332
343
"""
333
344
__slots__ = ("_child" ,)
334
345
346
+ _child : Matcher [ty .AnyStr ]
347
+
335
348
def __init__ (self , child : Matcher [ty .AnyStr ]):
336
349
super ().__init__ (child .is_binary )
337
350
338
- self ._child : Matcher [ ty . AnyStr ] = child
351
+ self ._child = child
339
352
340
353
def should_descend (self , path : ty .AnyStr ) -> bool :
341
354
return False
@@ -423,6 +436,9 @@ class FSNodeType(enum.Enum):
423
436
class walk (ty .Generator [FSNodeEntry , ty .Any , None ], ty .Generic [ty .AnyStr ]):
424
437
__slots__ = ("_generator" , "_close_fd" )
425
438
439
+ _generator : ty .Generator [FSNodeEntry , None , None ]
440
+ _close_fd : ty .Optional [int ]
441
+
426
442
def __init__ (
427
443
self ,
428
444
directory : ty .Union [ty .AnyStr , utils .PathLike [ty .AnyStr ], int ],
@@ -465,7 +481,7 @@ def __init__(
465
481
:class:`NoRecusionAdapterMatcher` and hence prevent the scanner from
466
482
doing any recursion.
467
483
"""
468
- self ._close_fd : ty . Optional [ int ] = None
484
+ self ._close_fd = None
469
485
470
486
# Create matcher object
471
487
matcher = matcher_from_spec ( # type: ignore[type-var]
@@ -480,7 +496,7 @@ def __init__(
480
496
raise NotImplementedError ("Passing a file descriptor as directory is "
481
497
"not supported on this platform" )
482
498
483
- self ._generator : ty . Generator [ FSNodeEntry , None , None ] = self ._walk (
499
+ self ._generator = self ._walk (
484
500
directory ,
485
501
None ,
486
502
matcher , # type: ignore[arg-type]
@@ -678,6 +694,6 @@ def _walk(
678
694
679
695
680
696
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 })
682
698
else : # pragma: no cover
683
699
supports_fd = frozenset ()
0 commit comments