Skip to content

Commit

Permalink
[fix] config ignore imported modules and functions (#1802)
Browse files Browse the repository at this point in the history
* [fix] config ignore modules and functions

* add unitest
  • Loading branch information
SuTanTank committed Mar 22, 2022
1 parent 42062ed commit ac52bb3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mmcv/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import shutil
import sys
import tempfile
import types
import uuid
import warnings
from argparse import Action, ArgumentParser
Expand Down Expand Up @@ -209,6 +210,8 @@ def _file2dict(filename, use_predefined_variables=True):
name: value
for name, value in mod.__dict__.items()
if not name.startswith('__')
and not isinstance(value, types.ModuleType)
and not isinstance(value, types.FunctionType)
}
# delete imported module
del sys.modules[temp_module_name]
Expand Down
6 changes: 6 additions & 0 deletions tests/data/config/l.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp


def func(x):
return x

_base_ = ['./l1.py', './l2.yaml', './l3.json', './l4.py']
item3 = False
item4 = 'test'
6 changes: 6 additions & 0 deletions tests/data/config/n.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp


def func(x):
return x

test_item1 = [1, 2]
bool_item2 = True
str_item3 = 'test'
Expand Down

0 comments on commit ac52bb3

Please sign in to comment.