From 604fecf05a23194bb373b8440a9843edce65807e Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Mon, 20 Aug 2012 20:56:00 +0400 Subject: [PATCH] Fixed type checking for 'math' module functions and arguments that define '__float__' (PY-7231) --- .../src/com/jetbrains/python/PyNames.java | 7 +- .../stdlib/StdlibTypes2.properties | 89 +++++++++---------- .../jetbrains/python/psi/types/PyABCUtil.java | 9 ++ 3 files changed, 59 insertions(+), 46 deletions(-) diff --git a/python/psi-api/src/com/jetbrains/python/PyNames.java b/python/psi-api/src/com/jetbrains/python/PyNames.java index e256c462a2f2..d943f69b6d96 100644 --- a/python/psi-api/src/com/jetbrains/python/PyNames.java +++ b/python/psi-api/src/com/jetbrains/python/PyNames.java @@ -80,6 +80,11 @@ public class PyNames { public static final String SEQUENCE = "Sequence"; public static final String MAPPING = "Mapping"; + public static final String COMPLEX = "Complex"; + public static final String REAL = "Real"; + public static final String RATIONAL = "Rational"; + public static final String INTEGRAL = "Integral"; + public static final String CONTAINS = "__contains__"; public static final String HASH = "__hash__"; public static final String ITER = "__iter__"; @@ -328,7 +333,7 @@ public class PyNames { ); public static Set BuiltinInterfaces = ImmutableSet.of( - CALLABLE, HASHABLE, ITERABLE, ITERATOR, SIZED, CONTAINER, SEQUENCE, MAPPING + CALLABLE, HASHABLE, ITERABLE, ITERATOR, SIZED, CONTAINER, SEQUENCE, MAPPING, COMPLEX, REAL, RATIONAL, INTEGRAL ); /** diff --git a/python/src/com/jetbrains/python/codeInsight/stdlib/StdlibTypes2.properties b/python/src/com/jetbrains/python/codeInsight/stdlib/StdlibTypes2.properties index 21f9ab00484f..673d3198fd80 100644 --- a/python/src/com/jetbrains/python/codeInsight/stdlib/StdlibTypes2.properties +++ b/python/src/com/jetbrains/python/codeInsight/stdlib/StdlibTypes2.properties @@ -3,7 +3,6 @@ ## 2. Built-in functions __builtin__.abs = \ - :type number: int or long or float or complex \n\ :rtype: int \n\ __builtin__.all = \ @@ -1577,72 +1576,72 @@ collections.Iterator.next = \ ## 9.2 math math.acos = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.acosh = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.asin = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.asinh = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.atan = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.atan2 = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.atanh = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.ceil = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.copysign = \ - :type x: int or long or float \n\ - :type y: int or long or float \n\ + :type x: float or numbers.Real \n\ + :type y: float or numbers.Real \n\ :rtype: float \n\ math.cos = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.cosh = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.degrees = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.erf = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.erfc = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.exp = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.expm1 = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.fabs = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.factorial = \ @@ -1650,16 +1649,16 @@ math.factorial = \ :rtype: int \n\ math.floor = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.fmod = \ - :type x: int or long or float \n\ - :type y: int or long or float \n\ + :type x: float or numbers.Real \n\ + :type y: float or numbers.Real \n\ :rtype: float \n\ math.frexp = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: (float, int) \n\ math.fsum = \ @@ -1667,79 +1666,79 @@ math.fsum = \ :rtype: float \n\ math.gamma = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.hypot = \ - :type x: int or long or float \n\ - :type y: int or long or float \n\ + :type x: float or numbers.Real \n\ + :type y: float or numbers.Real \n\ :rtype: float \n\ math.isinf = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: bool \n\ math.isnan = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: bool \n\ math.ldexp = \ - :type x: int or long or float \n\ - :type y: int or long or float \n\ + :type x: float or numbers.Real \n\ + :type y: float or numbers.Real \n\ :rtype: float \n\ math.lgamma = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.log = \ - :type x: int or long or float \n\ - :type base: int or long or float \n\ + :type x: float or numbers.Real \n\ + :type base: float or numbers.Real \n\ :rtype: float \n\ math.log10 = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.log1p = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.modf = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: (float, float) \n\ math.pow = \ - :type x: int or long or float \n\ - :type y: int or long or float \n\ + :type x: float or numbers.Real \n\ + :type y: float or numbers.Real \n\ :rtype: float \n\ math.radians = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.sin = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.sinh = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.sqrt = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.tan = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.tanh = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: float \n\ math.trunc = \ - :type x: int or long or float \n\ + :type x: float or numbers.Real \n\ :rtype: int \n\ diff --git a/python/src/com/jetbrains/python/psi/types/PyABCUtil.java b/python/src/com/jetbrains/python/psi/types/PyABCUtil.java index 6192436f2415..21833152f3ca 100644 --- a/python/src/com/jetbrains/python/psi/types/PyABCUtil.java +++ b/python/src/com/jetbrains/python/psi/types/PyABCUtil.java @@ -53,6 +53,15 @@ public class PyABCUtil { if (PyNames.MAPPING.equals(superClassName)) { return isSized && hasIter && isContainer && hasGetItem && hasMethod(subClass, PyNames.KEYS, inherited); } + if (PyNames.COMPLEX.equals(superClassName)) { + return hasMethod(subClass, "__complex__", inherited); + } + if (PyNames.REAL.equals(superClassName)) { + return hasMethod(subClass, "__float__", inherited); + } + if (PyNames.INTEGRAL.equals(superClassName)) { + return hasMethod(subClass, "__int__", inherited); + } return false; }