[issue40627] Bus error on 'except E as a.b:'

2020-05-14 Thread Guido van Rossum


Guido van Rossum  added the comment:

Sorry!

--
resolution:  -> duplicate
stage: patch review -> resolved
status: open -> closed
superseder:  -> PEG Parser: Invalid targets for augassign and except succeed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40627] Bus error on 'except E as a.b:'

2020-05-14 Thread Guido van Rossum


Guido van Rossum  added the comment:

Oh, looks like https://github.com/python/cpython/pull/20083 fixes it.

--
keywords: +patch
message_count: 1.0 -> 2.0
pull_requests: +19397
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/20083

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40627] Bus error on 'except E as a.b:'

2020-05-14 Thread Guido van Rossum


New submission from Guido van Rossum :

This seems due to some new check in pegen:

>>> try:
...   pass
... except E as a.b:
...   pass
... 
Bus error: 10

--
messages: 368860
nosy: gvanrossum, lys.nikolaou, pablogsal
priority: normal
severity: normal
stage: needs patch
status: open
title: Bus error on 'except E as a.b:'
type: crash

___
Python tracker 
<https://bugs.python.org/issue40627>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30641] No way to specify "File name too long" error in except statement.

2017-06-13 Thread R. David Murray

R. David Murray added the comment:

Since according to Eryk there's no way to have a reliable cross-platform 
exception class catching file name to long, I'm rejecting this feature request.

--
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30641] No way to specify "File name too long" error in except statement.

2017-06-13 Thread Eryk Sun

Eryk Sun added the comment:

An exception specifically for ENAMETOOLONG would be limited to Unix systems.

The Windows CRT defines ENAMETOOLONG but doesn't use it. Windows file systems 
do not return a specific status code for a filename that's too long. Per MS-FSA 
2.1.5.1 [1], a request to open a file must fail with STATUS_OBJECT_NAME_INVALID 
if the name is invalid according to the spec in MS-FSCC 2.1.5 [2] (e.g. max 
component length cannot exceed 255 characters and may be less). This doesn't 
tell the caller why the filename is invalid. Anyway, for what it's worth, the 
Windows API translates this status code to ERROR_INVALID_NAME (0x007B), and the 
CRT in turn maps the latter to EINVAL.

Also, for versions prior to Windows 10, or Windows 10 without the 
LongPathsEnabled policy setting, the observed error is more commonly due to 
path preprocessing in user mode. In this case DOS paths are limited to MAX_PATH 
(260). The error depends on the called function -- e.g. CreateFileA vs 
SetCurrentDirectoryA, or calling the [A]NSI vs [W]ide-character version. It 
could be ERROR_PATH_NOT_FOUND (ENOENT), ERROR_FILENAME_EXCED_RANGE (ENOENT), or 
ERROR_INVALID_PARAMETER (EINVAL). 

[1]: https://msdn.microsoft.com/en-us/library/ff469536
[2]: https://msdn.microsoft.com/en-us/library/cc422524

--
nosy: +eryksun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30641] No way to specify "File name too long" error in except statement.

2017-06-12 Thread Steven D'Aprano

Steven D'Aprano added the comment:

I don't understand what you actually are requesting here.

Are you requesting a way to tell whether or not the filename is too long? 
You've already been told that the way to do that is to check errno, and you say 
that you already knew that.

exc.errno == errno.ENAMETOOLONG

Or are you asking for a way to find out ahead of time what the maximum filename 
length will be? You say:

> it's almost impossible to reliably check the allowed filename length

I think that's right: it *is* almost impossible to reliably check the allowed 
filename length, except by trying it and seeing whether or not you can create 
the file.

The difficulty here is that there's no one maximum name length, it depends on 
the file system of the particular device you're accessing. So even if we had 
this `get_maximum_filename_length` function, and you wrote:

if len(fname) < get_maximum_filename_length():
with open(fname) as f: ...

the call to open might *still* fail with ENAMETOOLONG if you happen to be 
writing to a device or disk with a shorter than expected length.

E.g. FAT32 has a limit of either 8.3 bytes or 255 double-byte Unicode 
characters depending on the implementation; NTFS and HFS+ have a limit of 255 
characters; ext4 has a limit of 255 bytes; Joliet has a limit of 64 characters; 
etc.

And then there's the question of the maximum allowed path.

So I think the first thing you should do is clarify exactly what it is that 
you're asking for:

- a way to check whether the exception is ENAMETOOLONG;

- specifically a new sub-exception for that case;

- a constant or function that returns the maximum file name length;

- or the maximum path name length;

- or something else.


But any of these (except the first, which already exists) is a new feature, not 
a bug fix, to it can only go into 3.7.

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30641] No way to specify "File name too long" error in except statement.

2017-06-12 Thread Max Staff

Max Staff added the comment:

...at least those are the only two ways that I can think of.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30641] No way to specify "File name too long" error in except statement.

2017-06-12 Thread Max Staff

Max Staff added the comment:

Yes I know about the errno. There would be two ways to resolve this:

One way would be by introducing a new exception class which would be nice 
because it's almost impossible to reliably check the allowed filename length 
(except for trial and error) and I have quite a few functions where I would 
want the error to propagate further as long as it's not an ENAMETOOLONG.

The other way would be by introducing a new syntax feature ("except OSError as 
e if e.errno == errno.ENAMETOOLONG:") but I don't think that that approach is 
reasonable.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30641] No way to specify "File name too long" error in except statement.

2017-06-12 Thread Antoine Pitrou

Antoine Pitrou added the comment:

On Unix, you can simply check the errno value:

>>> fn = "x" * 999
>>> try: open(fn, "r")
... except OSError as e: exc = e
... 
>>> exc.errno
36
>>> exc.errno == errno.ENAMETOOLONG
True

I don't know about Windows.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30641] No way to specify "File name too long" error in except statement.

2017-06-12 Thread R. David Murray

R. David Murray added the comment:

There appears to be an errno for file name too long, so I presume you are 
making a feature request for a new exception class.  I believe Antoine tried to 
strike a balance between the utility of the sub-exceptions and their number, so 
you'll have to make an argument for its utility.

--
components: +Library (Lib) -IO
nosy: +pitrou, r.david.murray
type: behavior -> enhancement
versions:  -Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30641] No way to specify "File name too long" error in except statement.

2017-06-12 Thread Max Staff

New submission from Max Staff:

There are different ways to catch exceptions of the type "OSError": By using 
"except OSError as e:" and then checking the errno or by using "except 
FileNotFoundError e:" or "except FileExistsError e:" or whatever error one 
wants to catch. There's no such way for above mentioned error that occurs when 
a filename is too long for the filesystem/OS.

--
components: IO
messages: 295810
nosy: Max Staff
priority: normal
severity: normal
status: open
title: No way to specify "File name too long" error in except statement.
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30641>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



error in except

2013-02-04 Thread Rodrick Brown
For the life of me I cant figure out why this exception is being thrown.
How could I use pdb to debug this?

$ python udp_local2.py server
  File udp_local2.py, line 36
except:
 ^
SyntaxError: invalid syntax


#!/usr/bin/env python

import random, socket, sys
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

MAX = 65535
PORT = 1060

if 2 = len(sys.argv) = 3 and sys.argv[1] == 'server':
interface = sys.argv[2] if len(sys.argv)  2 else ''
s.bind((interface, PORT))
print 'Listening at', s.getsockname()
while True:
data, address = s.recvfrom(MAX)
if random.randint(0, 1):
print 'The client at', address, 'says:', repr(data)
s.sendto('Your data was %d bytes' % len(data), address)
else:
print 'Pretending to drop packet from', address

elif len(sys.argv) == 3 and sys.argv[1] == 'client':
hostname = sys.argv[2]
s.connect((hostname, PORT))
print 'Client socket name is', s.getsockname()
delay = 0.1
while True:
s.send('This is another message')
print 'Waiting up to', delay, 'seconds for a reply'
s.settimeout(delay)
try:
data = s.recv(MAX)
except socket.timeout:
delay *= 2
if delay  2.0:
raise RuntimeError('I think the server is down')
except:
raise
else:
break
print 'The server says', repr(data)
else:
print  sys.stderr, 'usage: %d server [interfae]' % sys.argv[0]
print  sys.stderr, '   or: %d client host' % sys.argv[0]
sys.exit(2)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error in except

2013-02-04 Thread Chris Angelico
On Tue, Feb 5, 2013 at 8:49 AM, Rodrick Brown rodrick.br...@gmail.com wrote:
 if delay  2.0:
 raise RuntimeError('I think the server is down')
 except:
 raise
 else:
 break

I think you have an indentation error here. Backtab the except maybe?
Or possibly just omit it altogether.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error in except

2013-02-04 Thread Steven D'Aprano
Rodrick Brown wrote:

 For the life of me I cant figure out why this exception is being thrown.
 How could I use pdb to debug this?
 
 $ python udp_local2.py server
   File udp_local2.py, line 36
 except:
  ^
 SyntaxError: invalid syntax

You can't use pdb to debug it, because you can't run the code until you fix
the syntax error. You use your text editor to debug it.

Sometimes if you have a missing bracket (round, square or curly), Python
reports the syntax error on the line *after* where it expected the closing
bracket.

I've also seen unexpected syntax errors if the source code contains binary
characters such as DOS end-of-file ^Z. Try opening the file in a hex editor
and looking for anything that shouldn't be there.

But the most likely problem is that you are mixing tabs and spaces, and
consequently have inadvertently become confused about the indent level. You
think that the except clause is indented level with a try, but it
actually is indented level with something else. Using spaces for indents is
good; using tabs for indents is also good; using both at the same time is a
nightmare. (Python 3 prohibits this.)

I recommend running TabNanny over the file:

python -m tabnanny file-or-directory


A couple of comments on your code:

 try:
 data = s.recv(MAX)
 except socket.timeout:
 delay *= 2
 if delay  2.0:
 raise RuntimeError('I think the server is down')

Five attempts and a total of 3.1 seconds (0.1 + 0.2 + 0.4 + 0.8 + 1.6) is
rather short to conclude that a server is down, although it depends on what
sort of server and where it is. I would have thought 30 seconds is more
appropriate. (By default, wget doesn't time out for 3 minutes, which is
possibly overkill.)

But either way, I don't think RuntimeError is the right exception to use. I
expect that a socket error would be more relevant.

 except:
 raise

What this does is:

Unconditionally catch anything. Then raise it again.

Don't do this. The right thing to do here is, just delete it and don't catch
it at all.




-- 
Steven

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error in except

2013-02-04 Thread John Evans
Should it not be try-except-else' instead of 'if-except-else'?

try:
if delay  2.0:
raise RuntimeError('I think the server is down')
except:
raise
else:
break


On Mon, Feb 4, 2013 at 5:21 PM, Steven D'Aprano 
steve+comp.lang.pyt...@pearwood.info wrote:

 Rodrick Brown wrote:

  For the life of me I cant figure out why this exception is being thrown.
  How could I use pdb to debug this?
 
  $ python udp_local2.py server
File udp_local2.py, line 36
  except:
   ^
  SyntaxError: invalid syntax

 You can't use pdb to debug it, because you can't run the code until you fix
 the syntax error. You use your text editor to debug it.

 Sometimes if you have a missing bracket (round, square or curly), Python
 reports the syntax error on the line *after* where it expected the closing
 bracket.

 I've also seen unexpected syntax errors if the source code contains binary
 characters such as DOS end-of-file ^Z. Try opening the file in a hex editor
 and looking for anything that shouldn't be there.

 But the most likely problem is that you are mixing tabs and spaces, and
 consequently have inadvertently become confused about the indent level. You
 think that the except clause is indented level with a try, but it
 actually is indented level with something else. Using spaces for indents is
 good; using tabs for indents is also good; using both at the same time is a
 nightmare. (Python 3 prohibits this.)

 I recommend running TabNanny over the file:

 python -m tabnanny file-or-directory


 A couple of comments on your code:

  try:
  data = s.recv(MAX)
  except socket.timeout:
  delay *= 2
  if delay  2.0:
  raise RuntimeError('I think the server is down')

 Five attempts and a total of 3.1 seconds (0.1 + 0.2 + 0.4 + 0.8 + 1.6) is
 rather short to conclude that a server is down, although it depends on what
 sort of server and where it is. I would have thought 30 seconds is more
 appropriate. (By default, wget doesn't time out for 3 minutes, which is
 possibly overkill.)

 But either way, I don't think RuntimeError is the right exception to use. I
 expect that a socket error would be more relevant.

  except:
  raise

 What this does is:

 Unconditionally catch anything. Then raise it again.

 Don't do this. The right thing to do here is, just delete it and don't
 catch
 it at all.




 --
 Steven

 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
John Evans
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error in except

2013-02-04 Thread Albert Hopkins


On Mon, Feb 4, 2013, at 04:49 PM, Rodrick Brown wrote:
 For the life of me I cant figure out why this exception is being thrown.
 How could I use pdb to debug this?
 
 $ python udp_local2.py server
   File udp_local2.py, line 36
 except:
  ^
 SyntaxError: invalid syntax
 
 
 #!/usr/bin/env python
 
 import random, socket, sys
 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 
 MAX = 65535
 PORT = 1060
 
 if 2 = len(sys.argv) = 3 and sys.argv[1] == 'server':
 interface = sys.argv[2] if len(sys.argv)  2 else ''
 s.bind((interface, PORT))
 print 'Listening at', s.getsockname()
 while True:
 data, address = s.recvfrom(MAX)
 if random.randint(0, 1):
 print 'The client at', address, 'says:', repr(data)
 s.sendto('Your data was %d bytes' % len(data), address)
 else:
 print 'Pretending to drop packet from', address
 
 elif len(sys.argv) == 3 and sys.argv[1] == 'client':
 hostname = sys.argv[2]
 s.connect((hostname, PORT))
 print 'Client socket name is', s.getsockname()
 delay = 0.1
 while True:
 s.send('This is another message')
 print 'Waiting up to', delay, 'seconds for a reply'
 s.settimeout(delay)
 try:
 data = s.recv(MAX)
 except socket.timeout:
 delay *= 2
 if delay  2.0:
 raise RuntimeError('I think the server is down')
 except:
 raise
 else:
 break
 print 'The server says', repr(data)
 else:
 print  sys.stderr, 'usage: %d server [interfae]' %
 sys.argv[0]
 print  sys.stderr, '   or: %d client host' % sys.argv[0]
 sys.exit(2)
 -- 
 http://mail.python.org/mailman/listinfo/python-list

Your except statement is on the same level as if delay  2.0..
effectively:

if delay  2.0
  ...
except:

which is not valid syntax.  Excepts go with try: blocks, not if: blocks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error in except

2013-02-04 Thread Laxmikant Chitare
One more thing, apart from what Albert mentioned.
Exceptions must be classes or instances. In effect you cannot just do
'raise'. 'raise' statement must be followed by a class or an instance.



On Tue, Feb 5, 2013 at 6:28 AM, Albert Hopkins mar...@letterboxes.orgwrote:



 On Mon, Feb 4, 2013, at 04:49 PM, Rodrick Brown wrote:
  For the life of me I cant figure out why this exception is being thrown.
  How could I use pdb to debug this?
 
  $ python udp_local2.py server
File udp_local2.py, line 36
  except:
   ^
  SyntaxError: invalid syntax
 
 
  #!/usr/bin/env python
 
  import random, socket, sys
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 
  MAX = 65535
  PORT = 1060
 
  if 2 = len(sys.argv) = 3 and sys.argv[1] == 'server':
  interface = sys.argv[2] if len(sys.argv)  2 else ''
  s.bind((interface, PORT))
  print 'Listening at', s.getsockname()
  while True:
  data, address = s.recvfrom(MAX)
  if random.randint(0, 1):
  print 'The client at', address, 'says:', repr(data)
  s.sendto('Your data was %d bytes' % len(data), address)
  else:
  print 'Pretending to drop packet from', address
 
  elif len(sys.argv) == 3 and sys.argv[1] == 'client':
  hostname = sys.argv[2]
  s.connect((hostname, PORT))
  print 'Client socket name is', s.getsockname()
  delay = 0.1
  while True:
  s.send('This is another message')
  print 'Waiting up to', delay, 'seconds for a reply'
  s.settimeout(delay)
  try:
  data = s.recv(MAX)
  except socket.timeout:
  delay *= 2
  if delay  2.0:
  raise RuntimeError('I think the server is down')
  except:
  raise
  else:
  break
  print 'The server says', repr(data)
  else:
  print  sys.stderr, 'usage: %d server [interfae]' %
  sys.argv[0]
  print  sys.stderr, '   or: %d client host' % sys.argv[0]
  sys.exit(2)
  --
  http://mail.python.org/mailman/listinfo/python-list

 Your except statement is on the same level as if delay  2.0..
 effectively:

 if delay  2.0
   ...
 except:

 which is not valid syntax.  Excepts go with try: blocks, not if: blocks.
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error in except

2013-02-04 Thread Chris Angelico
On Tue, Feb 5, 2013 at 5:51 PM, Laxmikant Chitare
laxmikant.gene...@gmail.com wrote:
 One more thing, apart from what Albert mentioned.
 Exceptions must be classes or instances. In effect you cannot just do
 'raise'. 'raise' statement must be followed by a class or an instance.

You can inside an except clause.

 try:
1/0
except:
print(I got an exception!)
raise

I got an exception!
Traceback (most recent call last):
  File pyshell#5, line 2, in module
1/0
ZeroDivisionError: division by zero


ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list