@@ -472,6 +472,7 @@ def _initialise(self):
472472 self .default_values = {}
473473 self .extra_values = []
474474 self ._created = False
475+ self .source_map = {}
475476
476477
477478 def _interpolate (self , key , value ):
@@ -514,7 +515,7 @@ def _check(entry):
514515 return val
515516
516517
517- def __setitem__ (self , key , value , unrepr = False ):
518+ def __setitem__ (self , key , value , unrepr = False , line_range = None ):
518519 """
519520 Correctly set a value.
520521
@@ -571,7 +572,8 @@ def __setitem__(self, key, value, unrepr=False):
571572 else :
572573 raise TypeError ('Value is not a string "%s".' % value )
573574 dict .__setitem__ (self , key , value )
574-
575+ if line_range :
576+ self .source_map [key ] = line_range
575577
576578 def __delitem__ (self , key ):
577579 """Remove items from the sequence when deleting."""
@@ -582,6 +584,8 @@ def __delitem__(self, key):
582584 self .sections .remove (key )
583585 del self .comments [key ]
584586 del self .inline_comments [key ]
587+ if key in self .source_map :
588+ del self .source_map [key ]
585589
586590
587591 def get (self , key , default = None ):
@@ -1023,6 +1027,7 @@ def restore_defaults(self):
10231027 self [section ].restore_defaults ()
10241028
10251029
1030+
10261031def _get_triple_quote (value ):
10271032 """Helper for triple-quoting round-trips."""
10281033 if ('"""' in value ) and ("'''" in value ):
@@ -1599,6 +1604,7 @@ def _parse(self, infile):
15991604 # it's not a section marker,
16001605 # so it should be a valid ``key = value`` line
16011606 mat = self ._keyword .match (line )
1607+ start_line = cur_index
16021608 if mat is None :
16031609 self ._handle_error (
16041610 'Invalid line ({0!r}) (matched as neither section nor keyword)' .format (line ),
@@ -1662,7 +1668,7 @@ def _parse(self, infile):
16621668 # add the key.
16631669 # we set unrepr because if we have got this far we will never
16641670 # be creating a new section
1665- this_section .__setitem__ (key , value , unrepr = True )
1671+ this_section .__setitem__ (key , value , unrepr = True , line_range = ( start_line , cur_index ) )
16661672 this_section .inline_comments [key ] = comment
16671673 this_section .comments [key ] = comment_list
16681674 continue
0 commit comments