mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fixed type assertions for named tuples (PY-4611)
This commit is contained in:
@@ -29,7 +29,7 @@ public class PyNamedTupleType extends PyClassType implements PyCallableType {
|
||||
private final boolean myDefinition;
|
||||
private final PsiElement myDeclaration;
|
||||
private final List<String> myFields;
|
||||
|
||||
|
||||
private static final ImmutableSet<String> ourClassMembers = ImmutableSet.of("_fields", "_make");
|
||||
private static final ImmutableSet<String> ourInstanceMembers = ImmutableSet.of("_asdict", "_replace");
|
||||
|
||||
@@ -83,7 +83,7 @@ public class PyNamedTupleType extends PyClassType implements PyCallableType {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "namedtuple '" + myName + "'";
|
||||
return myName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,6 +99,16 @@ public class PyNamedTupleType extends PyClassType implements PyCallableType {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PyClassType toInstance() {
|
||||
return myIsDefinition ? new PyNamedTupleType(myDeclaration, myName, myFields, false) : this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PyNamedTupleType: " + myName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PyType fromCall(PyCallExpression call) {
|
||||
final String name = PyUtil.strValue(call.getArgument(0, PyExpression.class));
|
||||
|
||||
@@ -10,3 +10,6 @@ print p.__add__
|
||||
print p._asdict()
|
||||
print Point._fields
|
||||
print p._replace
|
||||
|
||||
if isinstance(p, Point):
|
||||
p.x
|
||||
Reference in New Issue
Block a user