Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions aas_core_codegen/python/transpilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,16 @@ def transform_name(
def transform_not(
self, node: parse_tree.Not
) -> Tuple[Optional[Stripped], Optional[Error]]:
# NOTE (mristin):
# We rewrite the negated nullness check into ``is not``, as linters such as
# ruff (E714) complain about it.
if isinstance(node.operand, parse_tree.IsNone):
return self.transform_is_not_none(
parse_tree.IsNotNone(
value=node.operand.value, original_node=node.original_node
)
)

operand, error = self.transform(node.operand)
if error is not None:
return None, error
Expand Down
6 changes: 6 additions & 0 deletions dev/test_data/common_meta_models/optional_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def forwards_text(text: Optional[str]) -> bool:
return text_is_not_banned(text)


@verification
def text_is_given(text: Optional[str]) -> bool:
"""Check the negated nullness check of the optional argument."""
return not (text is None)


@verification
def number_is_small(number: Optional[int]) -> bool:
"""Check the optional integer argument."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,35 @@ SymbolTable(
postconditions=[]),
parsed=...,
arguments_by_name=...),
TranspilableVerification(
name='text_is_given',
visibility='PUBLIC',
arguments=[
Argument(
name='text',
type_annotation=OptionalTypeAnnotation(
value=PrimitiveTypeAnnotation(
a_type='STR',
parsed=...),
parsed=...),
default=None,
mutable=False,
parsed=...)],
returns=PrimitiveTypeAnnotation(
a_type='BOOL',
parsed=...),
description=DescriptionOfSignature(
summary='<paragraph>Check the negated nullness check of the optional argument.</paragraph>',
remarks=[],
arguments_by_name=[],
returns=None,
parsed=...),
contracts=Contracts(
preconditions=[],
snapshots=[],
postconditions=[]),
parsed=...,
arguments_by_name=...),
TranspilableVerification(
name='number_is_small',
visibility='PUBLIC',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ bool ForwardsText(
const common::optional<std::wstring>& text
);

/// \brief Check the negated nullness check of the optional argument.
bool TextIsGiven(
const common::optional<std::wstring>& text
);

/// \brief Check the optional integer argument.
bool NumberIsSmall(
const common::optional<int64_t>& number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ bool ForwardsText(
);
}

bool TextIsGiven(
const common::optional<std::wstring>& text
) {
return !(!(text.has_value()));
}

bool NumberIsSmall(
const common::optional<int64_t>& number
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ public static bool ForwardsText(
return Verification.TextIsNotBanned(text);
} // public static bool ForwardsText

/// <summary>
/// Check the negated nullness check of the optional argument.
/// </summary>
public static bool TextIsGiven(
string? text
)
{
return !(text == null);
} // public static bool TextIsGiven

/// <summary>
/// Check the optional integer argument.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ func ForwardsText(
return TextIsNotBanned(text)
}

// Check the negated nullness check of the optional argument.
func TextIsGiven(
text *string,
) bool {
return !(text == nil)
}

// Check the optional integer argument.
func NumberIsSmall(
number *int64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public static Boolean forwardsText(
return textIsNotBanned(text);
}

/**
* Check the negated nullness check of the optional argument.
*/
public static Boolean textIsGiven(
Optional<String> text) {
return !(!text.isPresent());
}

/**
* Check the optional integer argument.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ def forwards_text(
return text_is_not_banned(text)


def text_is_given(
text: Optional[str]
) -> bool:
"""Check the negated nullness check of the optional argument."""
return text is not None


def number_is_small(
number: Optional[int]
) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ export function forwardsText(
return textIsNotBanned(text);
}

/**
* Check the negated nullness check of the optional argument.
*/
export function textIsGiven(
text: string | null
): boolean {
return !(text === null);
}

/**
* Check the optional integer argument.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,46 @@ UnverifiedSymbolTable(
original_node=...)""")],
node=...,
arguments_by_name=...),
UnderstoodMethod(
name='text_is_given',
verification=True,
visibility='PUBLIC',
arguments=[
Argument(
name='text',
type_annotation=SubscriptedTypeAnnotation(
identifier='Optional',
subscripts=[
AtomicTypeAnnotation(
identifier='str',
node=...)],
node=...),
default=None,
node=...)],
returns=AtomicTypeAnnotation(
identifier='bool',
node=...),
description=Description(
document=...,
node=...),
contracts=Contracts(
preconditions=[],
snapshots=[],
postconditions=[]),
non_mutating=False,
body=[
textwrap.dedent("""\
Return(
value=Not(
operand=IsNone(
value=Name(
identifier='text',
original_node=...),
original_node=...),
original_node=...),
original_node=...)""")],
node=...,
arguments_by_name=...),
UnderstoodMethod(
name='number_is_small',
verification=True,
Expand Down
Loading