Changeset 228131 in webkit


Ignore:
Timestamp:
Feb 5, 2018 2:54:17 PM (6 years ago)
Author:
dbates@webkit.org
Message:

prepare-ChangeLog gets confused about Python docstrings that contain the word "class" or "def"
https://bugs.webkit.org/show_bug.cgi?id=182405

Reviewed by David Kilzer.

String literal statements, including docstrings, do not demarcate a new scope in Python.
So, do not treat them like they do when building up the list of modified functions.

  • Scripts/prepare-ChangeLog:

(get_function_line_ranges_for_python):

  • Scripts/webkitperl/prepare-ChangeLog_unittest/resources/python_unittests-expected.txt:

The expected ending line number for the last "pass" statement inside the scope of Class5 changed
from 97 to 98 because empty lines do not effect scope. This is consistent with the parsing
of the second "pass" statement in the scope of class Class5. A "pass" is a null operation that
is used as a syntactic placeholder when a statement is required. Ideally we would make
the parsing code smarter so as to avoid emitting ranges for "pass" statements that serve
not syntactic purpose.

  • Scripts/webkitperl/prepare-ChangeLog_unittest/resources/python_unittests.py:

(Class5):
(Class6):
(Class6.init):
(Class7):
(Class7.init):
(Class8):
(Class8.init):
Add some more tests.

Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r228118 r228131  
     12018-02-05  Daniel Bates  <dabates@apple.com>
     2
     3        prepare-ChangeLog gets confused about Python docstrings that contain the word "class" or "def"
     4        https://bugs.webkit.org/show_bug.cgi?id=182405
     5
     6        Reviewed by David Kilzer.
     7
     8        String literal statements, including docstrings, do not demarcate a new scope in Python.
     9        So, do not treat them like they do when building up the list of modified functions.
     10
     11        * Scripts/prepare-ChangeLog:
     12        (get_function_line_ranges_for_python):
     13        * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/python_unittests-expected.txt:
     14        The expected ending line number for the last "pass" statement inside the scope of Class5 changed
     15        from 97 to 98 because empty lines do not effect scope. This is consistent with the parsing
     16        of the second "pass" statement in the scope of class Class5. A "pass" is a null operation that
     17        is used as a syntactic placeholder when a statement is required. Ideally we would make
     18        the parsing code smarter so as to avoid emitting ranges for "pass" statements that serve
     19        not syntactic purpose.
     20        * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/python_unittests.py:
     21        (Class5):
     22        (Class6):
     23        (Class6.__init__):
     24        (Class7):
     25        (Class7.__init__):
     26        (Class8):
     27        (Class8.__init__):
     28        Add some more tests.
     29
    1302018-02-05  Matt Lewis  <jlewis3@apple.com>
    231
  • trunk/Tools/Scripts/prepare-ChangeLog

    r220032 r228131  
    17841784    my @ranges;
    17851785
     1786    my $multilineStringLiteralSentinelRegEx = qr#(?:"""|''')#;
     1787    my $multilineStringLiteralStartRegEx = qr#^\s*$multilineStringLiteralSentinelRegEx#;
     1788    my $multilineStringLiteralEndRegEx = qr#$multilineStringLiteralSentinelRegEx\s*$#;
     1789
    17861790    my @scopeStack = ({ line => 0, indent => -1, name => undef });
    17871791    my $lastLine = 0;
     1792    my $inComment = 0;
    17881793    until ($lastLine) {
    17891794        $_ = <$fileHandle>;
     
    17961801        }
    17971802        chomp;
    1798         next unless /^(\s*)([^#].*)$/;
     1803        next unless /^(\s*)([^#].*)$/; # Skip non-indented lines that begin with a comment.
    17991804
    18001805        my $indent = length $1;
     
    18241829            $scope->{line} = $.;
    18251830        }
     1831
     1832        # Skip multi-line string literals and docstrings.
     1833        next if /$multilineStringLiteralStartRegEx.*$multilineStringLiteralEndRegEx/;
     1834        if (!$inComment && /$multilineStringLiteralStartRegEx/) {
     1835            $inComment = 1;
     1836        } elsif ($inComment && /$multilineStringLiteralEndRegEx/) {
     1837            $inComment = 0;
     1838        }
     1839        next if $inComment;
     1840
     1841        next if /^\s*[#'"]/; # Skip indented and non-indented lines that begin with a comment or string literal (includes docstrings).
    18261842
    18271843        next unless $rest =~ /(?:class|def)\s+(\w+)/;
  • trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/python_unittests-expected.txt

    r105837 r228131  
    125125    [
    126126      '97',
    127       '97',
     127      '98',
    128128      'Class5'
    129     ]
     129    ],
     130    [
     131      '112',
     132      '113',
     133      'Class6'
     134    ],
     135    [
     136      '112',
     137      '113',
     138      'Class6'
     139    ],
     140    [
     141      '114',
     142      '117',
     143      'Class6.__init__'
     144    ],
     145    [
     146      '119',
     147      '120',
     148      'Class7'
     149    ],
     150    [
     151      '119',
     152      '120',
     153      'Class7'
     154    ],
     155    [
     156      '121',
     157      '124',
     158      'Class7.__init__'
     159    ],
     160    [
     161      '136',
     162      '141',
     163      'Class8'
     164    ],
     165    [
     166      '136',
     167      '141',
     168      'Class8'
     169    ],
     170    [
     171      '142',
     172      '143',
     173      'Class8.__init__'
     174    ],
    130175  ]
    131176}
  • trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/python_unittests.py

    r104132 r228131  
    9696        pass
    9797    pass
     98
     99"""class A"""
     100
     101'class A'
     102
     103"class A"
     104
     105"""def A"""
     106
     107'def A'
     108
     109"def A"
     110
     111"""class Class6"""
     112class Class6:
     113    """class Class6_1"""
     114    def __init__(self):
     115        """class Class6_2"""
     116        pass
     117
     118"""def Class7"""
     119class Class7:
     120    """def Class7_1"""
     121    def __init__(self):
     122        """def Class7_2"""
     123        pass
     124
     125"""a
     126class b
     127"""
     128
     129"""a
     130def b
     131"""
     132
     133"""
     134class class8
     135"""
     136class Class8:
     137    pass
     138
     139    """
     140    def Class8_1
     141    """
     142    def __init__(self):
     143        pass
Note: See TracChangeset for help on using the changeset viewer.