Adding python function arguments related customized rule in pylint
Hi all, I want to add a customized check to my pylintrc file to check and report cases whenever I define a function in a python file like this: def foo( var1, name1=value, *args ): The problem that I want to deal with is that we should not have keyword arguments( *name1* ) before positional arguments( **args* ). Although the function can still be called by passing *name1* as positional argument but there would be no way to not specify *name1* but specify **args*. How can I add this check to pylintrc file? Thanks in advance! -- Regards, Ahirnish
On Mon, Jun 29, 2015 at 12:32 PM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi all,
I want to add a customized check to my pylintrc file to check and report cases whenever I define a function in a python file like this:
def foo( var1, name1=value, *args ):
The problem that I want to deal with is that we should not have keyword arguments( name1 ) before positional arguments( *args ). Although the function can still be called by passing name1 as positional argument but there would be no way to not specify name1 but specify *args.
How can I add this check to pylintrc file?
Thanks in advance!
Hi, If you already have the checker, you can add it in the load-plugins entry from the pylintrc file, as in `load-plugins=qualified plugin path`. We don't have this check builtin right now, but it's something that could be useful, so if you could send it upstream, that would be really awesome. Thanks, Claudiu
Hi all, I was going through the *checkers/typecheck.py* for reference but could not understand it concretely. I am basically unable to find how to retrieve arguments from Astng Function node. I am using visit_function() inside a checker class to visit all function nodes but not able to get list of arguments(and varargs and kwargs too). Also, is there a function which returns <type function> if we pass Astng Function node to it? Thanks in advance! On Mon, Jun 29, 2015 at 11:46 PM, Claudiu Popa <pcmanticore@gmail.com> wrote:
On Mon, Jun 29, 2015 at 12:32 PM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi all,
I want to add a customized check to my pylintrc file to check and report cases whenever I define a function in a python file like this:
def foo( var1, name1=value, *args ):
The problem that I want to deal with is that we should not have keyword arguments( name1 ) before positional arguments( *args ). Although the function can still be called by passing name1 as positional argument but there would be no way to not specify name1 but specify *args.
How can I add this check to pylintrc file?
Thanks in advance!
Hi,
If you already have the checker, you can add it in the load-plugins entry from the pylintrc file, as in `load-plugins=qualified plugin path`. We don't have this check builtin right now, but it's something that could be useful, so if you could send it upstream, that would be really awesome.
Thanks,
Claudiu
-- Regards, Ahirnish
Hi, On Wed, Jul 1, 2015 at 12:40 PM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi all,
I was going through the checkers/typecheck.py for reference but could not understand it concretely.
I am basically unable to find how to retrieve arguments from Astng Function node.
I am using visit_function() inside a checker class to visit all function nodes but not able to get list of arguments(and varargs and kwargs too).
You should access node.args (an Arguments) node, as seen below: from astroid.test_utils import extract_node n = extract_node(''' def test(a, *args, b=None, **kwargs): pass ''') print(n.args.args, n.args.kwonlyargs, n.args.vararg, n.args.kwarg)
Also, is there a function which returns <type function> if we pass Astng Function node to it?
Do you mean the equivalent of type(function) from Python? You can try the new astroid.helpers.object_type from soon-to-be astroid 1.4: https://bitbucket.org/logilab/astroid/src/3d3cb4d45368bc80b0e80d24d758d884a1... /Claudiu
Thanks Claudiu. I was looking for this only. Yes, I meant type(function) from Python. My organization doesnt have asteroid in its python's site-packages. We are still importing from logilab.astng module. Thanks for the help! On Wed, Jul 1, 2015 at 3:31 PM, Claudiu Popa <pcmanticore@gmail.com> wrote:
Hi,
On Wed, Jul 1, 2015 at 12:40 PM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi all,
I was going through the checkers/typecheck.py for reference but could not understand it concretely.
I am basically unable to find how to retrieve arguments from Astng Function node.
I am using visit_function() inside a checker class to visit all function nodes but not able to get list of arguments(and varargs and kwargs too).
You should access node.args (an Arguments) node, as seen below:
from astroid.test_utils import extract_node n = extract_node(''' def test(a, *args, b=None, **kwargs): pass ''') print(n.args.args, n.args.kwonlyargs, n.args.vararg, n.args.kwarg)
Also, is there a function which returns <type function> if we pass Astng Function node to it?
Do you mean the equivalent of type(function) from Python? You can try the new astroid.helpers.object_type from soon-to-be astroid 1.4:
https://bitbucket.org/logilab/astroid/src/3d3cb4d45368bc80b0e80d24d758d884a1...
/Claudiu
-- Regards, Ahirnish
On Wed, Jul 1, 2015 at 2:32 PM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Thanks Claudiu.
I was looking for this only.
Yes, I meant type(function) from Python. My organization doesnt have asteroid in its python's site-packages. We are still importing from logilab.astng module. Thanks for the help!
Well, astroid is the old logilab.astng, but much better. ;-)
Hi all, I was wondering if there's a pattern to calculate Pylint's message-id numbers? I know that first alphabet indicates if its a warning, error, convention, refactor or fatal but how do we come up with 4-digit number after that? Like - E1605. E = Error but what is 1605? Thanks. On Wed, Jul 1, 2015 at 5:05 PM, Claudiu Popa <pcmanticore@gmail.com> wrote:
On Wed, Jul 1, 2015 at 2:32 PM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Thanks Claudiu.
I was looking for this only.
Yes, I meant type(function) from Python. My organization doesnt have asteroid in its python's site-packages. We are still importing from logilab.astng module. Thanks for the help!
Well, astroid is the old logilab.astng, but much better. ;-)
-- Regards, Ahirnish
On Thu, Jul 2, 2015 at 9:45 AM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi all,
I was wondering if there's a pattern to calculate Pylint's message-id numbers? I know that first alphabet indicates if its a warning, error, convention, refactor or fatal but how do we come up with 4-digit number after that?
Like - E1605. E = Error but what is 1605?
Thanks.
Base id of standard checkers (used in msg and report ids): 01: base 02: classes 03: format 04: import 05: misc 06: variables 07: exceptions 08: similar 09: design_analysis 10: newstyle 11: typecheck 12: logging 13: string_format 14: string_constant 15: stdlib 16: python3 So for E1605, that would be from the python 3 checker. Since it's pretty hard to remember all this, the message ids will be deprecated at some point, in favor of using symbolic names.
Hi, I have never patched anything to the open-source code and I am confused as to what are the right steps to follow. I need to patch a function argument related checker into the pylint code base. Can someone point me to the steps need to follow to ensure my changes go upstream? Thanks. On Fri, Jul 3, 2015 at 3:02 PM, Claudiu Popa <pcmanticore@gmail.com> wrote:
On Thu, Jul 2, 2015 at 9:45 AM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi all,
I was wondering if there's a pattern to calculate Pylint's message-id numbers? I know that first alphabet indicates if its a warning, error, convention, refactor or fatal but how do we come up with 4-digit number after that?
Like - E1605. E = Error but what is 1605?
Thanks.
Base id of standard checkers (used in msg and report ids): 01: base 02: classes 03: format 04: import 05: misc 06: variables 07: exceptions 08: similar 09: design_analysis 10: newstyle 11: typecheck 12: logging 13: string_format 14: string_constant 15: stdlib 16: python3
So for E1605, that would be from the python 3 checker. Since it's pretty hard to remember all this, the message ids will be deprecated at some point, in favor of using symbolic names.
-- Regards, Ahirnish
* Ahirnish Pareek <ahirnish@arista.com> [2015-08-05 13:49:39 +0530]:
I have never patched anything to the open-source code and I am confused as to what are the right steps to follow. I need to patch a function argument related checker into the pylint code base. Can someone point me to the steps need to follow to ensure my changes go upstream?
Can you share the plugin in its current state? Then we can probably help you better and see what goes where. Also see the contributing documentation: http://docs.pylint.org/contribute.html Florian -- http://www.the-compiler.org | me@the-compiler.org (Mail/XMPP) GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc I love long mails! | http://email.is-not-s.ms/
Hi, The idea of plugin is very simple and I felt the need of it in my organization's code base where we use python 2.7 to write the tests. There are a lot of functions which looks like this: def foo( var1, name1=value, *args ): The problem that I want to deal with is that we should not have keyword arguments( *name1* ) before positional arguments( **args* ). Although the function can still be called by passing *name1* as positional argument but there would be no way to not specify *name1* but specify **args*. def foo(a, b=3, *args): print a, b, args Case1: a = 0, b = 2, args = (4, 5) foo(0, 2, 4, 5) => 0 2 (4, 5) Case2: a = 0, b = <default_value>, args = (4, 5) foo(0, 4, 5) => 0 4 (5, ) ==> args list modified as well as value of 'b' And of course, we cant do this: foo(0, b=2, 4, 5) I plan to put this in design_analysis checker and the check looks like this: from astroid.test_utils import extract_node n = extract_node(''' def test(a, b=2, *args, c=3, **kwargs): pass ''') *if n.args.defaults and n.args.varargs:* print <ErrMsg> I already checked it by loading this plugin as an external plugin in my pylintrc file and it worked as expected. Claudio suggested that this might be a useful check, so I plan to merge it in the developing code-base. Do let me know your thoughts! On Wed, Aug 5, 2015 at 1:49 PM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi,
I have never patched anything to the open-source code and I am confused as to what are the right steps to follow. I need to patch a function argument related checker into the pylint code base. Can someone point me to the steps need to follow to ensure my changes go upstream?
Thanks.
On Fri, Jul 3, 2015 at 3:02 PM, Claudiu Popa <pcmanticore@gmail.com> wrote:
On Thu, Jul 2, 2015 at 9:45 AM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi all,
I was wondering if there's a pattern to calculate Pylint's message-id numbers? I know that first alphabet indicates if its a warning, error, convention, refactor or fatal but how do we come up with 4-digit number after that?
Like - E1605. E = Error but what is 1605?
Thanks.
Base id of standard checkers (used in msg and report ids): 01: base 02: classes 03: format 04: import 05: misc 06: variables 07: exceptions 08: similar 09: design_analysis 10: newstyle 11: typecheck 12: logging 13: string_format 14: string_constant 15: stdlib 16: python3
So for E1605, that would be from the python 3 checker. Since it's pretty hard to remember all this, the message ids will be deprecated at some point, in favor of using symbolic names.
-- Regards, Ahirnish
-- Regards, Ahirnish
Hi, I was being told to share my plugin in the current state. It would be helpful if someone take a look about it in my previous mail and provide feedback. Thanks. On Tue, Aug 11, 2015 at 11:20 AM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi,
The idea of plugin is very simple and I felt the need of it in my organization's code base where we use python 2.7 to write the tests.
There are a lot of functions which looks like this: def foo( var1, name1=value, *args ):
The problem that I want to deal with is that we should not have keyword arguments( *name1* ) before positional arguments( **args* ). Although the function can still be called by passing *name1* as positional argument but there would be no way to not specify *name1* but specify **args*. def foo(a, b=3, *args): print a, b, args
Case1: a = 0, b = 2, args = (4, 5) foo(0, 2, 4, 5) => 0 2 (4, 5)
Case2: a = 0, b = <default_value>, args = (4, 5) foo(0, 4, 5) => 0 4 (5, ) ==> args list modified as well as value of 'b'
And of course, we cant do this: foo(0, b=2, 4, 5)
I plan to put this in design_analysis checker and the check looks like this:
from astroid.test_utils import extract_node n = extract_node(''' def test(a, b=2, *args, c=3, **kwargs): pass ''')
*if n.args.defaults and n.args.varargs:* print <ErrMsg>
I already checked it by loading this plugin as an external plugin in my pylintrc file and it worked as expected.
Claudio suggested that this might be a useful check, so I plan to merge it in the developing code-base.
Do let me know your thoughts!
On Wed, Aug 5, 2015 at 1:49 PM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi,
I have never patched anything to the open-source code and I am confused as to what are the right steps to follow. I need to patch a function argument related checker into the pylint code base. Can someone point me to the steps need to follow to ensure my changes go upstream?
Thanks.
On Fri, Jul 3, 2015 at 3:02 PM, Claudiu Popa <pcmanticore@gmail.com> wrote:
On Thu, Jul 2, 2015 at 9:45 AM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi all,
I was wondering if there's a pattern to calculate Pylint's message-id numbers? I know that first alphabet indicates if its a warning, error, convention, refactor or fatal but how do we come up with 4-digit number after that?
Like - E1605. E = Error but what is 1605?
Thanks.
Base id of standard checkers (used in msg and report ids): 01: base 02: classes 03: format 04: import 05: misc 06: variables 07: exceptions 08: similar 09: design_analysis 10: newstyle 11: typecheck 12: logging 13: string_format 14: string_constant 15: stdlib 16: python3
So for E1605, that would be from the python 3 checker. Since it's pretty hard to remember all this, the message ids will be deprecated at some point, in favor of using symbolic names.
-- Regards, Ahirnish
-- Regards, Ahirnish
-- Regards, Ahirnish
On Thu, Aug 27, 2015 at 1:11 PM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi,
I was being told to share my plugin in the current state. It would be helpful if someone take a look about it in my previous mail and provide feedback.
Thanks.
Hi, This should probably go into typecheck.py, rather than in design_analysis.py. The next step would be to submit a pull request with your changes on https://bitbucket.org/logilab/pylint/. Thanks, Claudiu
Thanks for the suggestion Claudio. I'll do the same. On Mon, Aug 31, 2015 at 12:06 PM, Claudiu Popa <pcmanticore@gmail.com> wrote:
On Thu, Aug 27, 2015 at 1:11 PM, Ahirnish Pareek <ahirnish@arista.com> wrote:
Hi,
I was being told to share my plugin in the current state. It would be helpful if someone take a look about it in my previous mail and provide feedback.
Thanks.
Hi,
This should probably go into typecheck.py, rather than in design_analysis.py. The next step would be to submit a pull request with your changes on https://bitbucket.org/logilab/pylint/.
Thanks, Claudiu
-- Regards, Ahirnish
participants (3)
-
Ahirnish Pareek
-
Claudiu Popa
-
Florian Bruhin