Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Workaround to preserve original PyYAML module behavior #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ntoofu
Copy link

@ntoofu ntoofu commented Oct 7, 2017

Background

Workaround for issue #34.

Changes

  • Specify pyraml_yaml as module name for PyYAML module by using imp module

Notes

  • imp.load_module is deprecated, but equivalent implementation without deprecated functions will lose backward compatibility and will be difficult to fall back to deprecated implementation.
    • The equivalent implementation is like below.
      • In pyraml/__init__.py
        import importlib.util
        
        pyyaml_mod_spec = importlib.util.find_spec('yaml')
        pyyaml_module = importlib.util.module_from_spec(pyyaml_mod_spec)
        pyyaml_mod_spec.loader.exec_module(pyyaml_module)
        sys.modules['pyraml_yaml'] = pyyaml_module 
        yaml = pyyaml_module
        
        # yaml.add_representer(...)
        
      • In the other python scripts in pyraml directory
        import pyraml_yaml as yaml
        
        # yaml.load(...)
        

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant