On Thu, 24 Nov 2022 at 06:26, Stefan Ram <r...@zedat.fu-berlin.de> wrote: > > Jon Ribbens <jon+use...@unequivocal.eu> writes: > >If you want to catch this sort of mistake automatically then you need > >a linter such as pylint: > > output > > <string>, line 1 > list.clear > Warning: Attribute used as statement. > > <string>, line 5 > list.clear > Warning: Attribute used as statement. > > source code > > import ast, sys > > def check( point, source ): > if isinstance( point, ast.Expr ) and\ > type( point.value )== ast.Attribute: > print( "<string>, line", point.lineno, file=sys.stderr ) > print( source.split( '\n' )[ point.lineno-1 ], file=sys.stderr ) > print\ > ( "Warning:", "Attribute used as statement.", file=sys.stderr ) > print() > > def mylinter( source ): > for point in ast.walk( ast.parse( example )): > check( point, source ) > > example = """\ > list.clear > list.clear() > x = list.clear > print( list.clear ) > list.clear > """ > > mylinter( example ) >
Uhh, yes? You just created an extremely simplistic linter. Your point? ChrisA -- https://mail.python.org/mailman/listinfo/python-list