Skip to content

Commit d6e472f

Browse files
authored
[ty] Reachability constraints: minor documentation fixes (#21774)
1 parent 45842cc commit d6e472f

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

crates/ty_python_semantic/resources/mdtest/import/star.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ reveal_type(Y) # revealed: Unknown
715715

716716
# The `*` import is not considered a redefinition
717717
# of the global variable `Z` in this module, as the symbol in
718-
# the `a` module is in a branch that is statically known
718+
# the `exporter` module is in a branch that is statically known
719719
# to be dead code given the `python-version` configuration.
720720
# Thus this still reveals `Literal[True]`.
721721
reveal_type(Z) # revealed: Literal[True]

crates/ty_python_semantic/src/semantic_index/predicate.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ impl<'db> PatternPredicate<'db> {
166166
}
167167
}
168168

169-
/// A "placeholder predicate" that is used to model the fact that the boundness of a
170-
/// (possible) definition or declaration caused by a `*` import cannot be fully determined
171-
/// until type-inference time. This is essentially the same as a standard reachability constraint,
172-
/// so we reuse the [`Predicate`] infrastructure to model it.
169+
/// A "placeholder predicate" that is used to model the fact that the boundness of a (possible)
170+
/// definition or declaration caused by a `*` import cannot be fully determined until type-
171+
/// inference time. This is essentially the same as a standard reachability constraint, so we reuse
172+
/// the [`Predicate`] infrastructure to model it.
173173
///
174174
/// To illustrate, say we have a module `exporter.py` like so:
175175
///
@@ -183,14 +183,14 @@ impl<'db> PatternPredicate<'db> {
183183
/// ```py
184184
/// A = 1
185185
///
186-
/// from importer import *
186+
/// from exporter import *
187187
/// ```
188188
///
189-
/// Since we cannot know whether or not <condition> is true at semantic-index time,
190-
/// we record a definition for `A` in `b.py` as a result of the `from a import *`
191-
/// statement, but place a predicate on it to record the fact that we don't yet
192-
/// know whether this definition will be visible from all control-flow paths or not.
193-
/// Essentially, we model `b.py` as something similar to this:
189+
/// Since we cannot know whether or not <condition> is true at semantic-index time, we record
190+
/// a definition for `A` in `importer.py` as a result of the `from exporter import *` statement,
191+
/// but place a predicate on it to record the fact that we don't yet know whether this definition
192+
/// will be visible from all control-flow paths or not. Essentially, we model `importer.py` as
193+
/// something similar to this:
194194
///
195195
/// ```py
196196
/// A = 1
@@ -199,8 +199,8 @@ impl<'db> PatternPredicate<'db> {
199199
/// from a import A
200200
/// ```
201201
///
202-
/// At type-check time, the placeholder predicate for the `A` definition is evaluated by
203-
/// attempting to resolve the `A` symbol in `a.py`'s global namespace:
202+
/// At type-check time, the placeholder predicate for the `A` definition is evaluated by attempting
203+
/// to resolve the `A` symbol in `exporter.py`'s global namespace:
204204
/// - If it resolves to a definitely bound symbol, then the predicate resolves to [`Truthiness::AlwaysTrue`]
205205
/// - If it resolves to an unbound symbol, then the predicate resolves to [`Truthiness::AlwaysFalse`]
206206
/// - If it resolves to a possibly bound symbol, then the predicate resolves to [`Truthiness::Ambiguous`]

crates/ty_python_semantic/src/semantic_index/reachability_constraints.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! During semantic index building, we record so-called reachability constraints that keep track
44
//! of a set of conditions that need to apply in order for a certain statement or expression to
55
//! be reachable from the start of the scope. As an example, consider the following situation where
6-
//! we have just processed two `if`-statements:
6+
//! we have just processed an `if`-statement:
77
//! ```py
88
//! if test:
99
//! <is this reachable?>
@@ -101,13 +101,13 @@
101101
//! <is this reachable?>
102102
//! ```
103103
//! If we would not record any constraints at the branching point, we would have an `always-true`
104-
//! reachability for the no-loop branch, and a `always-false` reachability for the branch which enters
105-
//! the loop. Merging those would lead to a reachability of `always-true OR always-false = always-true`,
104+
//! reachability for the no-loop branch, and a `always-true` reachability for the branch which enters
105+
//! the loop. Merging those would lead to a reachability of `always-true OR always-true = always-true`,
106106
//! i.e. we would consider the end of the scope to be unconditionally reachable, which is not correct.
107107
//!
108108
//! Recording an ambiguous constraint at the branching point modifies the constraints in both branches to
109-
//! `always-true AND ambiguous = ambiguous` and `always-false AND ambiguous = always-false`, respectively.
110-
//! Merging these two using OR correctly leads to `ambiguous` for the end-of-scope reachability.
109+
//! `always-true AND ambiguous = ambiguous`. Merging these two using OR correctly leads to `ambiguous` for
110+
//! the end-of-scope reachability.
111111
//!
112112
//!
113113
//! ## Reachability constraints and bindings

0 commit comments

Comments
 (0)