Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2007165
[WIP] Include param_spec in callable types and support reveal_Type
JukkaL Nov 18, 2021
da6d041
[WIP] Simple type inference involving ParamSpec
JukkaL Nov 18, 2021
2506647
[WIP] Work towards using ParamSpec in classes
JukkaL Nov 18, 2021
56971f0
[WIP] Support defining decorators
JukkaL Nov 18, 2021
774a558
Various fixes
JukkaL Nov 19, 2021
cc8fc46
Fixes to mypy daemon (not tested yet)
JukkaL Nov 19, 2021
5b8a1c6
Various updates/fixes to ParamSpecType
JukkaL Nov 19, 2021
bb928ce
Fix to type semantic analysis
JukkaL Nov 19, 2021
f3a2596
Add missing get_proper_type call
JukkaL Nov 19, 2021
ef52db7
Fixes to self check
JukkaL Nov 19, 2021
c76ce08
Fix type check of mypy.constraints
JukkaL Nov 19, 2021
8a69923
Add missing get_proper_type() calls
JukkaL Nov 19, 2021
76ffb14
Move some param spec logic to CallableType
JukkaL Nov 19, 2021
be6f8e8
Fix applying types with ParamSpec
JukkaL Nov 19, 2021
c1686b0
Switch to simpler ParamSpec implementation + cleanup
JukkaL Nov 19, 2021
a3cb0ad
Fix inference against Any
JukkaL Nov 19, 2021
fd124c5
Update test cases
JukkaL Nov 19, 2021
22afc1d
Don't wrap ParamSpec *args and **kwargs types in tuple[...] or dict[...]
JukkaL Nov 19, 2021
044ddfd
Implement basic type checking for ParamSpec types
JukkaL Nov 19, 2021
6d25da4
Use Callable[P, T] in error messages
JukkaL Nov 22, 2021
1047f85
Support subtype checks
JukkaL Nov 22, 2021
a9b410e
Implement ParamSpec join
JukkaL Nov 22, 2021
f621fb7
Fix type erasure
JukkaL Nov 22, 2021
080049e
Add test case
JukkaL Nov 22, 2021
504267c
Disallow ParamSpec type in bad location
JukkaL Nov 22, 2021
2d02b62
Fix type check and lint
JukkaL Nov 22, 2021
dd28b93
Minor tweaks
JukkaL Nov 22, 2021
01ae7d5
Fix TODO in string conversion
JukkaL Nov 22, 2021
b6b09f1
Update docstrings
JukkaL Nov 22, 2021
1af097f
Respond to feedback
JukkaL Nov 23, 2021
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
Various updates/fixes to ParamSpecType
  • Loading branch information
JukkaL committed Nov 22, 2021
commit 5b8a1c6ac0d9d214eb7dd3cdc2aa1bd88d51dd64
28 changes: 18 additions & 10 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,47 +447,54 @@ def deserialize(cls, data: JsonDict) -> 'TypeVarType':
)


class ParamSpecFlavor(Enum):
class ParamSpecFlavor:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Enum? Like ArgKind: https://github.com/python/mypy/blob/master/mypy/nodes.py#L1636

Sorry, Enums are really my thing 🙂

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to avoid enums since mypyc only partially supports them, so it's possible to accidentally write code that it's pretty slow.

# Simple ParamSpec reference such as "P"
BARE = 0
BARE: Final = 0
# P.args
ARGS = 1
ARGS: Final = 1
# P.kwargs
KWARGS = 2
KWARGS: Final = 2


class ParamSpecType(TypeVarLikeType):
"""Definition of a single ParamSpec variable."""

__slots__ = ('flavor',)

flavor: ParamSpecFlavor
flavor: int

def __init__(
self, name: str, fullname: str, id: Union[TypeVarId, int], flavor: ParamSpecFlavor,
self, name: str, fullname: str, id: Union[TypeVarId, int], flavor: int, *,
line: int = -1, column: int = -1
) -> None:
super().__init__(name, fullname, id, line=line, column=column)
self.flavor = flavor

def __repr__(self) -> str:
return f"<ParamSpecType {self.name}:{self.flavor}>"

@staticmethod
def new_unification_variable(old: 'ParamSpecType') -> 'ParamSpecType':
new_id = TypeVarId.new(meta_level=1)
return ParamSpecType(old.name, old.fullname, new_id, old.line, old.column)
return ParamSpecType(old.name, old.fullname, new_id, old.flavor,
line=old.line, column=old.column)

def accept(self, visitor: 'TypeVisitor[T]') -> T:
return visitor.visit_param_spec(self)

def __hash__(self) -> int:
return hash((self.id, self.flavor))

def __eq__(self, other: object) -> bool:
if not isinstance(other, ParamSpecType):
return NotImplemented
return self.id == other.id and self.flavor == other.flavor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why upper_bound is missing here and in various other places like is_same_type()? Add a comment about this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not user-configurable and always depends on flavor (actually currently it's always object). Added some comments.


def serialize(self) -> JsonDict:
assert not self.id.is_meta_var()
return {
'.class': 'ParamSpecType',
'name': self.name,
'fullname': self.fullname,
'id': self.id.raw_id,
'flavor': self.flavor,
}

@classmethod
Expand All @@ -497,6 +504,7 @@ def deserialize(cls, data: JsonDict) -> 'ParamSpecType':
data['name'],
data['fullname'],
data['id'],
data['flavor'],
)


Expand Down