[py-svn] commit/py: hpk42: fix issue7 - raise a proper error if no valid statementrange can be found

Bitbucket commits-noreply at bitbucket.org
Sun Nov 20 21:56:25 CET 2011


1 new commit in py:


https://bitbucket.org/hpk42/py/changeset/c8e97602a6cb/
changeset:   c8e97602a6cb
user:        hpk42
date:        2011-11-20 21:55:43
summary:     fix issue7 - raise a proper error if no valid statementrange can be found
affected #:  5 files

diff -r 07ca410dedff1dceec578ad0a629e3bfd29869b7 -r c8e97602a6cb3a2b3332f1bb3f76a857bfa7c5fa CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,9 @@
+Changes between 1.4.5 and 1.4.x
+==================================================
+
+- fix issue7: source.getstatementrange() now raises proper error
+  if no valid statement can be found
+
 Changes between 1.4.4 and 1.4.5
 ==================================================
 


diff -r 07ca410dedff1dceec578ad0a629e3bfd29869b7 -r c8e97602a6cb3a2b3332f1bb3f76a857bfa7c5fa py/__init__.py
--- a/py/__init__.py
+++ b/py/__init__.py
@@ -8,7 +8,7 @@
 
 (c) Holger Krekel and others, 2004-2010
 """
-__version__ = '1.4.5'
+__version__ = '1.4.6.dev1'
 
 from py import _apipkg
 


diff -r 07ca410dedff1dceec578ad0a629e3bfd29869b7 -r c8e97602a6cb3a2b3332f1bb3f76a857bfa7c5fa py/_code/source.py
--- a/py/_code/source.py
+++ b/py/_code/source.py
@@ -108,6 +108,7 @@
     def getstatementrange(self, lineno, assertion=False):
         """ return (start, end) tuple which spans the minimal
             statement region which containing the given lineno.
+            raise a ValueError if no such statementrange can be found.
         """
         # XXX there must be a better than these heuristic ways ...
         # XXX there may even be better heuristics :-)
@@ -116,6 +117,7 @@
 
         # 1. find the start of the statement
         from codeop import compile_command
+        end = None
         for start in range(lineno, -1, -1):
             if assertion:
                 line = self.lines[start]
@@ -139,6 +141,8 @@
                 trysource = self[start:end]
                 if trysource.isparseable():
                     return start, end
+        if end is None:
+            raise ValueError("no valid source range around line %d " % (lineno,))
         return start, end
 
     def getblockend(self, lineno):


diff -r 07ca410dedff1dceec578ad0a629e3bfd29869b7 -r c8e97602a6cb3a2b3332f1bb3f76a857bfa7c5fa setup.py
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@
         name='py',
         description='library with cross-python path, ini-parsing, io, code, log facilities',
         long_description = open('README.txt').read(),
-        version='1.4.5',
+        version='1.4.6.dev1',
         url='http://pylib.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],


diff -r 07ca410dedff1dceec578ad0a629e3bfd29869b7 -r c8e97602a6cb3a2b3332f1bb3f76a857bfa7c5fa testing/code/test_source.py
--- a/testing/code/test_source.py
+++ b/testing/code/test_source.py
@@ -236,6 +236,10 @@
         r = source.getstatementrange(1)
         assert r == (1,2)
 
+    def test_getstatementrange_with_syntaxerror_issue7(self):
+        source = Source(":")
+        py.test.raises(ValueError, lambda: source.getstatementrange(0))
+
     @py.test.mark.skipif("sys.version_info < (2,6)")
     def test_compile_to_ast(self):
         import ast

Repository URL: https://bitbucket.org/hpk42/py/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the pytest-commit mailing list