Skip to content

Commit 5cd47e2

Browse files
committed
Use a List
1 parent a373269 commit 5cd47e2

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/singledispatch/mro.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::singledispatch::typeref::PyTypeReference;
33
use crate::singledispatch::typing::TypingModule;
44
use pyo3::exceptions::PyRuntimeError;
55
use pyo3::prelude::*;
6-
use pyo3::types::PyTuple;
6+
use pyo3::types::{PyList, PyTuple};
77
use pyo3::{intern, Bound, PyObject, PyResult, Python};
88
use std::borrow::Borrow;
99
use std::cmp::Reverse;
@@ -37,7 +37,7 @@ fn get_obj_bases(cls: &Bound<'_, PyAny>) -> PyResult<Vec<PyTypeReference>> {
3737
fn get_obj_subclasses(cls: &Bound<'_, PyAny>) -> PyResult<HashSet<PyTypeReference>> {
3838
let subclasses: HashSet<_> = cls
3939
.call_method0(intern!(cls.py(), "__subclasses__"))?
40-
.downcast::<PyTuple>()?
40+
.downcast::<PyList>()?
4141
.iter()
4242
.map(|item| PyTypeReference::new(item.unbind()))
4343
.collect();

tests/test_singledispatch_native.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from collections.abc import Sequence
2+
13
import pytest
24
from singledispatch_native import singledispatch
35

@@ -18,13 +20,27 @@ def _some_fun_str(o: int) -> str:
1820
return "It's an int!"
1921

2022

23+
@some_fun.register(Sequence)
24+
def _some_fun_sequence(l: Sequence) -> str:
25+
return "Sequence: " + ", ".join(l)
26+
27+
28+
@some_fun.register(tuple)
29+
def _some_fun_sequence(l: tuple) -> str:
30+
return "tuple: " + ", ".join(l)
31+
32+
2133
@pytest.mark.parametrize(
2234
"v,ret",
2335
[
2436
(None, "Got None <class 'NoneType'>"),
2537
("val", "It's a string!"),
2638
(1, "It's an int!"),
27-
# (True, "It's an int!"),
39+
(True, "It's an int!"),
40+
([], "Sequence: "),
41+
(["1"], "Sequence: 1"),
42+
(["1", "2", "3"], "Sequence: 1, 2, 3"),
43+
(("1", "2", "3"), "tuple: 1, 2, 3"),
2844
]
2945
)
3046
def test_singledispatch(v, ret):

0 commit comments

Comments
 (0)