Fix stub compat with older pyyaml versions that may unwittingly load it

This commit is contained in:
Matt Davis 2021-01-20 13:15:18 -08:00 committed by Ingy döt Net
parent 58d0cb7ee0
commit 2b37f155d4
2 changed files with 6 additions and 2 deletions

View file

@ -5,7 +5,9 @@
# close enough for anyone who's relying on it even when they shouldn't. # close enough for anyone who's relying on it even when they shouldn't.
import yaml import yaml
if not yaml.__with_libyaml__: # in some circumstances, the yaml module we imoprted may be from a different version, so we need
# to tread carefully when poking at it here (it may not have the attributes we expect)
if not getattr(yaml, '__with_libyaml__', False):
from sys import version_info from sys import version_info
exc = ModuleNotFoundError if version_info >= (3, 6) else ImportError exc = ModuleNotFoundError if version_info >= (3, 6) else ImportError

View file

@ -5,7 +5,9 @@
# close enough for anyone who's relying on it even when they shouldn't. # close enough for anyone who's relying on it even when they shouldn't.
import yaml import yaml
if not yaml.__with_libyaml__: # in some circumstances, the yaml module we imoprted may be from a different version, so we need
# to tread carefully when poking at it here (it may not have the attributes we expect)
if not getattr(yaml, '__with_libyaml__', False):
from sys import version_info from sys import version_info
exc = ModuleNotFoundError if version_info >= (3, 6) else ImportError exc = ModuleNotFoundError if version_info >= (3, 6) else ImportError