Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Import collisions (was Re: "from module import data; print(data)") Date: Thu, 25 Feb 2016 12:19:20 +1100 Lines: 17 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de C5BmuKd4mp7dWa9fwWFwNAPxtap/CdcNwu0+/gkQ99RQ== 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; 'python,': 0.02; 'received:209.85.223': 0.03; 'raises': 0.07; 'cc:addr:python- list': 0.09; 'globals': 0.09; 'imports': 0.09; 'subject:module': 0.09; 'warn': 0.09; 'whichever': 0.09; 'importing': 0.15; 'thu,': 0.15; '2016': 0.16; 'cc:name:python list': 0.16; 'detects': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'python;': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sense,': 0.16; 'subject:import': 0.16; 'wrote:': 0.16; 'tells': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'seems': 0.23; 'feb': 0.23; 'second': 0.24; 'import': 0.24; 'module': 0.25; "i've": 0.25; 'message-id:@mail.gmail.com': 0.27; 'dan': 0.29; 'intellectual': 0.29; 'symbols': 0.29; 'statement': 0.32; 'point': 0.33; 'symbol': 0.33; 'received:google.com': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'possible': 0.36; 'pm,': 0.36; 'two': 0.37; 'one,': 0.37; 'received:209': 0.38; 'sure': 0.39; 'whatever': 0.39; 'does': 0.39; 'subject:from': 0.39; 'ever': 0.60; 'different': 0.63; 'believe': 0.66; 'else.': 0.66; 'wanting': 0.66; 'situation': 0.67; 'chrisa': 0.84; 'subject:Import': 0.84; 'to:none': 0.91; 'subject:; ': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:cc; bh=SzuNPrKtuBU3D8x0MamWA3u5oE3KUub9f5rTDKkzuOA=; b=Tl7600dlmKuPKpdtsl8nsGffiKb/y3JtYd4php6nMaBS/fNBvUNEQE2cy5FnPpDOLp 0TmvzjyANQFI1eYoyyBR5ZJv5mrISSxgd4sDozdfJX7WV7Xt61qziaJIOQh4NChjdRz4 1rD9/HSQXKDjV0He1if5kNf3RNdPTDut71/lXqp8z8JLsNWsrqj1LQAehcVDkCHC6Myy rcJ8MzQq75cZALQsAsnNQSkDGvNO8ghReuEnslQNvoWXERfNfQzJe82Hx5yZLKHHPWF3 QYg/K+o0QWqZVW9XmfcGKtVqZHp0b91ut5wZJkFH9niCXrmkYNTY64qCpjNrPRco+owO mxzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:cc; bh=SzuNPrKtuBU3D8x0MamWA3u5oE3KUub9f5rTDKkzuOA=; b=RLjM+S3Uv8I6P5R0VbQTkwd3qD09seoQZDwYkgtn0TJw53Q8XsKtcYmgy3mjPeqU0S iUdshfydo+5yb9H4QJT7Yln/inxoWLOIM/SRNlZk44+J8xmsQGnPY/o8ZRxSFA8ei346 HVhbEYmnqdNjEbc3VZdkxrbJJRL8CVwX7MIJA1w8Gz9g8PISer7lzy6KucFg/kc4BW0p t7Ahzzjj3dDDOrWxh6YYWee4yPHcPf1oN679ny5TDaz84D1Msx/8QDjmelvCafGM+xCl Pu1ZSXMaC7fjj1c2wcN3RKGCtb9GlLqWJZaNLpWZjH0gt9LlDZwktoBEY79TJ6bd1YZU vwDw== X-Gm-Message-State: AG10YORxTJfkIyA9DR+K6IvcormMNnMtLsrvIr4QAdt6CD+Oo73Tj24MmDA6CgEuAe/umbwIA6+qwP9RbuBvEA== X-Received: by 10.107.132.90 with SMTP id g87mr430807iod.157.1456363160160; Wed, 24 Feb 2016 17:19:20 -0800 (PST) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:103473 On Thu, Feb 25, 2016 at 12:07 PM, Dan Stromberg wrote: > PS: Haskell seems better at the former than Python; Haskell tells you > if you import two identical symbols from two different places, when > you try to use one of them - not at import time. I believe in Python, > whichever symbol you import last, wins. Haskell does not warn you at > import time, which is fine. Not sure about OCaml or whatever else. In a sense, it's not the two imports that matter, but the situation that the second import statement is rebinding a name. Would it be possible to create a "mollyguard" import hook that snoops the globals of the importing module and raises an ImportWarning if it detects a rebind? Not that I've ever been in the situation of wanting one, but just as a point of intellectual curiosity. ChrisA