Skip to content

Commit 2adc781

Browse files
authored
Merge branch 'main' into float-int-stdlib
2 parents f1c985b + 666cee3 commit 2adc781

13 files changed

Lines changed: 168 additions & 78 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ When opening pull requests, do the following:
5353
documentation if possible.
5454
- Don't include a testing plan.
5555
- Add the name of the agent used to the PR description.
56+
- Never squash commits or force push.

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ to your PR to fix any minor issues, but this is not always possible.
476476
If a PR lingers with unresolved problems for too long, we may close it
477477
([see below](#closing-stale-prs)).
478478

479-
Also, do not squash your commits or use `git commit --amend` after you have submitted a pull request, as this
479+
Also, do not squash your commits, force push, or use `git commit --amend` after
480+
you have submitted a pull request, as this
480481
erases context during review. We will squash commits when the pull request is merged.
481482
This way, your pull request will appear as a single commit in our git history, even
482483
if it consisted of several smaller commits.

‎requirements-tests.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
mypy==2.4.1
44
pyrefly==1.4.1
55
pyright==1.1.414
6-
ty==0.0.100
6+
ty==0.0.104
77

88
# Libraries used by our various scripts.
99
aiohttp==3.14.4

‎stdlib/builtins.pyi‎

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,45 @@ class classmethod(Generic[_T, _P, _R_co]):
193193

194194
@disjoint_base
195195
class type:
196+
# On CPython, `type.__dict__["__basicsize__"]` holds a member descriptor, while `int.__basicsize__` returns an integer.
197+
# Annotating these attributes as `types.MemberDescriptorType` would give reads the type `Any` because its `__get__`
198+
# stub returns `Any`. We use `@property` so type checkers infer each attribute's type from its getter.
199+
#
196200
# object.__base__ is None. Otherwise, it would be a type.
197-
__base__: Final[type | None]
201+
@final
202+
@property # `types.MemberDescriptorType` on CPython
203+
def __base__(self) -> type | None: ...
198204
__bases__: tuple[type, ...]
199-
__basicsize__: Final[int]
205+
@final
206+
@property # `types.MemberDescriptorType` on CPython
207+
def __basicsize__(self) -> int: ...
200208
# type.__dict__ is read-only at runtime, but that can't be expressed currently.
201209
# See https://github.com/python/typeshed/issues/11033 for a discussion.
202210
__dict__: Final[types.MappingProxyType[str, Any]] # type: ignore[assignment]
203-
__dictoffset__: Final[int]
204-
__flags__: Final[int]
205-
__itemsize__: Final[int]
211+
@final
212+
@property # `types.MemberDescriptorType` on CPython
213+
def __dictoffset__(self) -> int: ...
214+
@final
215+
@property # `types.MemberDescriptorType` on CPython
216+
def __flags__(self) -> int: ...
217+
@final
218+
@property # `types.MemberDescriptorType` on CPython
219+
def __itemsize__(self) -> int: ...
206220
__module__: str
207-
__mro__: Final[tuple[type, ...]]
221+
# As with member descriptors, the stub for `types.GetSetDescriptorType.__get__` returns `Any`.
222+
# Type checkers special-case `property` so they can infer each attribute's type from its getter.
223+
@final
224+
@property # `types.GetSetDescriptorType` on CPython (`types.MemberDescriptorType` before 3.12)
225+
def __mro__(self) -> tuple[type, ...]: ...
226+
@final
227+
@property # `types.GetSetDescriptorType` on CPython
228+
def __text_signature__(self) -> str | None: ...
229+
@final
230+
@property # `types.MemberDescriptorType` on CPython
231+
def __weakrefoffset__(self) -> int: ...
232+
208233
__name__: str
209234
__qualname__: str
210-
__text_signature__: Final[str | None]
211-
__weakrefoffset__: Final[int]
212235

213236
@overload
214237
def __init__(self, o: object, /) -> None: ...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The metaclass of FuzzedDataProvider is pybind11_builtins.pybind11_type, which is
2+
# not importable from a stub, and pybind11 is not a runtime dependency of atheris.
3+
atheris.native.FuzzedDataProvider

‎stubs/atheris/atheris/__init__.pyi‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
from collections.abc import Callable
1+
from .function_hooks import enabled_hooks as enabled_hooks
2+
from .import_hook import instrument_imports as instrument_imports
3+
from .instrument_bytecode import instrument_all as instrument_all, instrument_func as instrument_func
4+
from .native import (
5+
ALL_REMAINING as ALL_REMAINING,
6+
Fuzz as Fuzz,
7+
FuzzedDataProvider as FuzzedDataProvider,
8+
Mutate as Mutate,
9+
Setup as Setup,
10+
)
11+
from .utils import path as path
212

3-
def Setup(
4-
args: list[str],
5-
test_one_input: Callable[[bytes], None],
6-
**kwargs: bool | Callable[[bytes, int, int], str | bytes] | Callable[[bytes, bytes, int, int], str | bytes] | None,
7-
) -> list[str]: ...
8-
def Fuzz() -> None: ...
9-
def Mutate(data: bytes, max_size: int) -> bytes: ...
13+
def get_hook_dirs() -> list[str]: ... # undocumented

‎stubs/atheris/atheris/native.pyi‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from collections.abc import Callable, Sequence
2+
from typing import Final, TypeVar
3+
4+
_T = TypeVar("_T")
5+
6+
ALL_REMAINING: Final[int] # undocumented
7+
8+
def Setup(
9+
args: Sequence[str],
10+
test_one_input: Callable[[bytes], object],
11+
/,
12+
**kwargs: bool | Callable[[bytes, int, int], str | bytes] | Callable[[bytes, bytes, int, int], str | bytes] | None,
13+
) -> list[str]: ...
14+
def Fuzz() -> None: ...
15+
def Mutate(data: bytes, max_size: int, /) -> bytes: ...
16+
17+
class FuzzedDataProvider:
18+
def __init__(self, data: bytes, /) -> None: ...
19+
def ConsumeUnicode(self, count: int) -> str: ...
20+
def ConsumeUnicodeNoSurrogates(self, count: int, /) -> str: ...
21+
def ConsumeBytes(self, count: int, /) -> bytes: ...
22+
def ConsumeString(self, count: int, /) -> str: ...
23+
def ConsumeInt(self, byte_size: int, /) -> int: ...
24+
def ConsumeUInt(self, byte_size: int, /) -> int: ...
25+
def ConsumeIntInRange(self, min: int, max: int, /) -> int: ...
26+
def ConsumeIntList(self, count: int, byte_size: int, /) -> list[int]: ...
27+
def ConsumeIntListInRange(self, count: int, min: int, max: int, /) -> list[int]: ...
28+
def ConsumeFloat(self) -> float: ...
29+
def ConsumeRegularFloat(self) -> float: ...
30+
def ConsumeProbability(self) -> float: ...
31+
def ConsumeFloatInRange(self, min: float | int, max: float | int, /) -> float: ...
32+
def ConsumeFloatList(self, count: int, /) -> list[float]: ...
33+
def ConsumeRegularFloatList(self, count: int, /) -> list[float]: ...
34+
def ConsumeProbabilityList(self, count: int, /) -> list[float]: ...
35+
def ConsumeFloatListInRange(self, count: int, min: float | int, max: float | int, /) -> list[float]: ...
36+
def PickValueInList(self, values: list[_T], /) -> _T: ...
37+
def ConsumeBool(self) -> bool: ...
38+
def remaining_bytes(self) -> int: ... # undocumented
39+
def buffer(self) -> bytes: ... # undocumented

‎stubs/networkx/networkx/_typing.pyi‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ from typing_extensions import TypeVar
66

77
import numpy as np
88

9-
_ScalarT = TypeVar("_ScalarT", bound=bool | int | float | complex | str | bytes | np.generic)
9+
Scalar: TypeAlias = bool | int | float | complex | str | bytes | np.generic
10+
_ScalarT = TypeVar("_ScalarT", bound=Scalar)
1011
_GenericT = TypeVar("_GenericT", bound=np.generic)
1112
_GenericT_co = TypeVar("_GenericT_co", bound=np.generic, covariant=True)
1213
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], default=Any, covariant=True)

‎stubs/networkx/networkx/classes/function.pyi‎

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from _typeshed import Incomplete, SupportsItems, SupportsKeysAndGetItem, Unused
22
from collections.abc import Callable, Collection, Generator, Iterable, Iterator
3-
from typing import Literal, TypeVar, overload
3+
from typing import Any, Literal, TypeVar, overload
44

55
from networkx import _dispatchable
6+
from networkx._typing import Scalar
67
from networkx.algorithms.planarity import PlanarEmbedding
78
from networkx.classes.digraph import DiGraph
89
from networkx.classes.graph import Graph, _EdgeData, _NBunch, _Node, _NodeData
@@ -82,51 +83,63 @@ def to_directed(graph): ...
8283
def to_undirected(graph): ...
8384
def create_empty_copy(G: Graph[_Node], with_data: bool = True): ...
8485

85-
# incomplete: Can "Any scalar value" be enforced?
86+
# Values can be a dict-like mapping or any scalar value when name is provided
8687
@overload
8788
def set_node_attributes(
8889
G: Graph[_Node],
89-
values: SupportsItems[_Node, Unused],
90+
values: SupportsItems[_Node, Unused] | Scalar,
9091
name: str,
9192
*,
92-
backend=None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload
93-
**backend_kwargs,
93+
backend: str | None = None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload
94+
**backend_kwargs: Any,
9495
) -> None: ...
9596
@overload
9697
def set_node_attributes(
9798
G: Graph[_Node],
9899
values: SupportsItems[_Node, SupportsKeysAndGetItem[Incomplete, Incomplete] | Iterable[tuple[Incomplete, Incomplete]]],
99100
name: None = None,
100101
*,
101-
backend=None,
102-
**backend_kwargs,
102+
backend: str | None = None,
103+
**backend_kwargs: Any,
103104
) -> None: ...
104105

105106
@_dispatchable
106107
def get_node_attributes(G: Graph[_Node], name: str, default=None) -> dict[_Node, Incomplete]: ...
107108
@_dispatchable
108109
def remove_node_attributes(G: Graph[_Node], *attr_names, nbunch=None) -> None: ...
109110

111+
@overload
112+
def set_edge_attributes(
113+
G: MultiGraph[_Node],
114+
values: dict[tuple[_Node, _Node, Incomplete], Incomplete] | Scalar,
115+
name: str,
116+
*,
117+
backend: str | None = None,
118+
**backend_kwargs: Any,
119+
) -> None: ...
110120
@overload
111121
def set_edge_attributes(
112122
G: Graph[_Node],
113-
values: SupportsItems[tuple[_Node, _Node], Incomplete],
123+
values: SupportsItems[tuple[_Node, _Node], Incomplete] | Scalar,
114124
name: str,
115125
*,
116126
backend: str | None = None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload
117-
**backend_kwargs,
127+
**backend_kwargs: Any,
118128
) -> None: ...
119129
@overload
120130
def set_edge_attributes(
121-
G: MultiGraph[_Node],
122-
values: dict[tuple[_Node, _Node, Incomplete], Incomplete],
123-
name: str,
131+
G: Graph[_Node],
132+
values: (
133+
SupportsItems[
134+
tuple[_Node, _Node], SupportsKeysAndGetItem[Incomplete, Incomplete] | Iterable[tuple[Incomplete, Incomplete]]
135+
]
136+
| Incomplete
137+
),
138+
name: None = None,
124139
*,
125140
backend: str | None = None,
126-
**backend_kwargs,
141+
**backend_kwargs: Any,
127142
) -> None: ...
128-
@overload
129-
def set_edge_attributes(G: Graph[_Node], values, name: None = None, *, backend: str | None = None, **backend_kwargs) -> None: ...
130143

131144
@_dispatchable
132145
def get_edge_attributes(G: Graph[_Node], name: str, default=None) -> dict[tuple[_Node, _Node], Incomplete]: ...

‎stubs/networkx/networkx/classes/reportviews.pyi‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from _typeshed import Incomplete, Unused
22
from abc import ABC
33
from collections.abc import Iterable, Iterator, Mapping, Set as AbstractSet
4-
from typing import Generic, Literal, TypeVar, overload
4+
from typing import Any, Generic, Literal, TypeVar, overload
55
from typing_extensions import Self
66

77
from networkx.classes.graph import Graph, _Edge, _EdgeData, _NBunch, _Node, _NodeData
@@ -43,22 +43,26 @@ class NodeView(Mapping[_Node, _NodeData], AbstractSet[_Node], Generic[_Node, _No
4343
def __contains__(self, n: object) -> bool: ...
4444

4545
@overload
46-
def __call__(self, data: Literal[False] = False, default=None) -> Self: ...
46+
def __call__(self, data: Literal[False] = False) -> Self: ...
4747
@overload
48-
def __call__(self, data: Literal[True] | str, default=None) -> NodeDataView[_Node, _NodeData, _EdgeData]: ...
48+
def __call__(self, data: Literal[True]) -> NodeDataView[_Node, _NodeData]: ...
49+
@overload
50+
def __call__(self, data: str, default: _U | None = None) -> NodeDataView[_Node, _U]: ...
4951

5052
@overload
51-
def data(self, data: Literal[False], default=None) -> Self: ...
53+
def data(self, data: Literal[False]) -> Self: ...
54+
@overload
55+
def data(self, data: Literal[True] = True) -> NodeDataView[_Node, _NodeData]: ...
5256
@overload
53-
def data(self, data: Literal[True] | str = True, default=None) -> NodeDataView[_Node, _NodeData, _EdgeData]: ...
57+
def data(self, data: str, default: _U | None = None) -> NodeDataView[_Node, _U]: ...
5458

55-
class NodeDataView(AbstractSet[_Node], Generic[_Node, _NodeData, _EdgeData]):
59+
class NodeDataView(AbstractSet[_Node], Generic[_Node, _D]):
5660
__slots__ = ("_nodes", "_data", "_default")
57-
def __init__(self, nodedict: _NodeData, data: bool | str = False, default=None) -> None: ...
61+
def __init__(self, nodedict: Mapping[_Node, Mapping[str, Any]], data: bool | str = False, default: Any = None) -> None: ...
5862
def __len__(self) -> int: ...
59-
def __iter__(self) -> Iterator[tuple[_Node, _NodeData]]: ... # type: ignore[override]
63+
def __iter__(self) -> Iterator[tuple[_Node, _D]]: ... # type: ignore[override]
6064
def __contains__(self, n: object) -> bool: ...
61-
def __getitem__(self, n: _Node) -> _NodeData | Incomplete: ...
65+
def __getitem__(self, n: _Node) -> _D: ...
6266

6367
class DiDegreeView(Generic[_Node, _NodeData, _EdgeData]):
6468
def __init__(

0 commit comments

Comments
 (0)