This repository was archived by the owner on Nov 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +33
-4
lines changed Expand file tree Collapse file tree 3 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -119,7 +119,6 @@ class Definition(Value):
119
119
module = property (lambda self : self .parent .module )
120
120
all = property (lambda self : self .module .all )
121
121
_slice = property (lambda self : slice (self .start - 1 , self .end ))
122
- source = property (lambda self : '' .join (self ._source [self ._slice ]))
123
122
is_class = False
124
123
125
124
def __iter__ (self ):
@@ -129,6 +128,17 @@ def __iter__(self):
129
128
def _publicity (self ):
130
129
return {True : 'public' , False : 'private' }[self .is_public ]
131
130
131
+ @property
132
+ def source (self ):
133
+ """Return the source code for the definition."""
134
+ full_src = self ._source [self ._slice ]
135
+
136
+ def predicate (line ):
137
+ return line .strip () == '' or line .strip ().startswith ('#' )
138
+
139
+ filtered_src = dropwhile (predicate , reversed (full_src ))
140
+ return '' .join (reversed (list (filtered_src )))
141
+
132
142
def __str__ (self ):
133
143
return 'in %s %s `%s`' % (self ._publicity , self ._human , self .name )
134
144
@@ -428,7 +438,7 @@ def parse_module(self):
428
438
return module
429
439
430
440
def parse_definition (self , class_ ):
431
- """Parse a defintion and return its value in a `class_` object."""
441
+ """Parse a definition and return its value in a `class_` object."""
432
442
start = self .line
433
443
self .consume (tk .NAME )
434
444
name = self .current .value
Original file line number Diff line number Diff line change
1
+ """Check for a bug in parsing comments after definitions."""
2
+
3
+ from .expected import Expectation
4
+
5
+ expectation = Expectation ()
6
+ expect = expectation .expect
7
+
8
+
9
+ def should_be_ok ():
10
+ """Just a function without violations."""
11
+
12
+
13
+ # This is a comment that triggers a bug that causes the previous function
14
+ # to generate a D202 error.
Original file line number Diff line number Diff line change @@ -138,14 +138,19 @@ def test_token_stream():
138
138
139
139
def test_pep257 ():
140
140
"""Run domain-specific tests from test.py file."""
141
- test_cases = ('test' , 'unicode_literals' , 'nested_class' , 'capitalization' )
141
+ test_cases = (
142
+ 'test' ,
143
+ 'unicode_literals' ,
144
+ 'nested_class' ,
145
+ 'capitalization' ,
146
+ 'comment_after_def_bug' ,
147
+ )
142
148
for test_case in test_cases :
143
149
case_module = __import__ ('test_cases.{0}' .format (test_case ),
144
150
globals = globals (),
145
151
locals = locals (),
146
152
fromlist = ['expectation' ],
147
153
level = 1 )
148
- # from .test_cases import test
149
154
results = list (check ([os .path .join (os .path .dirname (__file__ ),
150
155
'test_cases' , test_case + '.py' )],
151
156
select = set (ErrorRegistry .get_error_codes ())))
You can’t perform that action at this time.
0 commit comments