Skip to content

Commit 48d8165

Browse files
per PR comment: move Python 2 is_identifier replacement from _main_legacy_py.py to main.py
1 parent be712d9 commit 48d8165

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

src/makefun/_main_legacy_py.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,3 @@ def get_legacy_py_generator_body_template():
8888
# else:
8989
_y = _i.send(_s) # let the implementation decide if None means "no new input" or "new input = None"
9090
"""
91-
92-
93-
def is_identifier(string):
94-
"""
95-
Replacement for `str.isidentifier` when it is not available (e.g. on Python 2).
96-
:param string:
97-
:return:
98-
"""
99-
if len(string) == 0 or string[0].isdigit():
100-
return False
101-
return all([s.isalnum() for s in string.split("_")])

src/makefun/main.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
from types import FunctionType
1717

1818

19+
if sys.version_info >= (3, 0):
20+
is_identifier = str.isidentifier
21+
else:
22+
def is_identifier(string):
23+
"""
24+
Replacement for `str.isidentifier` when it is not available (e.g. on Python 2).
25+
:param string:
26+
:return:
27+
"""
28+
if len(string) == 0 or string[0].isdigit():
29+
return False
30+
return all([s.isalnum() for s in string.split("_")])
31+
1932
try: # python 3.3+
2033
from inspect import signature, Signature, Parameter
2134
except ImportError:
@@ -1558,9 +1571,3 @@ def compile_fun_manually(target,
15581571
new_f.__source__ = source_lines
15591572

15601573
return new_f
1561-
1562-
1563-
if sys.version_info >= (3, 0):
1564-
is_identifier = str.isidentifier
1565-
else:
1566-
from makefun._main_legacy_py import is_identifier

0 commit comments

Comments
 (0)