Skip to content

Commit 5d52ace

Browse files
fix: accept PathLike in Language()
1 parent 30d3660 commit 5d52ace

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "tree-sitter"
7-
version = "0.21.2"
7+
version = "0.21.3"
88
description = "Python bindings for the Tree-Sitter parsing library"
99
keywords = ["incremental", "parsing", "tree-sitter"]
1010
classifiers = [

tree_sitter/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from ctypes import c_void_p, cdll
44
from enum import IntEnum
5-
from os import path
5+
from os import PathLike, fspath, path
66
from platform import system
77
from tempfile import TemporaryDirectory
88
from typing import List, Optional, Union
@@ -120,24 +120,24 @@ def build_library(output_path: str, repo_paths: List[str]) -> bool:
120120
)
121121
return True
122122

123-
def __init__(self, path_or_ptr: Union[str, int], name: str):
123+
def __init__(self, path_or_ptr: Union[PathLike, str, int], name: str):
124124
"""
125125
Load the language with the given language pointer from the dynamic library,
126126
or load the language with the given name from the dynamic library at the
127127
given path.
128128
"""
129-
if isinstance(path_or_ptr, str):
129+
if isinstance(path_or_ptr, (str, PathLike)):
130130
_deprecate("Language(path, name)", "Language(ptr, name)")
131131
self.name = name
132-
self.lib = cdll.LoadLibrary(path_or_ptr)
132+
self.lib = cdll.LoadLibrary(fspath(path_or_ptr))
133133
language_function = getattr(self.lib, "tree_sitter_%s" % name)
134134
language_function.restype = c_void_p
135135
self.language_id = language_function()
136136
elif isinstance(path_or_ptr, int):
137137
self.name = name
138138
self.language_id = path_or_ptr
139139
else:
140-
raise TypeError("Expected a string or int for the first argument")
140+
raise TypeError("Expected a path or pointer for the first argument")
141141

142142
@property
143143
def version(self) -> int:

0 commit comments

Comments
 (0)