Is the given attribute a method with a None-compatible return type? Overloads are only checked if there is an implementation.
(self, type: TypeInfo, attr_name: str)
| 1871 | return callee.ret_type, callee |
| 1872 | |
| 1873 | def can_return_none(self, type: TypeInfo, attr_name: str) -> bool: |
| 1874 | """Is the given attribute a method with a None-compatible return type? |
| 1875 | |
| 1876 | Overloads are only checked if there is an implementation. |
| 1877 | """ |
| 1878 | if not state.strict_optional: |
| 1879 | # If strict-optional is not set, is_subtype(NoneType(), T) is always True. |
| 1880 | # So, we cannot do anything useful here in that case. |
| 1881 | return False |
| 1882 | for base in type.mro: |
| 1883 | symnode = base.names.get(attr_name) |
| 1884 | if symnode is None: |
| 1885 | continue |
| 1886 | node = symnode.node |
| 1887 | if isinstance(node, OverloadedFuncDef): |
| 1888 | node = node.impl |
| 1889 | if isinstance(node, Decorator): |
| 1890 | node = node.func |
| 1891 | if isinstance(node, FuncDef): |
| 1892 | if node.type is not None: |
| 1893 | assert isinstance(node.type, CallableType) |
| 1894 | return is_subtype(NoneType(), node.type.ret_type) |
| 1895 | return False |
| 1896 | |
| 1897 | def analyze_type_type_callee(self, item: ProperType, context: Context) -> Type: |
| 1898 | """Analyze the callee X in X(...) where X is Type[item]. |
no test coverage detected