@@ -45,18 +45,20 @@ def _is_attribute_marked_nullable(t: mypy.types.Type) -> bool:
4545 )
4646
4747
48- def _get_bool_literal (n : mypy .nodes .Node ) -> Optional [bool ]:
48+ def _get_bool_literal (node : mypy .nodes .Node ) -> Optional [bool ]:
4949 return {
5050 'builtins.False' : False ,
5151 '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
5353
5454
5555def _make_optional (t : mypy .types .Type ) -> mypy .types .UnionType :
56+ """Wraps a type in optionality"""
5657 return mypy .types .UnionType ([t , mypy .types .NoneType ()])
5758
5859
5960def _unwrap_optional (t : mypy .types .Type ) -> mypy .types .Type :
61+ """Unwraps a potentially optional type"""
6062 if not isinstance (t , mypy .types .UnionType ):
6163 return t
6264 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:
6971
7072
7173def _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+ """
7277 sig = ctx .default_signature
7378 if not _is_attribute_marked_nullable (ctx .type ):
7479 return sig
@@ -82,6 +87,9 @@ def _get_method_sig_hook(ctx: mypy.plugin.MethodSigContext) -> mypy.types.Callab
8287
8388
8489def _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+ """
8593 sig = ctx .default_signature
8694 if _is_attribute_marked_nullable (ctx .type ):
8795 return sig
0 commit comments