mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-20 15:38:55 +00:00
Move Vector
support from main section parser to types section parser
This commit is contained in:
parent
c41c128c76
commit
9ebf456e5a
@ -22,8 +22,11 @@ def collect_prev_forks(fork: str) -> list[str]:
|
||||
forks.append(fork)
|
||||
|
||||
|
||||
def is_byte_vector(value: str) -> bool:
|
||||
return value.startswith(('ByteVector'))
|
||||
def requires_mypy_type_ignore(value: str) -> bool:
|
||||
return (
|
||||
value.startswith(('ByteVector'))
|
||||
or (value.startswith(('Vector')) and 'floorlog2' in value)
|
||||
)
|
||||
|
||||
|
||||
def make_function_abstract(protocol_def: ProtocolDefinition, key: str):
|
||||
@ -41,7 +44,8 @@ def objects_to_spec(preset_name: str,
|
||||
new_type_definitions = (
|
||||
'\n\n'.join(
|
||||
[
|
||||
f"class {key}({value}):\n pass\n" if not is_byte_vector(value) else f"class {key}({value}): # type: ignore\n pass\n"
|
||||
f"class {key}({value}):\n pass\n" if not requires_mypy_type_ignore(value)
|
||||
else f"class {key}({value}): # type: ignore\n pass\n"
|
||||
for key, value in spec_object.custom_types.items()
|
||||
]
|
||||
)
|
||||
|
13
setup.py
13
setup.py
@ -218,19 +218,10 @@ def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str], pr
|
||||
class_name, parent_class = _get_class_info_from_source(source)
|
||||
# check consistency with spec
|
||||
assert class_name == current_name
|
||||
ignore_type = False
|
||||
if parent_class:
|
||||
if parent_class == "Container":
|
||||
pass
|
||||
elif parent_class == "Vector":
|
||||
ignore_type = True # Avoid Mypy error: Invalid base class "Vector"
|
||||
else:
|
||||
raise Exception("unrecognized parent class: " + source)
|
||||
assert parent_class == "Container"
|
||||
# NOTE: trim whitespace from spec
|
||||
lines = [line.rstrip() for line in source.splitlines()]
|
||||
if ignore_type:
|
||||
lines[0] += " # type: ignore"
|
||||
ssz_objects[current_name] = "\n".join(lines)
|
||||
ssz_objects[current_name] = "\n".join(line.rstrip() for line in source.splitlines())
|
||||
else:
|
||||
raise Exception("unrecognized python code element: " + source)
|
||||
elif isinstance(child, Table):
|
||||
|
Loading…
x
Reference in New Issue
Block a user