diff --git a/pyproject.toml b/pyproject.toml index fe26649..13d61a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "tree-sitter" -version = "0.21.2" +version = "0.21.3" description = "Python bindings for the Tree-Sitter parsing library" keywords = ["incremental", "parsing", "tree-sitter"] classifiers = [ diff --git a/tree_sitter/__init__.py b/tree_sitter/__init__.py index 86ea7a6..f03cfb4 100644 --- a/tree_sitter/__init__.py +++ b/tree_sitter/__init__.py @@ -2,7 +2,7 @@ from ctypes import c_void_p, cdll from enum import IntEnum -from os import path +from os import PathLike, fspath, path from platform import system from tempfile import TemporaryDirectory from typing import List, Optional, Union @@ -120,16 +120,16 @@ def build_library(output_path: str, repo_paths: List[str]) -> bool: ) return True - def __init__(self, path_or_ptr: Union[str, int], name: str): + def __init__(self, path_or_ptr: Union[PathLike, str, int], name: str): """ Load the language with the given language pointer from the dynamic library, or load the language with the given name from the dynamic library at the given path. """ - if isinstance(path_or_ptr, str): + if isinstance(path_or_ptr, (str, PathLike)): _deprecate("Language(path, name)", "Language(ptr, name)") self.name = name - self.lib = cdll.LoadLibrary(path_or_ptr) + self.lib = cdll.LoadLibrary(fspath(path_or_ptr)) language_function = getattr(self.lib, "tree_sitter_%s" % name) language_function.restype = c_void_p self.language_id = language_function() @@ -137,7 +137,7 @@ def __init__(self, path_or_ptr: Union[str, int], name: str): self.name = name self.language_id = path_or_ptr else: - raise TypeError("Expected a string or int for the first argument") + raise TypeError("Expected a path or pointer for the first argument") @property def version(self) -> int: