[issue29107] traceback module incorrectly formats args-less syntax errors

2016-12-30 Thread Naftali Harris

Naftali Harris added the comment:

Adding Georg, who is listed as an expert for the traceback module 
(https://docs.python.org/devguide/experts.html).

--
nosy: +georg.brandl

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



[issue29107] traceback module incorrectly formats args-less syntax errors

2016-12-30 Thread Naftali Harris

Naftali Harris added the comment:

For your convenience, here is a possible patch fixing these issues. It modifies 
the format_exception_only function in the traceback module to follow the 
behavior of the interpreter a little more closely for SyntaxError's. Feel free 
to use, in whole, in part, or not at all, as you wish. Happy new year! :-)

--
keywords: +patch
Added file: http://bugs.python.org/file46095/traceback_fixes.patch

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



[issue29107] traceback module incorrectly formats args-less syntax errors

2016-12-30 Thread Naftali Harris

Naftali Harris added the comment:

Two other minor discrepancies between the way traceback and the interpreter 
format SyntaxError's, in 2.7.13:

1.

>>> e = SyntaxError("some message", ("myfile.py", None, None, None))
>>> raise e
Traceback (most recent call last):
  File "", line 1, in 
SyntaxError: some message (myfile.py)
>>> try:
... raise e
... except:
... traceback.print_exc()
...
Traceback (most recent call last):
  File "", line 2, in 
Traceback (most recent call last):
  File "", line 4, in 
  File "/Users/naftali/repos/Python-2.7.13/Lib/traceback.py", line 233, in 
print_exc
print_exception(etype, value, tb, limit, file)
  File "/Users/naftali/repos/Python-2.7.13/Lib/traceback.py", line 126, in 
print_exception
lines = format_exception_only(etype, value)
  File "/Users/naftali/repos/Python-2.7.13/Lib/traceback.py", line 188, in 
format_exception_only
lines.append('  File "%s", line %d\n' % (filename, lineno))
TypeError: %d format: a number is required, not NoneType


2.

>>> e = SyntaxError("some message", ("myfile.py", 3, 10, "hello"))
>>> raise e
Traceback (most recent call last):
  File "", line 1, in 
  File "myfile.py", line 3
hello
 ^
SyntaxError: some message
>>> try:
... raise e
... except:
... traceback.print_exc()
...
Traceback (most recent call last):
  File "", line 2, in 
  File "myfile.py", line 3
hello
^
SyntaxError: some message

--

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



[issue29107] traceback module incorrectly formats args-less syntax errors

2016-12-29 Thread Naftali Harris

New submission from Naftali Harris:

The traceback documentation states that it "exactly mimics the behavior of the 
Python interpreter when it prints a stack trace." Here's a small case where it 
doesn't, on 2.7.13:

~/repos/Python-2.7.13$ cat example.py
def f(x):
global x
~/repos/Python-2.7.13$ ./python.exe
Python 2.7.13 (default, Dec 29 2016, 09:54:42)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import traceback
>>> import example
Traceback (most recent call last):
  File "", line 1, in 
  File "example.py", line 1
def f(x):
SyntaxError: name 'x' is local and global
>>> try:
... import example
... except:
... traceback.print_exc()
...
Traceback (most recent call last):
  File "", line 2, in 
SyntaxError: name 'x' is local and global (example.py, line 1)
>>>

I believe Kurt fixed this for Python 3000 with 
https://mail.python.org/pipermail/python-3000-checkins/2007-July/001259.html

--
components: Library (Lib)
messages: 284287
nosy: Naftali.Harris, benjamin.peterson, kbk
priority: normal
severity: normal
status: open
title: traceback module incorrectly formats args-less syntax errors
type: behavior
versions: Python 2.7

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



[issue20775] Modifications to global variables ignored after instantiating multiprocessing.Pool

2014-02-25 Thread Naftali Harris

New submission from Naftali Harris:

Hi everyone,

It appears that if you use a global variable in a function that you pass to 
Pool.map, but modify that global variable after instantiating the Pool, then 
the modification will not be reflected when Pool.map calls that function.

Here's a short script, (also attached), that demonstrates what I mean:

$ cat reproduces.py
from multiprocessing import Pool

name = Not Updated
def f(ignored):
print(name)


def main():
global name
p = Pool(3)
name = Updated
p.map(f, range(3))

if __name__ == __main__:
main()
$ python reproduces.py 
Not Updated
Not Updated
Not Updated


If the `name = Updated' line is moved above the `p = Pool(3)' line, then the 
script will print Updated three times instead.

This behavior is present in versions 2.6, 2.7, 3.1, 3.2, 3.3, and 3.4. I run 
Linux Mint 14 (nadia), on an Intel i5-3210M processor (four cores).

Is this expected behavior?

Thanks very much,

Naftali

--
components: Library (Lib)
files: reproduces.py
messages: 212221
nosy: Naftali.Harris
priority: normal
severity: normal
status: open
title: Modifications to global variables ignored after instantiating 
multiprocessing.Pool
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file34223/reproduces.py

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



[issue20775] Modifications to global variables ignored after instantiating multiprocessing.Pool

2014-02-25 Thread Naftali Harris

Naftali Harris added the comment:

Oh, ok, that makes a lot of sense. Thanks for the clear and patient 
explanation, Tim! Sorry to have bothered the Python bug tracker with this.

--Naftali

--
resolution:  - invalid
status: open - closed

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