[Tutor] CONSTANTS -- Is it appropriate to use uppercase names within a function or method?
Cameron Simpson
cs at cskk.id.au
Tue Nov 12 16:42:38 EST 2019
On 12Nov2019 15:00, boB Stepp <robertvstepp at gmail.com> wrote:
>On Tue, Nov 12, 2019 at 1:08 PM Mats Wichmann <mats at wichmann.us> wrote:
>> On 11/12/19 10:43 AM, boB Stepp wrote:
>> ...You can
>> also configure pylint not to issue that particular warning - describing
>> how is a bit out of scope for this message.
>
>A pity. Trying to determine how to configure pylint is what I am
>currently struggling with. I am not finding its official
>documentation easy to comprehend.
Fortunately you don't need to rely on that. Look at the output. Here's
an example:
% python -m pylint --rcfile=/Users/cameron/.pylintrc --disable=bad-whitespace,invalid-name,useless-object-inheritance cs/vt/blockify.py
************* Module python.cs.vt.blockify
cs/vt/blockify.py:323:10: E1307: Argument 'builtins.NoneType' does not match format type 'd' (bad-string-format-type)
and:
% grep pylint cs/vt/blockify.py
# pylint: disable=too-many-nested-blocks,too-many-statements
# pylint: disable=too-many-branches,too-many-locals
# pylint: disable=broad-except
and there's the ~/.pylintrc file referenced above.
So:
1: The error message recites the pylint rule which caused it, so
"bad-string-format-type" is fires on line 323 of cs/vt/blockify.py.
2: You can disable specific rules for a whole file by providing them on
the command line.
3: You can enable or disable rules for all files in a .pylintrc file.
4: You can disable specific rules for a suite in the code by preceeding
that suite with a special "# pylint: <rule-name-here>" comment. Example:
def blocked_chunks_of(
chunks,
scanner=None,
min_block=None,
max_block=None,
histogram=None,
):
''' Generator which connects to a scanner of a chunk stream in
order to emit low level edge aligned data chunks. [...]
'''
# pylint: disable=too-many-nested-blocks,too-many-statements
# pylint: disable=too-many-branches,too-many-locals
with Pfx("blocked_chunks_of"):
if min_block is None:
min_block = MIN_BLOCKSIZE
elif min_block < 8:
So my blocked_chunks_of function is rather exceptional: it is the
performance bottleneck of the cs.vt library, and is deliberately written
as a single huge function with several local variables because breaking
it up brings significant performance degradation just from the function
call overhead. There's even a C extension function to aid performance
for the really low level part, and it still benefits from being a big
inline function.
So this particular function turns off 4 of the pylint rules just for
itself, leaving them active for all the other code.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Tutor
mailing list