Skip to content

Commit 2d8bfcd

Browse files
committed
1 parent bb7fcb6 commit 2d8bfcd

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

pint/_vendor/flexparser.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import logging
2828
import pathlib
2929
import re
30+
import sys
3031
import typing as ty
3132
from collections.abc import Iterator
3233
from dataclasses import dataclass
@@ -1058,8 +1059,15 @@ def parse_resource_from_file(
10581059
resource_name
10591060
name of the resource
10601061
"""
1061-
with resources.path(package, resource_name) as p:
1062-
path = p.resolve()
1062+
if sys.version_info < (3, 9):
1063+
# Remove when Python 3.8 is dropped
1064+
with resources.path(package, resource_name) as p:
1065+
path = p.resolve()
1066+
else:
1067+
with resources.as_file(
1068+
resources.files(package).joinpath(resource_name)
1069+
) as p:
1070+
path = p.resolve()
10631071

10641072
if path.exists():
10651073
return self.parse_file(path)
@@ -1076,8 +1084,13 @@ def parse_resource(self, package: str, resource_name: str) -> ParsedSource[RBT,
10761084
resource_name
10771085
name of the resource
10781086
"""
1079-
with resources.open_binary(package, resource_name) as fi:
1080-
content = fi.read()
1087+
if sys.version_info < (3, 9):
1088+
# Remove when Python 3.8 is dropped
1089+
with resources.open_binary(package, resource_name) as fi:
1090+
content = fi.read()
1091+
else:
1092+
with resources.files(package).joinpath(resource_name).open("rb") as fi:
1093+
content = fi.read()
10811094

10821095
bos = BOR(
10831096
Hash.from_bytes(self._hasher, content), package, resource_name

0 commit comments

Comments
 (0)