[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
24 changed files with 39 additions and 39 deletions

View File

@@ -118,7 +118,7 @@ def takes_other_protocol(f: OtherProtocol): ...
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
from typing import Any, Literal

View File

@@ -1878,7 +1878,7 @@ date.day = 8
date.month = 4
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"
```
@@ -1894,10 +1894,10 @@ class Frozen:
existing: int = 1
def __setattr__(self, name, value) -> Never:
raise AttributeError("Attributes can not be modified")
raise AttributeError("Attributes cannot be modified")
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`"
```
@@ -1949,7 +1949,7 @@ def flag() -> bool:
class Frozen:
if flag():
def __setattr__(self, name, value) -> Never:
raise AttributeError("Attributes can not be modified")
raise AttributeError("Attributes cannot be modified")
instance = Frozen()
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
```
## 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
implicit dunder calls:

View File

@@ -84,7 +84,7 @@ class E(metaclass=Meta): ...
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
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
```
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
# error: [unresolved-attribute] "Object of type `C` has no attribute `f`"

View File

@@ -424,7 +424,7 @@ from dataclasses import dataclass
class 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

View File

@@ -26,7 +26,7 @@ def outer_generator():
## `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`
expression can not be determined
expression cannot be determined
```py
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"))
```
But instance attributes can not be accessed this way:
But instance attributes cannot be accessed this way:
```py
static_assert(not has_member(C, "instance_attr"))

View File

@@ -444,7 +444,7 @@ def _(
reveal_type(i07) # 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]`:
def example_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
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
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, 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))
```
@@ -84,7 +84,7 @@ static_assert(is_assignable_to(Small, 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`:
```py

View File

@@ -32,8 +32,8 @@ static_assert(not is_singleton(Literal[1]))
static_assert(not is_singleton(Literal[54165]))
```
This has implications for type-narrowing. For example, you can not use the `is not` operator to
check whether a variable has a specific integer literal type, but this is not a recommended practice
This has implications for type-narrowing. For example, you cannot use the `is not` operator to check
whether a variable has a specific integer literal type, but this is not a recommended practice
anyway.
```py
@@ -44,7 +44,7 @@ def f(x: int):
reveal_type(x) # revealed: Literal[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.
reveal_type(x) # revealed: int
```

View File

@@ -45,7 +45,7 @@ class C(B1, B2): ...
# ... which lies in their intersection:
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
class FinalSubclass(A): ...

View File

@@ -680,7 +680,7 @@ def _(p: Person) -> None:
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:
```py
@@ -714,7 +714,7 @@ reveal_type(Person.__required_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
def _(person: Person) -> None:
@@ -723,7 +723,7 @@ def _(person: Person) -> None:
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
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
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
statically determine the truthiness of a branch like `sys.platform == "win32"`.
`LiteralString` (the `typeshed` annotation for `sys.platform`). This means that we cannot statically
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
could be improved.