Skip to content

Commit 821bb86

Browse files
committed
revert: bring nameof back (#117)
1 parent 86236b6 commit 821bb86

File tree

13 files changed

+909
-282
lines changed

13 files changed

+909
-282
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ on:
1010
jobs:
1111

1212
build:
13-
runs-on: ubuntu-24.04
13+
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
python-version: [3.9, "3.10", 3.11, 3.12, 3.13]
16+
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
1717

1818
steps:
1919
- uses: actions/checkout@v4

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,31 @@ Special thanks to [@HanyuuLu][2] to give up the name `varname` in pypi for this
244244
# foo.__varname__ == 'foo'
245245
```
246246

247+
### Getting variable names directly using `nameof`
248+
249+
```python
250+
from varname import varname, nameof
251+
252+
a = 1
253+
nameof(a) # 'a'
254+
255+
b = 2
256+
nameof(a, b) # ('a', 'b')
257+
258+
def func():
259+
return varname() + '_suffix'
260+
261+
f = func() # f == 'f_suffix'
262+
nameof(f) # 'f'
263+
264+
# get full names of (chained) attribute calls
265+
func.a = func
266+
nameof(func.a, vars_only=False) # 'func.a'
267+
268+
func.a.b = 1
269+
nameof(func.a.b, vars_only=False) # 'func.a.b'
270+
```
271+
247272
### Detecting next immediate attribute name
248273

249274
```python

README.raw.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,31 @@ Special thanks to [@HanyuuLu][2] to give up the name `varname` in pypi for this
244244
# foo.__varname__ == {foo.__varname__!r}
245245
```
246246

247+
### Getting variable names directly using `nameof`
248+
249+
```python
250+
from varname import varname, nameof
251+
252+
a = 1
253+
nameof(a) # {_expr!r}
254+
255+
b = 2
256+
nameof(a, b) # {_expr!r}
257+
258+
def func():
259+
return varname() + '_suffix'
260+
261+
f = func() # f == {f!r}
262+
nameof(f) # {_expr!r}
263+
264+
# get full names of (chained) attribute calls
265+
func.a = func
266+
nameof(func.a, vars_only=False) # {_expr!r}
267+
268+
func.a.b = 1
269+
nameof(func.a.b, vars_only=False) # {_expr!r}
270+
```
271+
247272
### Detecting next immediate attribute name
248273

249274
```python

0 commit comments

Comments
 (0)