-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Labels
Description
I'd like to add the failing pattern to my debug logging. I tried this:
if (c := include_spec.check_file(p)).include:
logger.debug(
"Including {} {} because it is explicitly included by rule {!r}.",
ptype,
p,
include_spec.patterns[c.index].pattern,
)
return TrueBut I've run into two or three typing issues.
Patternhas no attribute.pattern; this could be solved if the include spec was made Generic so that it could know it has a subclass, but is there a better way to print out an arbitraryPattern?__str__()is not overloaded.c.indexcould beNone, so I get a complaint indexingpatternswith it, except it can't beNoneif.includeis True, I believe, so there might be a way to use a type guard or something here to indicate that these two types are linked..patternsis aSequence(instead of aCollectionfrom Python 3.6+), so you can't index it. It would be much more expensive for me to dolist(include_spec.patterns)[c.index], since I know it's a list, but maybe this should be typed differently? Is there a reason to only allowSequencehere, vs. allowing random access?
Those issues make me think maybe I'm not approaching this correctly; upon finding check_file as a replacement for match_file, I was pretty sure that's what this was for, but maybe there's a better way?
Reactions are currently unavailable