Path: csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed2.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'root': 0.05; 'debugging': 0.07; 'encoded': 0.07; 'plenty': 0.07; 'string': 0.09; 'global,': 0.09; 'seemed': 0.09; 'typed': 0.09; 'cc:addr:python-list': 0.11; 'suggest': 0.14; "'__doc__',": 0.16; "'help',": 0.16; "'set',": 0.16; 'builtins.': 0.16; 'dict': 0.16; 'inclined': 0.16; 'len,': 0.16; 'namespace,': 0.16; 'overriding': 0.16; 'password,': 0.16; 'pep8': 0.16; 'range,': 0.16; 'scope.': 0.16; 'then?': 0.16; 'tuple,': 0.16; 'underscores,': 0.16; 'uppercase': 0.16; 'obviously': 0.18; 'variable': 0.18; 'bit': 0.19; "python's": 0.19; 'seems': 0.21; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'string,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'sort': 0.25; 'right.': 0.26; 'header:In-Reply- To:1': 0.27; '(like': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'work.': 0.31; 'included': 0.31; 'easier': 0.31; "skip:' 10": 0.31; 'int,': 0.31; 'names.': 0.31; 'retirement': 0.31; 'safely': 0.31; 'beginning': 0.33; 'not.': 0.33; "i'd": 0.34; 'something': 0.35; 'editor': 0.35; 'etc': 0.35; 'etc.)': 0.35; 'good.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'should': 0.36; 'unit': 0.37; 'area': 0.37; 'being': 0.38; 'skip:[ 10': 0.38; 'list,': 0.38; 'that,': 0.38; 'above,': 0.60; 'mentioned': 0.61; "you're": 0.61; "you've": 0.63; 'making': 0.63; 'such': 0.63; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'safe': 0.72; 'money': 0.72; 'day': 0.76; 'subject:Don': 0.91; 'grey': 0.93; 'washington': 0.93 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:to :cc:content-type; bh=/Mx3UMw4d/hkgtHgVy6oGK9TO5jPuRV1w4FANPlwVAc=; b=KMBTS5RLykJo9G4fMQS39upo8J9sN15NnrBdg2PAVTrcqJh8ohx8XhzSrAbTO8+Gl/ qMoZciIAJWRsJaJy7b2lMWpjoVclmHkSEML+PSSQ0Dv6R05N5PrbpEgPsn+NI2jTJ8z9 L36y0UaJJ41W0WSpyXliFFCKhH4krv7pvH9MhjVZDQJMka+p7MOR2BZ2sLPWbnuLaVz0 zDfYvN72Zil/7LZ1bhOziKmcDhPQoN1X8cdhgb4kRyWmWJyiduGGwSNpc/dPH6Px9QZG chXXA2UTfdQ7i9uX71/qh3jfGvD/jifuvCArBoOO42G5IQh82LiUkRdFkwfWz42xf1lL i9Jg== MIME-Version: 1.0 X-Received: by 10.180.36.205 with SMTP id s13mr5974612wij.31.1371078434381; Wed, 12 Jun 2013 16:07:14 -0700 (PDT) In-Reply-To: References: Date: Wed, 12 Jun 2013 16:07:14 -0700 Subject: Re: "Don't rebind built-in names*" - it confuses readers From: Mark Janssen To: Chris Angelico Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org 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: 70 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371078442 news.xs4all.nl 15925 [2001:888:2000:d::a6]:56550 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47856 >> You're right. I was being sloppy. > > ['ArithmeticError', 'AssertionError', 'AttributeError', > 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', > 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', > 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', > 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', > 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', > 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', > 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', > 'InterruptedError', 'IsADirectoryError', 'KeyError', > 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', > 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', > 'OSError', 'OverflowError', 'PendingDeprecationWarning', > 'PermissionError', 'ProcessLookupError', 'ReferenceError', > 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopIteration', > 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', > 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', > 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', > 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', > 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_', > '__build_class__', '__debug__', '__doc__', '__import__', '__name__', > '__package__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', > 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', > 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', > 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', > 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', > 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', > 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', > 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', > 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', > 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', > 'type', 'vars', 'zip'] > > I think I can safely say that all the names beginning with an > uppercase letter (exceptions, True/False/None/Ellipsis), and the ones > beginning with underscores, should not be overridden. Well and good. > Still leaves 72 builtins. Obviously overriding len, print, range, etc > would be risky (unless, as mentioned above, you're making a drop-in > replacement), but there are plenty that you'd never notice (eg if you > use "hash" for an encoded password, or "input" for the string the user > typed into an HTML form). I would hope, for instance, that an editor > would not color-highlight 'credits' differently, as it's designed for > interactive work. There are plenty in the grey area - is it safe to > use "sum" as an accumulator or "min" for a unit of time? What about > using "super" to store the amount of retirement money you've put away? > I'd be inclined to avoid this sort any time I'm aware of them, just > because it'll make debugging easier on the day when something goes > wrong. Okay, now I'm a bit confused. "print" is both a and a member of the builtins. What happens then? And abs(), max(), hex() and such seemed like keywords to my scientific self (due to never having to "include"/import them), but clearly their not. And int, list, tuple, dict and such always seemed like keywords to my CS self because they were included in Python's type system (like "int" would be in C). They are all one-step removed from keywords. And yet, since they are not in a separate namespace, they should not be used as variable names. Perhaps since they are very different from one another, they should be put in separate namespaces off of a global, root namespace... (math, string, etc.) Despite that, seems like PEP8 should suggest this not shadowing these built-ins which are at global scope. MarkJ Tacoma, Washington