Skip to content

Commit

Permalink
Add test for accessing classmethod from derived class
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Feb 24, 2025
1 parent 1296fa5 commit e4858e6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/red_knot_python_semantic/resources/mdtest/call/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@ class D:
D.f()
```

When a class method is accessed on a derived class, it is bound to that derived class:

```py
class Derived(C):
pass

reveal_type(Derived.f) # revealed: <bound method `f` of `Literal[Derived]`>
reveal_type(Derived().f) # revealed: <bound method `f` of `type[Derived]`>

reveal_type(Derived.f(1)) # revealed: str
reveal_type(Derived().f(1)) # revealed: str
```

### Accessing the classmethod as a static member

Accessing a `@classmethod`-decorated function at runtime returns a `classmethod` object. We
Expand Down

0 comments on commit e4858e6

Please sign in to comment.