Repository navigation
pep612: more semantic analysis for paramspec #9422
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
Changes from 1 commit
6417364
489a3f8
dbfd6b5
8cb584f
335fdf6
fe7b655
21a15ae
77dd1cd
c7a80de
af72219
12fab24
1c1d15c
465113a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Creates a number of TODOs that I shall get to.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1015,7 +1015,7 @@ def __init__(self, | |
| fallback: Instance, | ||
| name: Optional[str] = None, | ||
| definition: Optional[SymbolNode] = None, | ||
| variables: Optional[List[TypeVarDef]] = None, | ||
| variables: Optional[Sequence[TypeVarLikeDef]] = None, | ||
| line: int = -1, | ||
| column: int = -1, | ||
| is_ellipsis_args: bool = False, | ||
|
|
@@ -1067,7 +1067,7 @@ def copy_modified(self, | |
| fallback: Bogus[Instance] = _dummy, | ||
| name: Bogus[Optional[str]] = _dummy, | ||
| definition: Bogus[SymbolNode] = _dummy, | ||
| variables: Bogus[List[TypeVarDef]] = _dummy, | ||
| variables: Bogus[Sequence[TypeVarLikeDef]] = _dummy, | ||
| line: Bogus[int] = _dummy, | ||
| column: Bogus[int] = _dummy, | ||
| is_ellipsis_args: Bogus[bool] = _dummy, | ||
|
|
@@ -2096,15 +2096,19 @@ def visit_callable_type(self, t: CallableType) -> str: | |
|
|
||
| if t.variables: | ||
| vs = [] | ||
| # We reimplement TypeVarDef.__repr__ here in order to support id_mapper. | ||
| for var in t.variables: | ||
| if var.values: | ||
| vals = '({})'.format(', '.join(val.accept(self) for val in var.values)) | ||
| vs.append('{} in {}'.format(var.name, vals)) | ||
| elif not is_named_instance(var.upper_bound, 'builtins.object'): | ||
| vs.append('{} <: {}'.format(var.name, var.upper_bound.accept(self))) | ||
| if isinstance(var, TypeVarDef): | ||
| # We reimplement TypeVarDef.__repr__ here in order to support id_mapper. | ||
| if var.values: | ||
| vals = '({})'.format(', '.join(val.accept(self) for val in var.values)) | ||
| vs.append('{} in {}'.format(var.name, vals)) | ||
| elif not is_named_instance(var.upper_bound, 'builtins.object'): | ||
| vs.append('{} <: {}'.format(var.name, var.upper_bound.accept(self))) | ||
| else: | ||
| vs.append(var.name) | ||
| else: | ||
| vs.append(var.name) | ||
| # For other TypeVarLikeDefs, just use the repr | ||
| vs.append(repr(var)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a TODO comment about actually implementing suitable repr? In the longer term, it would make sense to use a similar way of constructing the repr of both cases.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TypeVarLikeDef already implements a suitable repr. |
||
| s = '{} {}'.format('[{}]'.format(', '.join(vs)), s) | ||
|
|
||
| return 'def {}'.format(s) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we construct a new instance and set the full name, at least?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, TypeAnalyser visit methods seem pretty happy to return their input, so not sure I see the point (unless we were to add upper_bound to ParamSpecDef or TypeVarLikeDef, in which case we'd need to visit it and reconstruct).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was confused -- no change is needed here.