Lichen

Annotated lib/__builtins__/types.py

858:8f8361de472a
2018-07-21 Paul Boddie Invocations in parameter lists may require temporary storage for contexts and accessors, but the storage locations must be different. Otherwise, the code will generate a sequence-point warning. Here, distinct ranges for parameters in lists are introduced, and accessors are now also stored in arrays, permitting distinct storage.
paul@347 1
#!/usr/bin/env python
paul@347 2
paul@347 3
"""
paul@347 4
Common type validation functions.
paul@347 5
paul@787 6
Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
paul@347 7
paul@347 8
This program is free software; you can redistribute it and/or modify it under
paul@347 9
the terms of the GNU General Public License as published by the Free Software
paul@347 10
Foundation; either version 3 of the License, or (at your option) any later
paul@347 11
version.
paul@347 12
paul@347 13
This program is distributed in the hope that it will be useful, but WITHOUT
paul@347 14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
paul@347 15
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
paul@347 16
details.
paul@347 17
paul@347 18
You should have received a copy of the GNU General Public License along with
paul@347 19
this program.  If not, see <http://www.gnu.org/licenses/>.
paul@347 20
"""
paul@347 21
paul@787 22
from native import isinstance as _isinstance, is_int
paul@347 23
paul@347 24
def check_int(i):
paul@347 25
paul@347 26
    "Check the given int 'i'."
paul@347 27
paul@787 28
    if not is_int(i):
paul@347 29
        raise ValueError(i)
paul@347 30
paul@347 31
def check_string(s):
paul@347 32
paul@347 33
    "Check the given string 's'."
paul@347 34
paul@390 35
    if not _isinstance(s, basestring):
paul@347 36
        raise ValueError(s)
paul@347 37
paul@347 38
# vim: tabstop=4 expandtab shiftwidth=4