Skip to content

Commit 3fb8eb9

Browse files
committed
_utils.py: port to pure-python syntax
1 parent c753224 commit 3fb8eb9

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ requires = [
44
"setuptools>=36.6.0",
55
# In order to build wheels, and as required by PEP 517
66
"wheel",
7-
"Cython"
7+
"Cython>=3a"
88
]
99
build-backend = "setuptools.build_meta"
1010

src/buildstream/_utils.pyx renamed to src/buildstream/_utils.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
This module contains utilities that have been optimized in Cython
2323
"""
2424

25-
from cpython.pystate cimport PyThreadState_SetAsyncExc
26-
from cpython.ref cimport PyObject
25+
import cython
26+
from cython.cimports.cpython.pystate import PyThreadState_SetAsyncExc
27+
from cython.cimports.cpython.ref import PyObject
2728
from ._signals import TerminateException
2829

2930

30-
def url_directory_name(str url):
31+
def url_directory_name(url: str):
3132
"""Normalizes a url into a directory name
3233
3334
Args:
@@ -47,8 +48,8 @@ def url_directory_name(str url):
4748
# Args:
4849
# thread_id (int): the thread id in which to throw the exception
4950
#
50-
def terminate_thread(long thread_id):
51-
res = PyThreadState_SetAsyncExc(thread_id, <PyObject*> TerminateException)
51+
def terminate_thread(thread_id: cython.long):
52+
res = PyThreadState_SetAsyncExc(thread_id, cython.cast(cython.pointer(PyObject), TerminateException))
5253
assert res == 1
5354

5455

@@ -60,9 +61,9 @@ def terminate_thread(long thread_id):
6061
# Returns:
6162
# (bool): True if all characters are valid, False otherwise.
6263
#
63-
def valid_chars_name(str name):
64-
cdef int char_value
65-
cdef int forbidden_char
64+
def valid_chars_name(name: str):
65+
char_value: cython.int
66+
forbidden_char: cython.int
6667

6768
for char_value in name:
6869
# 0-31 are control chars, 127 is DEL, and >127 means non-ASCII
@@ -96,7 +97,7 @@ def valid_chars_name(str name):
9697
#
9798
# This transforms the value to "_" if is it not a ascii letter, a digit or "%" or "_"
9899
#
99-
cdef Py_UNICODE _transl(Py_UNICODE x):
100+
def _transl(x: cython.Py_UNICODE) -> cython.Py_UNICODE:
100101
if ("a" <= x <= "z") or ("A" <= x <= "Z") or ("0" <= x <= "9") or x == "%":
101102
return x
102103
return "_"

src/buildstream/_utils.pyi

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)