-
Notifications
You must be signed in to change notification settings - Fork 23
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
overload type returns for nameof #77
Comments
Are you using python 3.11? All the cases worked with python3.10: bpython version 0.22.1 on top of Python 3.10.0 /path/to/python
>>> from varname import nameof
>>> from typing import Tuple
>>> foo = "..."
>>> x1: str = nameof(foo)
>>> x2: Tuple[str, ...] = nameof(foo)
>>> x3: Tuple[str, ...] | str = nameof(foo)
>>> x1
'foo'
>>> x2
'foo'
>>> x3
'foo' Python 3.11 is not fully supported yet. |
@pwwang yes I am using the 3.10 It work, but the pylance/pyright type check gives the error |
Maybe we can consider separating it into You can temporarily disable the type check on that line with |
|
After some experiments, the following works: @overload
def nameof(
var: Any,
more_var: Any,
/, # <-------
*more_vars: Any,
) -> Tuple[str, ...]:
...
@overload
def nameof(
var: Any,
) -> str:
...
def nameof(
var: Any,
*more_vars: Any,
) -> str | Tuple[str, ...]:
... However, |
Link commit 1a4c450 |
the
nameof
always return an union, it makes it hard to use in places where we just want a stringwould be great to have an overload to only return
Tuple
when more names are passed,or maybe a new deterministic one var function?
The text was updated successfully, but these errors were encountered: