Skip to content

Commit

Permalink
fix: accept PathLike in Language()
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Mar 26, 2024
1 parent 30d3660 commit 5d52ace
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
10 changes: 5 additions & 5 deletions tree_sitter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -120,24 +120,24 @@ 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()
elif isinstance(path_or_ptr, int):
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:
Expand Down

0 comments on commit 5d52ace

Please sign in to comment.