Skip to content

Commit

Permalink
fix(Python bindings): Ignore type for fields that are overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Apr 7, 2021
1 parent 5954012 commit 6f80099
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions py/.mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[mypy]
ignore_missing_imports = True
pretty = True
2 changes: 1 addition & 1 deletion py/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ regen:

lint:
python3 -m pylint stencila/schema
python3 -m mypy stencila/schema --ignore-missing-imports
python3 -m mypy stencila/schema --config-file .mypy.ini

format:
python3 -m black --exclude stencila/schema/types.py ./stencila ./*.py
Expand Down
13 changes: 8 additions & 5 deletions py/stencila/schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ class Brand(Thing):
group, or similar.
"""

name: str
name: str # type: ignore
"""The name of the item."""

logo: Optional[Union[str, "ImageObject"]] = None
Expand Down Expand Up @@ -866,6 +866,9 @@ def __init__(
class Article(CreativeWork):
"""An article, including news and scholarly articles."""

content: Optional[Array["BlockContent"]] = None # type: ignore
"""The structured content of this article."""

pageEnd: Optional[Union[int, str]] = None
"""The page on which the article ends; for example "138" or "xvi"."""

Expand Down Expand Up @@ -959,7 +962,7 @@ def __init__(
class Collection(CreativeWork):
"""A created collection of CreativeWorks or other artefacts."""

parts: Array["CreativeWorkTypes"]
parts: Array["CreativeWorkTypes"] # type: ignore
"""Elements of the collection which can be a variety of different elements,
such as Articles, Datatables, Tables and more.
"""
Expand Down Expand Up @@ -1409,7 +1412,7 @@ def __init__(
class DatatableColumn(Thing):
"""A column of data within a Datatable."""

name: str
name: str # type: ignore
"""The name of the item."""

values: Array[Any]
Expand Down Expand Up @@ -1453,7 +1456,7 @@ def __init__(
class DefinedTerm(Thing):
"""A word, name, acronym, phrase, etc. with a formal definition."""

name: str
name: str # type: ignore
"""The name of the item."""

termCode: Optional[str] = None
Expand Down Expand Up @@ -3177,7 +3180,7 @@ def __init__(
class SoftwareEnvironment(Thing):
"""A computational environment."""

name: str
name: str # type: ignore
"""The name of the item."""

adds: Optional[Array["SoftwareSourceCode"]] = None
Expand Down
6 changes: 4 additions & 2 deletions ts/bindings/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ export function classGenerator(schema: JsonSchema): string {
const clas = `class ${title}${base}:\n${docString}`

const attrs = own
.map(({ name, schema, optional }) => {
.map(({ name, schema, optional, override }) => {
const type = schemaToType(schema)
const attrType = optional ? `Optional[${type}] = None` : type
const attrType =
(optional ? `Optional[${type}] = None` : type) +
(override ? ' # type: ignore' : '')
const { description = name } = schema
return ` ${name}: ${attrType}\n """${description}"""\n`
})
Expand Down

0 comments on commit 6f80099

Please sign in to comment.