From 5b0d4f3e64903f101d68a1d5cb78919b5c87d856 Mon Sep 17 00:00:00 2001
From: Sanbu <96160062+sanbuphy@users.noreply.github.com>
Date: Tue, 1 Nov 2022 17:29:17 +0800
Subject: [PATCH] [Fix] Set the default value of encoding in Config to utf-8
 (#653)

---
 mmengine/config/config.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mmengine/config/config.py b/mmengine/config/config.py
index ab61ba1b..8d3dc6d4 100644
--- a/mmengine/config/config.py
+++ b/mmengine/config/config.py
@@ -418,7 +418,7 @@ class Config:
                 base_cfg_dict.update(_cfg_dict)
 
             if filename.endswith('.py'):
-                with open(temp_config_file.name) as f:
+                with open(temp_config_file.name, encoding='utf-8') as f:
                     codes = ast.parse(f.read())
                     codes = RemoveAssignFromAST(BASE_KEY).visit(codes)
                 codeobj = compile(codes, '', mode='exec')
@@ -550,7 +550,7 @@ class Config:
         file_format = filename.partition('.')[-1]
         if file_format == 'py':
             Config._validate_py_syntax(filename)
-            with open(filename) as f:
+            with open(filename, encoding='utf-8') as f:
                 codes = ast.parse(f.read()).body
 
                 def is_base_line(c):
-- 
GitLab