Mercurial > hg
comparison mercurial/thirdparty/zope/interface/declarations.py @ 37208:b9dd8403d8ff
zope: force module import by importing symbols
Previously, we tried to import a module and handle the ImportError.
Our lazy module importer doesn't verify the module exists and returns
a dummy object representing the module. Only once we attempt to load
a symbol in the module does the ImportError get raises.
This means that simple imports inside `try..except ImportError` don't
detect missing modules.
This commit changes imports in zope.interface to access symbols, thus
forcing module load and triggering ImportError.
This fixes zope.interface for pure builds.
Differential Revision: https://phab.mercurial-scm.org/D2980
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 30 Mar 2018 13:39:06 -0700 |
parents | 49630e75635d |
children |
comparison
equal
deleted
inserted
replaced
37207:d3f1d3e4e58d | 37208:b9dd8403d8ff |
---|---|
638 ClassProvidesBasePy = ClassProvidesBaseFallback # BBB | 638 ClassProvidesBasePy = ClassProvidesBaseFallback # BBB |
639 ClassProvidesBase = ClassProvidesBaseFallback | 639 ClassProvidesBase = ClassProvidesBaseFallback |
640 | 640 |
641 # Try to get C base: | 641 # Try to get C base: |
642 try: | 642 try: |
643 from . import _zope_interface_coptimizations | 643 from ._zope_interface_coptimizations import ClassProvidesBase |
644 except ImportError: | 644 except ImportError: |
645 pass | 645 pass |
646 else: | |
647 from ._zope_interface_coptimizations import ClassProvidesBase | |
648 | |
649 | 646 |
650 class ClassProvides(Declaration, ClassProvidesBase): | 647 class ClassProvides(Declaration, ClassProvidesBase): |
651 """Special descriptor for class __provides__ | 648 """Special descriptor for class __provides__ |
652 | 649 |
653 The descriptor caches the implementedBy info, so that | 650 The descriptor caches the implementedBy info, so that |
915 return output | 912 return output |
916 | 913 |
917 _empty = Declaration() | 914 _empty = Declaration() |
918 | 915 |
919 try: | 916 try: |
920 from . import _zope_interface_coptimizations | 917 from ._zope_interface_coptimizations import ( |
918 getObjectSpecification, | |
919 implementedBy, | |
920 ObjectSpecificationDescriptor, | |
921 providedBy, | |
922 ) | |
921 except ImportError: | 923 except ImportError: |
922 pass | 924 pass |
923 else: | |
924 from ._zope_interface_coptimizations import implementedBy | |
925 from ._zope_interface_coptimizations import providedBy | |
926 from ._zope_interface_coptimizations import ( | |
927 getObjectSpecification) | |
928 from ._zope_interface_coptimizations import ( | |
929 ObjectSpecificationDescriptor) | |
930 | 925 |
931 objectSpecificationDescriptor = ObjectSpecificationDescriptor() | 926 objectSpecificationDescriptor = ObjectSpecificationDescriptor() |