Skip to content

Commit 664df36

Browse files
committed
Review feedback
1 parent c042e73 commit 664df36

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

crates/ty/docs/rules.md

Lines changed: 4 additions & 4 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/named_tuple.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ Vec2(0.0, 0.0)
411411

412412
## `super()` is not supported in NamedTuple methods
413413

414-
Using `super()` in a method of a `NamedTuple` subclass will raise an exception at runtime. In Python
414+
Using `super()` in a method of a `NamedTuple` class will raise an exception at runtime. In Python
415415
3.14+, a `TypeError` is raised; in earlier versions, a confusing `RuntimeError` about
416416
`__classcell__` is raised.
417417

@@ -422,35 +422,35 @@ class F(NamedTuple):
422422
x: int
423423

424424
def method(self):
425-
# error: [super-call-in-named-tuple-method] "Cannot use `super()` in a method of NamedTuple subclass `F`"
425+
# error: [super-call-in-named-tuple-method] "Cannot use `super()` in a method of NamedTuple class `F`"
426426
super()
427427

428428
def method_with_args(self):
429-
# error: [super-call-in-named-tuple-method] "Cannot use `super()` in a method of NamedTuple subclass `F`"
429+
# error: [super-call-in-named-tuple-method] "Cannot use `super()` in a method of NamedTuple class `F`"
430430
super(F, self)
431431

432432
def method_with_different_pivot(self):
433433
# Even passing a different pivot class fails.
434-
# error: [super-call-in-named-tuple-method] "Cannot use `super()` in a method of NamedTuple subclass `F`"
434+
# error: [super-call-in-named-tuple-method] "Cannot use `super()` in a method of NamedTuple class `F`"
435435
super(tuple, self)
436436

437437
@classmethod
438438
def class_method(cls):
439-
# error: [super-call-in-named-tuple-method] "Cannot use `super()` in a method of NamedTuple subclass `F`"
439+
# error: [super-call-in-named-tuple-method] "Cannot use `super()` in a method of NamedTuple class `F`"
440440
super()
441441

442442
@staticmethod
443443
def static_method():
444-
# error: [super-call-in-named-tuple-method] "Cannot use `super()` in a method of NamedTuple subclass `F`"
444+
# error: [super-call-in-named-tuple-method] "Cannot use `super()` in a method of NamedTuple class `F`"
445445
super()
446446

447447
@property
448448
def prop(self):
449-
# error: [super-call-in-named-tuple-method] "Cannot use `super()` in a method of NamedTuple subclass `F`"
449+
# error: [super-call-in-named-tuple-method] "Cannot use `super()` in a method of NamedTuple class `F`"
450450
return super()
451451
```
452452

453-
However, classes that **inherit from** a `NamedTuple` subclass (but don't directly inherit from
453+
However, classes that **inherit from** a `NamedTuple` class (but don't directly inherit from
454454
`NamedTuple`) can use `super()` normally:
455455

456456
```py
@@ -471,3 +471,14 @@ class Regular:
471471
def method(self):
472472
super() # fine
473473
```
474+
475+
Using `super()` on a `NamedTuple` class also works fine if it occurs outside the class:
476+
477+
```py
478+
from typing import NamedTuple
479+
480+
class F(NamedTuple):
481+
x: int
482+
483+
super(F, F(42)) # fine
484+
```

crates/ty_python_semantic/src/types/class.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5552,7 +5552,7 @@ impl KnownClass {
55525552
.report_lint(&SUPER_CALL_IN_NAMED_TUPLE_METHOD, call_expression)
55535553
{
55545554
builder.into_diagnostic(format_args!(
5555-
"Cannot use `super()` in a method of NamedTuple subclass `{}`",
5555+
"Cannot use `super()` in a method of NamedTuple class `{}`",
55565556
enclosing_class.name(db)
55575557
));
55585558
}
@@ -5606,7 +5606,7 @@ impl KnownClass {
56065606
.report_lint(&SUPER_CALL_IN_NAMED_TUPLE_METHOD, call_expression)
56075607
{
56085608
builder.into_diagnostic(format_args!(
5609-
"Cannot use `super()` in a method of NamedTuple subclass `{}`",
5609+
"Cannot use `super()` in a method of NamedTuple class `{}`",
56105610
enclosing_class.name(db)
56115611
));
56125612
}

crates/ty_python_semantic/src/types/diagnostic.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,10 +1763,10 @@ declare_lint! {
17631763

17641764
declare_lint! {
17651765
/// ## What it does
1766-
/// Checks for calls to `super()` inside methods of `NamedTuple` subclasses.
1766+
/// Checks for calls to `super()` inside methods of `NamedTuple` classes.
17671767
///
17681768
/// ## Why is this bad?
1769-
/// Using `super()` in a method of a `NamedTuple` subclass will raise an exception at runtime.
1769+
/// Using `super()` in a method of a `NamedTuple` class will raise an exception at runtime.
17701770
///
17711771
/// ## Examples
17721772
/// ```python
@@ -1776,14 +1776,14 @@ declare_lint! {
17761776
/// x: int
17771777
///
17781778
/// def method(self):
1779-
/// super() # error: super() is not supported in methods of NamedTuple subclasses
1779+
/// super() # error: super() is not supported in methods of NamedTuple classes
17801780
/// ```
17811781
///
17821782
/// ## References
17831783
/// - [Python documentation: super()](https://docs.python.org/3/library/functions.html#super)
17841784
pub(crate) static SUPER_CALL_IN_NAMED_TUPLE_METHOD = {
1785-
summary: "detects `super()` calls in methods of `NamedTuple` subclasses",
1786-
status: LintStatus::preview("1.0.0"),
1785+
summary: "detects `super()` calls in methods of `NamedTuple` classes",
1786+
status: LintStatus::preview("0.0.1-alpha.30"),
17871787
default_level: Level::Error,
17881788
}
17891789
}

ty.schema.json

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

0 commit comments

Comments
 (0)