Skip to content

Commit

Permalink
Migrated from deprecated open_text method to modern importlib_resourc…
Browse files Browse the repository at this point in the history
…es.files API
  • Loading branch information
sveinbjornt committed Aug 23, 2024
1 parent 491a765 commit 7f5c92b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/tokenizer/abbrev.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

from threading import Lock
from collections import defaultdict, OrderedDict
from importlib.resources import open_text
import importlib.resources as importlib_resources

from .definitions import BIN_Tuple

Expand Down Expand Up @@ -311,10 +311,11 @@ def initialize():
return

section = None
config = open_text(
package="tokenizer", resource="Abbrev.conf", encoding="utf-8"
) # TODO: Deprecated in Python 3.13
for s in config:

p = importlib_resources.files("tokenizer").joinpath("Abbrev.conf")
config = p.read_text(encoding="utf-8")

for s in config.split("\n"):
# Ignore comments
ix = s.find("#")
if ix >= 0:
Expand Down
2 changes: 1 addition & 1 deletion src/tokenizer/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ def parse_mixed(

# Check for currency abbreviations immediately followed by a number
if len(rt.txt) > 3 and rt.txt[0:3] in CURRENCY_ABBREV and rt.txt[3].isdigit():
# XXX: This feels a little hacky
# TODO: This feels a little hacky
temp_tok = Tok(TOK.RAW, rt.txt[3:], None)
digit_tok, _ = parse_digits(temp_tok, convert_numbers)
if digit_tok.kind == TOK.NUMBER:
Expand Down

0 comments on commit 7f5c92b

Please sign in to comment.