quicktype-core 23.0.2 → 23.0.3

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.
@@ -46,7 +46,7 @@ export declare class PythonRenderer extends ConvenienceRenderer {
46
46
  protected withImport(module: string, name: string): Sourcelike;
47
47
  protected withTyping(name: string): Sourcelike;
48
48
  protected namedType(t: Type): Sourcelike;
49
- protected pythonType(t: Type): Sourcelike;
49
+ protected pythonType(t: Type, _isRootTypeDef?: boolean): Sourcelike;
50
50
  protected declarationLine(t: Type): Sourcelike;
51
51
  protected declareType<T extends Type>(t: T, emitter: () => void): void;
52
52
  protected emitClassMembers(t: ClassType): void;
@@ -240,15 +240,19 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
240
240
  return name;
241
241
  return ["'", name, "'"];
242
242
  }
243
- pythonType(t) {
243
+ pythonType(t, _isRootTypeDef = false) {
244
244
  const actualType = (0, Transformers_1.followTargetType)(t);
245
245
  return (0, 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 => {
246
246
  const [hasNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(unionType);
247
247
  const memberTypes = Array.from(nonNulls).map(m => this.pythonType(m));
248
248
  if (hasNull !== null) {
249
249
  let rest = [];
250
- if (!this.getAlphabetizeProperties() && this.pyOptions.features.dataClasses)
250
+ if (!this.getAlphabetizeProperties() && this.pyOptions.features.dataClasses && _isRootTypeDef) {
251
+ // Only push "= None" if this is a root level type def
252
+ // otherwise we may get type defs like List[Optional[int] = None]
253
+ // which are invalid
251
254
  rest.push(" = None");
255
+ }
252
256
  if (nonNulls.size > 1) {
253
257
  this.withImport("typing", "Union");
254
258
  return [
@@ -344,7 +348,7 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
344
348
  else {
345
349
  this.forEachClassProperty(t, "none", (name, jsonName, cp) => {
346
350
  this.emitDescription(this.descriptionForClassProperty(t, jsonName));
347
- this.emitLine(name, this.typeHint(": ", this.pythonType(cp.type)));
351
+ this.emitLine(name, this.typeHint(": ", this.pythonType(cp.type, true)));
348
352
  });
349
353
  }
350
354
  this.ensureBlankLine();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.0.2",
3
+ "version": "23.0.3",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",