| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1801,9 +1801,11 @@ def __subclasscheck__(cls, other): | |||
| 1801 | 1801 | def __instancecheck__(cls, instance): | |
| 1802 | 1802 | # We need this method for situations where attributes are | |
| 1803 | 1803 | # assigned in __init__. | |
| 1804 | - is_protocol_cls = getattr(cls, "_is_protocol", False) | ||
| 1804 | + if not getattr(cls, "_is_protocol", False): | ||
| 1805 | + # i.e., it's a concrete subclass of a protocol | ||
| 1806 | + return super().__instancecheck__(instance) | ||
| 1807 | + | ||
| 1805 | 1808 | if ( | |
| 1806 | - is_protocol_cls and | ||
| 1807 | 1809 | not getattr(cls, '_is_runtime_protocol', False) and | |
| 1808 | 1810 | not _allow_reckless_class_checks(depth=2) | |
| 1809 | 1811 | ): | |
@@ -1813,17 +1815,16 @@ def __instancecheck__(cls, instance): | |||
| 1813 | 1815 | if super().__instancecheck__(instance): | |
| 1814 | 1816 | return True | |
| 1815 | 1817 | ||
| 1816 | - if is_protocol_cls: | ||
| 1817 | - getattr_static = _lazy_load_getattr_static() | ||
| 1818 | - for attr in cls.__protocol_attrs__: | ||
| 1819 | - try: | ||
| 1820 | - val = getattr_static(instance, attr) | ||
| 1821 | - except AttributeError: | ||
| 1822 | - break | ||
| 1823 | - if val is None and callable(getattr(cls, attr, None)): | ||
| 1824 | - break | ||
| 1825 | - else: | ||
| 1826 | - return True | ||
| 1818 | + getattr_static = _lazy_load_getattr_static() | ||
| 1819 | + for attr in cls.__protocol_attrs__: | ||
| 1820 | + try: | ||
| 1821 | + val = getattr_static(instance, attr) | ||
| 1822 | + except AttributeError: | ||
| 1823 | + break | ||
| 1824 | + if val is None and callable(getattr(cls, attr, None)): | ||
| 1825 | + break | ||
| 1826 | + else: | ||
| 1827 | + return True | ||
| 1827 | 1828 | ||
| 1828 | 1829 | return False | |
| 1829 | 1830 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments