Files
openide/python/testData/inspections/PyDataclassInspection/attrsUselessInitReprStrEq.py
Semyon Proshev 9ef2a6f638 Update parsing of attr.s for all the changes introduced in 19.2.0 and before (PY-36113, PY-38400)
GitOrigin-RevId: 11db701c16986bc8704f139f60a85f5b9c32a509
2019-12-04 12:33:00 +00:00

76 lines
1.7 KiB
Python

import attr
@attr.dataclass(repr=True, cmp=True, str=True)
class A1:
a: int = 1
def <warning descr="'__repr__' is ignored if the class already defines 'repr' parameter">__repr__</warning>(self):
return "repr1"
def <warning descr="'__str__' is ignored if the class already defines 'str' parameter">__str__</warning>(self):
return "str1"
def <warning descr="'__eq__' is ignored if the class already defines 'cmp/order' parameter">__eq__</warning>(self, other):
return "eq1"
@attr.dataclass(eq=True)
class A2:
a: int = 1
def <warning descr="'__eq__' is ignored if the class already defines 'cmp/order' parameter">__eq__</warning>(self, other):
return "eq1"
class Base:
def __repr__(self):
return "repr2"
def __str__(self):
return "str2"
def __eq__(self, other):
return "eq2"
@attr.dataclass(repr=True, cmp=True, str=True)
class Derived(Base):
d: int = 1
@attr.dataclass
class B1:
b: int = 1
def <warning descr="'__init__' is ignored if the class already defines 'init' parameter">__init__</warning>(self):
print("ok")
@attr.dataclass(init=True)
class B2:
b: int = 1
def <warning descr="'__init__' is ignored if the class already defines 'init' parameter">__init__</warning>(self):
print("ok")
@attr.dataclass
class C1:
c: int = 1
def <warning descr="'__eq__' is ignored if the class already defines 'cmp/order' parameter">__eq__</warning>(self, other):
return "eq1"
print(repr(A1()))
print(str(A1()))
print(A1() == A1())
print(A2() == A2())
print(repr(Derived()))
print(str(Derived()))
print(Derived() == Derived())
B1()
B2()