8000 Foundations for non-linear solver and polymorphic application by ilevkivskyi · Pull Request #15287 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Foundations for non-linear solver and polymorphic application #15287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Delete tests that are not going to be supported
  • Loading branch information
ilevkivskyi committed May 22, 2023
commit 9191761b642cd3ff7b596abf5875a5be7b10c690
8 changes: 5 additions & 3 deletions mypy/checkexpr.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,6 @@ def infer_function_type_arguments(
elif not first_arg or not is_subtype(self.named_type("builtins.str"), first_arg):
self.chk.fail(message_registry.KEYWORD_ARGUMENT_REQUIRES_STR_KEY_TYPE, context)

# TODO: Filter away (or handle) ParamSpec?
if any(
a is None or isinstance(get_proper_type(a), UninhabitedType) for a in inferred_args
):
Expand All @@ -1807,7 +1806,6 @@ def infer_function_type_arguments(
allow_polymorphic=True,
)
for i, pa in enumerate(get_proper_types(poly_inferred_args)):
# TODO: can we be more principled here?
if isinstance(pa, (NoneType, UninhabitedType)) or has_erased_component(pa):
poly_inferred_args[i] = None
poly_callee_type = self.apply_generic_arguments(
Expand Down Expand Up @@ -5363,7 +5361,11 @@ def visit_type_var(self, t: TypeVarType) -> Type:
return super().visit_type_var(t)

def visit_param_spec(self, t: ParamSpecType) -> Type:
# TODO: more careful here (also handle TypeVarTupleType)
# TODO: Support polymorphic apply for ParamSpec.
raise PolyTranslationError()

def visit_type_var_tuple(self, t: TypeVarTupleType) -> Type:
# TODO: Support polymorphic apply for TypeVarTuple.
raise PolyTranslationError()

def visit_type_alias_type(self, t: TypeAliasType) -> Type:
Expand Down
2 changes: 1 addition & 1 deletion mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ def visit_callable_type(self, template: CallableType) -> list[Constraint]:
param_spec = template.param_spec()
if param_spec is None:
# FIX verify argument counts
# TODO: Erase template vars if generic?
# TODO: Erase template variables if it is generic?
if cactual.variables and cactual.param_spec() is None:
unified = mypy.subtypes.unify_generic_callable(
cactual, template, ignore_return=True
Expand Down
31 changes: 0 additions & 31 deletions test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -1555,34 +1555,3 @@ def test(x: U) -> U: ...
reveal_type(dec) # N: Revealed type is "def [P, T] (f: def (*P.args, **P.kwargs) -> T`-2) -> def (*P.args, **P.kwargs) -> builtins.list[T`-2]"
reveal_type(dec(test)) # N: Revealed type is "def [U] (x: U`-1) -> builtins.list[U`-1]"
[builtins fixtures/paramspec.pyi]

[case testParamSpecDecoratorAppliedToGenericReverse]
from typing import Callable, List, TypeVar
from typing_extensions import ParamSpec

P = ParamSpec("P")
T = TypeVar("T")
U = TypeVar("U")

def dec(f: Callable[P, List[T]]) -> Callable[P, T]: ...
def test(x: U) -> U: ...
reveal_type(dec) # N: Revealed type is "def [P, T] (f: def (*P.args, **P.kwargs) -> T`-2) -> def (*P.args, **P.kwargs) -> builtins.list[T`-2]"
reveal_type(dec(test)) # N: Revealed type is "def [U] (x: U`-1) -> builtins.list[U`-1]"
[builtins fixtures/paramspec.pyi]

[case testParamSpecCurryAppliedToGeneric]
from typing import Callable, List, TypeVar
from typing_extensions import ParamSpec, Concatenate

P = ParamSpec("P")
S = TypeVar("S")
T = TypeVar("T")
U = TypeVar("U")

def dec(f: Callable[Concatenate[T, P], S]) -> Callable[P, Callable[[T], S]]: ...
def test(x: U) -> U: ...
def test2(x: U, y: U) -> U: ...
reveal_type(dec)
reveal_type(dec(test))
reveal_type(dec(test2))
[builtins fixtures/paramspec.pyi]
0