You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-6Lines changed: 28 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,13 +14,13 @@ This implementation supports string interpolation, so it's easy to reference var
14
14
Pip:
15
15
16
16
```bash
17
-
pip install python-nameof
17
+
pip install python_nameof
18
18
```
19
19
20
20
My recommendation is to always use [`uv`](https://docs.astral.sh/uv/) instead of pip – I personally think it's the best package and environment manager for Python.
21
21
22
22
```bash
23
-
uv add python-nameof
23
+
uv add python_nameof
24
24
```
25
25
26
26
## Usage
@@ -37,6 +37,27 @@ foo = 123
37
37
nameof(foo) # Output: 'foo'
38
38
```
39
39
40
+
You can test it in a simple refactoring operation. For example:
41
+
42
+
```python
43
+
defprint_variables(temperature: int)
44
+
print(f"The parameter {nameof(temperature)} is: {temperature}")
45
+
```
46
+
47
+
> The parameter temperature is: 34
48
+
49
+
If you refactor (_e.g. VSCode: press **F2** on the variable name_) the input parameter from `temperature` to `temperature_celsius`, you will get:
50
+
```python
51
+
defprint_variables(temperature_celsius: int)
52
+
print(f"The parameter {nameof(temperature_celsius)} is: {temperature_celsius}")
53
+
```
54
+
55
+
So the _printed name follows the name of the actual parameter after a refactor_.
56
+
57
+
> The parameter temperature_celsius is: 34
58
+
59
+
60
+
40
61
### Additional Parameters
41
62
42
63
The `nameof` function supports two optional parameters for formatting the output:
0 commit comments