Skip to content

Commit c75ec24

Browse files
committed
prettier
1 parent bb5663e commit c75ec24

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pynamodb_mypy/plugin.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5555
def _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

5960
def _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

7173
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+
"""
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

8489
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+
"""
8593
sig = ctx.default_signature
8694
if _is_attribute_marked_nullable(ctx.type):
8795
return sig

0 commit comments

Comments
 (0)