|
17 | 17 |
|
18 | 18 | import dill |
19 | 19 | from dill import Pickler, Unpickler |
20 | | -from ._dill import ModuleType, _import_module, _is_builtin_module |
| 20 | +from ._dill import ModuleType, _import_module, _is_builtin_module, _main_module |
21 | 21 | from .utils import AttrDict, CheckerSet, TransSet |
22 | 22 | from .settings import settings |
23 | 23 |
|
@@ -111,10 +111,14 @@ def _exclude_objs(main, exclude_extra, filters_extra, settings): |
111 | 111 | categories = {'ids': int, 'names': str, 'regex': re.Pattern, 'types': type} |
112 | 112 | exclude = AttrDict({cat: copy(settings.session_exclude[cat]) for cat in categories}) |
113 | 113 | filters = copy(settings.session_filters) |
| 114 | + del categories['ids'] # special case |
114 | 115 | if exclude_extra is not None: |
115 | 116 | if isinstance(exclude_extra, str): |
116 | 117 | raise ValueError("'exclude' can be of type Iterable[str], but not str") |
117 | 118 | for item in exclude_extra: |
| 119 | + if isinstance(item, int): |
| 120 | + exclude.ids.add(item, main=main) |
| 121 | + continue |
118 | 122 | for category, klass in categories.items(): |
119 | 123 | if isinstance(item, klass): |
120 | 124 | exclude[category].add(item) |
@@ -220,12 +224,12 @@ def load_session(filename: Union[os.PathLike, io.BytesIO] = '/tmp/session.pkl', |
220 | 224 | # Settings # |
221 | 225 | ############## |
222 | 226 |
|
223 | | -def _as_id(item): |
| 227 | +def _as_id(item, *, main=_main_module): |
224 | 228 | if isinstance(item, int): |
225 | | - import warnings, __main__ |
226 | | - if not any(id(obj) == item for obj in __main__.__dict__.values()): |
227 | | - warnings.warn("%d isn't the id of any object in __main__ namespace. " |
228 | | - "Did you mean 'id(%d)?'" % (item, item)) |
| 229 | + import warnings |
| 230 | + if not any(id(obj) == item for obj in main.__dict__.values()): |
| 231 | + warnings.warn("%d isn't the id of any object in the '%s' namespace. " |
| 232 | + "Did you mean 'id(%d)'?" % (item, main.__name__, item)) |
229 | 233 | return item |
230 | 234 | return id(item) |
231 | 235 |
|
|
0 commit comments