Skip to content

Commit

Permalink
🔧 change type of need fields with bool | None to just bool (#1293)
Browse files Browse the repository at this point in the history
It is unnecessary for these field to be nullable,
and this further reduces the size of `needs.json`, when `needs_json_remove_defaults = True`, since the default is clearer.
  • Loading branch information
chrisjsewell authored Sep 12, 2024
1 parent 5cf181c commit d0e9239
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 304 deletions.
8 changes: 4 additions & 4 deletions sphinx_needs/api/need.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,21 +306,21 @@ def run():
"status": status,
"tags": tags,
"constraints": constraints,
"constraints_passed": None,
"constraints_passed": True,
"constraints_results": {},
"id": need_id,
"title": trimmed_title,
"full_title": title,
"collapse": collapse,
"collapse": collapse or False,
"arch": {}, # extracted later
"style": style,
"layout": layout,
"template": template,
"pre_template": pre_template,
"post_template": post_template,
"hide": hide,
"delete": delete,
"jinja_content": jinja_content,
"delete": delete or False,
"jinja_content": jinja_content or False,
"parts": {},
"is_part": False,
"is_need": True,
Expand Down
16 changes: 8 additions & 8 deletions sphinx_needs/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class CoreFieldParameters(TypedDict):
},
"collapse": {
"description": "Hide the meta-data information of the need.",
"schema": {"type": ["boolean", "null"], "default": None},
"schema": {"type": "boolean", "default": False},
"exclude_json": True,
},
"hide": {
Expand All @@ -123,7 +123,7 @@ class CoreFieldParameters(TypedDict):
},
"delete": {
"description": "If true, the need is deleted entirely.",
"schema": {"type": ["boolean", "null"], "default": None},
"schema": {"type": "boolean", "default": False},
"show_in_layout": True,
},
"layout": {
Expand Down Expand Up @@ -216,7 +216,7 @@ class CoreFieldParameters(TypedDict):
},
"jinja_content": {
"description": "Whether the content should be pre-processed by jinja.",
"schema": {"type": ["boolean", "null"], "default": None},
"schema": {"type": "boolean", "default": False},
"show_in_layout": True,
},
"template": {
Expand Down Expand Up @@ -269,7 +269,7 @@ class CoreFieldParameters(TypedDict):
},
"constraints_passed": {
"description": "True if all constraints passed, False if any failed, None if not yet checked.",
"schema": {"type": ["boolean", "null"], "default": True},
"schema": {"type": "boolean", "default": True},
},
"constraints_error": {
"description": "An error message set if any constraint failed, and `error_message` field is set in config.",
Expand Down Expand Up @@ -325,11 +325,11 @@ class NeedsInfoType(TypedDict, total=False):
tags: Required[list[str]]

# rendering information
collapse: Required[None | bool]
collapse: Required[bool]
"""Hide the meta-data information of the need."""
hide: Required[bool]
"""If true, the need is not rendered."""
delete: Required[None | bool]
delete: Required[bool]
"""If true, the need is deleted entirely."""
layout: Required[None | str]
"""Key of the layout, which is used to render the need."""
Expand Down Expand Up @@ -373,7 +373,7 @@ class NeedsInfoType(TypedDict, total=False):
"""<parent ID>.<self ID>, or <self ID> if not a part."""

# content creation information
jinja_content: Required[None | bool]
jinja_content: Required[bool]
template: Required[None | str]
pre_template: Required[None | str]
post_template: Required[None | str]
Expand All @@ -395,7 +395,7 @@ class NeedsInfoType(TypedDict, total=False):
# set in process_need_nodes (-> process_constraints) transform
constraints_results: Required[dict[str, dict[str, bool]]]
"""Mapping of constraint name, to check name, to result."""
constraints_passed: Required[None | bool]
constraints_passed: Required[bool]
"""True if all constraints passed, False if any failed, None if not yet checked."""
constraints_error: str
"""An error message set if any constraint failed, and `error_message` field is set in config."""
Expand Down
27 changes: 9 additions & 18 deletions tests/__snapshots__/test_basic_doc.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'constraints_results': dict({
}),
'created_at': '',
'delete': None,
'delete': False,
'description': '',
'docname': 'index',
'doctype': '.rst',
Expand All @@ -35,7 +35,7 @@
'is_modified': False,
'is_need': True,
'is_part': False,
'jinja_content': None,
'jinja_content': False,
'layout': '',
'links': list([
]),
Expand Down Expand Up @@ -89,7 +89,7 @@
'constraints_results': dict({
}),
'created_at': '',
'delete': None,
'delete': False,
'description': '',
'docname': 'index',
'doctype': '.rst',
Expand All @@ -105,7 +105,7 @@
'is_modified': False,
'is_need': True,
'is_part': False,
'jinja_content': None,
'jinja_content': False,
'layout': '',
'links': list([
]),
Expand Down Expand Up @@ -200,10 +200,7 @@
'default': True,
'description': 'True if all constraints passed, False if any failed, None if not yet checked.',
'field_type': 'core',
'type': list([
'boolean',
'null',
]),
'type': 'boolean',
}),
'constraints_results': dict({
'additionalProperties': dict({
Expand All @@ -222,13 +219,10 @@
'type': 'string',
}),
'delete': dict({
'default': None,
'default': False,
'description': 'If true, the need is deleted entirely.',
'field_type': 'core',
'type': list([
'boolean',
'null',
]),
'type': 'boolean',
}),
'docname': dict({
'default': None,
Expand Down Expand Up @@ -320,13 +314,10 @@
'type': 'boolean',
}),
'jinja_content': dict({
'default': None,
'default': False,
'description': 'Whether the content should be pre-processed by jinja.',
'field_type': 'core',
'type': list([
'boolean',
'null',
]),
'type': 'boolean',
}),
'layout': dict({
'default': None,
Expand Down
51 changes: 21 additions & 30 deletions tests/__snapshots__/test_export_id.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
'constraints_results': dict({
}),
'created_at': '',
'delete': None,
'delete': False,
'description': '',
'docname': 'index',
'doctype': '.rst',
Expand All @@ -101,7 +101,7 @@
'is_modified': False,
'is_need': True,
'is_part': False,
'jinja_content': None,
'jinja_content': False,
'layout': '',
'links': list([
'REQ_002',
Expand Down Expand Up @@ -170,7 +170,7 @@
'constraints_results': dict({
}),
'created_at': '',
'delete': None,
'delete': False,
'description': '',
'docname': 'index',
'doctype': '.rst',
Expand All @@ -186,7 +186,7 @@
'is_modified': False,
'is_need': True,
'is_part': False,
'jinja_content': None,
'jinja_content': False,
'layout': '',
'links': list([
]),
Expand Down Expand Up @@ -251,7 +251,7 @@
'constraints_results': dict({
}),
'created_at': '',
'delete': None,
'delete': False,
'description': '',
'docname': 'index',
'doctype': '.rst',
Expand All @@ -267,7 +267,7 @@
'is_modified': False,
'is_need': True,
'is_part': False,
'jinja_content': None,
'jinja_content': False,
'layout': '',
'links': list([
]),
Expand Down Expand Up @@ -332,7 +332,7 @@
'constraints_results': dict({
}),
'created_at': '',
'delete': None,
'delete': False,
'description': '',
'docname': 'index',
'doctype': '.rst',
Expand All @@ -348,7 +348,7 @@
'is_modified': False,
'is_need': True,
'is_part': False,
'jinja_content': None,
'jinja_content': False,
'layout': '',
'links': list([
]),
Expand Down Expand Up @@ -413,7 +413,7 @@
'constraints_results': dict({
}),
'created_at': '',
'delete': None,
'delete': False,
'description': '''
:need_part:`(1) awesome part`

Expand All @@ -433,7 +433,7 @@
'is_modified': False,
'is_need': True,
'is_part': False,
'jinja_content': None,
'jinja_content': False,
'layout': '',
'links': list([
'REQ_001',
Expand Down Expand Up @@ -523,7 +523,7 @@
'constraints_results': dict({
}),
'created_at': '',
'delete': None,
'delete': False,
'description': '',
'docname': 'index',
'doctype': '.rst',
Expand All @@ -539,7 +539,7 @@
'is_modified': False,
'is_need': True,
'is_part': False,
'jinja_content': None,
'jinja_content': False,
'layout': '',
'links': list([
]),
Expand Down Expand Up @@ -605,7 +605,7 @@
'constraints_results': dict({
}),
'created_at': '',
'delete': None,
'delete': False,
'description': '',
'docname': 'index',
'doctype': '.rst',
Expand All @@ -621,7 +621,7 @@
'is_modified': False,
'is_need': True,
'is_part': False,
'jinja_content': None,
'jinja_content': False,
'layout': '',
'links': list([
'TEST_001',
Expand Down Expand Up @@ -686,7 +686,7 @@
'constraints_results': dict({
}),
'created_at': '',
'delete': None,
'delete': False,
'description': '',
'docname': 'index',
'doctype': '.rst',
Expand All @@ -702,7 +702,7 @@
'is_modified': False,
'is_need': True,
'is_part': False,
'jinja_content': None,
'jinja_content': False,
'layout': '',
'links': list([
'REQ_005.1',
Expand Down Expand Up @@ -825,10 +825,7 @@
'default': True,
'description': 'True if all constraints passed, False if any failed, None if not yet checked.',
'field_type': 'core',
'type': list([
'boolean',
'null',
]),
'type': 'boolean',
}),
'constraints_results': dict({
'additionalProperties': dict({
Expand All @@ -847,13 +844,10 @@
'type': 'string',
}),
'delete': dict({
'default': None,
'default': False,
'description': 'If true, the need is deleted entirely.',
'field_type': 'core',
'type': list([
'boolean',
'null',
]),
'type': 'boolean',
}),
'docname': dict({
'default': None,
Expand Down Expand Up @@ -945,13 +939,10 @@
'type': 'boolean',
}),
'jinja_content': dict({
'default': None,
'default': False,
'description': 'Whether the content should be pre-processed by jinja.',
'field_type': 'core',
'type': list([
'boolean',
'null',
]),
'type': 'boolean',
}),
'layout': dict({
'default': None,
Expand Down
Loading

0 comments on commit d0e9239

Please sign in to comment.