1"""Auxiliary definitions used in type annotations. 2""" 3 4# Copyright The Mbed TLS Contributors 5# SPDX-License-Identifier: Apache-2.0 6# 7# Licensed under the Apache License, Version 2.0 (the "License"); you may 8# not use this file except in compliance with the License. 9# You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, software 14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16# See the License for the specific language governing permissions and 17# limitations under the License. 18 19from typing import Any 20 21# The typing_extensions module is necessary for type annotations that are 22# checked with mypy. It is only used for type annotations or to define 23# things that are themselves only used for type annotations. It is not 24# available on a default Python installation. Therefore, try loading 25# what we need from it for the sake of mypy (which depends on, or comes 26# with, typing_extensions), and if not define substitutes that lack the 27# static type information but are good enough at runtime. 28try: 29 from typing_extensions import Protocol #pylint: disable=import-error 30except ImportError: 31 class Protocol: #type: ignore 32 #pylint: disable=too-few-public-methods 33 pass 34 35class Writable(Protocol): 36 """Abstract class for typing hints.""" 37 # pylint: disable=no-self-use,too-few-public-methods,unused-argument 38 def write(self, text: str) -> Any: 39 ... 40