From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 55338 invoked by alias); 27 Nov 2015 14:51:14 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 55330 invoked by uid 89); 27 Nov 2015 14:51:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wm0-f50.google.com Received: from mail-wm0-f50.google.com (HELO mail-wm0-f50.google.com) (74.125.82.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 27 Nov 2015 14:51:12 +0000 Received: by wmvv187 with SMTP id v187so73957636wmv.1 for ; Fri, 27 Nov 2015 06:51:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=rrsRuv30g4LhrqLlVsc7BwJLdiYE0OQYo33coYqnSgY=; b=JPkMoIwim3QfWk1sZh+2puOzMF+mIusVM0Nn9KERl305OklDofRnaauuOYFO53Odls 4rgF0oa5JGh1J4myrOKy5N4XZh+pUNndSovW/JkRbF5zuqrm7H4fCx54sGQf58fDsJHv nVIRu/pXzmpDVMtsbi6OJwwkSTOElt2NgTLbLMDGkK/cFwb2i4m/g6uuJCpZ0Co6UtjI Xz1lOSJkg0PDJc/YNRqKg/EjbRd4ZvlpkaX9mm2g8xG9Wp9yGy5a1mE/byzma0HOCY+p R6I/Gpm04DGRcugHuXh/Bi5LqGdNtkYJ3qf8BFmWkuTHgfYSHBpBIgAWatVtWap+1bl4 Lwgw== X-Gm-Message-State: ALoCoQmf8HXPfsOrG+nSNMcrzQTRYQkNeMfEnzrX+cOZ24R3NMDy6w2bJSvN9xSUptRR4AKvQ+HF X-Received: by 10.194.90.79 with SMTP id bu15mr65914995wjb.36.1448635869166; Fri, 27 Nov 2015 06:51:09 -0800 (PST) Received: from dinwoodie.org ([2001:ba8:0:1c0::9:1]) by smtp.gmail.com with ESMTPSA id 67sm7842997wmm.6.2015.11.27.06.51.07 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 27 Nov 2015 06:51:08 -0800 (PST) Date: Fri, 27 Nov 2015 15:07:00 -0000 From: Adam Dinwoodie To: cygwin@cygwin.com Subject: Incorrect Python errors when using os.remove to delete a directory Message-ID: <20151127145105.GG14466@dinwoodie.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg00454.txt.bz2 If I use os.remove in Python to remove a directory, I expect it to fail with an OSError on Python2 or a IsADirectoryError on Python3. On Python2, I get OSError, but with the wrong error code, whereas on Python3 I get completely the wrong exception. Simple testcases: $ rm -rf testdir && mkdir testdir && python -c 'import os; os.remove("testdir")' Traceback (most recent call last): File "", line 1, in OSError: [Errno 1] Operation not permitted: 'testdir' $ rm -rf testdir && mkdir testdir && python3 -c 'import os; os.remove("testdir")' Traceback (most recent call last): File "", line 1, in PermissionError: [Errno 1] Operation not permitted: 'testdir' On my handy CentOS box, I see the following instead: $ rm -rf testdir && mkdir testdir && python -c 'import os; os.remove("testdir")' Traceback (most recent call last): File "", line 1, in OSError: [Errno 21] Is a directory: 'testdir' $ rm -rf testdir && mkdir testdir && python3 -c 'import os; os.remove("testdir")' Traceback (most recent call last): File "", line 1, in IsADirectoryError: [Errno 21] Is a directory: 'testdir' Now I've realised what's going wrong I can work around it, but it'd be nice if the correct error were raised in the first place. -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple