Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] config ignore imported modules and functions #1802

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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