File tree 3 files changed +13
-4
lines changed 3 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
[flake8]
4
4
exclude =.tox,build,.eggs
5
- ignore =D100,D101
5
+ ignore =D100,D101,W504
6
6
max-line-length =120
7
7
8
8
[isort]
Original file line number Diff line number Diff line change @@ -233,6 +233,9 @@ def variable(self, name):
233
233
234
234
235
235
def cleanup_name (name ):
236
+ """
237
+ Convert name to a allowable identifier
238
+ """
236
239
# See https://docs.python.org/2/reference/lexical_analysis.html#grammar-token-identifier
237
240
name = _IDENTIFIER_SANITIZER_RE .sub ('' , name )
238
241
if not _IDENTIFIER_START_RE .match (name ):
Original file line number Diff line number Diff line change 3
3
from __future__ import absolute_import , unicode_literals
4
4
5
5
import ast
6
+ import builtins
6
7
import keyword
7
8
import textwrap
8
9
import unittest
9
10
10
11
from ast_decompiler .decompiler import Decompiler
11
- from hypothesis import given
12
+ from hypothesis import example , given
12
13
from hypothesis .strategies import text
13
14
14
15
from fluent_compiler import codegen
@@ -45,7 +46,7 @@ def as_source_code(codegen_ast):
45
46
46
47
# Stratgies
47
48
non_keyword_text = text ().filter (lambda t : t not in keyword .kwlist )
48
- non_builtin_text = non_keyword_text .filter (lambda t : t not in dir (__builtins__ ))
49
+ non_builtin_text = non_keyword_text .filter (lambda t : t not in dir (builtins ))
49
50
50
51
51
52
class TestCodeGen (unittest .TestCase ):
@@ -532,8 +533,13 @@ def test_cleanup_name_not_empty(self, t):
532
533
self .assertTrue (len (codegen .cleanup_name (t )) > 0 , " for t = {!r}" .format (t ))
533
534
534
535
@given (non_builtin_text )
536
+ @example ("!$abc<>" )
537
+ @example (":id" )
535
538
def test_cleanup_name_allowed_identifier (self , t ):
536
- self .assertTrue (allowable_name (codegen .cleanup_name (t )), " for t = {!r}" .format (t ))
539
+ cleaned = codegen .cleanup_name (t )
540
+ self .assertTrue (allowable_name (cleaned ) or
541
+ (cleaned in dir (builtins )) or
542
+ keyword .iskeyword (cleaned ), " for t = {!r}" .format (t ))
537
543
538
544
def test_dict_lookup (self ):
539
545
scope = codegen .Scope ()
You can’t perform that action at this time.
0 commit comments