Skip to content

Commit 3407739

Browse files
authored
Merge pull request #92 from smarie/feature/91_identifier_python2
Fixed `ValueError: Invalid co_name` on python 2
2 parents 362eb4f + 10f9108 commit 3407739

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

docs/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
### 1.15.1 - bugfixes
4+
5+
- Fixed `ValueError: Invalid co_name` happening on python 2 when the name of a function to create starts or ends with
6+
`_` or contains a double `__` . Fixes [#91](https://github.com/smarie/python-makefun/issues/91)
7+
38
### 1.15.0 - More PEP-compliant `wraps`
49

510
- `wraps` now always sets the `__wrapped__` attribute, and also sets the `__signature__` attribute when the signature changes, as specified by PEP 362. PR []() by [#86](https://github.com/smarie/python-makefun/pull/86) by [lucaswiman](https://github.com/lucaswiman).

src/makefun/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def is_identifier(string):
2727
"""
2828
if len(string) == 0 or string[0].isdigit():
2929
return False
30-
return all([s.isalnum() for s in string.split("_")])
30+
return all([(len(s) == 0) or s.isalnum() for s in string.split("_")])
3131

3232
try: # python 3.3+
3333
from inspect import signature, Signature, Parameter

tests/test_issues.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import pytest
55

6+
from makefun.main import is_identifier
7+
68
try: # python 3.3+
79
from inspect import signature, Signature, Parameter
810
except ImportError:
@@ -254,7 +256,6 @@ def test_issue_77_async_generator_partial():
254256
assert asyncio.get_event_loop().run_until_complete(asyncio.ensure_future(f_partial().__anext__())) == 1
255257

256258

257-
258259
@pytest.mark.skipif(sys.version_info < (3, 7, 6), reason="The __wrapped__ behavior in get_type_hints being tested was not added until python 3.7.6.")
259260
def test_issue_85_wrapped_forwardref_annotation():
260261
import typing
@@ -274,3 +275,9 @@ def wrapper(**kwargs):
274275
"return": _issue_85_module.ForwardRef,
275276
}
276277
assert typing.get_type_hints(wrapper) == expected_annotations
278+
279+
280+
def test_issue_91():
281+
"""This test should work also in python 2 ! """
282+
assert is_identifier("_results_bag")
283+
assert is_identifier("hello__bag")

0 commit comments

Comments
 (0)