| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent faac780 commit b6f2ea3
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2449,7 +2449,7 @@ def erase_override(t: Type) -> Type: | |||
| 2449 | 2449 | if not is_subtype(original_arg_type, erase_override(override_arg_type)): | |
| 2450 | 2450 | context: Context = node | |
| 2451 | 2451 | if isinstance(node, FuncDef) and not node.is_property: | |
| 2452 | - arg_node = node.arguments[i + len(override.bound_args)] | ||
| 2452 | + arg_node = node.arguments[i + override.bound()] | ||
| 2453 | 2453 | if arg_node.line != -1: | |
| 2454 | 2454 | context = arg_node | |
| 2455 | 2455 | self.msg.argument_incompatible_with_supertype( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4975,7 +4975,7 @@ def apply_type_arguments_to_callable( | |||
| 4975 | 4975 | tp.fallback, | |
| 4976 | 4976 | name="tuple", | |
| 4977 | 4977 | definition=tp.definition, | |
| 4978 | - bound_args=tp.bound_args, | ||
| 4978 | + is_bound=tp.is_bound, | ||
| 4979 | 4979 | ) | |
| 4980 | 4980 | self.msg.incompatible_type_application( | |
| 4981 | 4981 | min_arg_count, len(type_vars), len(args), ctx | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -921,7 +921,7 @@ def analyze_var( | |||
| 921 | 921 | bound_items = [] | |
| 922 | 922 | for ct in call_type.items if isinstance(call_type, UnionType) else [call_type]: | |
| 923 | 923 | p_ct = get_proper_type(ct) | |
| 924 | - if isinstance(p_ct, FunctionLike) and not p_ct.is_type_obj(): | ||
| 924 | + if isinstance(p_ct, FunctionLike) and (not p_ct.bound() or var.is_property): | ||
| 925 | 925 | item = expand_and_bind_callable(p_ct, var, itype, name, mx, is_trivial_self) | |
| 926 | 926 | else: | |
| 927 | 927 | item = expand_without_binding(ct, var, itype, original_itype, mx) | |
@@ -1498,6 +1498,6 @@ def bind_self_fast(method: F, original_type: Type | None = None) -> F: | |||
| 1498 | 1498 | arg_types=func.arg_types[1:], | |
| 1499 | 1499 | arg_kinds=func.arg_kinds[1:], | |
| 1500 | 1500 | arg_names=func.arg_names[1:], | |
| 1501 | - bound_args=[original_type], | ||
| 1501 | + is_bound=True, | ||
| 1502 | 1502 | ) | |
| 1503 | 1503 | return cast(F, res) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -271,9 +271,6 @@ def visit_callable_type(self, ct: CallableType) -> None: | |||
| 271 | 271 | ct.ret_type.accept(self) | |
| 272 | 272 | for v in ct.variables: | |
| 273 | 273 | v.accept(self) | |
| 274 | - for arg in ct.bound_args: | ||
| 275 | - if arg: | ||
| 276 | - arg.accept(self) | ||
| 277 | 274 | if ct.type_guard is not None: | |
| 278 | 275 | ct.type_guard.accept(self) | |
| 279 | 276 | if ct.type_is is not None: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -644,8 +644,8 @@ def incompatible_argument( | |||
| 644 | 644 | callee_name = callable_name(callee) | |
| 645 | 645 | if callee_name is not None: | |
| 646 | 646 | name = callee_name | |
| 647 | - if callee.bound_args and callee.bound_args[0] is not None: | ||
| 648 | - base = format_type(callee.bound_args[0], self.options) | ||
| 647 | + if object_type is not None: | ||
| 648 | + base = format_type(object_type, self.options) | ||
| 649 | 649 | else: | |
| 650 | 650 | base = extract_type(name) | |
| 651 | 651 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -460,6 +460,7 @@ def visit_callable_type(self, typ: CallableType) -> SnapshotItem: | |||
| 460 | 460 | typ.is_type_obj(), | |
| 461 | 461 | typ.is_ellipsis_args, | |
| 462 | 462 | snapshot_types(typ.variables), | |
| 463 | + typ.is_bound, | ||
| 463 | 464 | ) | |
| 464 | 465 | ||
| 465 | 466 | def normalize_callable_variables(self, typ: CallableType) -> CallableType: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -185,6 +185,7 @@ def type_object_type(info: TypeInfo, named_type: Callable[[str], Instance]) -> P | |||
| 185 | 185 | arg_kinds=[ARG_STAR, ARG_STAR2], | |
| 186 | 186 | arg_names=["_args", "_kwds"], | |
| 187 | 187 | ret_type=any_type, | |
| 188 | + is_bound=True, | ||
| 188 | 189 | fallback=named_type("builtins.function"), | |
| 189 | 190 | ) | |
| 190 | 191 | return class_callable(sig, info, fallback, None, is_new=False) | |
@@ -479,7 +480,7 @@ class B(A): pass | |||
| 479 | 480 | arg_kinds=func.arg_kinds[1:], | |
| 480 | 481 | arg_names=func.arg_names[1:], | |
| 481 | 482 | variables=variables, | |
| 482 | - bound_args=[original_type], | ||
| 483 | + is_bound=True, | ||
| 483 | 484 | ) | |
| 484 | 485 | return cast(F, res) | |
| 485 | 486 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1605,6 +1605,9 @@ def with_name(self, name: str) -> FunctionLike: | |||
| 1605 | 1605 | def get_name(self) -> str | None: | |
| 1606 | 1606 | pass | |
| 1607 | 1607 | ||
| 1608 | + def bound(self) -> bool: | ||
| 1609 | + return bool(self.items) and self.items[0].is_bound | ||
| 1610 | + | ||
| 1608 | 1611 | ||
| 1609 | 1612 | class FormalArgument(NamedTuple): | |
| 1610 | 1613 | name: str | None | |
@@ -1834,8 +1837,7 @@ class CallableType(FunctionLike): | |||
| 1834 | 1837 | # 'dict' and 'partial' for a `functools.partial` evaluation) | |
| 1835 | 1838 | "from_type_type", # Was this callable generated by analyzing Type[...] | |
| 1836 | 1839 | # instantiation? | |
| 1837 | - "bound_args", # Bound type args, mostly unused but may be useful for | ||
| 1838 | - # tools that consume mypy ASTs | ||
| 1840 | + "is_bound", # Is this a bound method? | ||
| 1839 | 1841 | "def_extras", # Information about original definition we want to serialize. | |
| 1840 | 1842 | # This is used for more detailed error messages. | |
| 1841 | 1843 | "type_guard", # T, if -> TypeGuard[T] (ret_type is bool in this case). | |
@@ -1863,7 +1865,7 @@ def __init__( | |||
| 1863 | 1865 | implicit: bool = False, | |
| 1864 | 1866 | special_sig: str | None = None, | |
| 1865 | 1867 | from_type_type: bool = False, | |
| 1866 | - bound_args: Sequence[Type | None] = (), | ||
| 1868 | + is_bound: bool = False, | ||
| 1867 | 1869 | def_extras: dict[str, Any] | None = None, | |
| 1868 | 1870 | type_guard: Type | None = None, | |
| 1869 | 1871 | type_is: Type | None = None, | |
@@ -1896,9 +1898,7 @@ def __init__( | |||
| 1896 | 1898 | self.from_type_type = from_type_type | |
| 1897 | 1899 | self.from_concatenate = from_concatenate | |
| 1898 | 1900 | self.imprecise_arg_kinds = imprecise_arg_kinds | |
| 1899 | - if not bound_args: | ||
| 1900 | - bound_args = () | ||
| 1901 | - self.bound_args = bound_args | ||
| 1901 | + self.is_bound = is_bound | ||
| 1902 | 1902 | if def_extras: | |
| 1903 | 1903 | self.def_extras = def_extras | |
| 1904 | 1904 | elif isinstance(definition, FuncDef): | |
@@ -1935,7 +1935,7 @@ def copy_modified( | |||
| 1935 | 1935 | implicit: Bogus[bool] = _dummy, | |
| 1936 | 1936 | special_sig: Bogus[str | None] = _dummy, | |
| 1937 | 1937 | from_type_type: Bogus[bool] = _dummy, | |
| 1938 | - bound_args: Bogus[list[Type | None]] = _dummy, | ||
| 1938 | + is_bound: Bogus[bool] = _dummy, | ||
| 1939 | 1939 | def_extras: Bogus[dict[str, Any]] = _dummy, | |
| 1940 | 1940 | type_guard: Bogus[Type | None] = _dummy, | |
| 1941 | 1941 | type_is: Bogus[Type | None] = _dummy, | |
@@ -1960,7 +1960,7 @@ def copy_modified( | |||
| 1960 | 1960 | implicit=implicit if implicit is not _dummy else self.implicit, | |
| 1961 | 1961 | special_sig=special_sig if special_sig is not _dummy else self.special_sig, | |
| 1962 | 1962 | from_type_type=from_type_type if from_type_type is not _dummy else self.from_type_type, | |
| 1963 | - bound_args=bound_args if bound_args is not _dummy else self.bound_args, | ||
| 1963 | + is_bound=is_bound if is_bound is not _dummy else self.is_bound, | ||
| 1964 | 1964 | def_extras=def_extras if def_extras is not _dummy else dict(self.def_extras), | |
| 1965 | 1965 | type_guard=type_guard if type_guard is not _dummy else self.type_guard, | |
| 1966 | 1966 | type_is=type_is if type_is is not _dummy else self.type_is, | |
@@ -2285,7 +2285,7 @@ def serialize(self) -> JsonDict: | |||
| 2285 | 2285 | "variables": [v.serialize() for v in self.variables], | |
| 2286 | 2286 | "is_ellipsis_args": self.is_ellipsis_args, | |
| 2287 | 2287 | "implicit": self.implicit, | |
| 2288 | - "bound_args": [(None if t is None else t.serialize()) for t in self.bound_args], | ||
| 2288 | + "is_bound": self.is_bound, | ||
| 2289 | 2289 | "def_extras": dict(self.def_extras), | |
| 2290 | 2290 | "type_guard": self.type_guard.serialize() if self.type_guard is not None else None, | |
| 2291 | 2291 | "type_is": (self.type_is.serialize() if self.type_is is not None else None), | |
@@ -2308,7 +2308,7 @@ def deserialize(cls, data: JsonDict) -> CallableType: | |||
| 2308 | 2308 | variables=[cast(TypeVarLikeType, deserialize_type(v)) for v in data["variables"]], | |
| 2309 | 2309 | is_ellipsis_args=data["is_ellipsis_args"], | |
| 2310 | 2310 | implicit=data["implicit"], | |
| 2311 | - bound_args=[(None if t is None else deserialize_type(t)) for t in data["bound_args"]], | ||
| 2311 | + is_bound=data["is_bound"], | ||
| 2312 | 2312 | def_extras=data["def_extras"], | |
| 2313 | 2313 | type_guard=( | |
| 2314 | 2314 | deserialize_type(data["type_guard"]) if data["type_guard"] is not None else None | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4292,7 +4292,7 @@ int.__eq__(3, 4) | |||
| 4292 | 4292 | [builtins fixtures/args.pyi] | |
| 4293 | 4293 | [out] | |
| 4294 | 4294 | main:33: error: Too few arguments for "__eq__" of "int" | |
| 4295 | - main:33: error: Unsupported operand types for == ("int" and "type[int]") | ||
| 4295 | + main:33: error: Unsupported operand types for == ("type[int]" and "type[int]") | ||
| 4296 | 4296 | ||
| 4297 | 4297 | [case testDupBaseClasses] | |
| 4298 | 4298 | class A: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3591,3 +3591,45 @@ class Bar(Foo): | |||
| 3591 | 3591 | ||
| 3592 | 3592 | def foo(self, value: Union[int, str]) -> Union[int, str]: | |
| 3593 | 3593 | return super().foo(value) # E: Call to abstract method "foo" of "Foo" with trivial body via super() is unsafe | |
| 3594 | + | ||
| 3595 | + [case testBoundMethodsAssignedInClassBody] | ||
| 3596 | + from typing import Callable | ||
| 3597 | + | ||
| 3598 | + class A: | ||
| 3599 | + def f(self, x: int) -> str: | ||
| 3600 | + pass | ||
| 3601 | + @classmethod | ||
| 3602 | + def g(cls, x: int) -> str: | ||
| 3603 | + pass | ||
| 3604 | + @staticmethod | ||
| 3605 | + def h(x: int) -> str: | ||
| 3606 | + pass | ||
| 3607 | + attr: Callable[[int], str] | ||
| 3608 | + | ||
| 3609 | + class C: | ||
| 3610 | + x1 = A.f | ||
| 3611 | + x2 = A.g | ||
| 3612 | + x3 = A().f | ||
| 3613 | + x4 = A().g | ||
| 3614 | + x5 = A.h | ||
| 3615 | + x6 = A().h | ||
| 3616 | + x7 = A().attr | ||
| 3617 | + | ||
| 3618 | + reveal_type(C.x1) # N: Revealed type is "def (self: __main__.A, x: builtins.int) -> builtins.str" | ||
| 3619 | + reveal_type(C.x2) # N: Revealed type is "def (x: builtins.int) -> builtins.str" | ||
| 3620 | + reveal_type(C.x3) # N: Revealed type is "def (x: builtins.int) -> builtins.str" | ||
| 3621 | + reveal_type(C.x4) # N: Revealed type is "def (x: builtins.int) -> builtins.str" | ||
| 3622 | + reveal_type(C.x5) # N: Revealed type is "def (x: builtins.int) -> builtins.str" | ||
| 3623 | + reveal_type(C.x6) # N: Revealed type is "def (x: builtins.int) -> builtins.str" | ||
| 3624 | + reveal_type(C.x7) # N: Revealed type is "def (builtins.int) -> builtins.str" | ||
| 3625 | + | ||
| 3626 | + reveal_type(C().x1) # E: Invalid self argument "C" to attribute function "x1" with type "Callable[[A, int], str]" \ | ||
| 3627 | + # N: Revealed type is "def (x: builtins.int) -> builtins.str" | ||
| 3628 | + reveal_type(C().x2) # N: Revealed type is "def (x: builtins.int) -> builtins.str" | ||
| 3629 | + reveal_type(C().x3) # N: Revealed type is "def (x: builtins.int) -> builtins.str" | ||
| 3630 | + reveal_type(C().x4) # N: Revealed type is "def (x: builtins.int) -> builtins.str" | ||
| 3631 | + reveal_type(C().x5) # N: Revealed type is "def (x: builtins.int) -> builtins.str" | ||
| 3632 | + reveal_type(C().x6) # N: Revealed type is "def (x: builtins.int) -> builtins.str" | ||
| 3633 | + reveal_type(C().x7) # E: Invalid self argument "C" to attribute function "x7" with type "Callable[[int], str]" \ | ||
| 3634 | + # N: Revealed type is "def () -> builtins.str" | ||
| 3635 | + [builtins fixtures/classmethod.pyi] | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments