Mercurial > public > mercurial-scm > hg
comparison mercurial/thirdparty/zope/interface/declarations.py @ 37179:49630e75635d
thirdparty: allow zope.interface.advice to be lazily imported
The symbol from this module is only used in functions. Let's access
that symbol through its imported module so importing
zope.interface.advice can be lazy.
Differential Revision: https://phab.mercurial-scm.org/D2931
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 21 Mar 2018 18:13:40 -0700 |
parents | 68ee61822182 |
children | b9dd8403d8ff |
comparison
equal
deleted
inserted
replaced
37178:68ee61822182 | 37179:49630e75635d |
---|---|
32 from types import FunctionType | 32 from types import FunctionType |
33 from types import MethodType | 33 from types import MethodType |
34 from types import ModuleType | 34 from types import ModuleType |
35 import weakref | 35 import weakref |
36 | 36 |
37 from .advice import addClassAdvisor | 37 from . import advice as advicemod |
38 from .interface import InterfaceClass | 38 from .interface import InterfaceClass |
39 from .interface import SpecificationBase | 39 from .interface import SpecificationBase |
40 from .interface import Specification | 40 from .interface import Specification |
41 from ._compat import CLASS_TYPES as DescriptorAwareMetaClasses | 41 from ._compat import CLASS_TYPES as DescriptorAwareMetaClasses |
42 from ._compat import PYTHON3 | 42 from ._compat import PYTHON3 |
449 | 449 |
450 if '__implements_advice_data__' in locals: | 450 if '__implements_advice_data__' in locals: |
451 raise TypeError(name+" can be used only once in a class definition.") | 451 raise TypeError(name+" can be used only once in a class definition.") |
452 | 452 |
453 locals['__implements_advice_data__'] = interfaces, classImplements | 453 locals['__implements_advice_data__'] = interfaces, classImplements |
454 addClassAdvisor(_implements_advice, depth=3) | 454 advicemod.addClassAdvisor(_implements_advice, depth=3) |
455 | 455 |
456 def implements(*interfaces): | 456 def implements(*interfaces): |
457 """Declare interfaces implemented by instances of a class | 457 """Declare interfaces implemented by instances of a class |
458 | 458 |
459 This function is called in a class definition. | 459 This function is called in a class definition. |
730 raise TypeError( | 730 raise TypeError( |
731 "classProvides can only be used once in a class definition.") | 731 "classProvides can only be used once in a class definition.") |
732 | 732 |
733 locals["__provides__"] = _normalizeargs(interfaces) | 733 locals["__provides__"] = _normalizeargs(interfaces) |
734 | 734 |
735 addClassAdvisor(_classProvides_advice, depth=2) | 735 advicemod.addClassAdvisor(_classProvides_advice, depth=2) |
736 | 736 |
737 def _classProvides_advice(cls): | 737 def _classProvides_advice(cls): |
738 # This entire approach is invalid under Py3K. Don't even try to fix | 738 # This entire approach is invalid under Py3K. Don't even try to fix |
739 # the coverage for this block there. :( | 739 # the coverage for this block there. :( |
740 interfaces = cls.__dict__['__provides__'] | 740 interfaces = cls.__dict__['__provides__'] |