Deutsch   English   Français   Italiano  
<v57t3f$tpf$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!feed.opticnetworks.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Lawrence D'Oliveiro <ldo@nz.invalid>
Newsgroups: comp.lang.python
Subject: Checking That Two Args Are Of Same Type (Posting On Python-List
 Prohibited)
Date: Sun, 23 Jun 2024 01:17:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <v57t3f$tpf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 23 Jun 2024 03:17:35 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="be24819e5877b282c066214411113658";
	logging-data="30511"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/Fuyg17HXDKMK9Gu4DQd7d"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:iWHC3QZ2JbLFDy715wW0lsPu3o8=
Bytes: 1314

Consider a function taking two args “a” and “b”, which can be of str,
bytes or bytearray type, just so long as both are of the same type.
One easy way to test this is

    if sum(isinstance(a, t) and isinstance(b, t) for t in (str, bytes, bytearray)) != 1 :
        raise TypeError("args must both be str or bytes")
    #end if

Actually, both “and’ and “or” will work.