Skip to content

Commit 59004b6

Browse files
committed
feat(typeshed): private protocol X for module-internal protocols
1 parent 95cd189 commit 59004b6

69 files changed

Lines changed: 976 additions & 585 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/by_override_patch/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ path = "src/main.rs"
1818
anyhow = { workspace = true }
1919
ruff_db = { workspace = true, features = ["os", "testing"] }
2020
ruff_ranged_value = { workspace = true }
21-
ruff_text_size = { workspace = true }
2221
ty_project = { workspace = true }
2322
ty_python_semantic = { workspace = true }
2423
walkdir = { workspace = true }

crates/by_typeshed_patch/src/lib.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ pub fn all_patches() -> Vec<Box<dyn Patch>> {
6363
/// each post-patch is applied on its own re-parse so two patches never have to
6464
/// coordinate disjoint edits; they run in declared order
6565
///
66-
/// `root` is the typeshed `stdlib/` directory; a patch whose decision depends on
67-
/// the rest of the tree (currently only `private_type_aliases`) scans it here,
68-
/// once, before any file is rewritten
66+
/// `root` is the typeshed `stdlib/` directory; the patches whose decision
67+
/// depends on the rest of the tree (`private_type_aliases` and
68+
/// `private_protocols`) share one scan of it, taken here before any file is
69+
/// rewritten
6970
pub fn all_post_patches(root: &Path) -> Vec<Box<dyn Patch>> {
71+
let private_names = patches::private_names::scan(root);
7072
vec![
7173
// widens invariant list/set/dict output typevars over the explicit-variance
7274
// form; runs first so later idiom patches (e.g. `any_to_dynamic`) still see
@@ -93,8 +95,13 @@ pub fn all_post_patches(root: &Path) -> Vec<Box<dyn Patch>> {
9395
Box::new(patches::type_aliases::TypeAliasStatements),
9496
// runs after the alias statements exist, so an alias promoted from
9597
// `_X: TypeAlias = …` this pass is a candidate on the next sync
96-
Box::new(patches::private_type_aliases::PrivateTypeAliases::scan(
97-
root,
98+
Box::new(patches::private_type_aliases::PrivateTypeAliases::new(
99+
private_names.aliases,
100+
)),
101+
// `protocol_keyword` above turned `class _X(Protocol)` into
102+
// `protocol _X`, which is the form the scan looked for
103+
Box::new(patches::private_protocols::PrivateProtocols::new(
104+
private_names.protocols,
98105
)),
99106
Box::new(patches::homogeneous_tuple::HomogeneousTuple),
100107
Box::new(patches::any_to_dynamic::AnyToDynamic),

crates/by_typeshed_patch/src/patches/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub mod init_shorthand;
1818
pub mod literal_unwrap;
1919
pub mod mapping;
2020
pub mod output_widening;
21+
pub(crate) mod private_names;
22+
pub mod private_protocols;
2123
pub mod private_type_aliases;
2224
pub mod property_to_let;
2325
pub mod protocol_keyword;

0 commit comments

Comments
 (0)