| 123 | raise ExtensionNotFound(f"No {oid} extension was found", oid) |
| 124 | |
| 125 | def get_extension_for_class( |
| 126 | self, extclass: type[ExtensionTypeVar] |
| 127 | ) -> Extension[ExtensionTypeVar]: |
| 128 | if extclass is UnrecognizedExtension: |
| 129 | raise TypeError( |
| 130 | "UnrecognizedExtension can't be used with " |
| 131 | "get_extension_for_class because more than one instance of the" |
| 132 | " class may be present." |
| 133 | ) |
| 134 | |
| 135 | for ext in self: |
| 136 | if isinstance(ext.value, extclass): |
| 137 | return ext |
| 138 | |
| 139 | raise ExtensionNotFound( |
| 140 | f"No {extclass} extension was found", extclass.oid |
| 141 | ) |
| 142 | |
| 143 | __len__, __iter__, __getitem__ = _make_sequence_methods("_extensions") |
| 144 | |