8000 Basic ParamSpec Concatenate and literal support by A5rocks · Pull Request #11847 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Basic ParamSpec Concatenate and literal support #11847

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 50 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ef32680
Add ParamSpec literals
A5rocks Dec 24, 2021
816f3cd
Improve ParamSpec and Parameters checking
A5rocks Dec 25, 2021
d9b352f
Get basic Concatenate features working
A5rocks Dec 26, 2021
58e6dbe
Fix "cache" bug
A5rocks Dec 26, 2021
51ba4ea
Check Concatenate prefixes
A5rocks Dec 26, 2021
24432ee
Polish work
A5rocks Dec 26, 2021
c507152
Merge branch 'master' into paramspec-literals
A5rocks Dec 26, 2021
d202d1e
Tests for literals
A5rocks Dec 26, 2021
9ed9830
Tests for Concatenate
A5rocks Dec 26, 2021
3ffc343
Appease CI
A5rocks Dec 26, 2021
ae8ac73
Forgot to comment out the directives...
A5rocks Dec 26, 2021
9c849cc
Improve literal TODOs
A5rocks Dec 27, 2021
d9dcc76
Add more tests
A5rocks Dec 28, 2021
0e2b207
Allow TypeVars in Concatenate
A5rocks Dec 28, 2021
bd445e5
Fix a couple of dumb oversights
A5rocks Dec 28, 2021
604c304
Allow Callables along with Parameters
A5rocks Dec 28, 2021
f8004ec
Fix tests
A5rocks Dec 28, 2021
9e75481
Misc changes
A5rocks Dec 29, 2021
7b89f06
Solve with self types
A5rocks Jan 1, 2022
f24cf4f
Add fallback return to meeting paramspec literals
A5rocks Jan 1, 2022
472b20c
Type application of ParamSpec literals
A5rocks Jan 3, 2022
14ecfb9
Ellipsis paramspec literals
A5rocks Jan 3, 2022
5e0ae49
Merge branch 'master' into paramspec-literals
A5rocks Jan 3, 2022
45c8057
Appease flake8
A5rocks Jan 3, 2022
10966ea
Merge branch 'master' into paramspec-literals
hauntsaninja Jan 7, 2022
c46feec
Minor code cleanup
A5rocks Jan 9, 2022
6a9cd71
Error notes and better subtyping for paramspec literals
A5rocks Jan 9, 2022
afc1a57
Appease CI
A5rocks Jan 9, 2022
41e38b2
Merge remote-tracking branch 'upstream/master' into paramspec-literals
A5rocks Jan 19, 2022
86e23c2
Fix something I assumed incorrectly
A5rocks Jan 27, 2022
3f4cf5c
Merge branch 'master' into paramspec-literals
A5rocks Jan 27, 2022
61b00cd
Revert "Minor code cleanup"
A5rocks Jan 29, 2022
9c2cefd
Merge branch 'master' into paramspec-literals
A5rocks Mar 1, 2022
a44937b
Fixed raised bugs
A5rocks Mar 1, 2022
bbabbf1
Fix CI errors
A5rocks Mar 1, 2022
ddfd34a
Squash some more bugs
A5rocks Mar 5, 2022
2d54ac4
Concatenate flag
A5rocks Mar 5, 2022
bba91e5
Prepare for GitHub Actions
A5rocks Mar 5, 2022
e0a7663
Merge branch 'master' into paramspec-literals
A5rocks Mar 7, 2022
0363803
Bug report with nested decorators and Concatenate
A5rocks Mar 7, 2022
278b8c4
Switch over to using Parameters instead of CallableType
A5rocks Mar 7, 2022
c2b7628
Add variance to paramspecs
A5rocks Mar 7, 2022
0b1fdfb
Apply suggestions from code review
A5rocks Mar 10, 2022
0fff609
Update tests
A5rocks Mar 10, 2022
4475515
Some of the PR feedback
A5rocks Mar 25, 2022
0091762
Merge branch 'master' into paramspec-literals
A5rocks Mar 26, 2022
81994f1
Prepare for GitHub actions
A5rocks Mar 26, 2022
1ff96c1
Merge branch 'master' into paramspec-literals
A5rocks Apr 5, 2022
c79918e
Fix tests to latest output
A5rocks Apr 5, 2022
9b1fc75
Copy pyright's representation of Concatenate
A5rocks Apr 5, 2022
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
Polish work
  • Loading branch information
A5rocks committed Dec 26, 2021
commit 24432ee4afdfebd23de1e5e4c14a95a88578ff9a
43 changes: 23 additions & 20 deletions mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ def visit_instance(self, template: Instance) -> List[Constraint]:
# N.B: We use zip instead of indexing because the lengths might have
# mismatches during daemon reprocessing.
for tvar, mapped_arg, instance_arg in zip(tvars, mapped.args, instance.args):
# TODO(PEP612): More ParamSpec work (or is Parameters the only thing accepted)
if isinstance(tvar, TypeVarType):
# The constraints for generic type parameters depend on variance.
# Include constraints from both directions if invariant.
Expand All @@ -455,16 +456,17 @@ def visit_instance(self, template: Instance) -> List[Constraint]:
if tvar.variance != COVARIANT:
res.extend(infer_constraints(
mapped_arg, instance_arg, neg_op(self.direction)))
elif isinstance(tvar, ParamSpecType):
# no such thing as variance for ParamSpecs
# TODO: is there a case I am missing?
# TODO: what is setting meta_level to 0?
suffix = template_arg
prefix = mapped_arg.prefix
suffix = suffix.copy_modified(suffix.arg_types[len(prefix.arg_types):],
suffix.arg_kinds[len(prefix.arg_kinds):],
suffix.arg_names[len(prefix.arg_names):])
res.append(Constraint(mapped_arg.id, SUPERTYPE_OF, suffix))
elif isinstance(tvar, ParamSpecType) and isinstance(mapped_arg, ParamSpecType):
suffix = get_proper_type(instance_arg)
if isinstance(suffix, Parameters):
# no such thing as variance for ParamSpecs
# TODO: is there a case I am missing?
# TODO: what is setting meta_level to 0?
prefix = mapped_arg.prefix
suffix = suffix.copy_modified(suffix.arg_types[len(prefix.arg_types):],
suffix.arg_kinds[len(prefix.arg_kinds):],
suffix.arg_names[len(prefix.arg_names):])
res.append(Constraint(mapped_arg.id, SUPERTYPE_OF, suffix))
return res
elif (self.direction == SUPERTYPE_OF and
instance.type.has_base(template.type.fullname)):
Expand All @@ -482,16 +484,17 @@ def visit_instance(self, template: Instance) -> List[Constraint]:
if tvar.variance != COVARIANT:
res.extend(infer_constraints(
template_arg, mapped_arg, neg_op(self.direction)))
elif isinstance(tvar, ParamSpecType):
# no such thing as variance for ParamSpecs
# TODO: is there a case I am missing?
# TODO: what is setting meta_level to 0?
suffix = mapped_arg
prefix = template_arg.prefix
suffix = suffix.copy_modified(suffix.arg_types[len(prefix.arg_types):],
suffix.arg_kinds[len(prefix.arg_kinds):],
suffix.arg_names[len(prefix.arg_names):])
res.append(Constraint(template_arg.id, SUPERTYPE_OF, suffix))
elif isinstance(tvar, ParamSpecType) and isinstance(template_arg, ParamSpecType):
suffix = get_proper_type(mapped_arg)
if isinstance(suffix, Parameters):
# no such thing as variance for ParamSpecs
# TODO: is there a case I am missing?
# TODO: what is setting meta_level to 0?
prefix = template_arg.prefix
suffix = suffix.copy_modified(suffix.arg_types[len(prefix.arg_types):],
suffix.arg_kinds[len(prefix.arg_kinds):],
suffix.arg_names[len(prefix.arg_names):])
res.append(Constraint(template_arg.id, SUPERTYPE_OF, suffix))
return res
if (template.type.is_protocol and self.direction == SUPERTYPE_OF and
# We avoid infinite recursion for structural subtypes by checking
Expand Down
8 changes: 6 additions & 2 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def cannot_resolve_type(self, t: UnboundType) -> None:
'Cannot resolve name "{}" (possible cyclic definition)'.format(t.name),
t)

def apply_concatenate_operator(self, t: UnboundType) -> Optional[ParamSpecType]:
def apply_concatenate_operator(self, t: UnboundType) -> Type:
if len(t.args) == 0:
self.api.fail('Concatenate needs type arguments', t)
return AnyType(TypeOfAny.from_error)
Expand All @@ -295,9 +295,13 @@ def apply_concatenate_operator(self, t: UnboundType) -> Optional[ParamSpecType]:

args = self.anal_array(t.args[:-1])
pre = ps.prefix

# mypy can't infer this :(
names: List[Optional[str]] = [None] * len(args)

pre = Para A6A9 meters(args + pre.arg_types,
[ARG_POS] * len(args) + pre.arg_kinds,
[None] * len(args) + pre.arg_names)
names + pre.arg_names)
return ps.copy_modified(prefix=pre)

def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Optional[Type]:
Expand Down
2 changes: 1 addition & 1 deletion mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def deserialize(cls, data: JsonDict) -> 'ParamSpecType':
data['id'],
data['flavor'],
deserialize_type(data['upper_bound']),
prefix=deserialize_type(data['prefix'])
prefix=Parameters.deserialize(data['prefix'])
)


Expand Down
0