Skip to content

Commit 65e6c54

Browse files
authored
Merge pull request #1218 from PyThaiNLP/copilot/fix-coverage-parser-error
Fix Python 3.13 SyntaxError: global declaration before variable use in tokenizer modules
2 parents 809f271 + 3ed7a6c commit 65e6c54

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

pythainlp/tokenize/budoux.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def segment(text: str) -> list[str]:
4949
return []
5050

5151
# Thread-safe lazy initialization
52+
global _parser
5253
with _parser_lock:
5354
if _parser is None:
54-
global _parser
5555
_parser = _init_parser()
5656
parser = _parser
5757

pythainlp/tokenize/oskut.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def segment(text: str, engine: str = "ws") -> list[str]:
3838
return []
3939

4040
# Thread-safe model loading
41+
global _DEFAULT_ENGINE
4142
with _engine_lock:
4243
if engine != _DEFAULT_ENGINE:
4344
# Need to update global state and reload model
44-
global _DEFAULT_ENGINE
4545
_DEFAULT_ENGINE = engine
4646
oskut.load_model(engine=_DEFAULT_ENGINE)
4747

pythainlp/tokenize/sefr_cut.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def segment(text: str, engine: str = "ws1000") -> list[str]:
3737
return []
3838

3939
# Thread-safe model loading
40+
global _DEFAULT_ENGINE
4041
with _engine_lock:
4142
if engine != _DEFAULT_ENGINE:
4243
# Need to update global state and reload model
43-
global _DEFAULT_ENGINE
4444
_DEFAULT_ENGINE = engine
4545
sefr_cut.load_model(engine=_DEFAULT_ENGINE)
4646

pythainlp/tokenize/wtsplit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def _tokenize(
3333
thread-safety guarantees.
3434
"""
3535
# Thread-safe model loading
36+
global _MODEL, _MODEL_NAME
3637
with _model_lock:
3738
if _MODEL_NAME != model:
38-
global _MODEL, _MODEL_NAME
3939
_MODEL = WtP(model_name_or_model=model)
4040
_MODEL_NAME = model
4141
model_instance = _MODEL

0 commit comments

Comments
 (0)