ppannuto / python-titlecase

Python library to capitalize strings as specified by the New York Times Manual of Style
MIT License
244 stars 36 forks source link

Can't import 2.1.0 #82

Closed marban closed 3 years ago

marban commented 3 years ago

Getting something like the below right after import:

/lib/python3.8/site-packages/titlecase/__init__.py", line 29, in <module>
    INLINE_PERIOD = regex.compile(r'[\p{Letter}][.][\p{Letter}]', regex.I)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/re.py", line 252, in compile
    return _compile(pattern, flags)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/sre_parse.py", line 554, in _parse
    code1 = _class_escape(source, this)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/sre_parse.py", line 349, in _class_escape
    raise source.error('bad escape %s' % escape, len(escape))
re.error: bad escape \p at position 1
fireundubh commented 3 years ago

Unfortunately, titlecase now requires regex to be installed.

ppannuto commented 3 years ago

There was some work on this in #75, I thought regex was sufficiently made optional. If that's not the case, happy to take a PR that goes the rest of the way.

sbue commented 3 years ago

Same here 👍

fireundubh commented 3 years ago

@ppannuto re doesn't support \p.

brocksam commented 3 years ago

Hi all,

2.1.0 has unfortunately broken a number of my packages upstream so I am keen we get this sorted ASAP.

@fireundubh has hit the nail on the head with why attempting to use 're' in place of 'regex' has causes this issue. There is good reason why 'regex' exists in the first place as it provides significantly better support for regular expressions with Unicode than 're' does.

I have spent this afternoon trying to implement a fix to the problems introduced by PR #76 on my fork. I have attempted to allow both 're' and 'regex' to be used. However, getting 're' to work without \p is proving problematic and not the correct way approach this IMO.

I think:

I'm not apportioning blame here, just trying to help us get this fixed ASAP 🙂

ppannuto commented 3 years ago

I just pushed v2.2 to PyPI with the combined fixes from #84. Apologies again for the breakage and thank you for the quick fixes!!