8000 Implementation of PEP 673 (typing.Self) by Gobot1234 · Pull Request #11666 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Implementation of PEP 673 (typing.Self) #11666

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

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
acf87a3
Much better initial implementation of typing.Self
Gobot1234 Aug 28, 2021
7a6d771
Some extra stuff
Gobot1234 Oct 2, 2021
b1d67ca
Slight improvements
Gobot1234 Nov 5, 2021
c09d95f
Merge branch 'master' into master
Gobot1234 Dec 5, 2021
6a7a084
Remove removed type
Gobot1234 Dec 5, 2021
2ac45c9
Update meet.py
Gobot1234 Dec 5, 2021
1ebe034
Update mypy/type_visitor.py
Gobot1234 Dec 5, 2021
0e6d128
Fix most of the CI issues and respond to comments
Gobot1234 Dec 6, 2021
f844fbe
Merge branch 'master' of https://github.com/Gobot1234/mypy
Gobot1234 Dec 6, 2021
5904918
Merge remote-tracking branch 'upstream/master'
Gobot1234 Jan 14, 2022
e932f52
Merge branch 'master' into master
Gobot1234 Feb 16, 2022
ff779e8
I think this works properly now
Gobot1234 Feb 18, 2022
f94254f
Merge branch 'master' of https://github.com/Gobot1234/mypy
Gobot1234 Feb 18, 2022
c9b2ac9
Merge branch 'master' into master
Gobot1234 Feb 18, 2022
ad0b9b0
Merge remote-tracking branch 'origin/master' into gobot-master
erikkemperman May 20, 2022
6766132
Make tests pass
erikkemperman May 20, 2022
cada36a
Unit tests
erikkemperman May 20, 2022
68c1339
Merge pull request #1 from erikkemperman/gobot-master
Gobot1234 Jun 22, 2022
46d8b70
Merge remote-tracking branch 'upstream/master'
Gobot1234 Jun 22, 2022
fb6d552
I don't think this is entirely correct but lets see
Gobot1234 Jun 22, 2022
6c71758
Fix tests
Gobot1234 Jun 27, 2022
791c9e3
Fixes for signatures of form (type[Self]/Self) -> Self
Gobot1234 Jul 1, 2022
09e966e
Fix some CI
Gobot1234 Jul 1, 2022
ce2d5fa
Fix some CI failures
Gobot1234 Jul 6, 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
Merge remote-tracking branch 'origin/master' into gobot-master
  • Loading branch information
erikkemperman committed May 20, 2022
commit ad0b9b057c54ced60c4936a220dae182d5d9cb14
5 changes: 2 additions & 3 deletions mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
CallableType, Type, TypeVisitor, UnboundType, AnyType, NoneType, TypeVarType, Instance,
TupleType, TypedDictType, UnionType, Overloaded, ErasedType, PartialType, DeletedType,
UninhabitedType, TypeType, TypeVarId, TypeQuery, is_named_instance, TypeOfAny, LiteralType,
ProperType, ParamSpecType, get_proper_type, TypeAliasType, SelfType, is_union_with_any,
callable_with_ellipsis,
TUPLE_LIKE_INSTANCE_NAMES,
ProperType, ParamSpecType, get_proper_type, TypeAliasType, is_union_with_any, SelfType,
UnpackType, callable_with_ellipsis, Parameters, TUPLE_LIKE_INSTANCE_NAMES, TypeVarTupleType,
)
from mypy.maptype import map_instance_to_supertype
import mypy.subtypes
Expand Down
3 changes: 2 additions & 1 deletion mypy/erasetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Type, TypeVisitor, UnboundType, AnyType, NoneType, TypeVarId, Instance, TypeVarType,
CallableType, TupleType, TypedDictType, UnionType, Overloaded, ErasedType, PartialType,
DeletedType, TypeTranslator, UninhabitedType, TypeType, TypeOfAny, LiteralType, ProperType,
get_proper_type, get_proper_types, TypeAl 8000 iasType, ParamSpecType, SelfType
get_proper_type, get_proper_types, TypeAliasType, ParamSpecType, Parameters, UnpackType,
TypeVarTupleType, SelfType,
)
from mypy.nodes import ARG_STAR, ARG_STAR2

Expand Down
3 changes: 2 additions & 1 deletion mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
NoneType, Overloaded, TupleType, TypedDictType, UnionType,
ErasedType, PartialType, DeletedType, UninhabitedType, TypeType, TypeVarId,
FunctionLike, TypeVarType, LiteralType, get_proper_type, ProperType,
TypeAliasType, ParamSpecType, SelfType, TypeVarLikeType
TypeAliasType, ParamSpecType, TypeVarLikeType, Parameters, ParamSpecFlavor,
UnpackType, TypeVarTupleType, SelfType,
)


Expand Down
4 changes: 2 additions & 2 deletions mypy/fixup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from mypy.types import (
CallableType, Instance, Overloaded, TupleType, TypedDictType,
TypeVarType, UnboundType, UnionType, TypeVisitor, LiteralType,
TypeType, NOT_READY, TypeAliasType, AnyType, TypeOfAny, ParamSpecType,
SelfType
TypeType, NOT_READY, TypeAliasType, AnyType, TypeOfAny, ParamSpecType,
Parameters, UnpackType, TypeVarTupleType, SelfType,
)
from mypy.visitor import NodeVisitor
from mypy.lookup import lookup_fully_qualified
Expand Down
3 changes: 2 additions & 1 deletion mypy/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
Type, AnyType, NoneType, TypeVisitor, Instance, UnboundType, TypeVarType, CallableType,
TupleType, TypedDictType, ErasedType, UnionType, FunctionLike, Overloaded, LiteralType,
PartialType, DeletedType, UninhabitedType, TypeType, TypeOfAny, get_proper_type,
ProperType, get_proper_types, TypeAliasType, PlaceholderType, ParamSpecType, SelfType
ProperType, get_proper_types, TypeAliasType, PlaceholderType, ParamSpecType, Parameters,
UnpackType, TypeVarTupleType, SelfType,
)
from mypy.maptype import map_instance_to_supertype
from mypy.subtypes import (
Expand Down
4 changes: 2 additions & 2 deletions mypy/meet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Type, AnyType, TypeVisitor, UnboundType, NoneType, TypeVarType, Instance, CallableType,
TupleType, TypedDictType, ErasedType, UnionType, PartialType, DeletedType,
UninhabitedType, TypeType, TypeOfAny, Overloaded, FunctionLike, LiteralType,
ProperType, get_proper_type, get_proper_types, TypeAliasType, TypeGuardedType, SelfType,
ParamSpecType
ProperType, get_proper_type, get_proper_types, TypeAliasType, TypeGuardedType,
ParamSpecType, Parameters, UnpackType, TypeVarTupleType, SelfType,
)
from mypy.subtypes import is_equivalent, is_subtype, is_callable_compatible, is_proper_subtype
from mypy.erasetype import erase_type
Expand Down
3 changes: 2 additions & 1 deletion mypy/sametypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Type, UnboundType, AnyType, NoneType, TupleType, TypedDictType,
UnionType, CallableType, TypeVarType, Instance, TypeVisitor, ErasedType,
Overloaded, PartialType, DeletedType, UninhabitedType, TypeType, LiteralType,
ProperType, get_proper_type, TypeAliasType, SelfType, ParamSpecType
ProperType, get_proper_type, TypeAliasType, ParamSpecType, Parameters,
UnpackType, TypeVarTupleType, SelfType,
)
from mypy.typeops import tuple_fallback, make_simplified_union, is_simple_literal

Expand Down
4 changes: 2 additions & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@
NEVER_NAMES, FunctionLike, UnboundType, TypeVarType, TupleType, UnionType, StarType,
CallableType, Overloaded, Instance, Type, AnyType, LiteralType, LiteralValue,
TypeTranslator, TypeOfAny, TypeType, NoneType, PlaceholderType, TPDICT_NAMES, ProperType,
get_proper_type, get_proper_types, TypeAliasType, SelfType, TypeVarLikeType,
get_proper_type, get_proper_types, TypeAliasType, TypeVarLikeType, Parameters, ParamSpecType,
PROTOCOL_NAMES, TYPE_ALIAS_NAMES, FINAL_TYPE_NAMES, FINAL_DECORATOR_NAMES, REVEAL_TYPE_NAMES,
ASSERT_TYPE_NAMES, OVERLOAD_NAMES, is_named_instance,
ASSERT_TYPE_NAMES, OVERLOAD_NAMES, is_named_instance, SelfType,
)
from mypy.typeops import function_type, get_type_vars
from mypy.type_visitor import TypeQuery
Expand Down
17 changes: 16 additions & 1 deletion mypy/server/astdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class level -- these are handled at attribute level (say, 'mod.Cls.method'
Type, TypeVisitor, UnboundType, AnyType, NoneType, UninhabitedType,
ErasedType, DeletedType, Instance, TypeVarType, CallableType, TupleType, TypedDictType,
UnionType, Overloaded, PartialType, TypeType, LiteralType, TypeAliasType, ParamSpecType,
SelfType
Parameters, UnpackType, TypeVarTupleType, SelfType,
)
from mypy.util import get_prefix

Exp F438 and Down Expand Up @@ -318,6 +318,21 @@ def visit_param_spec(self, typ: ParamSpecType) -> SnapshotItem:
typ.flavor,
snapshot_type(typ.upper_bound))

def visit_type_var_tuple(self, typ: TypeVarTupleType) -> SnapshotItem:
return ('TypeVarTupleType',
typ.id.raw_id,
typ.id.meta_level,
snapshot_type(typ.upper_bound))

def visit_unpack_type(self, typ: UnpackType) -> SnapshotItem:
return ('UnpackType', snapshot_type(typ.type))

def visit_parameters(self, typ: Parameters) -> SnapshotItem:
return ('Parameters',
snapshot_types(typ.arg_types),
tuple(encode_optional_str(name) for name in typ.arg_names),
tuple(typ.arg_kinds))

def visit_self_type(self, typ: SelfType) -> SnapshotItem:
return ('SelfType',
typ.fullname,
Expand Down
13 changes: 12 additions & 1 deletion mypy/server/astmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
Type, SyntheticTypeVisitor, Instance, AnyType, NoneType, CallableType, ErasedType, DeletedType,
TupleType, TypeType, TypedDictType, UnboundType, UninhabitedType, UnionType,
Overloaded, TypeVarType, TypeList, CallableArgument, EllipsisType, StarType, LiteralType,
RawExpressionType, PartialType, PlaceholderType, TypeAliasType, ParamSpecType, SelfType
RawExpressionType, PartialType, PlaceholderType, TypeAliasType, ParamSpecType, Parameters,
UnpackType, TypeVarTupleType, SelfType,
)
from mypy.util import get_prefix, replace_object_state
from mypy.typestate import TypeState
Expand Down Expand Up @@ -415,6 +416,16 @@ def visit_type_var(self, typ: TypeVarType) -> None:
def visit_param_spec(self, typ: ParamSpecType) -> None:
pass

def visit_type_var_tuple(self, typ: TypeVarTupleType) -> None:
typ.upper_bound.accept(self)

def visit_unpack_type(self, typ: UnpackType) -> None:
typ.type.accept(self)

def visit_parameters(self, typ: Parameters) -> None:
for arg in typ.arg_types:
arg.accept(self)

def visit_self_type(self, typ: SelfType) -> None:
typ.instance.accept(self)

Expand Down
18 changes: 17 additions & 1 deletion mypy/server/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class 'mod.Cls'. This can also refer to an attribute inherited from a
Type, Instance, AnyType, NoneType, TypeVisitor, CallableType, DeletedType, PartialType,
TupleType, TypeType, TypeVarType, TypedDictType, UnboundType, UninhabitedType, UnionType,
FunctionLike, Overloaded, TypeOfAny, LiteralType, ErasedType, get_proper_type, ProperType,
TypeAliasType, ParamSpecType, SelfType
TypeAliasType, ParamSpecType, Parameters, UnpackType, TypeVarTupleType, SelfType,
)
from mypy.server.trigger import make_trigger, make_wildcard_trigger
from mypy.util import correct_relative_import
Expand Down Expand Up @@ -966,6 +966,22 @@ def visit_param_spec(self, typ: ParamSpecType) -> List[str]:
triggers.extend(self.get_type_triggers(typ.upper_bound))
return triggers

def visit_type_var_tuple(self, typ: TypeVarTupleType) -> List[str]:
triggers = []
if typ.fullname:
triggers.append(make_trigger(typ.fullname))
triggers.extend(self.get_type_triggers(typ.upper_bound))
return triggers

def visit_unpack_type(self, typ: UnpackType) -> List[str]:
return typ.type.accept(self)

def visit_parameters(self, typ: Parameters) -> List[str]:
triggers = []
for arg in typ.arg_types:
triggers.extend(self.get_type_triggers(arg))
return triggers

def visit_self_type(self, typ: SelfType) -> List[str]:
triggers = []
if typ.fullname:
Expand Down
3 changes: 1 addition & 2 deletions mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
Instance, TypeVarType, CallableType, TupleType, TypedDictType, UnionType, Overloaded,
ErasedType, PartialType, DeletedType, UninhabitedType, TypeType, is_named_instance,
FunctionLike, TypeOfAny, LiteralType, get_proper_type, TypeAliasType, ParamSpecType,
SelfType,
TUPLE_LIKE_INSTANCE_NAMES,
Parameters, UnpackType, TUPLE_LIKE_INSTANCE_NAMES, TypeVarTupleType, SelfType,
)
import mypy.applytype
import mypy.constraints
Expand Down
3 changes: 2 additions & 1 deletion mypy/type_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
Parameters, RawExpressionType, Instance, NoneType, TypeType,
UnionType, TypeVarType, PartialType, DeletedType, UninhabitedType, TypeVarLikeType,
UnboundType, ErasedType, StarType, EllipsisType, TypeList, CallableArgument,
PlaceholderType, TypeAliasType, ParamSpecType, SelfType, get_proper_type
PlaceholderType, TypeAliasType, ParamSpecType, UnpackType, TypeVarTupleType,
get_proper_type, SelfType,
)


Expand Down
5 changes: 3 additions & 2 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
StarType, PartialType, EllipsisType, UninhabitedType, TypeType, CallableArgument,
Parameters, TypeQuery, union_items, TypeOfAny, LiteralType, RawExpressionType,
PlaceholderType, Overloaded, get_proper_type, TypeAliasType, RequiredType,
TypeVarLikeType, ParamSpecType, ParamSpecFlavor, SelfType, callable_with_ellipsis,
TYPE_ALIAS_NAMES, FINAL_TYPE_NAMES, LITERAL_TYPE_NAMES, ANNOTATED_TYPE_NAMES,
TypeVarLikeType, ParamSpecType, ParamSpecFlavor, UnpackType, TypeVarTupleType,
callable_with_ellipsis, TYPE_ALIAS_NAMES, FINAL_TYPE_NAMES,
LITERAL_TYPE_NAMES, ANNOTATED_TYPE_NAMES, SelfType,
)

from mypy.nodes import (
Expand Down
3 changes: 1 addition & 2 deletions mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
TupleType, Instance, FunctionLike, Type, CallableType, TypeVarLikeType, Overloaded,
TypeVarType, UninhabitedType, FormalArgument, UnionType, NoneType,
AnyType, TypeOfAny, TypeType, ProperType, LiteralType, get_proper_type, get_proper_types,
copy_type, TypeAliasType, TypeQuery, ParamSpecType, SelfType,
ENUM_REMOVED_PROPS
TypeAliasType, TypeQuery, ParamSpecType, Parameters, ENUM_REMOVED_PROPS,
)
from mypy.nodes import (
FuncBase, FuncItem, FuncDef, OverloadedFuncDef, TypeInfo, ARG_STAR, ARG_STAR2, ARG_POS,
Expand Down
3 changes: 2 additions & 1 deletion mypy/typetraverser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
Type, SyntheticTypeVisitor, AnyType, UninhabitedType, NoneType, ErasedType, DeletedType,
TypeVarType, LiteralType, Instance, CallableType, TupleType, TypedDictType, UnionType,
Overloaded, TypeType, CallableArgument, UnboundType, TypeList, StarType, EllipsisType,
PlaceholderType, PartialType, RawExpressionType, TypeAliasType, ParamSpecType, SelfType,
PlaceholderType, PartialType, RawExpressionType, TypeAliasType, ParamSpecType, Parameters,
UnpackType, TypeVarTupleType, SelfType,
)


Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0