@@ -45,18 +45,20 @@ def _is_attribute_marked_nullable(t: mypy.types.Type) -> bool:
45
45
)
46
46
47
47
48
- def _get_bool_literal (n : mypy .nodes .Node ) -> Optional [bool ]:
48
+ def _get_bool_literal (node : mypy .nodes .Node ) -> Optional [bool ]:
49
49
return {
50
50
'builtins.False' : False ,
51
51
'builtins.True' : True ,
52
- }.get (n .fullname or '' ) if isinstance (n , mypy .nodes .NameExpr ) else None
52
+ }.get (node .fullname or '' ) if isinstance (node , mypy .nodes .NameExpr ) else None
53
53
54
54
55
55
def _make_optional (t : mypy .types .Type ) -> mypy .types .UnionType :
56
+ """Wraps a type in optionality"""
56
57
return mypy .types .UnionType ([t , mypy .types .NoneType ()])
57
58
58
59
59
60
def _unwrap_optional (t : mypy .types .Type ) -> mypy .types .Type :
61
+ """Unwraps a potentially optional type"""
60
62
if not isinstance (t , mypy .types .UnionType ):
61
63
return t
62
64
t = mypy .types .UnionType ([item for item in t .items if not isinstance (item , mypy .types .NoneType )])
@@ -69,6 +71,9 @@ def _unwrap_optional(t: mypy.types.Type) -> mypy.types.Type:
69
71
70
72
71
73
def _get_method_sig_hook (ctx : mypy .plugin .MethodSigContext ) -> mypy .types .CallableType :
74
+ """
75
+ Patches up the signature of Attribute.__get__ to respect attribute's nullability.
76
+ """
72
77
sig = ctx .default_signature
73
78
if not _is_attribute_marked_nullable (ctx .type ):
74
79
return sig
@@ -82,6 +87,9 @@ def _get_method_sig_hook(ctx: mypy.plugin.MethodSigContext) -> mypy.types.Callab
82
87
83
88
84
89
def _set_method_sig_hook (ctx : mypy .plugin .MethodSigContext ) -> mypy .types .CallableType :
90
+ """
91
+ Patches up the signature of Attribute.__set__ to respect attribute's nullability.
92
+ """
85
93
sig = ctx .default_signature
86
94
if _is_attribute_marked_nullable (ctx .type ):
87
95
return sig
0 commit comments