@@ -769,15 +769,16 @@ def _find_config(path: str) -> Tuple[str, Dict[str, Any]]:
769
769
def _get_config_data (file_path : str , sections : Tuple [str ]) -> Dict [str , Any ]:
770
770
settings : Dict [str , Any ] = {}
771
771
772
- with open (file_path , encoding = "utf-8" ) as config_file :
773
- if file_path .endswith (".toml" ):
774
- config = tomli .load (config_file )
775
- for section in sections :
776
- config_section = config
777
- for key in section .split ("." ):
778
- config_section = config_section .get (key , {})
779
- settings .update (config_section )
780
- else :
772
+ if file_path .endswith (".toml" ):
773
+ with open (file_path , "rb" ) as bin_config_file :
774
+ config = tomli .load (bin_config_file )
775
+ for section in sections :
776
+ config_section = config
777
+ for key in section .split ("." ):
778
+ config_section = config_section .get (key , {})
779
+ settings .update (config_section )
780
+ else :
781
+ with open (file_path , encoding = "utf-8" ) as config_file :
781
782
if file_path .endswith (".editorconfig" ):
782
783
line = "\n "
783
784
last_position = config_file .tell ()
@@ -790,22 +791,22 @@ def _get_config_data(file_path: str, sections: Tuple[str]) -> Dict[str, Any]:
790
791
791
792
config = configparser .ConfigParser (strict = False )
792
793
config .read_file (config_file )
793
- for section in sections :
794
- if section .startswith ("*.{" ) and section .endswith ("}" ):
795
- extension = section [len ("*.{" ) : - 1 ]
796
- for config_key in config .keys ():
797
- if (
798
- config_key .startswith ("*.{" )
799
- and config_key .endswith ("}" )
800
- and extension
801
- in map (
802
- lambda text : text .strip (), config_key [len ("*.{" ) : - 1 ].split ("," ) # type: ignore # noqa
803
- )
804
- ):
805
- settings .update (config .items (config_key ))
806
-
807
- elif config .has_section (section ):
808
- settings .update (config .items (section ))
794
+ for section in sections :
795
+ if section .startswith ("*.{" ) and section .endswith ("}" ):
796
+ extension = section [len ("*.{" ) : - 1 ]
797
+ for config_key in config .keys ():
798
+ if (
799
+ config_key .startswith ("*.{" )
800
+ and config_key .endswith ("}" )
801
+ and extension
802
+ in map (
803
+ lambda text : text .strip (), config_key [len ("*.{" ) : - 1 ].split ("," ) # type: ignore # noqa
804
+ )
805
+ ):
806
+ settings .update (config .items (config_key ))
807
+
808
+ elif config .has_section (section ):
809
+ settings .update (config .items (section ))
809
810
810
811
if settings :
811
812
settings ["source" ] = file_path
0 commit comments