@@ -911,27 +911,25 @@ def _rc_params_in_file(fname, fail_on_error=False):
911911 Unlike `rc_params_from_file`, the configuration class only contains the
912912 parameters specified in the file (i.e. default values are not filled in).
913913 """
914- cnt = 0
915914 rc_temp = {}
916915 with _open_file_or_url (fname ) as fd :
917916 try :
918- for line in fd :
919- cnt += 1
917+ for line_no , line in enumerate (fd , 1 ):
920918 strippedline = line .split ('#' , 1 )[0 ].strip ()
921919 if not strippedline :
922920 continue
923921 tup = strippedline .split (':' , 1 )
924922 if len (tup ) != 2 :
925- error_details = _error_details_fmt % (cnt , line , fname )
923+ error_details = _error_details_fmt % (line_no , line , fname )
926924 _log .warning ('Illegal %s' , error_details )
927925 continue
928926 key , val = tup
929927 key = key .strip ()
930928 val = val .strip ()
931929 if key in rc_temp :
932930 _log .warning ('Duplicate key in file %r line #%d.' ,
933- fname , cnt )
934- rc_temp [key ] = (val , line , cnt )
931+ fname , line_no )
932+ rc_temp [key ] = (val , line , line_no )
935933 except UnicodeDecodeError :
936934 _log .warning ('Cannot decode configuration file %s with encoding '
937935 '%s, check LANG and LC_* variables.' ,
@@ -942,15 +940,15 @@ def _rc_params_in_file(fname, fail_on_error=False):
942940
943941 config = RcParams ()
944942
945- for key , (val , line , cnt ) in rc_temp .items ():
943+ for key , (val , line , line_no ) in rc_temp .items ():
946944 if key in defaultParams :
947945 if fail_on_error :
948946 config [key ] = val # try to convert to proper type or raise
949947 else :
950948 try :
951949 config [key ] = val # try to convert to proper type or skip
952950 except Exception as msg :
953- error_details = _error_details_fmt % (cnt , line , fname )
951+ error_details = _error_details_fmt % (line_no , line , fname )
954952 _log .warning ('Bad val %r on %s\n \t %s' ,
955953 val , error_details , msg )
956954 elif key in _deprecated_ignore_map :
@@ -959,14 +957,13 @@ def _rc_params_in_file(fname, fail_on_error=False):
959957 version , name = key , alternative = alt_key ,
960958 addendum = "Please update your matplotlibrc." )
961959 else :
962- print ("""
963- Bad key "%s" on line %d in
964- %s.
960+ version = 'master' if '.post' in __version__ else f'v{ __version__ } '
961+ print (f"""
962+ Bad key "{ key } " on line { line_no } in
963+ { fname } .
965964You probably need to get an updated matplotlibrc file from
966- http://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template
967- or from the matplotlib source distribution""" % (key , cnt , fname ),
968- file = sys .stderr )
969-
965+ https://github.com/matplotlib/matplotlib/blob/{ version } /matplotlibrc.template
966+ or from the matplotlib source distribution""" , file = sys .stderr )
970967 return config
971968
972969
0 commit comments