1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| | #! /usr/bin/python3
# SPDX-License-Identifier: GPL-2.0-or-later
#
# tasst - Test A Simple Socket Transport
# library of test helpers for passt & pasta
#
# tasst/typing.py - Type checking and related helpers
#
# Copyright Red Hat
# Author: David Gibson <david@gibson.dropbear.id.au>
def typecheck(val, ty_):
if not isinstance(val, ty_):
raise TypeError("Expected {} instead of {}".format(ty_, type(val)))
return val
def typecheck_default(val, ty_, default):
if val is None:
return default
return typecheck(val, ty_)
|