Skip to content

Commit a083c56

Browse files
committed
renamed project to align with conventions
1 parent 202092a commit a083c56

2 files changed

Lines changed: 31 additions & 9 deletions

File tree

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ This implementation supports string interpolation, so it's easy to reference var
1414
Pip:
1515

1616
```bash
17-
pip install python-nameof
17+
pip install python_nameof
1818
```
1919

2020
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.
2121

2222
```bash
23-
uv add python-nameof
23+
uv add python_nameof
2424
```
2525

2626
## Usage
@@ -37,6 +37,27 @@ foo = 123
3737
nameof(foo) # Output: 'foo'
3838
```
3939

40+
You can test it in a simple refactoring operation. For example:
41+
42+
```python
43+
def print_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+
def print_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+
4061
### Additional Parameters
4162

4263
The `nameof` function supports two optional parameters for formatting the output:
@@ -58,12 +79,13 @@ nameof(some_param, "`", "_") # Output: '`some param`'
5879
This is useful when generating Markdown documentation or error messages:
5980

6081
```python
61-
def validate(some_param):
62-
if some_param < 0:
63-
# Prints: The parameter `someparam` must be positive.
64-
print(f"The parameter {nameof(some_param, wrap_in_chars='`', replace_with_whitespace='_')} must be positive.")
82+
def print_variables(temperature_celsius: int)
83+
print(f"The parameter {nameof(temperature_celsius, "`", "_")} is: {temperature_celsius}")
6584
```
6685

86+
This will plot a nicely formatted markdown, useful if you do logging in markdown:
87+
> The parameter `temperature celsius` is: 34
88+
6789

6890
### Multiple assignments
6991

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ requires = ["setuptools>=61.0"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
6-
name = "python-nameof"
7-
version = "2.0.0"
6+
name = "python_nameof"
7+
version = "2.0.2"
88
description = "A Python implementation of the C# nameof operator."
99
authors = [
1010
{ name="Alessio Lombardi", email="work@alelom.com" }
@@ -20,7 +20,7 @@ classifiers = [
2020
dependencies = []
2121

2222
[project.urls]
23-
Homepage = "https://github.com/alelom/python-nameof"
23+
Homepage = "https://github.com/alelom/python_nameof"
2424

2525
[tool.setuptools]
2626
packages = ["nameof"]

0 commit comments

Comments
 (0)