Skip to content

Commit 71344c2

Browse files
authored
Merge pull request #5119 from microsoft/shem/fix_null_for_zero_error
remove falsy check for nulls in method parameters
2 parents b507208 + ba5e39c commit 71344c2

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Added
1313

14-
- Adds generation of default 'color.png`and`outline.png` files when generating plugins. [#4993](https://github.com/microsoft/kiota/issues/4993)
14+
- Adds generation of default `color.png` and `outline.png` files when generating plugins. [#4993](https://github.com/microsoft/kiota/issues/4993)
1515

1616
### Changed
1717

@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- Exclude the `x-openai-isConsequential` extension from cleanup. [#4962](https://github.com/microsoft/kiota/issues/4962)
2424
- Fixed file name and namespace sanitization when generating plugins. [#5019](https://github.com/microsoft/kiota/issues/5019)
2525
- Added TypeScript typecheck suppression to generated method prototype, where anused arguments can cause build fail in projects which use `noUnusedLocals: true` compiler option. [#5095](https://github.com/microsoft/kiota/issues/5095)
26+
- Fixed a bug where defensive programming would consider some default values as invalid in Python.
2627

2728
## [1.16.0] - 2024-07-05
2829

src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public override void WriteCodeElement(CodeMethod codeElement, LanguageWriter wri
4343
foreach (var parameter in codeElement.Parameters.Where(static x => !x.Optional).OrderBy(static x => x.Name))
4444
{
4545
var parameterName = parameter.Name;
46-
writer.StartBlock($"if not {parameterName}:");
46+
writer.StartBlock($"if {parameterName} is None:");
4747
writer.WriteLine($"raise TypeError(\"{parameterName} cannot be null.\")");
4848
writer.DecreaseIndent();
4949
}

tests/Kiota.Builder.Tests/Writers/Python/CodeMethodWriterTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ public void WritesNameMapperMethod()
20862086
});
20872087
writer.Write(method);
20882088
var result = tw.ToString();
2089-
Assert.Contains("if not original_name:", result);
2089+
Assert.Contains("if original_name is None:", result);
20902090
Assert.Contains("if original_name == \"select\":", result);
20912091
Assert.Contains("return \"%24select\"", result);
20922092
Assert.Contains("if original_name == \"expand\":", result);
@@ -2124,7 +2124,7 @@ public void WritesNameMapperMethodWithUnescapedProperties()
21242124
});
21252125
writer.Write(method);
21262126
var result = tw.ToString();
2127-
Assert.Contains("if not original_name:", result);
2127+
Assert.Contains("if original_name is None:", result);
21282128
Assert.Contains("if original_name == \"start_date_time\":", result);
21292129
Assert.Contains("return \"startDateTime\"", result);
21302130
Assert.Contains("return original_name", result);

0 commit comments

Comments
 (0)