Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Laugh while you can, monkey-boy." -- Dr. Emilio Lizardo


devel / comp.lang.python / Re: Argument name should be lowercase

SubjectAuthor
o Re: Argument name should be lowercaseThomas Passin

1
Re: Argument name should be lowercase

<mailman.915.1668175803.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20274&group=comp.lang.python#20274

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: lis...@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Argument name should be lowercase
Date: Fri, 11 Nov 2022 09:09:51 -0500
Lines: 113
Message-ID: <mailman.915.1668175803.20444.python-list@python.org>
References: <0eba3f9d-c89c-062e-425a-54aea7216b11@DancesWithMice.info>
<d725dde2-d793-8aad-0f8c-10a7f263f601@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de Z78E99gZAW4VfzhRNTviawTUMqMkFezAvpaU+Q6iW8LQ==
Return-Path: <list1@tompassin.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=tompassin.net header.i=@tompassin.net header.b=oKZronM/;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.014
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'argument': 0.04; 'def':
0.04; 'pycharm': 0.04; 'parameter': 0.05; 'formal': 0.07;
'string': 0.07; 'subject:name': 0.07; 'thing.': 0.07; '"""': 0.09;
'designation': 0.09; 'meant': 0.09; 'skip:x 10': 0.09; 'treated':
0.09; 'typically': 0.09; 'import': 0.15; 'above)': 0.16;
'argument:': 0.16; 'call,': 0.16; 'command-line': 0.16;
'confusion': 0.16; 'constant': 0.16; 'dict': 0.16; 'incompatible':
0.16; 'object,': 0.16; 'programmer.': 0.16; 'received:10.0.0':
0.16; 'received:64.90': 0.16; 'received:64.90.62': 0.16;
'received:64.90.62.162': 0.16; 'received:dreamhost.com': 0.16;
'yield': 0.16; 'wrote:': 0.16; 'values': 0.17; "can't": 0.17;
'calls': 0.19; 'to:addr:python-list': 0.20; 'language': 0.21;
'written': 0.22; 'code': 0.23; 'skip:p 30': 0.23; "i'd": 0.24;
'anything': 0.25; 'python,': 0.25; 'actual': 0.25; 'saying': 0.25;
'function': 0.27; 'sense': 0.28; 'header:User-Agent:1': 0.30;
'am,': 0.31; 'default': 0.31; 'module': 0.31; 'think': 0.32;
"doesn't": 0.32; 'concerned': 0.32; 'negative': 0.32;
'programmers': 0.32; 'received:10.0': 0.32;
'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'but': 0.32; 'there':
0.33; 'script': 0.33; 'use,': 0.33; 'same': 0.34; 'mean': 0.34;
'header:In-Reply-To:1': 0.34; 'failed': 0.35; 'particularly':
0.35; 'yes,': 0.35; 'functions': 0.36; 'using': 0.37; 'way': 0.38;
'could': 0.38; 'quite': 0.39; 'use': 0.39; 'wrote': 0.39; 'ide':
0.40; 'should': 0.40; 'tell': 0.60; 'skip:b 30': 0.61; 'skip:h
10': 0.61; 'skip:\xc2 10': 0.62; 'come': 0.62; 'key': 0.64;
'definition': 0.64; 'your': 0.64; 'plan': 0.64; 'upon': 0.64;
'less': 0.65; 'lead': 0.67; 'forget': 0.67; 'maximum': 0.67;
'mind.': 0.67; 'header:Received:6': 0.67; 'received:64': 0.67;
'matter': 0.68; 'files:': 0.69; 'analysis': 0.69; 'skip:w 20':
0.69; 'within': 0.69; 'depending': 0.70; 'ignore': 0.71; 'skip:f
30': 0.71; 'product': 0.71; 'global': 0.73; 'relevant': 0.73;
'8bit%:100': 0.76; '....': 0.76; 'cross': 0.76; 'poor': 0.76;
'quick': 0.77; 'comments,': 0.84; 'indicates': 0.84; 'reading,':
0.84; 'warning': 0.84; 'positive': 0.86; 'behind': 0.88;
'consists': 0.93; 'skip:b 50': 0.93
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1668175791; a=rsa-sha256;
cv=none;
b=yNqPKbIISY7weDQSGplH4mXHrkItWLp9HlcHF/jA1EwlEH449crFJOix8ggTbB/w3WHh5y
haNPgX9iW4HHhdLgE7674fxmCelgL4JkzwFf8MQCrkfJOA+8yheId4cmlI2z7kECEEhMNH
8O5qzkSjMXI4JCeL8WMyKKibDsS7yTYbYLYI2sd8cR8zalQiepi9MsT+ag1y1bOPaw8RjO
cDopHnAXFevx1xNWNf+/pz+sHercdOtEY5DYUNqC38El7GNLPqWrL8SN6Ao+oQ5skt7m7G
3sd554j3tM+FREcVEZgyDAMjCXDxvbyaUg3baHV/6U7LtuMSmo0Qk3N5W//zMg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1668175791;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=GlefE9EGAxMUKFci/S9T4Zci0dXQWekLxuPerCEYHx0=;
b=Ms2IFhc1XGOmDYUCvPuG8lEeWAlgaN4dssBBzvuWdOfndpYaE5zJhObfM/1eEfRgXWZGhL
pnG0zaZeAMcoblYgxlurLyroGIe+Bax2f6uyQYjs1ya1Ok8l4PDg9GDvKUDsGJa3Fx1/OS
M9nhyqG0n6M6VkST+itVy/PkLxEJPHqvDZS9oIOxESye1nAinRgXDTUl6lpbYvYhq9TIoI
DCmnjg5dhrEM0uedZWfaDK6UPjV89sBkG01Yei7F7/djJvRIR9Jsu97rTNR8GaMMfFVGA7
4QkNzZmMK9QS72rk86q1VkcQs3KueQPyAJhQMSnFWJ5lSF5TPih4ocl7bM44jA==
ARC-Authentication-Results: i=1; rspamd-7f9bbcf788-bggqn;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Shoe-Society: 52cc9fed28f119bc_1668175791832_257710055
X-MC-Loop-Signature: 1668175791832:1416963030
X-MC-Ingress-Time: 1668175791832
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1668175791;
bh=SWCV5ScvjmqjqnYtBVWXnBe4hqE4Avn/UtgRkOJ6Mc8=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=oKZronM/XPhmsoR4Nz9wYLG+YP3P3VQ2Wh9XVqJKSX5GslvxUSCYNhK8NmdrNcxDv
DE2O4aQqSgZMpdmrB0yENxddplHecUDmJlFQYqMwyaSQybWtMtmdK0GqhtCy4SO7sS
1b4+evHO3UtqB3VfOaDBBN+oeoy4KX+o37NOYFVh/rYwHXWC7QCKVsr7Xiv2jsWT+p
Z6NmqNCBNEa5CV27F8XFk8Hh++rzC/rNHMB96o31ecorkMVe7abN/vk0+I3h0SXgS2
pMsz8zjybQx/C49sZPiTgmiFFgbAmmqoQgpuG9HfD8DBEZpd1Y7q4aU34UeWb8pqej
kIYCTxc2q85nw==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Content-Language: en-US
In-Reply-To: <0eba3f9d-c89c-062e-425a-54aea7216b11@DancesWithMice.info>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <d725dde2-d793-8aad-0f8c-10a7f263f601@tompassin.net>
X-Mailman-Original-References: <0eba3f9d-c89c-062e-425a-54aea7216b11@DancesWithMice.info>
 by: Thomas Passin - Fri, 11 Nov 2022 14:09 UTC

This is a matter of convention. Historically, many language
practitioners got used to using all-caps for key constants. This makes
it easier to tell when you are using (or misusing) one, for one thing.

For myself, I also will use all-caps for quasi-constants, ones that are
set only once, for example from command-line parameters.

In your example,I would not use all-caps for the formal parameter in the
function definition. I would have written

def build_product_prices_dictionary(workbook_definitions:dict )->dict:
....
price_array = xl.iget_array(
file_name=workbook_definitions[ "file_name" ],

There is no value in making a formal parameter's name be all-caps, since
even if it were the same string as an actual global parameter, it would
not mean that actual parameter: it is only a placeholder. There could
even be a negative consequence, because later you might forget and think
that the formal parameter's name meant that the global parameter would
be used automatically in the function call, as if it were a default
parameter. At a minimum, this could lead to confusion about your
intent, at a maximum it could end up being a bug.

Perhaps you wrote it that way as a reminder which dict to use. If so,
that kind of information would better go into the docstring:

def build_product_prices_dictionary(workbook_definitions:dict) -> dict:
"""Return a dictionary of product prices given their definitions.

ARGUMENT
workbook_definitions -- a dict of product definitions, typically
the global WORKBOOK_DEFINITIONS.
"""
# ...

Alternatively, you could make the global be the default for the argument:

def build_product_prices_dictionary(workbook_definitions:dict =
WORKBOOK_DEFINITIONS)->dict:

This might or might not make sense depending on how you plan to use the
function.

So basically, PyCharm is suggesting that you use a clearer, less
problem-prone style of naming. I'd heed the advice. It would also be
in line with what many other programmers are used to reading, and that's
a positive advantage.

On 11/11/2022 3:54 AM, dn wrote:
> PyCharm is warning against using an identifier of all upper-case letters
> as a function's parameter, saying "Argument name should be lowercase".
> (weak, code smell)
>
>
> The application consists of three+ files:
> - configuration
> - mainline script
> - module of workbook functions
>
> The mainline reads the configuration parameters to set the application's
> environment. All of the config/settings are constants. Some of them
> appear as a dictionary (PRICES_WORKBOOK) defining a workbook's
> (spreadsheet's) parameters, eg the filename, which work-sheet to use, etc.
>
>
> The mainline calls the relevant functions from within the module,
> as-needed:-
>
> import prices_workbook as pw
> ...
> product_prices = pw.build_product_prices_dictionary( PRICES_WORKBOOK )
>
>
> The module's function definition is:
>
> def build_product_prices_dictionary( WORKBOOK_DEFINITIONS:dict )->dict:
> ...
>     price_array = xl.iget_array(
>         file_name=WORKBOOK_DEFINITIONS[ "file_name" ],
>         ...
>
> (the function def is flagged, as above)
>
>
> A quick scan of PEP-008 failed to yield anything relevant. Why is this
> frowned upon as poor Python, or a matter of style?
>
> Yes, a dict is mutable, but the upper-case denoting a constant indicates
> that none of its values are to be changed by the programmer.
>
> As far as the function is concerned, the dict and its contents are
> constants.
> (but the dict can't be treated as a global ENV[IRONMENT] object, because
> it has to cross into the module's namespace)
>
>
> Is passing the dict as an argument/parameter considered to be
> incompatible with its designation as a constant?
>
> Perhaps the style should be more enum-like, ie the dict's name in
> lower-case, with the key-named in upper case, eg
>
>     workbook_definitions[ "FILE_NAME" ]
>
>
> Am not particularly concerned by the IDE raising this as a 'problem' -
> will quite happily ignore and carry-on; but am curious as to the logic
> behind the analysis - and why it doesn't come readily to mind.
>
> Advice, comments, critique welcome!
>

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor