Skip to content

Commit

Permalink
Fix code explosion from long enum in Python 3, Cython 0.24+
Browse files Browse the repository at this point in the history
  • Loading branch information
honnibal committed Sep 16, 2017
1 parent 8a829eb commit 11f2a05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spacy/symbols.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cpdef enum symbol_t:
cdef enum symbol_t:
NIL
IS_ALPHA
IS_ASCII
Expand Down
11 changes: 10 additions & 1 deletion spacy/symbols.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# coding: utf8
#cython: optimize.unpack_method_calls=False

from __future__ import unicode_literals

IDS = {
Expand Down Expand Up @@ -458,4 +460,11 @@ IDS = {
"xcomp": xcomp
}

NAMES = [it[0] for it in sorted(IDS.items(), key=lambda it: it[1])]
def sort_nums(x):
return x[1]

NAMES = [it[0] for it in sorted(IDS.items(), key=sort_nums)]
# Unfortunate hack here, to work around problem with long cpdef enum
# (which is generating an enormous amount of C++ in Cython 0.24+)
# We keep the enum cdef, and just make sure the names are available to Python
locals().update(IDS)

0 comments on commit 11f2a05

Please sign in to comment.