문제 설명
Python 3.12 이상 버전에서 soynlp를 import할 때 다음과 같은 SyntaxWarning이 발생합니다:
SyntaxWarning: "\w" is an invalid escape sequence. Did you mean "\w"? A raw string is
also an option.
SyntaxWarning: "is" with 'str' literal. Did you mean "=="?
Python 3.12부터 invalid escape sequence가 DeprecationWarning에서 SyntaxWarning으로
격상되었으며, 향후 버전에서는 SyntaxError로 변경될 예정입니다.
환경
- Python 버전: 3.14
- soynlp 버전: 0.0.493
- OS: macOS
영향받는 파일
1. Invalid Escape Sequence (raw string 미사용)
| 파일 |
라인 |
문제 코드 |
soynlp/tokenizer/_normalizer.py |
7-10 |
re.compile('(\w...)\\1{3,}') |
soynlp/normalizer/_normalizer.py |
10-11 |
re.compile('\s+'), |
re.compile('(\w)\\1{3,}') |
|
|
soynlp/hangle/_hangle.py |
41-42 |
re.compile('\s+'), re.compile('(\w)\\1{3,}') |
|
| soynlp/tokenizer/_tokenizer.py | 15, 22 | re.compile(u'[-+]?\d*...'),
re.compile('\s+') |
2. is 연산자와 문자열 리터럴 비교
| 파일 |
라인 |
문제 코드 |
soynlp/predicator/_predicator.py |
486, 489 |
if answer is 'Verb':, `if answer is |
| 'Adjective':` |
|
|
수정 제안
- 정규식 패턴에 raw string prefix
r 추가:
# 수정 전
re.compile('(\w)\\1{3,}')
# 수정 후
re.compile(r'(\w)\1{3,}')
- 문자열 비교에 == 연산자 사용:
수정 전
if answer is 'Verb':
수정 후
if answer == 'Verb':
참고
문제 설명
Python 3.12 이상 버전에서 soynlp를 import할 때 다음과 같은 SyntaxWarning이 발생합니다:
SyntaxWarning: "\w" is an invalid escape sequence. Did you mean "\w"? A raw string is
also an option.
SyntaxWarning: "is" with 'str' literal. Did you mean "=="?
Python 3.12부터 invalid escape sequence가 DeprecationWarning에서 SyntaxWarning으로
격상되었으며, 향후 버전에서는 SyntaxError로 변경될 예정입니다.
환경
영향받는 파일
1. Invalid Escape Sequence (raw string 미사용)
soynlp/tokenizer/_normalizer.pyre.compile('(\w...)\\1{3,}')soynlp/normalizer/_normalizer.pyre.compile('\s+'),re.compile('(\w)\\1{3,}')soynlp/hangle/_hangle.pyre.compile('\s+'),re.compile('(\w)\\1{3,}')|
|
soynlp/tokenizer/_tokenizer.py| 15, 22 |re.compile(u'[-+]?\d*...'),re.compile('\s+')|2.
is연산자와 문자열 리터럴 비교soynlp/predicator/_predicator.pyif answer is 'Verb':, `if answer is수정 제안
r추가:수정 전
if answer is 'Verb':
수정 후
if answer == 'Verb':
참고
문제가 해결되면 많은 사용자에게 도움이 될 것입니다.