From f8ec9be846a8649bcaed67be2685585468cd5410 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 10 Oct 2014 13:41:08 -0400 Subject: Emit an error when a print statement is used. Part of issue #20. --- checkers/python3.py | 10 +++++++ test/functional/access_to__name__.py | 2 +- test/functional/access_to_protected_members.py | 3 +- test/functional/bad_continuation.py | 2 +- test/functional/boolean_datetime.py | 2 +- test/functional/cellvar_escaping_loop.py | 1 + test/functional/cellvar_escaping_loop.txt | 16 +++++----- test/functional/class_members_py27.py | 2 +- test/functional/confidence_filter.rc | 2 +- test/functional/defined_and_used_on_same_line.py | 2 +- test/functional/docstrings.py | 2 +- test/functional/exception_is_binary_op.py | 10 +++---- test/functional/generated_members.rc | 2 +- test/functional/genexpr_variable_scope.py | 4 +-- test/functional/globals.py | 7 +++-- test/functional/globals.txt | 12 ++++---- test/functional/invalid_exceptions_caught.py | 2 +- test/functional/member_checks.py | 2 +- test/functional/method_hidden.py | 2 +- test/functional/missing_final_newline.py | 4 +-- test/functional/name_styles.py | 1 + test/functional/name_styles.txt | 34 +++++++++++----------- test/functional/namedtuple_member_inference.py | 8 +++-- test/functional/namedtuple_member_inference.txt | 6 ++-- test/functional/names_in__all__.py | 4 +-- test/functional/redefined_builtin.py | 2 +- test/functional/socketerror_import.py | 4 +-- test/functional/superfluous_parens.py | 4 +-- test/functional/undefined_variable.py | 2 +- test/functional/unpacked_exceptions.py | 4 +-- test/functional/useless_else_on_loop.py | 14 ++++----- test/input/func_3k_removed_stuff_py_30.py | 4 +-- test/input/func_attrs_definition_order.py | 2 +- test/input/func_backtick_deprecated_py_30.py | 4 +-- test/input/func_bad_assigment_to_exception_var.py | 3 +- test/input/func_base_useless_pass.py | 2 +- test/input/func_block_disable_msg.py | 2 +- test/input/func_break_or_return_in_try_finally.py | 4 +-- test/input/func_dangerous_default.py | 2 +- test/input/func_deprecated_module_py_30.py | 6 ++-- test/input/func_disable_linebased.py | 2 +- test/input/func_e0203.py | 4 +-- test/input/func_e0204.py | 8 ++--- test/input/func_e0601.py | 4 +-- test/input/func_e13xx.py | 3 +- test/input/func_f0401.py | 4 +-- test/input/func_indent.py | 1 + test/input/func_init_vars.py | 3 +- test/input/func_interfaces.py | 4 +-- test/input/func_method_could_be_function.py | 2 +- test/input/func_module___dict__.py | 6 ++-- test/input/func_names_imported_from_module.py | 3 +- test/input/func_no_dummy_redefined.py | 2 +- ...oerror_access_attr_before_def_false_positive.py | 2 +- test/input/func_noerror_base_init_vars.py | 3 +- test/input/func_noerror_decorator_scope.py | 2 +- test/input/func_noerror_e1101_but_getattr.py | 4 +-- test/input/func_noerror_except_pass.py | 3 +- test/input/func_noerror_factory_method.py | 2 +- test/input/func_noerror_function_as_method.py | 2 +- .../input/func_noerror_lambda_use_before_assign.py | 3 +- test/input/func_noerror_mcs_attr_access.py | 2 +- test/input/func_noerror_nested_classes.py | 2 +- test/input/func_noerror_new_style_class_py_30.py | 8 ++--- test/input/func_noerror_no_warning_docstring.py | 6 ++-- test/input/func_noerror_overloaded_operator.py | 2 +- test/input/func_noerror_static_method.py | 6 ++-- .../func_noerror_staticmethod_as_decorator_py24.py | 4 +-- test/input/func_noerror_super_protected.py | 2 +- test/input/func_noerror_used_before_assignment.py | 2 +- test/input/func_noerror_yield_assign_py25.py | 2 +- test/input/func_r0903.py | 5 ++-- test/input/func_set_literal_as_default_py27.py | 4 +-- test/input/func_trailing_whitespace.py | 2 +- test/input/func_typecheck_callfunc_assigment.py | 2 +- test/input/func_unreachable.py | 11 ++++--- test/input/func_unused_overridden_argument.py | 3 +- test/input/func_use_for_or_listcomp_var.py | 2 +- test/input/func_w0103.py | 4 +-- test/input/func_w0104.py | 2 +- test/input/func_w0105.py | 2 +- test/input/func_w0112.py | 2 +- test/input/func_w0205.py | 6 ++-- test/input/func_w0223.py | 4 +-- test/input/func_w0231.py | 8 ++--- test/input/func_w0233.py | 6 ++-- test/input/func_w0312.py | 6 ++-- test/input/func_w0401.py | 1 + test/input/func_w0404.py | 4 +-- test/input/func_w0405.py | 10 +++---- test/input/func_w0406.py | 4 +-- test/input/func_w0611.py | 3 ++ test/input/func_w0612.py | 3 +- test/input/func_w0613.py | 3 +- test/input/func_w0623_py_30.py | 2 +- test/input/func_w0631.py | 7 ++--- test/input/func_w0702.py | 10 +++---- test/input/func_w0703.py | 4 +-- test/input/func_with_without_as_py25.py | 6 ++-- test/input/w0401_cycle.py | 2 +- test/messages/func_indent.txt | 6 ++-- test/messages/func_r0903.txt | 2 +- test/messages/func_w0406.txt | 2 +- test/messages/func_w0611.txt | 2 +- test/regrtest_data/absimp/string.py | 4 +-- test/regrtest_data/decimal_inference.py | 4 +-- test/regrtest_data/precedence_test.py | 4 +-- test/unittest_checker_python3.py | 7 +++++ 108 files changed, 238 insertions(+), 225 deletions(-) diff --git a/checkers/python3.py b/checkers/python3.py index 3472b57..d064191 100644 --- a/checkers/python3.py +++ b/checkers/python3.py @@ -15,6 +15,7 @@ from __future__ import absolute_import from pylint import checkers, interfaces +from pylint.checkers import utils class Python3Checker(checkers.BaseChecker): @@ -26,6 +27,11 @@ class Python3Checker(checkers.BaseChecker): msgs = { # Errors for what will syntactically break in Python 3, warnings for # everything else. + 'E1601': ('print statement used', + 'print-statement', + 'Used when a print statement is used ' + '(`print` is a function in Python 3)', + {'maxversion': (3,0)}), 'W1601': ('apply built-in referenced', 'apply-builtin', 'Used when the apply built-in function is referenced ' @@ -151,6 +157,10 @@ class Python3Checker(checkers.BaseChecker): message = node.name.lower() + '-builtin' self.add_message(message, node=node) + @utils.check_messages('print-statement') + def visit_print(self, node): + self.add_message('print-statement', node=node) + def register(linter): linter.register_checker(Python3Checker(linter)) diff --git a/test/functional/access_to__name__.py b/test/functional/access_to__name__.py index 21da530..45e500e 100644 --- a/test/functional/access_to__name__.py +++ b/test/functional/access_to__name__.py @@ -1,4 +1,4 @@ -# pylint: disable=too-few-public-methods,star-args +# pylint: disable=too-few-public-methods,star-args, print-statement """test access to __name__ gives undefined member on new/old class instances but not on new/old class object """ diff --git a/test/functional/access_to_protected_members.py b/test/functional/access_to_protected_members.py index 8f1c928..809e7dc 100644 --- a/test/functional/access_to_protected_members.py +++ b/test/functional/access_to_protected_members.py @@ -1,4 +1,4 @@ -# pylint: disable=too-few-public-methods, W0231 +# pylint: disable=too-few-public-methods, W0231, print-statement """Test external access to protected class members.""" @@ -36,4 +36,3 @@ INST._protected = 2 # [protected-access] print INST._protected # [protected-access] INST._cls_protected = 3 # [protected-access] print INST._cls_protected # [protected-access] - diff --git a/test/functional/bad_continuation.py b/test/functional/bad_continuation.py index 3d62521..d7e90c0 100644 --- a/test/functional/bad_continuation.py +++ b/test/functional/bad_continuation.py @@ -1,5 +1,5 @@ """Regression test case for bad-continuation.""" - +# pylint: disable=print-statement # Various alignment for brackets LIST0 = [ 1, 2, 3 diff --git a/test/functional/boolean_datetime.py b/test/functional/boolean_datetime.py index 0ea9d27..5de0a0c 100644 --- a/test/functional/boolean_datetime.py +++ b/test/functional/boolean_datetime.py @@ -1,5 +1,5 @@ """ Checks for boolean uses of datetime.time. """ -# pylint: disable=superfluous-parens +# pylint: disable=superfluous-parens,print-statement import datetime if datetime.time(0, 0, 0): # [boolean-datetime] diff --git a/test/functional/cellvar_escaping_loop.py b/test/functional/cellvar_escaping_loop.py index 316bc47..dfacaf4 100644 --- a/test/functional/cellvar_escaping_loop.py +++ b/test/functional/cellvar_escaping_loop.py @@ -1,3 +1,4 @@ +# pylint: disable=print-statement """Tests for loopvar-in-closure.""" def good_case(): diff --git a/test/functional/cellvar_escaping_loop.txt b/test/functional/cellvar_escaping_loop.txt index 4448d44..90d787e 100644 --- a/test/functional/cellvar_escaping_loop.txt +++ b/test/functional/cellvar_escaping_loop.txt @@ -1,8 +1,8 @@ -unused-variable:18:good_case3:Unused variable 'i' -undefined-loop-variable:42:good_case6.:Using possibly undefined loop variable 'i' -cell-var-from-loop:75:bad_case.:Cell variable i defined in loop -cell-var-from-loop:80:bad_case2.:Cell variable i defined in loop -cell-var-from-loop:88:bad_case3.:Cell variable j defined in loop -cell-var-from-loop:98:bad_case4.nested:Cell variable i defined in loop -cell-var-from-loop:119:bad_case5.:Cell variable i defined in loop -cell-var-from-loop:127:bad_case6.:Cell variable i defined in loop +unused-variable:19:good_case3:Unused variable 'i' +undefined-loop-variable:43:good_case6.:Using possibly undefined loop variable 'i' +cell-var-from-loop:76:bad_case.:Cell variable i defined in loop +cell-var-from-loop:81:bad_case2.:Cell variable i defined in loop +cell-var-from-loop:89:bad_case3.:Cell variable j defined in loop +cell-var-from-loop:99:bad_case4.nested:Cell variable i defined in loop +cell-var-from-loop:120:bad_case5.:Cell variable i defined in loop +cell-var-from-loop:128:bad_case6.:Cell variable i defined in loop diff --git a/test/functional/class_members_py27.py b/test/functional/class_members_py27.py index d60458b..9192e4f 100644 --- a/test/functional/class_members_py27.py +++ b/test/functional/class_members_py27.py @@ -1,5 +1,5 @@ """ Various tests for class members access. """ -# pylint: disable=R0903 +# pylint: disable=R0903,print-statement class MyClass(object): """class docstring""" diff --git a/test/functional/confidence_filter.rc b/test/functional/confidence_filter.rc index 5d21cb5..74953b6 100644 --- a/test/functional/confidence_filter.rc +++ b/test/functional/confidence_filter.rc @@ -1,3 +1,3 @@ [Messages Control] -disable=no-init,too-few-public-methods,undefined-variable +disable=no-init,too-few-public-methods,undefined-variable,print-statement confidence=INFERENCE,HIGH,UNDEFINED diff --git a/test/functional/defined_and_used_on_same_line.py b/test/functional/defined_and_used_on_same_line.py index 3c180b8..d56031d 100644 --- a/test/functional/defined_and_used_on_same_line.py +++ b/test/functional/defined_and_used_on_same_line.py @@ -1,5 +1,5 @@ """Check for definitions and usage happening on the same line.""" -#pylint: disable=missing-docstring,multiple-statements +#pylint: disable=missing-docstring,multiple-statements,print-statement print [index for index in range(10)] diff --git a/test/functional/docstrings.py b/test/functional/docstrings.py index 4cdc37e..8b92b08 100644 --- a/test/functional/docstrings.py +++ b/test/functional/docstrings.py @@ -1,4 +1,4 @@ -# pylint: disable=R0201 +# pylint: disable=R0201,print-statement # -1: [missing-docstring] __revision__ = '' diff --git a/test/functional/exception_is_binary_op.py b/test/functional/exception_is_binary_op.py index 76326e0..b9c51d4 100644 --- a/test/functional/exception_is_binary_op.py +++ b/test/functional/exception_is_binary_op.py @@ -1,12 +1,12 @@ """Warn about binary operations used as exceptions.""" - +from __future__ import print_function try: pass except Exception or BaseException: # [binary-op-exception] - print "caught1" + print("caught1") except Exception and BaseException: # [binary-op-exception] - print "caught2" + print("caught2") except Exception or BaseException: # [binary-op-exception] - print "caught3" + print("caught3") except (Exception or BaseException), exc: # [binary-op-exception] - print "caught4" + print("caught4") diff --git a/test/functional/generated_members.rc b/test/functional/generated_members.rc index 73fb671..4657c4e 100644 --- a/test/functional/generated_members.rc +++ b/test/functional/generated_members.rc @@ -1,5 +1,5 @@ [Messages Control] -disable=too-few-public-methods +disable=too-few-public-methods,print-statement [typecheck] generated-members=DoesNotExist,"[a-zA-Z]+_set{1,2}"" diff --git a/test/functional/genexpr_variable_scope.py b/test/functional/genexpr_variable_scope.py index 4089439..a00d72d 100644 --- a/test/functional/genexpr_variable_scope.py +++ b/test/functional/genexpr_variable_scope.py @@ -1,5 +1,5 @@ """test name defined in generator expression are not available outside the genexpr scope """ - -print n # [undefined-variable] +from __future__ import print_function +print(n) # [undefined-variable] diff --git a/test/functional/globals.py b/test/functional/globals.py index 04bfd95..c2844b1 100644 --- a/test/functional/globals.py +++ b/test/functional/globals.py @@ -1,21 +1,22 @@ """Warnings about global statements and usage of global variables.""" +from __future__ import print_function global CSTE # [global-at-module-level] -print CSTE # [undefined-variable] +print(CSTE) # [undefined-variable] CONSTANT = 1 def fix_contant(value): """all this is ok, but try not using global ;)""" global CONSTANT # [global-statement] - print CONSTANT + print(CONSTANT) CONSTANT = value def other(): """global behaviour test""" global HOP # [global-variable-not-assigned] - print HOP # [undefined-variable] + print(HOP) # [undefined-variable] def define_constant(): diff --git a/test/functional/globals.txt b/test/functional/globals.txt index 0f9d13a..c675906 100644 --- a/test/functional/globals.txt +++ b/test/functional/globals.txt @@ -1,6 +1,6 @@ -global-at-module-level:3::Using the global statement at the module level -undefined-variable:4::Undefined variable 'CSTE' -global-statement:10:fix_contant:Using the global statement -global-variable-not-assigned:17:other:Using global for 'HOP' but no assignment is done -undefined-variable:18:other:Undefined variable 'HOP' -global-variable-undefined:23:define_constant:Global variable 'SOMEVAR' undefined at the module level +global-at-module-level:4::Using the global statement at the module level +undefined-variable:5::Undefined variable 'CSTE' +global-statement:11:fix_contant:Using the global statement +global-variable-not-assigned:18:other:Using global for 'HOP' but no assignment is done +undefined-variable:19:other:Undefined variable 'HOP' +global-variable-undefined:24:define_constant:Global variable 'SOMEVAR' undefined at the module level diff --git a/test/functional/invalid_exceptions_caught.py b/test/functional/invalid_exceptions_caught.py index a48cd0f..d0bb7f1 100644 --- a/test/functional/invalid_exceptions_caught.py +++ b/test/functional/invalid_exceptions_caught.py @@ -1,6 +1,6 @@ """Test for catching non-exceptions.""" import socket -# pylint: disable=too-many-ancestors +# pylint: disable=too-many-ancestors,print-statement class MyException(object): """Custom 'exception'.""" diff --git a/test/functional/member_checks.py b/test/functional/member_checks.py index fccf160..78c4625 100644 --- a/test/functional/member_checks.py +++ b/test/functional/member_checks.py @@ -1,4 +1,4 @@ -# pylint: disable= +# pylint: disable=print-statement """check getattr if inference succeed""" diff --git a/test/functional/method_hidden.py b/test/functional/method_hidden.py index 0510f55..98fd4c7 100644 --- a/test/functional/method_hidden.py +++ b/test/functional/method_hidden.py @@ -1,4 +1,4 @@ -# pylint: disable=too-few-public-methods +# pylint: disable=too-few-public-methods,print-statement """check method hidding ancestor attribute """ diff --git a/test/functional/missing_final_newline.py b/test/functional/missing_final_newline.py index b2a9e0c..370f902 100644 --- a/test/functional/missing_final_newline.py +++ b/test/functional/missing_final_newline.py @@ -1,4 +1,4 @@ """This file does not have a final newline.""" - +from __future__ import print_function # +1:[missing-final-newline] -print 1 \ No newline at end of file +print(1) \ No newline at end of file diff --git a/test/functional/name_styles.py b/test/functional/name_styles.py index be3e96d..5d62929 100644 --- a/test/functional/name_styles.py +++ b/test/functional/name_styles.py @@ -1,4 +1,5 @@ """Test for the invalid-name warning.""" +# pylint: disable=print-statement import abc import collections diff --git a/test/functional/name_styles.txt b/test/functional/name_styles.txt index e81d27a..0d578c8 100644 --- a/test/functional/name_styles.txt +++ b/test/functional/name_styles.txt @@ -1,17 +1,17 @@ -invalid-name:6::"Invalid constant name ""bad_const_name""" -invalid-name:9:BADFUNCTION_name:"Invalid function name ""BADFUNCTION_name""" -invalid-name:11:BADFUNCTION_name:"Invalid variable name ""BAD_LOCAL_VAR""" -invalid-name:15:func_bad_argname:"Invalid argument name ""NOT_GOOD""" -invalid-name:25:bad_class_name:"Invalid class name ""bad_class_name""" -invalid-name:36:CorrectClassName.__init__:"Invalid attribute name ""_Bad_AtTR_name""" -invalid-name:37:CorrectClassName.__init__:"Invalid attribute name ""Bad_PUBLIC_name""" -invalid-name:39:CorrectClassName:"Invalid class attribute name ""zz""" -invalid-name:42:CorrectClassName.BadMethodName:"Invalid method name ""BadMethodName""":INFERENCE -invalid-name:48:CorrectClassName.__DunDER_IS_not_free_for_all__:"Invalid method name ""__DunDER_IS_not_free_for_all__""":INFERENCE -invalid-name:78::"Invalid class name ""BAD_NAME_FOR_CLASS""" -invalid-name:79::"Invalid class name ""NEXT_BAD_NAME_FOR_CLASS""" -invalid-name:86::"Invalid class name ""NOT_CORRECT""" -invalid-name:92:test_globals:"Invalid constant name ""AlsoCorrect""" -invalid-name:105:FooClass.PROPERTY_NAME:"Invalid attribute name ""PROPERTY_NAME""":INFERENCE -invalid-name:110:FooClass.ABSTRACT_PROPERTY_NAME:"Invalid attribute name ""ABSTRACT_PROPERTY_NAME""":INFERENCE -invalid-name:115:FooClass.PROPERTY_NAME_SETTER:"Invalid attribute name ""PROPERTY_NAME_SETTER""":INFERENCE +invalid-name:7::"Invalid constant name ""bad_const_name""" +invalid-name:10:BADFUNCTION_name:"Invalid function name ""BADFUNCTION_name""" +invalid-name:12:BADFUNCTION_name:"Invalid variable name ""BAD_LOCAL_VAR""" +invalid-name:16:func_bad_argname:"Invalid argument name ""NOT_GOOD""" +invalid-name:26:bad_class_name:"Invalid class name ""bad_class_name""" +invalid-name:37:CorrectClassName.__init__:"Invalid attribute name ""_Bad_AtTR_name""" +invalid-name:38:CorrectClassName.__init__:"Invalid attribute name ""Bad_PUBLIC_name""" +invalid-name:40:CorrectClassName:"Invalid class attribute name ""zz""" +invalid-name:43:CorrectClassName.BadMethodName:"Invalid method name ""BadMethodName""":INFERENCE +invalid-name:49:CorrectClassName.__DunDER_IS_not_free_for_all__:"Invalid method name ""__DunDER_IS_not_free_for_all__""":INFERENCE +invalid-name:79::"Invalid class name ""BAD_NAME_FOR_CLASS""" +invalid-name:80::"Invalid class name ""NEXT_BAD_NAME_FOR_CLASS""" +invalid-name:87::"Invalid class name ""NOT_CORRECT""" +invalid-name:93:test_globals:"Invalid constant name ""AlsoCorrect""" +invalid-name:106:FooClass.PROPERTY_NAME:"Invalid attribute name ""PROPERTY_NAME""":INFERENCE +invalid-name:111:FooClass.ABSTRACT_PROPERTY_NAME:"Invalid attribute name ""ABSTRACT_PROPERTY_NAME""":INFERENCE +invalid-name:116:FooClass.PROPERTY_NAME_SETTER:"Invalid attribute name ""PROPERTY_NAME_SETTER""":INFERENCE diff --git a/test/functional/namedtuple_member_inference.py b/test/functional/namedtuple_member_inference.py index 675c3e2..c630f6b 100644 --- a/test/functional/namedtuple_member_inference.py +++ b/test/functional/namedtuple_member_inference.py @@ -3,6 +3,8 @@ Regression test for: https://bitbucket.org/logilab/pylint/issue/93/pylint-crashes-on-namedtuple-attribute """ +from __future__ import print_function + __revision__ = None from collections import namedtuple @@ -12,10 +14,10 @@ Fantastic = namedtuple('Fantastic', ['foo']) def test(): """Test member access in named tuples.""" - print Thing.x # [no-member] + print(Thing.x) # [no-member] fan = Fantastic(1) - print fan.foo + print(fan.foo) # Should not raise protected-access. fan2 = fan._replace(foo=2) # [protected-access] # This is a bug. - print fan2.foo # [no-member] + print(fan2.foo) # [no-member] diff --git a/test/functional/namedtuple_member_inference.txt b/test/functional/namedtuple_member_inference.txt index 308336f..2f0f85c 100644 --- a/test/functional/namedtuple_member_inference.txt +++ b/test/functional/namedtuple_member_inference.txt @@ -1,3 +1,3 @@ -no-member:15:test:Class 'Thing' has no 'x' member:INFERENCE -protected-access:19:test:Access to a protected member _replace of a client class -no-member:21:test:Instance of 'Fantastic' has no 'foo' member:INFERENCE +no-member:17:test:Class 'Thing' has no 'x' member:INFERENCE +protected-access:21:test:Access to a protected member _replace of a client class +no-member:23:test:Instance of 'Fantastic' has no 'foo' member:INFERENCE diff --git a/test/functional/names_in__all__.py b/test/functional/names_in__all__.py index acd94c3..a71aeee 100644 --- a/test/functional/names_in__all__.py +++ b/test/functional/names_in__all__.py @@ -7,7 +7,7 @@ * This module imports path and republished it in __all__. No errors are expected. """ - +from __future__ import print_function from os import path from collections import deque @@ -39,7 +39,7 @@ class Klass(object): def func(self): """A klass method""" inner = None - print inner + print(inner) class InnerKlass(object): """A inner klass""" diff --git a/test/functional/redefined_builtin.py b/test/functional/redefined_builtin.py index ace2ea6..c41d06d 100644 --- a/test/functional/redefined_builtin.py +++ b/test/functional/redefined_builtin.py @@ -3,7 +3,7 @@ def function(): """Redefined local.""" type = 1 # [redefined-builtin] - print type + print type # pylint: disable=print-statement # pylint:disable=invalid-name map = {} # [redefined-builtin] diff --git a/test/functional/socketerror_import.py b/test/functional/socketerror_import.py index 37310cf..98d6f2e 100644 --- a/test/functional/socketerror_import.py +++ b/test/functional/socketerror_import.py @@ -1,6 +1,6 @@ """ds""" - +from __future__ import print_function __revision__ = '$Id: socketerror_import.py,v 1.2 2005-12-28 14:58:22 syt Exp $' from socket import error -print error +print(error) diff --git a/test/functional/superfluous_parens.py b/test/functional/superfluous_parens.py index 35a8d0a..8bb3dd6 100644 --- a/test/functional/superfluous_parens.py +++ b/test/functional/superfluous_parens.py @@ -1,5 +1,5 @@ """Test the superfluous-parens warning.""" - +from __future__ import print_function if (3 == 5): # [superfluous-parens] pass @@ -8,7 +8,7 @@ if not (3 == 5): # [superfluous-parens] if not (3 or 5): pass for (x) in (1, 2, 3): # [superfluous-parens] - print x + print(x) if (1) in (1, 2, 3): # [superfluous-parens] pass if (1, 2) in (1, 2, 3): diff --git a/test/functional/undefined_variable.py b/test/functional/undefined_variable.py index 0b5f7aa..efaa1b8 100644 --- a/test/functional/undefined_variable.py +++ b/test/functional/undefined_variable.py @@ -1,5 +1,5 @@ """Test warnings about access to undefined variables.""" -# pylint: disable=too-few-public-methods, no-init, no-self-use, old-style-class +# pylint: disable=too-few-public-methods, no-init, no-self-use, old-style-class,print-statement DEFINED = 1 diff --git a/test/functional/unpacked_exceptions.py b/test/functional/unpacked_exceptions.py index f3c633f..1eb6675 100644 --- a/test/functional/unpacked_exceptions.py +++ b/test/functional/unpacked_exceptions.py @@ -5,7 +5,7 @@ def new_style(): try: pass except IOError, (errno, message): # [unpacking-in-except] - print errno, message + print errno, message # pylint: disable=print-statement # +1: [redefine-in-handler,redefine-in-handler,unpacking-in-except] except IOError, (new_style, tuple): - print new_style, tuple + print new_style, tuple # pylint: disable=print-statement diff --git a/test/functional/useless_else_on_loop.py b/test/functional/useless_else_on_loop.py index 4f27cf7..2fcde8b 100644 --- a/test/functional/useless_else_on_loop.py +++ b/test/functional/useless_else_on_loop.py @@ -1,5 +1,5 @@ """Check for else branches on loops with break an return only.""" - +from __future__ import print_function __revision__ = 0 def test_return_for(): @@ -8,14 +8,14 @@ def test_return_for(): if i % 2: return i else: # [useless-else-on-loop] - print 'math is broken' + print('math is broken') def test_return_while(): """else + return is not accetable.""" while True: return 1 else: # [useless-else-on-loop] - print 'math is broken' + print('math is broken') while True: @@ -24,19 +24,19 @@ while True: for _ in range(10): break else: # [useless-else-on-loop] - print 'or else!' + print('or else!') while True: while False: break else: # [useless-else-on-loop] - print 'or else!' + print('or else!') for j in range(10): pass else: # [useless-else-on-loop] - print 'fat chance' + print('fat chance') for j in range(10): break @@ -52,4 +52,4 @@ def test_return_for2(): else: break else: - print 'great math' + print('great math') diff --git a/test/input/func_3k_removed_stuff_py_30.py b/test/input/func_3k_removed_stuff_py_30.py index 69d4eea..c47b9e5 100644 --- a/test/input/func_3k_removed_stuff_py_30.py +++ b/test/input/func_3k_removed_stuff_py_30.py @@ -1,13 +1,13 @@ """test relative import """ __revision__ = filter(None, map(str, (1, 2, 3))) -from __future__ import generators +from __future__ import generators, print_function import func_w0302 def function(): """something""" - print func_w0302 + print(func_w0302) unic = u"unicode" low = unic.looower return low diff --git a/test/input/func_attrs_definition_order.py b/test/input/func_attrs_definition_order.py index 3c65d73..896426d 100644 --- a/test/input/func_attrs_definition_order.py +++ b/test/input/func_attrs_definition_order.py @@ -1,4 +1,4 @@ -# pylint: disable=R0903 +# pylint: disable=R0903, print-statement """yo""" __revision__ = '$I$' diff --git a/test/input/func_backtick_deprecated_py_30.py b/test/input/func_backtick_deprecated_py_30.py index bca85cc..db3203b 100644 --- a/test/input/func_backtick_deprecated_py_30.py +++ b/test/input/func_backtick_deprecated_py_30.py @@ -1,4 +1,4 @@ """W0333: flag backtick as deprecated""" - +from __future__ import print_function __revision__ = None -print `1` +print(`1`) diff --git a/test/input/func_bad_assigment_to_exception_var.py b/test/input/func_bad_assigment_to_exception_var.py index 6b859ba..61892ce 100644 --- a/test/input/func_bad_assigment_to_exception_var.py +++ b/test/input/func_bad_assigment_to_exception_var.py @@ -1,4 +1,4 @@ -# pylint:disable=C0103 +# pylint:disable=C0103, print-statement """ho ho ho""" __revision__ = 'toto' @@ -28,4 +28,3 @@ def reraise(): raise exc raise e3 - diff --git a/test/input/func_base_useless_pass.py b/test/input/func_base_useless_pass.py index 67c39fa..9faae59 100644 --- a/test/input/func_base_useless_pass.py +++ b/test/input/func_base_useless_pass.py @@ -5,5 +5,5 @@ __revision__ = None try: A = 2 except ValueError: - print A + print A # pylint: disable=print-statement pass diff --git a/test/input/func_block_disable_msg.py b/test/input/func_block_disable_msg.py index 480eac0..927b218 100644 --- a/test/input/func_block_disable_msg.py +++ b/test/input/func_block_disable_msg.py @@ -1,4 +1,4 @@ -# pylint: disable=C0302,bare-except +# pylint: disable=C0302,bare-except,print-statement """pylint option block-disable""" __revision__ = None diff --git a/test/input/func_break_or_return_in_try_finally.py b/test/input/func_break_or_return_in_try_finally.py index 303ac45..d9a50f9 100644 --- a/test/input/func_break_or_return_in_try_finally.py +++ b/test/input/func_break_or_return_in_try_finally.py @@ -1,12 +1,12 @@ 'Exeptions may be silently swallowed' - +from __future__ import print_function __revision__ = None def insidious_break_and_return(): """I found you !""" for i in range(0, -5, -1): my_var = 0 - print i + print(i) try: my_var += 1.0/i if i < -3: diff --git a/test/input/func_dangerous_default.py b/test/input/func_dangerous_default.py index 8bf2c3f..768f70f 100644 --- a/test/input/func_dangerous_default.py +++ b/test/input/func_dangerous_default.py @@ -1,5 +1,5 @@ """docstring""" - +# pylint: disable=print-statement __revision__ = '' HEHE = {} diff --git a/test/input/func_deprecated_module_py_30.py b/test/input/func_deprecated_module_py_30.py index 89d362d..db0dc3f 100644 --- a/test/input/func_deprecated_module_py_30.py +++ b/test/input/func_deprecated_module_py_30.py @@ -1,12 +1,12 @@ """test deprecated module """ - +from __future__ import print_function __revision__ = 0 if __revision__: import Bastion - print Bastion + print(Bastion) # false positive (#10061) import stringfile - print stringfile + print(stringfile) diff --git a/test/input/func_disable_linebased.py b/test/input/func_disable_linebased.py index fe59fa1..953848b 100644 --- a/test/input/func_disable_linebased.py +++ b/test/input/func_disable_linebased.py @@ -1,5 +1,5 @@ # This is a very very very very very very very very very very very very very very very very very very very very very long line. -# pylint: disable=line-too-long +# pylint: disable=line-too-long, print-statement """Make sure enable/disable pragmas work for messages that are applied to lines and not syntax nodes. A disable pragma for a message that applies to nodes is applied to the whole diff --git a/test/input/func_e0203.py b/test/input/func_e0203.py index d95a8dd..d86f479 100644 --- a/test/input/func_e0203.py +++ b/test/input/func_e0203.py @@ -1,6 +1,6 @@ """check for method without self as first argument """ - +from __future__ import print_function __revision__ = 0 @@ -16,4 +16,4 @@ class Abcd(object): def edf(self): """justo ne more method""" - print 'yapudju in', self + print('yapudju in', self) diff --git a/test/input/func_e0204.py b/test/input/func_e0204.py index 26cbd52..7ab9cff 100644 --- a/test/input/func_e0204.py +++ b/test/input/func_e0204.py @@ -1,6 +1,6 @@ """check for method without self as first argument """ - +from __future__ import print_function __revision__ = 0 @@ -9,11 +9,11 @@ class Abcd(object): def __init__(truc): """method without self""" - print 1 + print(1) def abdc(yoo): """another test""" - print yoo + print(yoo) def edf(self): """just another method""" - print 'yapudju in', self + print('yapudju in', self) diff --git a/test/input/func_e0601.py b/test/input/func_e0601.py index 2b704d5..122ba01 100644 --- a/test/input/func_e0601.py +++ b/test/input/func_e0601.py @@ -1,9 +1,9 @@ """test local variable used before assignment """ - +from __future__ import print_function __revision__ = 0 def function(): """dummy""" - print aaaa + print(aaaa) aaaa = 1 diff --git a/test/input/func_e13xx.py b/test/input/func_e13xx.py index 1eaf598..e2bd77e 100644 --- a/test/input/func_e13xx.py +++ b/test/input/func_e13xx.py @@ -1,6 +1,6 @@ """test string format error """ - +# pylint: disable=print-statement __revision__ = 1 PARG_1 = PARG_2 = PARG_3 = 1 @@ -19,4 +19,3 @@ def pprint(): print "%2z" % PARG_1 print "strange format %2" % PARG_2 print "works in 3 %a" % 1 - diff --git a/test/input/func_f0401.py b/test/input/func_f0401.py index c663431..143c148 100644 --- a/test/input/func_f0401.py +++ b/test/input/func_f0401.py @@ -1,9 +1,9 @@ """test failed import """ - +from __future__ import print_function __revision__ = 0 def function(): """yo""" from tutu import toto - print toto + print(toto) diff --git a/test/input/func_indent.py b/test/input/func_indent.py index 3c6ee41..c593b49 100644 --- a/test/input/func_indent.py +++ b/test/input/func_indent.py @@ -1,3 +1,4 @@ +# pylint: disable=print-statement """docstring""" __revision__ = '$Id: func_indent.py,v 1.4 2003-10-17 21:59:31 syt Exp $' diff --git a/test/input/func_init_vars.py b/test/input/func_init_vars.py index db94475..0cb4773 100644 --- a/test/input/func_init_vars.py +++ b/test/input/func_init_vars.py @@ -1,6 +1,6 @@ """Checks that class variables are seen as inherited ! """ - +# pylint: disable=print-statement __revision__ = '' @@ -43,4 +43,3 @@ class MySubClass(MyClass): if __name__ == '__main__': OBJ = MyClass() OBJ.met() - diff --git a/test/input/func_interfaces.py b/test/input/func_interfaces.py index 9756183..21f42fb 100644 --- a/test/input/func_interfaces.py +++ b/test/input/func_interfaces.py @@ -1,4 +1,4 @@ -# pylint:disable=R0201 +# pylint:disable=R0201, print-statement """docstring""" __revision__ = '' @@ -110,5 +110,3 @@ class EmptyImplements(object): def besilent(self): """public method 2/2""" - - diff --git a/test/input/func_method_could_be_function.py b/test/input/func_method_could_be_function.py index a28e48a..7544793 100644 --- a/test/input/func_method_could_be_function.py +++ b/test/input/func_method_could_be_function.py @@ -1,4 +1,4 @@ -# pylint: disable=R0903,R0922,W0232 +# pylint: disable=R0903,R0922,W0232,print-statement """test detection of method which could be a function""" __revision__ = None diff --git a/test/input/func_module___dict__.py b/test/input/func_module___dict__.py index 0cf1550..5451422 100644 --- a/test/input/func_module___dict__.py +++ b/test/input/func_module___dict__.py @@ -1,9 +1,9 @@ """http://www.logilab.org/ticket/6949.""" - +from __future__ import print_function __revision__ = None -print __dict__ is not None +print(__dict__ is not None) __dict__ = {} -print __dict__ is not None +print(__dict__ is not None) diff --git a/test/input/func_names_imported_from_module.py b/test/input/func_names_imported_from_module.py index 64c8f6c..fb271a5 100644 --- a/test/input/func_names_imported_from_module.py +++ b/test/input/func_names_imported_from_module.py @@ -1,4 +1,4 @@ -#pylint: disable=W0401,W0611 +#pylint: disable=W0401,W0611,print-statement """check unexistant names imported are reported""" __revision__ = None @@ -25,4 +25,3 @@ from re import findiiter, compiile import os 'SOMEVAR' in os.environ - diff --git a/test/input/func_no_dummy_redefined.py b/test/input/func_no_dummy_redefined.py index 8af89d8..7d40f81 100644 --- a/test/input/func_no_dummy_redefined.py +++ b/test/input/func_no_dummy_redefined.py @@ -11,4 +11,4 @@ def clobbering(): """Clobbers a dummy name from the outer scope.""" value = 9 for _ in range(7): - print value + print value # pylint: disable=print-statement diff --git a/test/input/func_noerror_access_attr_before_def_false_positive.py b/test/input/func_noerror_access_attr_before_def_false_positive.py index 7f8bbb4..c721278 100644 --- a/test/input/func_noerror_access_attr_before_def_false_positive.py +++ b/test/input/func_noerror_access_attr_before_def_false_positive.py @@ -1,4 +1,4 @@ -#pylint: disable=C0103,R0904,R0903,W0201,old-style-class +#pylint: disable=C0103,R0904,R0903,W0201,old-style-class,print-statement """ This module demonstrates a possible problem of pyLint with calling __init__ s from inherited classes. diff --git a/test/input/func_noerror_base_init_vars.py b/test/input/func_noerror_base_init_vars.py index 0870cef..d74f040 100644 --- a/test/input/func_noerror_base_init_vars.py +++ b/test/input/func_noerror_base_init_vars.py @@ -1,4 +1,4 @@ -# pylint:disable=R0201 +# pylint:disable=R0201, print-statement """Checks that class variables are seen as inherited ! """ __revision__ = '' @@ -33,4 +33,3 @@ class MyClass(BaseClass): if __name__ == '__main__': OBJ = MyClass() OBJ.met() - diff --git a/test/input/func_noerror_decorator_scope.py b/test/input/func_noerror_decorator_scope.py index 95e7a47..9c84d61 100644 --- a/test/input/func_noerror_decorator_scope.py +++ b/test/input/func_noerror_decorator_scope.py @@ -1,4 +1,4 @@ -# -*- pylint: disable=W0232,R0903 +# -*- pylint: disable=W0232,R0903,print-statement """Test that decorators sees the class namespace - just like function default values does but function body doesn't. diff --git a/test/input/func_noerror_e1101_but_getattr.py b/test/input/func_noerror_e1101_but_getattr.py index 03b8fb9..529b413 100644 --- a/test/input/func_noerror_e1101_but_getattr.py +++ b/test/input/func_noerror_e1101_but_getattr.py @@ -1,5 +1,5 @@ """don't want E1101 if __getattr__ is defined""" - +from __future__ import print_function __revision__ = None class MyString(object): @@ -20,4 +20,4 @@ class MyString(object): return self.string.upper() MYSTRING = MyString("abc") -print MYSTRING.title() +print(MYSTRING.title()) diff --git a/test/input/func_noerror_except_pass.py b/test/input/func_noerror_except_pass.py index a28c4ea..5bb8011 100644 --- a/test/input/func_noerror_except_pass.py +++ b/test/input/func_noerror_except_pass.py @@ -2,10 +2,11 @@ #3205: W0704 (except doesn't do anything) false positive if some statements follow a "pass" """ +from __future__ import print_function __revision__ = None try: A = 2 except ValueError: pass # pylint: disable=W0107 - print A + print(A) diff --git a/test/input/func_noerror_factory_method.py b/test/input/func_noerror_factory_method.py index 80ad433..a7cff43 100644 --- a/test/input/func_noerror_factory_method.py +++ b/test/input/func_noerror_factory_method.py @@ -1,4 +1,4 @@ -# pylint: disable=R0903 +# pylint: disable=R0903, print-statement """use new astroid context sensitive inference""" __revision__ = 1 diff --git a/test/input/func_noerror_function_as_method.py b/test/input/func_noerror_function_as_method.py index 6d96a65..e59fb5c 100644 --- a/test/input/func_noerror_function_as_method.py +++ b/test/input/func_noerror_function_as_method.py @@ -1,4 +1,4 @@ -# pylint: disable=R0903 +# pylint: disable=R0903, print-statement '''Test that a function is considered a method when looked up through a class. ''' __revision__ = 1 diff --git a/test/input/func_noerror_lambda_use_before_assign.py b/test/input/func_noerror_lambda_use_before_assign.py index 0ab8c2c..af2775c 100644 --- a/test/input/func_noerror_lambda_use_before_assign.py +++ b/test/input/func_noerror_lambda_use_before_assign.py @@ -1,7 +1,8 @@ """https://www.logilab.net/elo/ticket/18862""" +from __future__ import print_function __revision__ = 1 def function(): """hop""" ggg = lambda: xxx xxx = 1 - print ggg() + print(ggg()) diff --git a/test/input/func_noerror_mcs_attr_access.py b/test/input/func_noerror_mcs_attr_access.py index 8556f8f..ba3ee32 100644 --- a/test/input/func_noerror_mcs_attr_access.py +++ b/test/input/func_noerror_mcs_attr_access.py @@ -1,4 +1,4 @@ -# pylint: disable=R0903 +# pylint: disable=R0903, print-statement """test attribute access on metaclass""" diff --git a/test/input/func_noerror_nested_classes.py b/test/input/func_noerror_nested_classes.py index 0996c66..56e57bb 100644 --- a/test/input/func_noerror_nested_classes.py +++ b/test/input/func_noerror_nested_classes.py @@ -1,4 +1,4 @@ -# pylint: disable=R0903 +# pylint: disable=R0903, print-statement """crash test""" __revision__ = 1 diff --git a/test/input/func_noerror_new_style_class_py_30.py b/test/input/func_noerror_new_style_class_py_30.py index 1121196..a33ae19 100644 --- a/test/input/func_noerror_new_style_class_py_30.py +++ b/test/input/func_noerror_new_style_class_py_30.py @@ -3,7 +3,7 @@ on a file are correctly handled bug notified by Pierre Rouleau on 2005-04-24 """ - +from __future__ import print_function __revision__ = None class File(file): # pylint: disable=file-builtin @@ -17,8 +17,8 @@ class File(file): # pylint: disable=file-builtin self.verbose = verbose super(File, self).__init__(name, mode, buffering) if self.verbose: - print "File %s is opened. The mode is: %s" % (self.name, - self.mode) + print("File %s is opened. The mode is: %s" % (self.name, + self.mode)) # def write(self, a_string): @@ -39,7 +39,7 @@ class File(file): # pylint: disable=file-builtin """Close the file.""" if self.verbose: - print "Closing file %s" % self.name + print("Closing file %s" % self.name) super(File, self).close() self.was_modified = False diff --git a/test/input/func_noerror_no_warning_docstring.py b/test/input/func_noerror_no_warning_docstring.py index 1af00c2..5af0bf8 100644 --- a/test/input/func_noerror_no_warning_docstring.py +++ b/test/input/func_noerror_no_warning_docstring.py @@ -1,5 +1,5 @@ ''' Test for inheritence ''' - +from __future__ import print_function __revision__ = 1 class AAAA(object): @@ -10,11 +10,11 @@ class AAAA(object): def method1(self): ''' method 1 ''' - print self + print(self) def method2(self): ''' method 2 ''' - print self + print(self) class BBBB(AAAA): ''' class BBBB ''' diff --git a/test/input/func_noerror_overloaded_operator.py b/test/input/func_noerror_overloaded_operator.py index a013673..4e29946 100644 --- a/test/input/func_noerror_overloaded_operator.py +++ b/test/input/func_noerror_overloaded_operator.py @@ -1,4 +1,4 @@ -# pylint: disable=C0111,R0903 +# pylint: disable=C0111,R0903,print-statement """#3291""" __revision__ = 1 diff --git a/test/input/func_noerror_static_method.py b/test/input/func_noerror_static_method.py index ea5f7d8..ef21cb9 100644 --- a/test/input/func_noerror_static_method.py +++ b/test/input/func_noerror_static_method.py @@ -1,6 +1,6 @@ """Checks if static / class methods works fine in Pylint """ - +from __future__ import print_function __revision__ = '' class MyClass(object): @@ -12,12 +12,12 @@ class MyClass(object): def static_met(var1, var2): """This is a static method """ - print var1, var2 + print(var1, var2) def class_met(cls, var1): """This is a class method """ - print cls, var1 + print(cls, var1) static_met = staticmethod(static_met) class_met = classmethod(class_met) diff --git a/test/input/func_noerror_staticmethod_as_decorator_py24.py b/test/input/func_noerror_staticmethod_as_decorator_py24.py index d671879..7884cbd 100644 --- a/test/input/func_noerror_staticmethod_as_decorator_py24.py +++ b/test/input/func_noerror_staticmethod_as_decorator_py24.py @@ -1,4 +1,4 @@ -# pylint: disable=R0903 +# pylint: disable=R0903, print-statement """test staticmethod and classmethod as decorator""" __revision__ = None @@ -31,5 +31,3 @@ class ClassMethod2(object): def do_work_with_arg(cls, job): "Working on something" print "Working on %s..." % job - - diff --git a/test/input/func_noerror_super_protected.py b/test/input/func_noerror_super_protected.py index 5e78eea..b0961be 100644 --- a/test/input/func_noerror_super_protected.py +++ b/test/input/func_noerror_super_protected.py @@ -1,6 +1,6 @@ """Accessing a protected method through super() is ok.""" -# pylint: disable=missing-docstring,too-few-public-methods +# pylint: disable=missing-docstring,too-few-public-methods, print-statement __revision__ = None diff --git a/test/input/func_noerror_used_before_assignment.py b/test/input/func_noerror_used_before_assignment.py index 6ba0b88..844ee05 100644 --- a/test/input/func_noerror_used_before_assignment.py +++ b/test/input/func_noerror_used_before_assignment.py @@ -1,4 +1,4 @@ -# pylint: disable = line-too-long, multiple-statements, missing-module-attribute +# pylint: disable = line-too-long, multiple-statements, missing-module-attribute, print-statement """https://bitbucket.org/logilab/pylint/issue/111/false-positive-used-before-assignment-with""" try: raise IOError(1, "a") diff --git a/test/input/func_noerror_yield_assign_py25.py b/test/input/func_noerror_yield_assign_py25.py index 5c365e2..011634b 100644 --- a/test/input/func_noerror_yield_assign_py25.py +++ b/test/input/func_noerror_yield_assign_py25.py @@ -1,5 +1,5 @@ """http://www.logilab.org/ticket/8771""" - +# pylint: disable=print-statement __revision__ = 2 def generator(): diff --git a/test/input/func_r0903.py b/test/input/func_r0903.py index ccbad58..917b0ea 100644 --- a/test/input/func_r0903.py +++ b/test/input/func_r0903.py @@ -1,4 +1,5 @@ """test min methods""" +from __future__ import print_function __revision__ = None class Aaaa(object): @@ -7,7 +8,7 @@ class Aaaa(object): pass def meth1(self): """hehehe""" - print self + print(self) def _dontcount(self): """not public""" - print self + print(self) diff --git a/test/input/func_set_literal_as_default_py27.py b/test/input/func_set_literal_as_default_py27.py index 5c7200e..1bd3f7e 100644 --- a/test/input/func_set_literal_as_default_py27.py +++ b/test/input/func_set_literal_as_default_py27.py @@ -1,7 +1,7 @@ """docstring""" - +from __future__ import print_function __revision__ = '' def function1(value={1}): """set is mutable and dangerous.""" - print value + print(value) diff --git a/test/input/func_trailing_whitespace.py b/test/input/func_trailing_whitespace.py index aca4a2f..946d748 100644 --- a/test/input/func_trailing_whitespace.py +++ b/test/input/func_trailing_whitespace.py @@ -1,5 +1,5 @@ """Regression test for trailing-whitespace (C0303).""" -# pylint: disable=mixed-line-endings +# pylint: disable=mixed-line-endings, print-statement __revision__ = 0 print 'some trailing whitespace' diff --git a/test/input/func_typecheck_callfunc_assigment.py b/test/input/func_typecheck_callfunc_assigment.py index 838b27c..3a668ab 100644 --- a/test/input/func_typecheck_callfunc_assigment.py +++ b/test/input/func_typecheck_callfunc_assigment.py @@ -1,4 +1,4 @@ -# pylint: disable=R0921 +# pylint: disable=R0921, print-statement """check assignment to function call where the function doesn't return 'E1111': ('Assigning to function call which doesn\'t return', diff --git a/test/input/func_unreachable.py b/test/input/func_unreachable.py index c5f7eec..4034e4f 100644 --- a/test/input/func_unreachable.py +++ b/test/input/func_unreachable.py @@ -1,22 +1,21 @@ """docstring""" - +from __future__ import print_function __revision__ = '' def func1(): """docstring""" return 1 - print 'unreachable' + print('unreachable') def func2(): """docstring""" while 1: break - print 'unreachable' + print('unreachable') def func3(): """docstring""" for i in (1, 2, 3): - print i + print(i) continue - print 'unreachable' - + print('unreachable') diff --git a/test/input/func_unused_overridden_argument.py b/test/input/func_unused_overridden_argument.py index b587a12..85430d4 100644 --- a/test/input/func_unused_overridden_argument.py +++ b/test/input/func_unused_overridden_argument.py @@ -1,4 +1,4 @@ -# pylint: disable=R0903 +# pylint: disable=R0903, print-statement """for Sub.inherited, only the warning for "aay" is desired. The warnings for "aab" and "aac" are most likely false positives though, because there could be another subclass that overrides the same method and does @@ -29,4 +29,3 @@ class Sub2(Base): def inherited(self, aaa, aab, aac): "overridden method, use every argument" return aaa + aab + aac - diff --git a/test/input/func_use_for_or_listcomp_var.py b/test/input/func_use_for_or_listcomp_var.py index 3de5a72..5690a2c 100644 --- a/test/input/func_use_for_or_listcomp_var.py +++ b/test/input/func_use_for_or_listcomp_var.py @@ -1,5 +1,5 @@ """test a warning is triggered when using for a lists comprehension variable""" - +# pylint: disable=print-statement __revision__ = 'yo' TEST_LC = [C for C in __revision__ if C.isalpha()] diff --git a/test/input/func_w0103.py b/test/input/func_w0103.py index f8216d9..04cb4c1 100644 --- a/test/input/func_w0103.py +++ b/test/input/func_w0103.py @@ -1,8 +1,8 @@ """test max branch """ - +from __future__ import print_function __revision__ = '' def stupid_function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9): """reallly stupid function""" - print arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 + print(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) diff --git a/test/input/func_w0104.py b/test/input/func_w0104.py index d601682..6588e98 100644 --- a/test/input/func_w0104.py +++ b/test/input/func_w0104.py @@ -1,6 +1,6 @@ """test max branch """ - +# pylint: disable=print-statement __revision__ = '' def stupid_function(arg1, arg2, arg3, arg4, arg5): diff --git a/test/input/func_w0105.py b/test/input/func_w0105.py index c951e9d..c40870e 100644 --- a/test/input/func_w0105.py +++ b/test/input/func_w0105.py @@ -1,6 +1,6 @@ """test max branch """ - +# pylint: disable=print-statement __revision__ = '' def stupid_function(arg): diff --git a/test/input/func_w0112.py b/test/input/func_w0112.py index cdf2bd0..6bddf00 100644 --- a/test/input/func_w0112.py +++ b/test/input/func_w0112.py @@ -1,6 +1,6 @@ """test max branch """ - +# pylint: disable=print-statement __revision__ = '' def stupid_function(arg): diff --git a/test/input/func_w0205.py b/test/input/func_w0205.py index 6e7bf43..97db817 100644 --- a/test/input/func_w0205.py +++ b/test/input/func_w0205.py @@ -1,5 +1,5 @@ """check different signatures""" - +from __future__ import print_function __revision__ = 0 class Abcd(object): @@ -8,7 +8,7 @@ class Abcd(object): self.aarg = False def abcd(self, aaa=1, bbbb=None): """hehehe""" - print self, aaa, bbbb + print(self, aaa, bbbb) def args(self): """gaarrrggll""" self.aarg = True @@ -21,4 +21,4 @@ class Cdef(Abcd): def abcd(self, aaa, bbbb=None): """hehehe""" - print self, aaa, bbbb + print(self, aaa, bbbb) diff --git a/test/input/func_w0223.py b/test/input/func_w0223.py index 1563b41..5d380cc 100644 --- a/test/input/func_w0223.py +++ b/test/input/func_w0223.py @@ -1,7 +1,7 @@ # pylint: disable=R0903,R0922 """test overriding of abstract method """ - +from __future__ import print_function __revision__ = '$Id: func_w0223.py,v 1.2 2004-09-29 08:35:13 syt Exp $' class Abstract(object): @@ -33,4 +33,4 @@ class Concret(Abstract): def aaaa(self): """overidden form Abstract""" - print self + print(self) diff --git a/test/input/func_w0231.py b/test/input/func_w0231.py index 7c4cc02..eeefd0c 100644 --- a/test/input/func_w0231.py +++ b/test/input/func_w0231.py @@ -1,20 +1,20 @@ # pylint: disable=R0903 """test for __init__ not called """ - +from __future__ import print_function __revision__ = '$Id: func_w0231.py,v 1.3 2004-09-29 08:35:13 syt Exp $' class AAAA: """ancestor 1""" def __init__(self): - print 'init', self + print('init', self) class BBBB: """ancestor 2""" def __init__(self): - print 'init', self + print('init', self) class CCCC: """ancestor 3""" @@ -30,7 +30,7 @@ class NewStyleA(object): """new style class""" def __init__(self): super(NewStyleA, self).__init__() - print 'init', self + print('init', self) class NewStyleB(NewStyleA): """derived new style class""" diff --git a/test/input/func_w0233.py b/test/input/func_w0233.py index ef5f205..4dbf26f 100644 --- a/test/input/func_w0233.py +++ b/test/input/func_w0233.py @@ -1,21 +1,21 @@ # pylint: disable=R0903,W0212,W0403,W0406 """test for call to __init__ from a non ancestor class """ - +from __future__ import print_function __revision__ = '$Id: func_w0233.py,v 1.2 2004-09-29 08:35:13 syt Exp $' class AAAA(object): """ancestor 1""" def __init__(self): - print 'init', self + print('init', self) BBBBMixin.__init__(self) class BBBBMixin(object): """ancestor 2""" def __init__(self): - print 'init', self + print('init', self) import nonexistant import func_w0233 diff --git a/test/input/func_w0312.py b/test/input/func_w0312.py index 06a8110..491f75b 100644 --- a/test/input/func_w0312.py +++ b/test/input/func_w0312.py @@ -1,11 +1,11 @@ """test mixed tabs and spaces""" - +from __future__ import print_function __revision__ = 1 def spaces_func(): """yo""" - print "yo" + print("yo") def tab_func(): """yo""" - print "yo" + print("yo") diff --git a/test/input/func_w0401.py b/test/input/func_w0401.py index 160b555..25ca7b8 100644 --- a/test/input/func_w0401.py +++ b/test/input/func_w0401.py @@ -1,5 +1,6 @@ """test cyclic import """ +# pylint: disable=print-statement __revision__ = 0 from input import w0401_cycle diff --git a/test/input/func_w0404.py b/test/input/func_w0404.py index f475a4d..bc0dbed 100644 --- a/test/input/func_w0404.py +++ b/test/input/func_w0404.py @@ -1,5 +1,5 @@ """Unittests for W0404 (reimport)""" - +from __future__ import print_function __revision__ = 0 import sys @@ -15,7 +15,7 @@ import sys def no_reimport(): """docstring""" import os - print os + print(os) def reimport(): diff --git a/test/input/func_w0405.py b/test/input/func_w0405.py index 8b96cd9..8d7f8b1 100644 --- a/test/input/func_w0405.py +++ b/test/input/func_w0405.py @@ -1,6 +1,6 @@ """check reimport """ - +from __future__ import print_function __revision__ = 0 import os @@ -12,9 +12,9 @@ import re as _re _re.match('yo', '.*') if __revision__: - print os + print(os) from os.path import exists - print join, exists + print(join, exists) def func(yooo): """reimport in different scope""" @@ -25,7 +25,7 @@ def func(yooo): if 1: import sys - print sys.modules + print(sys.modules) else: - print 'bla' + print('bla') import sys diff --git a/test/input/func_w0406.py b/test/input/func_w0406.py index e20508f..3bb0fef 100644 --- a/test/input/func_w0406.py +++ b/test/input/func_w0406.py @@ -1,9 +1,9 @@ """test module importing itself """ +from __future__ import print_function __revision__ = 0 import func_w0406 if __revision__: - print func_w0406 - + print(func_w0406) diff --git a/test/input/func_w0611.py b/test/input/func_w0611.py index 6bef753..57e7238 100644 --- a/test/input/func_w0611.py +++ b/test/input/func_w0611.py @@ -1,6 +1,9 @@ """check unused import """ +# pylint: disable=print-statement + __revision__ = 1 + import os import sys diff --git a/test/input/func_w0612.py b/test/input/func_w0612.py index e871bb2..8c8a8b2 100644 --- a/test/input/func_w0612.py +++ b/test/input/func_w0612.py @@ -1,6 +1,6 @@ """test unused variable """ -# pylint: disable=invalid-name, redefined-outer-name +# pylint: disable=invalid-name, redefined-outer-name, print-statement __revision__ = 0 PATH = OS = collections = deque = None @@ -35,4 +35,3 @@ def test_global(): from sys import version as VERSION import this import re as RE - diff --git a/test/input/func_w0613.py b/test/input/func_w0613.py index 1df71dd..333699c 100644 --- a/test/input/func_w0613.py +++ b/test/input/func_w0613.py @@ -1,4 +1,4 @@ -# pylint: disable=R0903 +# pylint: disable=R0903, print-statement """test unused argument """ @@ -40,4 +40,3 @@ class BBBB(object): def __init__(self, arg): """Constructor with an extra parameter. Should raise a warning""" self.spam = 1 - diff --git a/test/input/func_w0623_py_30.py b/test/input/func_w0623_py_30.py index 8f1f34c..539c0b1 100644 --- a/test/input/func_w0623_py_30.py +++ b/test/input/func_w0623_py_30.py @@ -1,5 +1,5 @@ """Test for W0623, overwriting names in exception handlers.""" -# pylint: disable=broad-except,bare-except,pointless-except +# pylint: disable=broad-except,bare-except,pointless-except,print-statement __revision__ = '' import exceptions diff --git a/test/input/func_w0631.py b/test/input/func_w0631.py index 2524f5e..0390ac7 100644 --- a/test/input/func_w0631.py +++ b/test/input/func_w0631.py @@ -1,13 +1,13 @@ """Check possible undefined loopvar """ - +from __future__ import print_function __revision__ = 0 def do_stuff(some_random_list): """This is not right.""" for var in some_random_list: pass - print var + print(var) def do_else(some_random_list): @@ -17,5 +17,4 @@ def do_else(some_random_list): break else: var = 84 - print var - + print(var) diff --git a/test/input/func_w0702.py b/test/input/func_w0702.py index 38a6417..1f82a23 100644 --- a/test/input/func_w0702.py +++ b/test/input/func_w0702.py @@ -1,17 +1,17 @@ """check empty except statement """ - +from __future__ import print_function __revision__ = 0 if __revision__: try: - print __revision__ + print(__revision__) except: - print 'error' + print('error') try: __revision__ += 1 except TypeError: - print 'error' + print('error') except Exception: - print 'error' + print('error') diff --git a/test/input/func_w0703.py b/test/input/func_w0703.py index 4040540..fb633fd 100644 --- a/test/input/func_w0703.py +++ b/test/input/func_w0703.py @@ -1,9 +1,9 @@ """check empty except statement """ - +from __future__ import print_function __revision__ = 0 try: __revision__ += 1 except Exception: - print 'error' + print('error') diff --git a/test/input/func_with_without_as_py25.py b/test/input/func_with_without_as_py25.py index e3b2c71..7ecf574 100644 --- a/test/input/func_with_without_as_py25.py +++ b/test/input/func_with_without_as_py25.py @@ -1,14 +1,12 @@ '''This is a little non regression test on a with statement without 'as'. ''' -from __future__ import with_statement +from __future__ import with_statement, print_function __revision__ = 32321313 def do_nothing(arg): 'ho foo' - print arg + print(arg) with open('x'): base.baz base = 7 - - diff --git a/test/input/w0401_cycle.py b/test/input/w0401_cycle.py index bf731e0..7d8fa99 100644 --- a/test/input/w0401_cycle.py +++ b/test/input/w0401_cycle.py @@ -1,6 +1,6 @@ """w0401 dependency """ - +# pylint: disable=print-statement __revision__ = 0 import input.func_w0401 diff --git a/test/messages/func_indent.txt b/test/messages/func_indent.txt index e24af18..c8fe133 100644 --- a/test/messages/func_indent.txt +++ b/test/messages/func_indent.txt @@ -1,5 +1,5 @@ -W: 5: Bad indentation. Found 1 spaces, expected 4 W: 6: Bad indentation. Found 1 spaces, expected 4 -W: 13: Bad indentation. Found 5 spaces, expected 4 +W: 7: Bad indentation. Found 1 spaces, expected 4 W: 14: Bad indentation. Found 5 spaces, expected 4 -W: 14:titii: Statement seems to have no effect +W: 15: Bad indentation. Found 5 spaces, expected 4 +W: 15:titii: Statement seems to have no effect diff --git a/test/messages/func_r0903.txt b/test/messages/func_r0903.txt index bd4cc2a..3ca8004 100644 --- a/test/messages/func_r0903.txt +++ b/test/messages/func_r0903.txt @@ -1 +1 @@ -R: 4:Aaaa: Too few public methods (1/2) +R: 5:Aaaa: Too few public methods (1/2) diff --git a/test/messages/func_w0406.txt b/test/messages/func_w0406.txt index 6145515..8779d98 100644 --- a/test/messages/func_w0406.txt +++ b/test/messages/func_w0406.txt @@ -1 +1 @@ -W: 5: Module import itself +W: 6: Module import itself diff --git a/test/messages/func_w0611.txt b/test/messages/func_w0611.txt index 10952da..2be0d0a 100644 --- a/test/messages/func_w0611.txt +++ b/test/messages/func_w0611.txt @@ -1 +1 @@ -W: 4: Unused import os +W: 7: Unused import os diff --git a/test/regrtest_data/absimp/string.py b/test/regrtest_data/absimp/string.py index a4d01cb..f47e9a5 100644 --- a/test/regrtest_data/absimp/string.py +++ b/test/regrtest_data/absimp/string.py @@ -2,6 +2,6 @@ http://www.logilab.org/ticket/70495 http://www.logilab.org/ticket/70565 """ -from __future__ import absolute_import +from __future__ import absolute_import, print_function import string -print string +print(string) diff --git a/test/regrtest_data/decimal_inference.py b/test/regrtest_data/decimal_inference.py index b47bc1c..00c9130 100644 --- a/test/regrtest_data/decimal_inference.py +++ b/test/regrtest_data/decimal_inference.py @@ -3,8 +3,8 @@ using setattr/locals :( 2007/02/17 update: .prec attribute is now detected by astroid :o) """ +from __future__ import print_function import decimal decimal.getcontext().prec = 200 -print decimal.getcontext().prec - +print(decimal.getcontext().prec) diff --git a/test/regrtest_data/precedence_test.py b/test/regrtest_data/precedence_test.py index 087b5cf..260eeb3 100644 --- a/test/regrtest_data/precedence_test.py +++ b/test/regrtest_data/precedence_test.py @@ -13,9 +13,9 @@ print AudioTime.DECIMAL """ - +from __future__ import print_function __revision__ = 0 from package import AudioTime -print AudioTime.DECIMAL +print(AudioTime.DECIMAL) diff --git a/test/unittest_checker_python3.py b/test/unittest_checker_python3.py index 56a2339..5c0ff20 100644 --- a/test/unittest_checker_python3.py +++ b/test/unittest_checker_python3.py @@ -122,6 +122,13 @@ class Python3CheckerTest(testutils.CheckerTestCase): with self.assertAddsMessages(message): self.checker.visit_function(node) + @python2_only + def test_print_statement(self): + node = test_utils.extract_node('print "Hello, World!" #@') + message = testutils.Message('print-statement', node=node) + with self.assertAddsMessages(message): + self.checker.visit_print(node) + if __name__ == '__main__': unittest.main() -- cgit v1.2.1