Skip to content

Commit

Permalink
fix(Python bindings): Fix spacing and regnerate test snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Jul 23, 2019
1 parent 1e7a6c0 commit 7050b5c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
13 changes: 8 additions & 5 deletions src/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ async function build(): Promise<void> {
globals = []
const classesCode = types(schemas)
.map(classGenerator)
.join('')
.join('\n\n')
const unionsCode = unions(schemas)
.map(unionGenerator)
.join('')
.join('\n\n')
const globalsCode = globals.join('\n')

const code = `from typing import Any, Dict, List as Array, Optional, Union
Expand Down Expand Up @@ -139,7 +139,7 @@ export function classGenerator(schema: Schema): string {
)
.join('\n')

const init = ` def __init__(${initPars}) -> None:\n${superCall}\n${initSetters}\n\n`
const init = ` def __init__(${initPars}) -> None:\n${superCall}\n${initSetters}`

return clas + (attrs.length > 0 ? attrs + '\n\n' : '') + init + '\n'
}
Expand All @@ -149,8 +149,11 @@ export function classGenerator(schema: Schema): string {
*/
export function unionGenerator(schema: Schema): string {
const { title, description } = schema
let code = `"""\n${description}\n"""\n`
code += `${title} = ${schemaToType(schema)}\n\n`
let code = ''
if (description !== undefined) {
code += `"""\n${formatDocstring(description)}\n"""\n`
}
code += `${title} = ${schemaToType(schema)}\n`
return code
}

Expand Down
1 change: 0 additions & 1 deletion tests/__file_snapshots__/BlockContent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
Block content.
"""
BlockContent = Union["CodeBlock", "CodeChunk", "Heading", "List", "ListItem", "Paragraph", "QuoteBlock", "Table", "ThematicBreak"]

35 changes: 22 additions & 13 deletions tests/__file_snapshots__/Person.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,25 @@ def __init__(
name=name,
url=url
)
if address is not None: self.address = address
if affiliations is not None: self.affiliations = affiliations
if emails is not None: self.emails = emails
if familyNames is not None: self.familyNames = familyNames
if funders is not None: self.funders = funders
if givenNames is not None: self.givenNames = givenNames
if honorificPrefix is not None: self.honorificPrefix = honorificPrefix
if honorificSuffix is not None: self.honorificSuffix = honorificSuffix
if jobTitle is not None: self.jobTitle = jobTitle
if memberOf is not None: self.memberOf = memberOf
if telephoneNumbers is not None: self.telephoneNumbers = telephoneNumbers


if address is not None:
self.address = address
if affiliations is not None:
self.affiliations = affiliations
if emails is not None:
self.emails = emails
if familyNames is not None:
self.familyNames = familyNames
if funders is not None:
self.funders = funders
if givenNames is not None:
self.givenNames = givenNames
if honorificPrefix is not None:
self.honorificPrefix = honorificPrefix
if honorificSuffix is not None:
self.honorificSuffix = honorificSuffix
if jobTitle is not None:
self.jobTitle = jobTitle
if memberOf is not None:
self.memberOf = memberOf
if telephoneNumbers is not None:
self.telephoneNumbers = telephoneNumbers

0 comments on commit 7050b5c

Please sign in to comment.