Skip to content

Commit

Permalink
Merge pull request #92 from smarie/feature/91_identifier_python2
Browse files Browse the repository at this point in the history
Fixed `ValueError: Invalid co_name` on python 2
  • Loading branch information
smarie committed Feb 23, 2023
2 parents 362eb4f + 10f9108 commit 3407739
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### 1.15.1 - bugfixes

- Fixed `ValueError: Invalid co_name` happening on python 2 when the name of a function to create starts or ends with
`_` or contains a double `__` . Fixes [#91](https://github.com/smarie/python-makefun/issues/91)

### 1.15.0 - More PEP-compliant `wraps`

- `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).
Expand Down
2 changes: 1 addition & 1 deletion src/makefun/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def is_identifier(string):
"""
if len(string) == 0 or string[0].isdigit():
return False
return all([s.isalnum() for s in string.split("_")])
return all([(len(s) == 0) or s.isalnum() for s in string.split("_")])

try: # python 3.3+
from inspect import signature, Signature, Parameter
Expand Down
9 changes: 8 additions & 1 deletion tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import pytest

from makefun.main import is_identifier

try: # python 3.3+
from inspect import signature, Signature, Parameter
except ImportError:
Expand Down Expand Up @@ -254,7 +256,6 @@ def test_issue_77_async_generator_partial():
assert asyncio.get_event_loop().run_until_complete(asyncio.ensure_future(f_partial().__anext__())) == 1



@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.")
def test_issue_85_wrapped_forwardref_annotation():
import typing
Expand All @@ -274,3 +275,9 @@ def wrapper(**kwargs):
"return": _issue_85_module.ForwardRef,
}
assert typing.get_type_hints(wrapper) == expected_annotations


def test_issue_91():
"""This test should work also in python 2 ! """
assert is_identifier("_results_bag")
assert is_identifier("hello__bag")

0 comments on commit 3407739

Please sign in to comment.