Skip to content

Can't reload module that has __reload__ defined #23

@overfl0

Description

@overfl0

Hello, I'm having an issue when I'm trying to reload a module that has the __reload__ function defines.
I've narrowed the problem to even just having `logging' imported:

module.py:

import logging
a = 42
def __reload__(state):
    pass

Run.py:

import reloader
reloader.enable(blacklist=['logging'])  # It's pointless here, isn't it?

import module
reloader.reload(module)

I think the issue seems to be with deepcopying the logginng module. Should it also be deleted in _deepcopy_module_dict() as you're doing with __builtins__? (just a wild guess)

The errors seem to differ each time I run run.py. I'm getting one of those on python 3.5:
TypeError: cannot serialize '_io.TextIOWrapper' object
AttributeError: 'NoneType' object has no attribute 'update'
TypeError: cannot create 'sys.version_info' instances
TypeError: cannot create 'sys.flags' instances
TypeError: can't pickle _thread.lock objects

Example stacktrace:

Traceback (most recent call last):
  File "run.py", line 5, in <module>
    reloader.reload(module)
  File "C:\Python35-x64\lib\site-packages\reloader.py", line 146, in reload
    _reload(m, set())
  File "C:\Python35-x64\lib\site-packages\reloader.py", line 130, in _reload
    d = _deepcopy_module_dict(m)
  File "C:\Python35-x64\lib\site-packages\reloader.py", line 87, in _deepcopy_module_dict
    return copy.deepcopy(d)
  File "C:\Python35-x64\lib\copy.py", line 155, in deepcopy
    y = copier(x, memo)
  File "C:\Python35-x64\lib\copy.py", line 243, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python35-x64\lib\copy.py", line 182, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "C:\Python35-x64\lib\copy.py", line 297, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Python35-x64\lib\copy.py", line 155, in deepcopy
    y = copier(x, memo)
  File "C:\Python35-x64\lib\copy.py", line 243, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python35-x64\lib\copy.py", line 182, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "C:\Python35-x64\lib\copy.py", line 306, in _reconstruct
    y.__dict__.update(state)
AttributeError: 'NoneType' object has no attribute 'update'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions