Skip to content

Commit 404404a

Browse files
committed
Improve typing for sql.visitors
1 parent a0e1ae4 commit 404404a

File tree

1 file changed

+74
-56
lines changed

1 file changed

+74
-56
lines changed

sqlalchemy-stubs/sql/visitors.pyi

Lines changed: 74 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,110 @@
11
from typing import Any
2+
from typing import Callable
3+
from typing import Dict
4+
from typing import Iterable
5+
from typing import Iterator
6+
from typing import List
7+
from typing import Optional
8+
from typing import TypeVar
9+
10+
_ET = TypeVar("_ET", bound=ExternalTraversal)
11+
_T = TypeVar("_T")
212

313
class TraversibleType(type):
414
def __init__(cls, clsname: Any, bases: Any, clsdict: Any) -> None: ...
515

6-
class Traversible: ...
16+
class Traversible(metaclass=TraversibleType): ...
717

818
class _InternalTraversalType(type):
919
def __init__(cls, clsname: Any, bases: Any, clsdict: Any) -> None: ...
1020

11-
class InternalTraversal:
12-
def dispatch(self, visit_symbol: Any): ...
21+
class InternalTraversal(object, metaclass=_InternalTraversalType):
22+
def dispatch(self, visit_symbol: Any) -> Optional[Callable[..., Any]]: ...
1323
def run_generated_dispatch(
1424
self,
1525
target: Any,
1626
internal_dispatch: Any,
1727
generate_dispatcher_name: Any,
18-
): ...
28+
) -> Any: ...
1929
def generate_dispatch(
2030
self,
2131
target_cls: Any,
2232
internal_dispatch: Any,
2333
generate_dispatcher_name: Any,
24-
): ...
25-
dp_has_cache_key: Any = ...
26-
dp_has_cache_key_list: Any = ...
27-
dp_clauseelement: Any = ...
28-
dp_fromclause_canonical_column_collection: Any = ...
29-
dp_clauseelement_tuples: Any = ...
30-
dp_clauseelement_list: Any = ...
31-
dp_clauseelement_tuple: Any = ...
32-
dp_executable_options: Any = ...
33-
dp_fromclause_ordered_set: Any = ...
34-
dp_string: Any = ...
35-
dp_string_list: Any = ...
36-
dp_anon_name: Any = ...
37-
dp_boolean: Any = ...
38-
dp_operator: Any = ...
39-
dp_type: Any = ...
40-
dp_plain_dict: Any = ...
41-
dp_dialect_options: Any = ...
42-
dp_string_clauseelement_dict: Any = ...
43-
dp_string_multi_dict: Any = ...
44-
dp_annotations_key: Any = ...
45-
dp_plain_obj: Any = ...
46-
dp_named_ddl_element: Any = ...
47-
dp_prefix_sequence: Any = ...
48-
dp_table_hint_list: Any = ...
49-
dp_setup_join_tuple: Any = ...
50-
dp_statement_hint_list: Any = ...
51-
dp_unknown_structure: Any = ...
52-
dp_dml_ordered_values: Any = ...
53-
dp_dml_values: Any = ...
54-
dp_dml_multi_values: Any = ...
55-
dp_propagate_attrs: Any = ...
34+
) -> Any: ...
35+
dp_has_cache_key: int = ...
36+
dp_has_cache_key_list: int = ...
37+
dp_clauseelement: int = ...
38+
dp_fromclause_canonical_column_collection: int = ...
39+
dp_clauseelement_tuples: int = ...
40+
dp_clauseelement_list: int = ...
41+
dp_clauseelement_tuple: int = ...
42+
dp_executable_options: int = ...
43+
dp_fromclause_ordered_set: int = ...
44+
dp_string: int = ...
45+
dp_string_list: int = ...
46+
dp_anon_name: int = ...
47+
dp_boolean: int = ...
48+
dp_operator: int = ...
49+
dp_type: int = ...
50+
dp_plain_dict: int = ...
51+
dp_dialect_options: int = ...
52+
dp_string_clauseelement_dict: int = ...
53+
dp_string_multi_dict: int = ...
54+
dp_annotations_key: int = ...
55+
dp_plain_obj: int = ...
56+
dp_named_ddl_element: int = ...
57+
dp_prefix_sequence: int = ...
58+
dp_table_hint_list: int = ...
59+
dp_setup_join_tuple: int = ...
60+
dp_statement_hint_list: int = ...
61+
dp_unknown_structure: int = ...
62+
dp_dml_ordered_values: int = ...
63+
dp_dml_values: int = ...
64+
dp_dml_multi_values: int = ...
65+
dp_propagate_attrs: int = ...
5666

5767
class ExtendedInternalTraversal(InternalTraversal):
58-
dp_ignore: Any = ...
59-
dp_inspectable: Any = ...
60-
dp_multi: Any = ...
61-
dp_multi_list: Any = ...
62-
dp_has_cache_key_tuples: Any = ...
63-
dp_inspectable_list: Any = ...
68+
dp_ignore: int = ...
69+
dp_inspectable: int = ...
70+
dp_multi: int = ...
71+
dp_multi_list: int = ...
72+
dp_has_cache_key_tuples: int = ...
73+
dp_inspectable_list: int = ...
6474

6575
class ExternalTraversal:
6676
__traverse_options__: Any = ...
67-
def traverse_single(self, obj: Any, **kw: Any): ...
68-
def iterate(self, obj: Any): ...
69-
def traverse(self, obj: Any): ...
77+
def traverse_single(self, obj: Any, **kw: Any) -> Any: ...
78+
def iterate(self, obj: Any) -> Iterator[Any]: ...
79+
def traverse(self, obj: _T) -> _T: ...
7080
@property
71-
def visitor_iterator(self) -> None: ...
72-
def chain(self, visitor: Any): ...
81+
def visitor_iterator(self) -> Iterator[Any]: ...
82+
def chain(self: _ET, visitor: Any) -> _ET: ...
7383

7484
class CloningExternalTraversal(ExternalTraversal):
75-
def copy_and_process(self, list_: Any): ...
76-
def traverse(self, obj: Any): ...
85+
def copy_and_process(self, list_: Iterable[_T]) -> List[_T]: ...
86+
def traverse(self, obj: _T) -> _T: ...
7787

7888
class ReplacingExternalTraversal(CloningExternalTraversal):
79-
def replace(self, elem: Any) -> None: ...
80-
def traverse(self, obj: Any): ...
89+
def replace(self, elem: Any) -> Optional[Any]: ...
90+
def traverse(self, obj: _T) -> _T: ...
8191

8292
Visitable = Traversible
8393
VisitableType = TraversibleType
8494
ClauseVisitor = ExternalTraversal
8595
CloningVisitor = CloningExternalTraversal
8696
ReplacingCloningVisitor = ReplacingExternalTraversal
8797

88-
def iterate(obj: Any, opts: Any = ...) -> None: ...
89-
def traverse_using(iterator: Any, obj: Any, visitors: Any): ...
90-
def traverse(obj: Any, opts: Any, visitors: Any): ...
91-
def cloned_traverse(obj: Any, opts: Any, visitors: Any): ...
92-
def replacement_traverse(obj: Any, opts: Any, replace: Any): ...
98+
def iterate(obj: Any, opts: Dict[str, Any] = ...) -> Iterator[Any]: ...
99+
def traverse_using(
100+
iterator: Iterator[Any], obj: _T, visitors: Dict[str, Callable[..., Any]]
101+
) -> _T: ...
102+
def traverse(
103+
obj: _T, opts: Dict[str, Any], visitors: Dict[str, Callable[..., Any]]
104+
) -> _T: ...
105+
def cloned_traverse(
106+
obj: _T, opts: Dict[str, Any], visitors: Dict[str, Callable[..., Any]]
107+
) -> _T: ...
108+
def replacement_traverse(
109+
obj: _T, opts: Dict[str, Any], replace: Callable[[Any], Any]
110+
) -> _T: ...

0 commit comments

Comments
 (0)