Skip to content

Commit a39f4c9

Browse files
authored
0.7.0 (#54)
* Support single-dispatched function for argname() * Fix CI pylint to 2.8.* * 0.7.0 * Raise error when possible wrong frame specified for argname2
1 parent 54075db commit a39f4c9

File tree

15 files changed

+838
-400
lines changed

15 files changed

+838
-400
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Build and Deploy
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
release:
6+
types: [published]
47

58
jobs:
69

@@ -19,34 +22,34 @@ jobs:
1922
- name: Install dependencies
2023
run: |
2124
python -m pip install --upgrade pip
22-
python -m pip install pylint
25+
python -m pip install pylint=='2.8.*'
2326
python -m pip install poetry
27+
poetry config virtualenvs.create false
2428
poetry install -v
2529
- name: Run pylint
2630
run: pylint varname
2731
- name: Test with pytest
28-
run: poetry run pytest tests/ --junitxml=junit/test-results-${{ matrix.python-version }}.xml
32+
run: pytest tests/ --junitxml=junit/test-results-${{ matrix.python-version }}.xml
2933
- name: Upload pytest test results
3034
uses: actions/upload-artifact@v2
3135
with:
3236
name: pytest-results-${{ matrix.python-version }}
3337
path: junit/test-results-${{ matrix.python-version }}.xml
3438
# Use always() to always run this step to publish test results when there are test failures
3539
if: ${{ always() }}
36-
- name: Run codacy-coverage-reporter
37-
uses: codacy/codacy-coverage-reporter-action@master
38-
if: matrix.python-version == 3.8
39-
with:
40-
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
41-
coverage-reports: .coverage.xml
40+
- name: Upload Coverage
41+
run: |
42+
export CODACY_PROJECT_TOKEN=${{ secrets.CODACY_PROJECT_TOKEN }}
43+
bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r .coverage.xml
44+
if: matrix.python-version == 3.7
4245

4346
deploy:
4447
needs: build
4548
runs-on: ubuntu-latest
46-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
49+
if: github.event_name == 'release'
4750
strategy:
4851
matrix:
49-
python-version: [3.8]
52+
python-version: [3.9]
5053
steps:
5154
- uses: actions/checkout@v2
5255
- name: Setup Python # Set Python version

.pylintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ disable=print-statement,
158158
not-callable,
159159
unsubscriptable-object,
160160
unused-arguments,
161-
fixme
161+
fixme,
162+
consider-using-dict-items,
163+
C0330
162164

163165
# Enable the message, report, category or checker with the given id(s). You can
164166
# either give multiple identifier separated by comma (,) or put this option

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ pip install -U varname
2020
- Retrieving names of variables a function/class call is assigned to from inside it, using `varname`.
2121
- Retrieving variable names directly, using `nameof`
2222
- Detecting next immediate attribute name, using `will`
23-
- Fetching argument names/sources passed to a function using `argname`
23+
- Fetching argument names/sources passed to a function using `argname2`
24+
(`argname` is superseded by `argname2`)
2425

2526
- Other helper APIs (built based on core features):
2627

@@ -257,28 +258,28 @@ awesome.permit() # AttributeError: Should do something with AwesomeClass object
257258
awesome.permit().do() == 'I am doing!'
258259
```
259260

260-
### Fetching argument names/sources using `argname`
261+
### Fetching argument names/sources using `argname2`
261262
```python
262-
from varname import argname
263+
from varname import argname2
263264

264265
def func(a, b=1):
265-
print(argname(a))
266+
print(argname2('a'))
266267

267268
x = y = z = 2
268269
func(x) # prints: x
269270

270271
def func2(a, b=1):
271-
print(argname(a, b))
272+
print(argname2('a', 'b'))
272273
func2(y, b=x) # prints: ('y', 'x')
273274

274275
# allow expressions
275276
def func3(a, b=1):
276-
print(argname(a, b, vars_only=False))
277+
print(argname2('a', 'b', vars_only=False))
277278
func3(x+y, y+x) # prints: ('x+y', 'y+x')
278279

279280
# positional and keyword arguments
280281
def func4(*args, **kwargs):
281-
print(argname(args[1], kwargs['c']))
282+
print(argname2('args[1]', 'kwargs["c"]'))
282283
func4(y, x, c=z) # prints: ('x', 'z')
283284
```
284285

@@ -353,9 +354,9 @@ For example:
353354
[9]: https://img.shields.io/github/workflow/status/pwwang/python-varname/Build%20Docs?label=docs&style=flat-square
354355
[10]: https://img.shields.io/github/workflow/status/pwwang/python-varname/Build%20and%20Deploy?style=flat-square
355356
[11]: https://mybinder.org/v2/gh/pwwang/python-varname/dev?filepath=playground%2Fplayground.ipynb
356-
[12]: https://img.shields.io/codacy/grade/ed851ff47b194e3e9389b2a44d6f21da?style=flat-square
357-
[13]: https://app.codacy.com/manual/pwwang/python-varname/dashboard
358-
[14]: https://img.shields.io/codacy/coverage/ed851ff47b194e3e9389b2a44d6f21da?style=flat-square
357+
[12]: https://img.shields.io/codacy/grade/6fdb19c845f74c5c92056e88d44154f7?style=flat-square
358+
[13]: https://app.codacy.com/gh/pwwang/python-varname/dashboard
359+
[14]: https://img.shields.io/codacy/coverage/6fdb19c845f74c5c92056e88d44154f7?style=flat-square
359360
[15]: https://pwwang.github.io/python-varname/api/varname
360361
[16]: https://pwwang.github.io/python-varname/CHANGELOG/
361362
[17]: https://img.shields.io/gitter/room/pwwang/python-varname?style=flat-square

README.rst

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
:target: https://img.shields.io/github/workflow/status/pwwang/python-varname/Build%20Docs?label=docs&style=flat-square
2828
:alt: Docs and API
2929
<https://pwwang.github.io/python-varname/api/varname>`_ `
30-
.. image:: https://img.shields.io/codacy/grade/ed851ff47b194e3e9389b2a44d6f21da?style=flat-square
31-
:target: https://img.shields.io/codacy/grade/ed851ff47b194e3e9389b2a44d6f21da?style=flat-square
30+
.. image:: https://img.shields.io/codacy/grade/6fdb19c845f74c5c92056e88d44154f7?style=flat-square
31+
:target: https://img.shields.io/codacy/grade/6fdb19c845f74c5c92056e88d44154f7?style=flat-square
3232
:alt: Codacy
33-
<https://app.codacy.com/manual/pwwang/python-varname/dashboard>`_ `
34-
.. image:: https://img.shields.io/codacy/coverage/ed851ff47b194e3e9389b2a44d6f21da?style=flat-square
35-
:target: https://img.shields.io/codacy/coverage/ed851ff47b194e3e9389b2a44d6f21da?style=flat-square
33+
<https://app.codacy.com/gh/pwwang/python-varname/dashboard>`_ `
34+
.. image:: https://img.shields.io/codacy/coverage/6fdb19c845f74c5c92056e88d44154f7?style=flat-square
35+
:target: https://img.shields.io/codacy/coverage/6fdb19c845f74c5c92056e88d44154f7?style=flat-square
3636
:alt: Codacy coverage
37-
<https://app.codacy.com/manual/pwwang/python-varname/dashboard>`_
37+
<https://app.codacy.com/gh/pwwang/python-varname/dashboard>`_
3838
`
3939
.. image:: https://img.shields.io/gitter/room/pwwang/python-varname?style=flat-square
4040
:target: https://img.shields.io/gitter/room/pwwang/python-varname?style=flat-square
@@ -63,7 +63,8 @@ Features
6363
* Retrieving names of variables a function/class call is assigned to from inside it, using ``varname``.
6464
* Retrieving variable names directly, using ``nameof``
6565
* Detecting next immediate attribute name, using ``will``
66-
* Fetching argument names/sources passed to a function using ``argname``
66+
* Fetching argument names/sources passed to a function using ``argname2``
67+
(\ ``argname`` is superseded by ``argname2``\ )
6768

6869
*
6970
Other helper APIs (built based on core features):
@@ -324,31 +325,31 @@ Detecting next immediate attribute name
324325
awesome.permit() # AttributeError: Should do something with AwesomeClass object
325326
awesome.permit().do() == 'I am doing!'
326327
327-
Fetching argument names/sources using ``argname``
328-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
328+
Fetching argument names/sources using ``argname2``
329+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
329330

330331
.. code-block:: python
331332
332-
from varname import argname
333+
from varname import argname2
333334
334335
def func(a, b=1):
335-
print(argname(a))
336+
print(argname2('a'))
336337
337338
x = y = z = 2
338339
func(x) # prints: x
339340
340341
def func2(a, b=1):
341-
print(argname(a, b))
342+
print(argname2('a', 'b'))
342343
func2(y, b=x) # prints: ('y', 'x')
343344
344345
# allow expressions
345346
def func3(a, b=1):
346-
print(argname(a, b, vars_only=False))
347+
print(argname2('a', 'b', vars_only=False))
347348
func3(x+y, y+x) # prints: ('x+y', 'y+x')
348349
349350
# positional and keyword arguments
350351
def func4(*args, **kwargs):
351-
print(argname(args[1], kwargs['c']))
352+
print(argname2('args[1]', 'kwargs["c"]'))
352353
func4(y, x, c=z) # prints: ('x', 'z')
353354
354355
Value wrapper

docs/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## v0.7.0
2+
- `ImproperUseError` is now independent of `VarnameRetrievingError`
3+
- Deprecate `argname`, superseded by `argname2`
4+
```python
5+
>>> argname(a, b, ...) # before
6+
>>> argname2('a', 'b', ...) # after
7+
```
8+
- Add `dispatch` argument to `argname`/`argment2` to be used for single-dispatched functions.
9+
110
## v0.6.5
211
- Add `sep` argument to `helpers.debug()`
312

0 commit comments

Comments
 (0)