-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to migrate away from 'nameof'? #117
Comments
What do you think this will return:
|
I think
["ftdi_install", "ftdi_uninstall", 'serial_install", "serial_uninstall"]
That is, nameof maps arg references to arg names.
…On Sat, Dec 21, 2024 at 8:04 PM pwwang ***@***.***> wrote:
What do you think this will return:
nameof(ftdi_install, ftdi_uninstall, serial_install, serial_uninstall)?
—
Reply to this email directly, view it on GitHub
<#117 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQVMQK2ELRSO4GDTNUVGZL2GY23TAVCNFSM6AAAAABUBHXWU2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNJYGMZDEMBWGI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
So then why not just use |
Because the IDE and tools like linters will not be aware of the association |
I don't get it. If you change, say, def cli(
cmd_ctx: click.core.Context,
# Options:
ftdi_install2: bool,
ftdi_uninstall: bool,
serial_install: bool,
serial_uninstall: bool,
):
"""Implements the drivers command."""
# User should select exactly on of these operations.
cmd_util.check_exactly_one_param(
cmd_ctx,
["ftdi_install2", "ftdi_uninstall", "serial_install", "serial_uninstall"),
) |
The tools will not complain that there is no arg called
|
I am still confused. Why did you put |
To demonstrate a mismatch (e.g. a typo) between the arg name and the string. If instead of |
I see what you meant. But I am not convinced that from varname import argname
def my_nameof(*args):
return argname('*args')
a = b = 1
my_nameof(a, b) # ('a', 'b') |
You can look at the code in the link below. All the places that argument |
What you referred to as "associated" or "isolated" is merely due to the help of the IDE, rather than being based on the code itself. |
Thanks! I will give it a try.
I believe that they are associated by the semantics of python, because they
are two references to the same semantic construct. On the other hand, two
variables x in different functions are considered independent of each
other. The tools just follow the semantic of the language.
…On Sat, Dec 21, 2024 at 10:50 PM pwwang ***@***.***> wrote:
What you referred to as "associated" or "isolated" is merely due to the
help of the IDE, rather than being based on the code itself.
—
Reply to this email directly, view it on GitHub
<#117 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQVMQLLOWDIE5YMM4MCB3D2GZOM3AVCNFSM6AAAAABUBHXWU2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNJYGM2TENRRGY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
You are correct, and that is the foundation of the IDE. I won’t argue about code style. However, |
I implemented I just had to rename |
We have a code similar to the one below where we use
nameof
to convert arg names to strings. The advantage is that the ide tools are aware of the relation between the function args and nameof's args (e.g. when renaming or linting).We tried to upgrade to the latest varname version and get a warning that we should use argname() instead but it seems to require the name of the arg a a string which defeats the reason we use varname.
Are we missing anything? What is the use case of argname() if the user requires to provide the arg name string?
The text was updated successfully, but these errors were encountered: