Skip to content

Commit

Permalink
fix(Python bindings): Use is not None
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Jul 22, 2019
1 parent 0a6d9f5 commit 2f41f2a
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
import crypto from 'crypto'
import path from 'path'
import fs from 'fs-extra'
import {
read,
types,
props,
Schema,
unions
} from './bindings'
import { read, types, props, Schema, unions } from './bindings'

/**
* Run `build()` when this file is run as a Node script
Expand All @@ -31,8 +25,12 @@ async function build(): Promise<void> {
const schemas = await read()

globals = []
const classesCode = types(schemas).map(classGenerator).join('')
const unionsCode = unions(schemas).map(unionGenerator).join('')
const classesCode = types(schemas)
.map(classGenerator)
.join('')
const unionsCode = unions(schemas)
.map(unionGenerator)
.join('')
const globalsCode = globals.join('\n')

const code = `
Expand All @@ -52,7 +50,7 @@ ${unionsCode}
/**
* Generate a `class`.
*/
function classGenerator (schema: Schema): string {
function classGenerator(schema: Schema): string {
const { title, extends: parent, description } = schema
const { inherited, own, required, optional } = props(schema)

Expand Down Expand Up @@ -88,7 +86,7 @@ function classGenerator (schema: Schema): string {
const superCall = ` super().__init__(${superArgs})`

const initSetters = own
.map(({ name }) => ` if ${name} != None: self.${name} = ${name}`)
.map(({ name }) => ` if ${name} is not None: self.${name} = ${name}`)
.join('\n')

const init = ` def __init__(${initPars}) -> None:\n${superCall}\n${initSetters}\n\n`
Expand All @@ -99,8 +97,8 @@ function classGenerator (schema: Schema): string {
/**
* Generate a `Union` type.
*/
function unionGenerator (schema: Schema): string {
const {title, description} = schema
function unionGenerator(schema: Schema): string {
const { title, description } = schema
let code = `"""\n${description}\n"""\n`
code += `${title} = ${schemaToType(schema)}\n\n`
return code
Expand Down

0 comments on commit 2f41f2a

Please sign in to comment.