Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Teijo Holzer: Fixing Python

Teijo Holzer: Fixing Python

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Teijo Holzer:
Fixing Python
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
@ Kiwi PyCon 2014 - Saturday, 13 Sep 2014 - Track 2
http://kiwi.pycon.org/

**Audience level**

Intermediate

**Description**

Discover a bug in a standard Python library, provide a reproducible test case, log a bug report with the Python maintainers, prepare & submit a patch. Get patch accepted into 2.x & 3.x master.

**Abstract**

This talk will provide a real-world walk-through of how to discover a bug in Python, prepare a reproducible test case and log a bug report. It will then continue to show on how to provide a patch and get it accepted and deployed into Python 2.7.7 and 3.4.1

**YouTube**

https://www.youtube.com/watch?v=i7EZAfhIvCs

New Zealand Python User Group

September 13, 2014
Tweet

More Decks by New Zealand Python User Group

Other Decks in Programming

Transcript

  1. Hello World Fail #1 $ python test.py | head ­n

    1 Hello World Traceback (most recent call last): File "test.py", line 2, in <module> print 'Hello World' IOError: [Errno 32] Broken pipe
  2. Hello World Fail #2 $ python test.py > /dev/tcp/localhost/22 Traceback

    (most recent call last): File "test.py", line 2, in <module> print 'Hello World' IOError: [Errno 104] Connection reset by peer
  3. Hello World Fail #3 $ python test.py >&­ Traceback (most

    recent call last): File "test.py", line 2, in <module> print 'Hello World' IOError: [Errno 9] Bad file descriptor
  4. Fixing the Standard Library  tempfile.NamedTemporaryFile  Creates a temporary

    file  Takes 'mode' argument  Invalid mode argument triggers bug  Bug is a file descriptor leak
  5. Patch # Lib/tempfile.py ­ file = _os.fdopen(fd, mode, bufsize) +

    try: + file = _os.fdopen(fd, mode, bufsize) + except Exception as ex: + _os.close(fd) + raise
  6. Submit Bug, Test Case & Patch  http://bugs.python.org/  Sign

    up  Search for existing bug reports  Submit bug report, test case & patch (if available)  Wait for reply & adaption into main branches
  7. Summary  Every program has bugs  Fixing Python is

    possible  Help out by improving Python  Always provide reproducible test case  tempfile patch (Issue 21058) is in 2.7.8 & 3.4.1