@@ -478,6 +478,7 @@ def _initialise(self):
478478 self .default_values = {}
479479 self .extra_values = []
480480 self ._created = False
481+ self .source_map = {}
481482
482483
483484 def _interpolate (self , key , value ):
@@ -520,7 +521,7 @@ def _check(entry):
520521 return val
521522
522523
523- def __setitem__ (self , key , value , unrepr = False ):
524+ def __setitem__ (self , key , value , unrepr = False , line_range = None ):
524525 """
525526 Correctly set a value.
526527
@@ -577,7 +578,8 @@ def __setitem__(self, key, value, unrepr=False):
577578 else :
578579 raise TypeError ('Value is not a string "%s".' % value )
579580 dict .__setitem__ (self , key , value )
580-
581+ if line_range :
582+ self .source_map [key ] = line_range
581583
582584 def __delitem__ (self , key ):
583585 """Remove items from the sequence when deleting."""
@@ -588,6 +590,8 @@ def __delitem__(self, key):
588590 self .sections .remove (key )
589591 del self .comments [key ]
590592 del self .inline_comments [key ]
593+ if key in self .source_map :
594+ del self .source_map [key ]
591595
592596
593597 def get (self , key , default = None ):
@@ -1029,6 +1033,7 @@ def restore_defaults(self):
10291033 self [section ].restore_defaults ()
10301034
10311035
1036+
10321037def _get_triple_quote (value ):
10331038 """Helper for triple-quoting round-trips."""
10341039 if ('"""' in value ) and ("'''" in value ):
@@ -1602,6 +1607,7 @@ def _parse(self, infile):
16021607 # it's not a section marker,
16031608 # so it should be a valid ``key = value`` line
16041609 mat = self ._keyword .match (line )
1610+ start_line = cur_index
16051611 if mat is None :
16061612 self ._handle_error (
16071613 'Invalid line ({!r}) (matched as neither section nor keyword)' .format (line ),
@@ -1665,7 +1671,7 @@ def _parse(self, infile):
16651671 # add the key.
16661672 # we set unrepr because if we have got this far we will never
16671673 # be creating a new section
1668- this_section .__setitem__ (key , value , unrepr = True )
1674+ this_section .__setitem__ (key , value , unrepr = True , line_range = ( start_line , cur_index ) )
16691675 this_section .inline_comments [key ] = comment
16701676 this_section .comments [key ] = comment_list
16711677 continue
0 commit comments