Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'example:': 0.03; 'subject:Python': 0.06; 'happen.': 0.09; 'try:': 0.09; 'works.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'messy': 0.16; 'nameerror:': 0.16; 'subject:versions': 0.16; 'top:': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'feb': 0.22; 'otherwise,': 0.22; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'unicode': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'could': 0.34; 'common': 0.35; 'except': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'pm,': 0.38; 'does': 0.39; 'delete': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'simply': 0.61; "you're": 0.61; 'name': 0.63; 'more': 0.64; 'chance': 0.65; 'forward': 0.65; 'avoids': 0.84; 'collision': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=t8ulOZ5AWEmun0aHbiJhjTu4nZewgcUN/o0G3gxq4xg=; b=J3DezF6N8/Hg9SFmLbXJaG2ET+4V1Z/vQvAWCICZCsDbVvKmVnD8rQWMwni+HQnw/w HtrPPuH7eAjAyuEcDG5RV3j3l01ASkmnfpogkmJm7uMwLjY0equMs0nGAwMd2pYvb2eZ 6j+cY6Oq+Pn2u6q/XpUA86ty+5UMPOpZ20vM169NLEkceo9J4Bqsai/mIsr025ZNFTC6 kfDOUkem/oWQN2VuivUfvsx8g0OGiAnU1mkvvwiQHFvjdhXhq9jKAFnm1QAiEkQpzc2r iZkYtAvoGgGOeEPqiy+saQm63Jtst8DwTZAjQMifXgHddLZpvHEJnhzK4BZCowl9bhMx tjdQ== MIME-Version: 1.0 X-Received: by 10.68.162.66 with SMTP id xy2mr37920073pbb.46.1392040776456; Mon, 10 Feb 2014 05:59:36 -0800 (PST) In-Reply-To: <317fd2a4-186b-4b97-ad7f-084609d0a9a4@googlegroups.com> References: <317fd2a4-186b-4b97-ad7f-084609d0a9a4@googlegroups.com> Date: Tue, 11 Feb 2014 00:59:36 +1100 Subject: Re: Pylint across Python versions From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392040780 news.xs4all.nl 2941 [2001:888:2000:d::a6]:47790 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65814 On Mon, Feb 10, 2014 at 10:39 PM, wrote: > Example: > I'm using a construct like this: > > if sys.version.startswith("3."): > unicode = str > > The reason is that Python 3 does not have this > function anymore but pylint yells for Python < 3 > about redefinition also it does not happen. > > How to get forward with this? It's more common to spell that with a try/except. Does pylint complain if you use this instead? try: unicode except NameError: unicode = str Although it would be better to write your code for Python 3, and have compatibility code at the top for Python 2. That would mean using 'str' everywhere, and then having this at the top: try: str = unicode except NameError: pass That way, when you're ready to drop support for Python 2, you simply delete the compat code and everything works. Otherwise, you have to maintain messy code indefinitely. Alternatively, to avoid redefinition at all, you could use your own name everywhere: try: unicode_string = unicode except NameError: unicode_string = str Use something less unwieldy if you prefer, but this avoids any chance of collision :) ChrisA