-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
help wantedContributions especially welcomeContributions especially welcometestingRelated to testing Ruff itselfRelated to testing Ruff itselftyMulti-file analysis & type inferenceMulti-file analysis & type inference
Description
It doesn't look like we yet have any test cases for classes where __new__ and __init__ are incompatible with each other. Construction of these classes always fails at runtime, but we should make sure we handle them correctly anyway. (It looks like we do handle them correctly, but that doesn't mean we shouldn't add tests for it.)
import abc
class Foo:
def __new__(cls) -> "Foo":
return object.__new__(cls)
def __init__(self, x):
self.x = 42
Foo() # fails due to incorrect arguments to `__init__`
Foo(42) # fails due to incorrect arguments to `__new__`
class Foo2:
def __new__(cls, x) -> "Foo2":
return object.__new__(cls)
def __init__(self):
pass
Foo2() # fails
Foo2(42) # also fails
class Foo3(metaclass=abc.ABCMeta):
def __new__(cls) -> "Foo3":
return object.__new__(cls)
def __init__(self, x):
self.x = 42
Foo3() # fails
Foo3(42) # also fails
class Foo4(metaclass=abc.ABCMeta):
def __new__(cls, x) -> "Foo4":
return object.__new__(cls)
def __init__(self):
pass
Foo4() # fails
Foo4(42) # also failsThese tests should be added to crates/red_knot_python_semantic/resources/mdtest/call/constructor.md.
Metadata
Metadata
Assignees
Labels
help wantedContributions especially welcomeContributions especially welcometestingRelated to testing Ruff itselfRelated to testing Ruff itselftyMulti-file analysis & type inferenceMulti-file analysis & type inference