Skip to content

Commit bcefa45

Browse files
[ty] Rename call-possibly-unbound-method to possibly-unbound-implicit-call (#18017)
1 parent 91b7a57 commit bcefa45

File tree

8 files changed

+127
-101
lines changed

8 files changed

+127
-101
lines changed

crates/ty/docs/rules.md

Lines changed: 83 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ty_python_semantic/resources/mdtest/call/constructor.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ def _(flag: bool) -> None:
158158
def __new__(cls):
159159
return object.__new__(cls)
160160

161-
# error: [call-possibly-unbound-method]
161+
# error: [possibly-unbound-implicit-call]
162162
reveal_type(Foo()) # revealed: Foo
163163

164-
# error: [call-possibly-unbound-method]
164+
# error: [possibly-unbound-implicit-call]
165165
# error: [too-many-positional-arguments]
166166
reveal_type(Foo(1)) # revealed: Foo
167167
```

crates/ty_python_semantic/resources/mdtest/call/dunder.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _(flag: bool):
112112

113113
this_fails = ThisFails()
114114

115-
# error: [call-possibly-unbound-method]
115+
# error: [possibly-unbound-implicit-call]
116116
reveal_type(this_fails[0]) # revealed: Unknown | str
117117
```
118118

@@ -236,6 +236,6 @@ def _(flag: bool):
236236
return str(key)
237237

238238
c = C()
239-
# error: [call-possibly-unbound-method]
239+
# error: [possibly-unbound-implicit-call]
240240
reveal_type(c[0]) # revealed: str
241241
```

crates/ty_python_semantic/resources/mdtest/subscript/class.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _(flag: bool):
6363

6464
else:
6565
class Spam: ...
66-
# error: [call-possibly-unbound-method] "Method `__class_getitem__` of type `<class 'Spam'> | <class 'Spam'>` is possibly unbound"
66+
# error: [possibly-unbound-implicit-call] "Method `__class_getitem__` of type `<class 'Spam'> | <class 'Spam'>` is possibly unbound"
6767
# revealed: str
6868
reveal_type(Spam[42])
6969
```

crates/ty_python_semantic/src/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bitflags::bitflags;
88
use call::{CallDunderError, CallError, CallErrorKind};
99
use context::InferContext;
1010
use diagnostic::{
11-
CALL_POSSIBLY_UNBOUND_METHOD, INVALID_CONTEXT_MANAGER, INVALID_SUPER_ARGUMENT, NOT_ITERABLE,
11+
INVALID_CONTEXT_MANAGER, INVALID_SUPER_ARGUMENT, NOT_ITERABLE, POSSIBLY_UNBOUND_IMPLICIT_CALL,
1212
UNAVAILABLE_IMPLICIT_SUPER_ARGUMENTS,
1313
};
1414
use ruff_db::diagnostic::{
@@ -6652,7 +6652,7 @@ impl<'db> ConstructorCallError<'db> {
66526652
let report_init_error = |call_dunder_error: &CallDunderError<'db>| match call_dunder_error {
66536653
CallDunderError::MethodNotAvailable => {
66546654
if let Some(builder) =
6655-
context.report_lint(&CALL_POSSIBLY_UNBOUND_METHOD, context_expression_node)
6655+
context.report_lint(&POSSIBLY_UNBOUND_IMPLICIT_CALL, context_expression_node)
66566656
{
66576657
// If we are using vendored typeshed, it should be impossible to have missing
66586658
// or unbound `__init__` method on a class, as all classes have `object` in MRO.
@@ -6666,7 +6666,7 @@ impl<'db> ConstructorCallError<'db> {
66666666
}
66676667
CallDunderError::PossiblyUnbound(bindings) => {
66686668
if let Some(builder) =
6669-
context.report_lint(&CALL_POSSIBLY_UNBOUND_METHOD, context_expression_node)
6669+
context.report_lint(&POSSIBLY_UNBOUND_IMPLICIT_CALL, context_expression_node)
66706670
{
66716671
builder.into_diagnostic(format_args!(
66726672
"Method `__init__` on type `{}` is possibly unbound.",
@@ -6684,7 +6684,7 @@ impl<'db> ConstructorCallError<'db> {
66846684
let report_new_error = |error: &DunderNewCallError<'db>| match error {
66856685
DunderNewCallError::PossiblyUnbound(call_error) => {
66866686
if let Some(builder) =
6687-
context.report_lint(&CALL_POSSIBLY_UNBOUND_METHOD, context_expression_node)
6687+
context.report_lint(&POSSIBLY_UNBOUND_IMPLICIT_CALL, context_expression_node)
66886688
{
66896689
builder.into_diagnostic(format_args!(
66906690
"Method `__new__` on type `{}` is possibly unbound.",

crates/ty_python_semantic/src/types/diagnostic.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::fmt::Formatter;
2424
/// Registers all known type check lints.
2525
pub(crate) fn register_lints(registry: &mut LintRegistryBuilder) {
2626
registry.register_lint(&CALL_NON_CALLABLE);
27-
registry.register_lint(&CALL_POSSIBLY_UNBOUND_METHOD);
27+
registry.register_lint(&POSSIBLY_UNBOUND_IMPLICIT_CALL);
2828
registry.register_lint(&CONFLICTING_ARGUMENT_FORMS);
2929
registry.register_lint(&CONFLICTING_DECLARATIONS);
3030
registry.register_lint(&CONFLICTING_METACLASS);
@@ -107,12 +107,25 @@ declare_lint! {
107107

108108
declare_lint! {
109109
/// ## What it does
110-
/// Checks for calls to possibly unbound methods.
110+
/// Checks for implicit calls to possibly unbound methods.
111111
///
112112
/// ## Why is this bad?
113+
/// Expressions such as `x[y]` and `x * y` call methods
114+
/// under the hood (`__getitem__` and `__mul__` respectively).
113115
/// Calling an unbound method will raise an `AttributeError` at runtime.
114-
pub(crate) static CALL_POSSIBLY_UNBOUND_METHOD = {
115-
summary: "detects calls to possibly unbound methods",
116+
///
117+
/// ## Examples
118+
/// ```python
119+
/// import datetime
120+
///
121+
/// class A:
122+
/// if datetime.date.today().weekday() != 6:
123+
/// def __getitem__(self, v): ...
124+
///
125+
/// A()[0] # TypeError: 'A' object is not subscriptable
126+
/// ```
127+
pub(crate) static POSSIBLY_UNBOUND_IMPLICIT_CALL = {
128+
summary: "detects implicit calls to possibly unbound methods",
116129
status: LintStatus::preview("1.0.0"),
117130
default_level: Level::Warn,
118131
}

crates/ty_python_semantic/src/types/infer.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ use crate::symbol::{
6767
use crate::types::call::{Argument, Bindings, CallArgumentTypes, CallArguments, CallError};
6868
use crate::types::class::{MetaclassErrorKind, SliceLiteral};
6969
use crate::types::diagnostic::{
70-
self, CALL_NON_CALLABLE, CALL_POSSIBLY_UNBOUND_METHOD, CONFLICTING_DECLARATIONS,
71-
CONFLICTING_METACLASS, CYCLIC_CLASS_DEFINITION, DIVISION_BY_ZERO, INCONSISTENT_MRO,
72-
INVALID_ARGUMENT_TYPE, INVALID_ASSIGNMENT, INVALID_ATTRIBUTE_ACCESS, INVALID_BASE,
73-
INVALID_DECLARATION, INVALID_GENERIC_CLASS, INVALID_LEGACY_TYPE_VARIABLE,
74-
INVALID_PARAMETER_DEFAULT, INVALID_TYPE_ALIAS_TYPE, INVALID_TYPE_FORM,
75-
INVALID_TYPE_VARIABLE_CONSTRAINTS, POSSIBLY_UNBOUND_IMPORT, TypeCheckDiagnostics,
70+
self, CALL_NON_CALLABLE, CONFLICTING_DECLARATIONS, CONFLICTING_METACLASS,
71+
CYCLIC_CLASS_DEFINITION, DIVISION_BY_ZERO, INCONSISTENT_MRO, INVALID_ARGUMENT_TYPE,
72+
INVALID_ASSIGNMENT, INVALID_ATTRIBUTE_ACCESS, INVALID_BASE, INVALID_DECLARATION,
73+
INVALID_GENERIC_CLASS, INVALID_LEGACY_TYPE_VARIABLE, INVALID_PARAMETER_DEFAULT,
74+
INVALID_TYPE_ALIAS_TYPE, INVALID_TYPE_FORM, INVALID_TYPE_VARIABLE_CONSTRAINTS,
75+
POSSIBLY_UNBOUND_IMPLICIT_CALL, POSSIBLY_UNBOUND_IMPORT, TypeCheckDiagnostics,
7676
UNDEFINED_REVEAL, UNRESOLVED_ATTRIBUTE, UNRESOLVED_IMPORT, UNSUPPORTED_OPERATOR,
7777
report_implicit_return_type, report_invalid_arguments_to_annotated,
7878
report_invalid_arguments_to_callable, report_invalid_assignment,
@@ -7428,7 +7428,7 @@ impl<'db> TypeInferenceBuilder<'db> {
74287428
Err(err @ CallDunderError::PossiblyUnbound { .. }) => {
74297429
if let Some(builder) = self
74307430
.context
7431-
.report_lint(&CALL_POSSIBLY_UNBOUND_METHOD, value_node)
7431+
.report_lint(&POSSIBLY_UNBOUND_IMPLICIT_CALL, value_node)
74327432
{
74337433
builder.into_diagnostic(format_args!(
74347434
"Method `__getitem__` of type `{}` is possibly unbound",
@@ -7476,7 +7476,7 @@ impl<'db> TypeInferenceBuilder<'db> {
74767476
if boundness == Boundness::PossiblyUnbound {
74777477
if let Some(builder) = self
74787478
.context
7479-
.report_lint(&CALL_POSSIBLY_UNBOUND_METHOD, value_node)
7479+
.report_lint(&POSSIBLY_UNBOUND_IMPLICIT_CALL, value_node)
74807480
{
74817481
builder.into_diagnostic(format_args!(
74827482
"Method `__class_getitem__` of type `{}` \

ty.schema.json

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

0 commit comments

Comments
 (0)