Consolidate placeholder tracking in the source tracker. - #150
Conversation
|
@davepeck Thanks for merging those changes. Here is the next "chunk" that continues to move things into alignment with the error messaging. |
There was a problem hiding this comment.
LGTM! Two very small and ignorable comments:
-
There are a couple places in
parser.pywhere we doif self.source:orif self.source and ...:. Maybe these should becomeif self.source is not Nonefor future safety (it's fine now, but what happens if we add, say,__len__?) -
Should we have a variant of
test_iterthat testst""andt"one-string-only"cases?
As for find_placeholders and remove_placeholders: I think it works, but agree you have to be cautious.
Anyway, extremely minor feedback! LMK when you're good for a merge.
|
@davepeck I added a parametrized test for those simple string cases you mentioned. If this looks ok I think you should merge it so I can start prep'ing the next part. |
|
@ianjosephwilson Merged; thanks! By the way, one thing I've been contemplating is moving the source structure to something more standard in the python world, specifically:
This is just a bunch of churn, so I want to avoid it until you are in a position to take it. If that's now, cool; if that's, like, after the error handling stuff is settled, cool too -- just let me know. (And if you don't like this structure, LMK what you'd prefer!) |
Haha don't you dare DAVE! Thanks for asking and I think these are both good ideas for once we get the error stuff in assuming nothing else is going on. But it would probably be safer to wait in case I need to scissor-and-glue-stick together more sub-sub PRs for us to digest to get this thing in. |
Yup, no rush on this one. Will do later. |
SourceTrackerinto an Iterator.SourceTracker.TemplateParser's placeholder extraction to proxy methods of the `SourceTracker. The parser still needs to know when its just looking at a snapshot versus when it is "marking" the placeholder as found. Not ideal but this composition feels better and more distinct from the regular parsing duties.configure_source_trackerfactory function because later we bind thePlaceholderConfigto members other thanPlaceholderStatethat depend on the size of the placeholders (defined by the config).The
SourceTrackermethodsget_expressionandformat_starttagwill be removed in another PR and those responsibilities will be in theSourceReader(constructed and accessed during exceptions).