Skip to content

Move self argument checks to a later phase - after decorator application, if any #19490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Prev Previous commit
Add decorated scenarios too
  • Loading branch information
sterliakov committed Jul 28, 2025
commit b71402ae4d08d3c3a8ac42c8e90ba18a18c68f93
35 changes: 35 additions & 0 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -7912,27 +7912,62 @@ reveal_type(D().fn3) # E: Invalid self argument "D" to attribute function "fn3"
[builtins fixtures/tuple.pyi]

[case testMethodSelfArgumentChecksInUntyped]
from typing import Callable, ParamSpec, TypeVar

T = TypeVar("T")
P = ParamSpec("P")

def to_same_callable(fn: Callable[P, T]) -> Callable[P, T]:
return fn

def unchecked():
class Bad:
def fn() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument?
def fn2(x: int) -> None: ... # E: Self argument missing for a non-static method (or an invalid type for self)

# TODO: would be nice to make this error, but now we see the func
# being decorated as Any, not as a callable
@to_same_callable
def gaaa() -> None: ...
@to_same_callable
def gaaa2(x: int) -> None: ...

class Ok:
def fn(): ...
def fn2(x): ...

@to_same_callable
def g(): ...
@to_same_callable
def g2(x): ...

def checked() -> None:
class Bad:
def fn() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument?
def fn2(x: int) -> None: ... # E: Self argument missing for a non-static method (or an invalid type for self)

@to_same_callable
def g() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument?
@to_same_callable
def g2(x: int) -> None: ... # E: Self argument missing for a non-static method (or an invalid type for self)

class AlsoBad:
def fn(): ... # E: Method must have at least one argument. Did you forget the "self" argument?
def fn2(x): ...

@to_same_callable
def g(): ... # E: Method must have at least one argument. Did you forget the "self" argument?
@to_same_callable
def g2(x): ...

class Ok:
def fn(): ... # E: Method must have at least one argument. Did you forget the "self" argument?
def fn2(x): ...

@to_same_callable
def g(): ... # E: Method must have at least one argument. Did you forget the "self" argument?
@to_same_callable
def g2(x): ...
[builtins fixtures/tuple.pyi]

[case testTypeAfterAttributeAccessWithDisallowAnyExpr]
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy