quicktype-core 7.0.6 → 7.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -247,15 +247,23 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
247
247
  pythonType(t) {
248
248
  const actualType = Transformers_1.followTargetType(t);
249
249
  return TypeUtils_1.matchType(actualType, _anyType => this.withTyping("Any"), _nullType => "None", _boolType => "bool", _integerType => "int", _doubletype => "float", _stringType => "str", arrayType => [this.withTyping("List"), "[", this.pythonType(arrayType.items), "]"], classType => this.namedType(classType), mapType => [this.withTyping("Dict"), "[str, ", this.pythonType(mapType.values), "]"], enumType => this.namedType(enumType), unionType => {
250
- const maybeNullable = TypeUtils_1.nullableFromUnion(unionType);
251
- if (maybeNullable !== null) {
250
+ const [hasNull, nonNulls] = TypeUtils_1.removeNullFromUnion(unionType);
251
+ const memberTypes = Array.from(nonNulls).map(m => this.pythonType(m));
252
+ if (hasNull !== null) {
252
253
  let rest = [];
253
254
  if (!this.getAlphabetizeProperties() && this.pyOptions.features.dataClasses)
254
255
  rest.push(" = None");
255
- return [this.withTyping("Optional"), "[", this.pythonType(maybeNullable), "]", ...rest];
256
+ if (nonNulls.size > 1) {
257
+ this.withImport("typing", "Union");
258
+ return [this.withTyping("Optional"), "[Union[", collection_utils_1.arrayIntercalate(", ", memberTypes), "]]", ...rest];
259
+ }
260
+ else {
261
+ return [this.withTyping("Optional"), "[", Support_1.defined(collection_utils_1.iterableFirst(memberTypes)), "]", ...rest];
262
+ }
263
+ }
264
+ else {
265
+ return [this.withTyping("Union"), "[", collection_utils_1.arrayIntercalate(", ", memberTypes), "]"];
256
266
  }
257
- const memberTypes = Array.from(unionType.sortedMembers).map(m => this.pythonType(m));
258
- return [this.withTyping("Union"), "[", collection_utils_1.arrayIntercalate(", ", memberTypes), "]"];
259
267
  }, transformedStringType => {
260
268
  if (transformedStringType.kind === "date-time") {
261
269
  return this.withImport("datetime", "datetime");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "7.0.6",
3
+ "version": "7.0.8",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -45,6 +45,6 @@
45
45
  "fs": false
46
46
  },
47
47
  "config": {
48
- "commit": "6165d1a3cd069a88b7266c29f531776439bbc014"
48
+ "commit": "f4487c279b4d7a4131e6822bdda846904760dd63"
49
49
  }
50
50
  }