[ty] Use "cannot" consistently over "can not" (#21255)

This commit is contained in:
Alex Waygood 2025-11-03 10:38:20 -05:00 committed by GitHub
parent e8c35b9704
commit 39f105bc4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 39 additions and 39 deletions

View File

@ -487,7 +487,7 @@ pub trait FormatElements {
/// Represents the width by adding 1 to the actual width so that the width can be represented by a [`NonZeroU32`], /// Represents the width by adding 1 to the actual width so that the width can be represented by a [`NonZeroU32`],
/// allowing [`TextWidth`] or [`Option<Width>`] fit in 4 bytes rather than 8. /// allowing [`TextWidth`] or [`Option<Width>`] fit in 4 bytes rather than 8.
/// ///
/// This means that 2^32 can not be precisely represented and instead has the same value as 2^32-1. /// This means that 2^32 cannot be precisely represented and instead has the same value as 2^32-1.
/// This imprecision shouldn't matter in practice because either text are longer than any configured line width /// This imprecision shouldn't matter in practice because either text are longer than any configured line width
/// and thus, the text should break. /// and thus, the text should break.
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]

View File

@ -299,7 +299,7 @@ impl<'a> CanOmitOptionalParenthesesVisitor<'a> {
} }
// `case 4+3j:` or `case 4-3j: // `case 4+3j:` or `case 4-3j:
// Can not contain arbitrary expressions. Limited to complex numbers. // Cannot contain arbitrary expressions. Limited to complex numbers.
Expr::BinOp(_) => { Expr::BinOp(_) => {
self.update_max_precedence(OperatorPrecedence::Additive, 1); self.update_max_precedence(OperatorPrecedence::Additive, 1);
} }

View File

@ -118,7 +118,7 @@ def takes_other_protocol(f: OtherProtocol): ...
takes_other_protocol(SubclassOfAny()) takes_other_protocol(SubclassOfAny())
``` ```
A subclass of `Any` cannot be assigned to literal types, since those can not be subclassed: A subclass of `Any` cannot be assigned to literal types, since those cannot be subclassed:
```py ```py
from typing import Any, Literal from typing import Any, Literal

View File

@ -1878,7 +1878,7 @@ date.day = 8
date.month = 4 date.month = 4
date.year = 2025 date.year = 2025
# error: [unresolved-attribute] "Can not assign object of type `Literal["UTC"]` to attribute `tz` on type `Date` with custom `__setattr__` method." # error: [unresolved-attribute] "Cannot assign object of type `Literal["UTC"]` to attribute `tz` on type `Date` with custom `__setattr__` method."
date.tz = "UTC" date.tz = "UTC"
``` ```
@ -1894,10 +1894,10 @@ class Frozen:
existing: int = 1 existing: int = 1
def __setattr__(self, name, value) -> Never: def __setattr__(self, name, value) -> Never:
raise AttributeError("Attributes can not be modified") raise AttributeError("Attributes cannot be modified")
instance = Frozen() instance = Frozen()
instance.non_existing = 2 # error: [invalid-assignment] "Can not assign to unresolved attribute `non_existing` on type `Frozen`" instance.non_existing = 2 # error: [invalid-assignment] "Cannot assign to unresolved attribute `non_existing` on type `Frozen`"
instance.existing = 2 # error: [invalid-assignment] "Cannot assign to attribute `existing` on type `Frozen` whose `__setattr__` method returns `Never`/`NoReturn`" instance.existing = 2 # error: [invalid-assignment] "Cannot assign to attribute `existing` on type `Frozen` whose `__setattr__` method returns `Never`/`NoReturn`"
``` ```
@ -1949,7 +1949,7 @@ def flag() -> bool:
class Frozen: class Frozen:
if flag(): if flag():
def __setattr__(self, name, value) -> Never: def __setattr__(self, name, value) -> Never:
raise AttributeError("Attributes can not be modified") raise AttributeError("Attributes cannot be modified")
instance = Frozen() instance = Frozen()
instance.non_existing = 2 # error: [invalid-assignment] instance.non_existing = 2 # error: [invalid-assignment]

View File

@ -194,7 +194,7 @@ class_with_descriptor_dunder = ClassWithDescriptorDunder()
reveal_type(class_with_descriptor_dunder[0]) # revealed: str reveal_type(class_with_descriptor_dunder[0]) # revealed: str
``` ```
## Dunders can not be overwritten on instances ## Dunders cannot be overwritten on instances
If we attempt to overwrite a dunder method on an instance, it does not affect the behavior of If we attempt to overwrite a dunder method on an instance, it does not affect the behavior of
implicit dunder calls: implicit dunder calls:

View File

@ -84,7 +84,7 @@ class E(metaclass=Meta): ...
reveal_type(inspect.getattr_static(E, "attr")) # revealed: int reveal_type(inspect.getattr_static(E, "attr")) # revealed: int
``` ```
Metaclass attributes can not be added when probing an instance of the class: Metaclass attributes cannot be added when probing an instance of the class:
```py ```py
reveal_type(inspect.getattr_static(E(), "attr", "non_existent")) # revealed: Literal["non_existent"] reveal_type(inspect.getattr_static(E(), "attr", "non_existent")) # revealed: Literal["non_existent"]

View File

@ -308,7 +308,7 @@ reveal_type(C.f) # revealed: bound method <class 'C'>.f(arg: int) -> str
reveal_type(C.f(1)) # revealed: str reveal_type(C.f(1)) # revealed: str
``` ```
The method `f` can not be accessed from an instance of the class: The method `f` cannot be accessed from an instance of the class:
```py ```py
# error: [unresolved-attribute] "Object of type `C` has no attribute `f`" # error: [unresolved-attribute] "Object of type `C` has no attribute `f`"

View File

@ -424,7 +424,7 @@ from dataclasses import dataclass
class MyFrozenClass: ... class MyFrozenClass: ...
frozen = MyFrozenClass() frozen = MyFrozenClass()
frozen.x = 2 # error: [invalid-assignment] "Can not assign to unresolved attribute `x` on type `MyFrozenClass`" frozen.x = 2 # error: [invalid-assignment] "Cannot assign to unresolved attribute `x` on type `MyFrozenClass`"
``` ```
A diagnostic is also emitted if a frozen dataclass is inherited, and an attempt is made to mutate an A diagnostic is also emitted if a frozen dataclass is inherited, and an attempt is made to mutate an

View File

@ -26,7 +26,7 @@ def outer_generator():
## `yield from` with a custom iterable ## `yield from` with a custom iterable
`yield from` can also be used with custom iterable types. In that case, the type of the `yield from` `yield from` can also be used with custom iterable types. In that case, the type of the `yield from`
expression can not be determined expression cannot be determined
```py ```py
from typing import Generator, TypeVar, Generic from typing import Generator, TypeVar, Generic

View File

@ -130,7 +130,7 @@ static_assert(has_member(C, "base_attr"))
static_assert(not has_member(C, "non_existent")) static_assert(not has_member(C, "non_existent"))
``` ```
But instance attributes can not be accessed this way: But instance attributes cannot be accessed this way:
```py ```py
static_assert(not has_member(C, "instance_attr")) static_assert(not has_member(C, "instance_attr"))

View File

@ -444,7 +444,7 @@ def _(
reveal_type(i07) # revealed: Never reveal_type(i07) # revealed: Never
reveal_type(i08) # revealed: Never reveal_type(i08) # revealed: Never
# `bool` is final and can not be subclassed, so `type[bool]` is equivalent to `Literal[bool]`, which # `bool` is final and cannot be subclassed, so `type[bool]` is equivalent to `Literal[bool]`, which
# is disjoint from `type[str]`: # is disjoint from `type[str]`:
def example_type_bool_type_str( def example_type_bool_type_str(
i: Intersection[type[bool], type[str]], i: Intersection[type[bool], type[str]],

View File

@ -390,7 +390,7 @@ static_assert(not is_single_valued(Literal["a"] | Literal["b"]))
We use `TypeOf` to get the inferred type of an expression. This is useful when we want to refer to We use `TypeOf` to get the inferred type of an expression. This is useful when we want to refer to
it in a type expression. For example, if we want to make sure that the class literal type `str` is a it in a type expression. For example, if we want to make sure that the class literal type `str` is a
subtype of `type[str]`, we can not use `is_subtype_of(str, type[str])`, as that would test if the subtype of `type[str]`, we cannot use `is_subtype_of(str, type[str])`, as that would test if the
type `str` itself is a subtype of `type[str]`. Instead, we can use `TypeOf[str]` to get the type of type `str` itself is a subtype of `type[str]`. Instead, we can use `TypeOf[str]` to get the type of
the expression `str`: the expression `str`:

View File

@ -54,7 +54,7 @@ class Small(Medium): ...
static_assert(is_assignable_to(Any | Medium, Big)) static_assert(is_assignable_to(Any | Medium, Big))
static_assert(is_assignable_to(Any | Medium, Medium)) static_assert(is_assignable_to(Any | Medium, Medium))
# `Any | Medium` is at least as large as `Medium`, so we can not assign it to `Small`: # `Any | Medium` is at least as large as `Medium`, so we cannot assign it to `Small`:
static_assert(not is_assignable_to(Any | Medium, Small)) static_assert(not is_assignable_to(Any | Medium, Small))
``` ```
@ -84,7 +84,7 @@ static_assert(is_assignable_to(Small, Intersection[Any, Medium]))
static_assert(is_assignable_to(Medium, Intersection[Any, Medium])) static_assert(is_assignable_to(Medium, Intersection[Any, Medium]))
``` ```
`Any & Medium` is no larger than `Medium`, so we can not assign `Big` to it. There is no possible `Any & Medium` is no larger than `Medium`, so we cannot assign `Big` to it. There is no possible
materialization of `Any & Medium` that would make it as big as `Big`: materialization of `Any & Medium` that would make it as big as `Big`:
```py ```py

View File

@ -32,8 +32,8 @@ static_assert(not is_singleton(Literal[1]))
static_assert(not is_singleton(Literal[54165])) static_assert(not is_singleton(Literal[54165]))
``` ```
This has implications for type-narrowing. For example, you can not use the `is not` operator to This has implications for type-narrowing. For example, you cannot use the `is not` operator to check
check whether a variable has a specific integer literal type, but this is not a recommended practice whether a variable has a specific integer literal type, but this is not a recommended practice
anyway. anyway.
```py ```py
@ -44,7 +44,7 @@ def f(x: int):
reveal_type(x) # revealed: Literal[54165] reveal_type(x) # revealed: Literal[54165]
if x is not 54165: if x is not 54165:
# But here, we can not narrow the type (to `int & ~Literal[54165]`), because `x` might also # But here, we cannot narrow the type (to `int & ~Literal[54165]`), because `x` might also
# have the value `54165`, but a different object identity. # have the value `54165`, but a different object identity.
reveal_type(x) # revealed: int reveal_type(x) # revealed: int
``` ```

View File

@ -45,7 +45,7 @@ class C(B1, B2): ...
# ... which lies in their intersection: # ... which lies in their intersection:
static_assert(is_subtype_of(C, Intersection[B1, B2])) static_assert(is_subtype_of(C, Intersection[B1, B2]))
# However, if a class is marked final, it can not be subclassed ... # However, if a class is marked final, it cannot be subclassed ...
@final @final
class FinalSubclass(A): ... class FinalSubclass(A): ...

View File

@ -680,7 +680,7 @@ def _(p: Person) -> None:
reveal_type(p.__class__) # revealed: <class 'dict[str, object]'> reveal_type(p.__class__) # revealed: <class 'dict[str, object]'>
``` ```
Also, the "attributes" on the class definition can not be accessed. Neither on the class itself, nor Also, the "attributes" on the class definition cannot be accessed. Neither on the class itself, nor
on inhabitants of the type defined by the class: on inhabitants of the type defined by the class:
```py ```py
@ -714,7 +714,7 @@ reveal_type(Person.__required_keys__) # revealed: frozenset[str]
reveal_type(Person.__optional_keys__) # revealed: frozenset[str] reveal_type(Person.__optional_keys__) # revealed: frozenset[str]
``` ```
These attributes can not be accessed on inhabitants: These attributes cannot be accessed on inhabitants:
```py ```py
def _(person: Person) -> None: def _(person: Person) -> None:
@ -723,7 +723,7 @@ def _(person: Person) -> None:
person.__optional_keys__ # error: [unresolved-attribute] person.__optional_keys__ # error: [unresolved-attribute]
``` ```
Also, they can not be accessed on `type(person)`, as that would be `dict` at runtime: Also, they cannot be accessed on `type(person)`, as that would be `dict` at runtime:
```py ```py
def _(person: Person) -> None: def _(person: Person) -> None:

View File

@ -187,8 +187,8 @@ python-platform = "all"
If `python-platform` is set to `all`, we treat the platform as unspecified. This means that we do If `python-platform` is set to `all`, we treat the platform as unspecified. This means that we do
not infer a literal type like `Literal["win32"]` for `sys.platform`, but instead fall back to not infer a literal type like `Literal["win32"]` for `sys.platform`, but instead fall back to
`LiteralString` (the `typeshed` annotation for `sys.platform`). This means that we can not `LiteralString` (the `typeshed` annotation for `sys.platform`). This means that we cannot statically
statically determine the truthiness of a branch like `sys.platform == "win32"`. determine the truthiness of a branch like `sys.platform == "win32"`.
See <https://github.com/astral-sh/ruff/issues/16983#issuecomment-2777146188> for a plan on how this See <https://github.com/astral-sh/ruff/issues/16983#issuecomment-2777146188> for a plan on how this
could be improved. could be improved.

View File

@ -733,7 +733,7 @@ pub(crate) fn place_by_id<'db>(
}; };
// If a symbol is undeclared, but qualified with `typing.Final`, we use the right-hand side // If a symbol is undeclared, but qualified with `typing.Final`, we use the right-hand side
// inferred type, without unioning with `Unknown`, because it can not be modified. // inferred type, without unioning with `Unknown`, because it cannot be modified.
if let Some(qualifiers) = declared.is_bare_final() { if let Some(qualifiers) = declared.is_bare_final() {
let bindings = all_considered_bindings(); let bindings = all_considered_bindings();
return place_from_bindings_impl(db, bindings, requires_explicit_reexport) return place_from_bindings_impl(db, bindings, requires_explicit_reexport)

View File

@ -13,7 +13,7 @@
//! of `test`. When evaluating a constraint, there are three possible outcomes: always true, always //! of `test`. When evaluating a constraint, there are three possible outcomes: always true, always
//! false, or ambiguous. For a simple constraint like this, always-true and always-false correspond //! false, or ambiguous. For a simple constraint like this, always-true and always-false correspond
//! to the case in which we can infer that the type of `test` is `Literal[True]` or `Literal[False]`. //! to the case in which we can infer that the type of `test` is `Literal[True]` or `Literal[False]`.
//! In any other case, like if the type of `test` is `bool` or `Unknown`, we can not statically //! In any other case, like if the type of `test` is `bool` or `Unknown`, we cannot statically
//! determine whether `test` is truthy or falsy, so the outcome would be "ambiguous". //! determine whether `test` is truthy or falsy, so the outcome would be "ambiguous".
//! //!
//! //!
@ -29,7 +29,7 @@
//! Here, we would accumulate a reachability constraint of `test1 AND test2`. We can statically //! Here, we would accumulate a reachability constraint of `test1 AND test2`. We can statically
//! determine that this position is *always* reachable only if both `test1` and `test2` are //! determine that this position is *always* reachable only if both `test1` and `test2` are
//! always true. On the other hand, we can statically determine that this position is *never* //! always true. On the other hand, we can statically determine that this position is *never*
//! reachable if *either* `test1` or `test2` is always false. In any other case, we can not //! reachable if *either* `test1` or `test2` is always false. In any other case, we cannot
//! determine whether this position is reachable or not, so the outcome is "ambiguous". This //! determine whether this position is reachable or not, so the outcome is "ambiguous". This
//! corresponds to a ternary *AND* operation in [Kleene] logic: //! corresponds to a ternary *AND* operation in [Kleene] logic:
//! //!
@ -60,7 +60,7 @@
//! The third branch ends in a terminal statement [^1]. When we merge control flow, we need to consider //! The third branch ends in a terminal statement [^1]. When we merge control flow, we need to consider
//! the reachability through either the first or the second branch. The current position is only //! the reachability through either the first or the second branch. The current position is only
//! *definitely* unreachable if both `test1` and `test2` are always false. It is definitely //! *definitely* unreachable if both `test1` and `test2` are always false. It is definitely
//! reachable if *either* `test1` or `test2` is always true. In any other case, we can not statically //! reachable if *either* `test1` or `test2` is always true. In any other case, we cannot statically
//! determine whether it is reachable or not. This operation corresponds to a ternary *OR* operation: //! determine whether it is reachable or not. This operation corresponds to a ternary *OR* operation:
//! //!
//! ```text //! ```text
@ -91,7 +91,7 @@
//! ## Explicit ambiguity //! ## Explicit ambiguity
//! //!
//! In some cases, we explicitly record an “ambiguous” constraint. We do this when branching on //! In some cases, we explicitly record an “ambiguous” constraint. We do this when branching on
//! something that we can not (or intentionally do not want to) analyze statically. `for` loops are //! something that we cannot (or intentionally do not want to) analyze statically. `for` loops are
//! one example: //! one example:
//! ```py //! ```py
//! def _(): //! def _():

View File

@ -27,7 +27,7 @@ fn from_negative_i32(index: i32) -> usize {
static_assertions::const_assert!(usize::BITS >= 32); static_assertions::const_assert!(usize::BITS >= 32);
index.checked_neg().map(from_nonnegative_i32).unwrap_or({ index.checked_neg().map(from_nonnegative_i32).unwrap_or({
// 'checked_neg' only fails for i32::MIN. We can not // 'checked_neg' only fails for i32::MIN. We cannot
// represent -i32::MIN as a i32, but we can represent // represent -i32::MIN as a i32, but we can represent
// it as a usize, since usize is at least 32 bits. // it as a usize, since usize is at least 32 bits.
from_nonnegative_i32(i32::MAX) + 1 from_nonnegative_i32(i32::MAX) + 1

View File

@ -297,7 +297,7 @@ impl AttributeKind {
/// When invoked on a class object, the fallback type (a class attribute) can shadow a /// When invoked on a class object, the fallback type (a class attribute) can shadow a
/// non-data descriptor of the meta-type (the class's metaclass). However, this is not /// non-data descriptor of the meta-type (the class's metaclass). However, this is not
/// true for instances. When invoked on an instance, the fallback type (an attribute on /// true for instances. When invoked on an instance, the fallback type (an attribute on
/// the instance) can not completely shadow a non-data descriptor of the meta-type (the /// the instance) cannot completely shadow a non-data descriptor of the meta-type (the
/// class), because we do not currently attempt to statically infer if an instance /// class), because we do not currently attempt to statically infer if an instance
/// attribute is definitely defined (i.e. to check whether a particular method has been /// attribute is definitely defined (i.e. to check whether a particular method has been
/// called). /// called).
@ -4412,7 +4412,7 @@ impl<'db> Type<'db> {
}; };
if result.is_class_var() && self.is_typed_dict() { if result.is_class_var() && self.is_typed_dict() {
// `ClassVar`s on `TypedDictFallback` can not be accessed on inhabitants of `SomeTypedDict`. // `ClassVar`s on `TypedDictFallback` cannot be accessed on inhabitants of `SomeTypedDict`.
// They can only be accessed on `SomeTypedDict` directly. // They can only be accessed on `SomeTypedDict` directly.
return Place::Undefined.into(); return Place::Undefined.into();
} }
@ -12050,7 +12050,7 @@ pub(crate) mod tests {
assert!(todo1.is_assignable_to(&db, int)); assert!(todo1.is_assignable_to(&db, int));
// We lose information when combining several `Todo` types. This is an // We lose information when combining several `Todo` types. This is an
// acknowledged limitation of the current implementation. We can not // acknowledged limitation of the current implementation. We cannot
// easily store the meta information of several `Todo`s in a single // easily store the meta information of several `Todo`s in a single
// variant, as `TodoType` needs to implement `Copy`, meaning it can't // variant, as `TodoType` needs to implement `Copy`, meaning it can't
// contain `Vec`/`Box`/etc., and can't be boxed itself. // contain `Vec`/`Box`/etc., and can't be boxed itself.

View File

@ -2000,7 +2000,7 @@ pub(super) fn report_slice_step_size_zero(context: &InferContext, node: AnyNodeR
let Some(builder) = context.report_lint(&ZERO_STEPSIZE_IN_SLICE, node) else { let Some(builder) = context.report_lint(&ZERO_STEPSIZE_IN_SLICE, node) else {
return; return;
}; };
builder.into_diagnostic("Slice step size can not be zero"); builder.into_diagnostic("Slice step size cannot be zero");
} }
fn report_invalid_assignment_with_message( fn report_invalid_assignment_with_message(

View File

@ -714,7 +714,7 @@ fn is_subtype_in_invariant_position<'db>(
// TODO: // TODO:
// This should be removed and properly handled in the respective // This should be removed and properly handled in the respective
// `(Type::TypeVar(_), _) | (_, Type::TypeVar(_))` branch of // `(Type::TypeVar(_), _) | (_, Type::TypeVar(_))` branch of
// `Type::has_relation_to_impl`. Right now, we can not generally // `Type::has_relation_to_impl`. Right now, we cannot generally
// return `ConstraintSet::from(true)` from that branch, as that // return `ConstraintSet::from(true)` from that branch, as that
// leads to union simplification, which means that we lose track // leads to union simplification, which means that we lose track
// of type variables without recording the constraints under which // of type variables without recording the constraints under which

View File

@ -3804,7 +3804,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
let msg = if !member_exists { let msg = if !member_exists {
format!( format!(
"Can not assign to unresolved attribute `{attribute}` on type `{}`", "Cannot assign to unresolved attribute `{attribute}` on type `{}`",
object_ty.display(db) object_ty.display(db)
) )
} else if is_setattr_synthesized { } else if is_setattr_synthesized {
@ -3840,7 +3840,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
self.context.report_lint(&UNRESOLVED_ATTRIBUTE, target) self.context.report_lint(&UNRESOLVED_ATTRIBUTE, target)
{ {
builder.into_diagnostic(format_args!( builder.into_diagnostic(format_args!(
"Can not assign object of type `{}` to attribute \ "Cannot assign object of type `{}` to attribute \
`{attribute}` on type `{}` with \ `{attribute}` on type `{}` with \
custom `__setattr__` method.", custom `__setattr__` method.",
value_ty.display(db), value_ty.display(db),