From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10708 invoked by alias); 21 Aug 2013 14:59:39 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 10699 invoked by uid 89); 21 Aug 2013 14:59:39 -0000 X-Spam-SWARE-Status: No, score=-7.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 21 Aug 2013 14:59:38 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7LExb9T028177 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 21 Aug 2013 10:59:37 -0400 Received: from barimba (ovpn-113-142.phx2.redhat.com [10.3.113.142]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r7LExaBh002584 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 21 Aug 2013 10:59:37 -0400 From: Tom Tromey To: Phil Muldoon Cc: gdb-patches@sourceware.org Subject: Re: [patch] [python] Fix Python 3 build and testsuite issues References: <521230C8.2040803@redhat.com> <878uzxlkl1.fsf@fleche.redhat.com> <52124B8D.6010609@redhat.com> <87ppt9jzrl.fsf@fleche.redhat.com> <5213C6BA.7030703@redhat.com> <87d2p8gmlo.fsf@fleche.redhat.com> <5213D26D.4070003@redhat.com> <5214CECF.30103@redhat.com> Date: Wed, 21 Aug 2013 14:59:00 -0000 In-Reply-To: <5214CECF.30103@redhat.com> (Phil Muldoon's message of "Wed, 21 Aug 2013 15:29:35 +0100") Message-ID: <8761uzf5t3.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-08/txt/msg00584.txt.bz2 Phil> Strings in Python 3 are now always encoded and are encapsulated by the Phil> "str" class. Phil> In Python 2 you had str() and unicode(), where unicode was encoded and Phil> str just represented bytes (IE just an unencoded string). Phil> Reading around the suggestion seems to be to do this: Phil> try: Phil> # basestring catches both types of Python 2.x strings Phil> if isinstance(sym, basestring) Phil> return True Phil> except NameError: Phil> # If we are here, basestring does not exist, so Python 3.x Phil> if isinstance(sym, str) Phil> return True Phil> # Continue to process objects that are not a string. We can do this check once, at top-level: try: if isinstance('hi', basestring): def is_string(x): return isinstance(x, basestring) except NameError: def isinstance(x): return isinstance(x, str) Maybe duck typing is still preferable though. Not sure if this needs a third def in case the 'if' fails without throwing. Probably not. Tom