Skip to content

Commit 3081978

Browse files
committed
Fix types
1 parent b8b775e commit 3081978

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

pycardano/address.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ def save(
416416
path: str,
417417
key_type: Optional[str] = None,
418418
description: Optional[str] = None,
419+
**kwargs,
419420
):
420421
"""
421422
Save the Address object to a file.
@@ -427,6 +428,7 @@ def save(
427428
path (str): The file path to save the object to.
428429
key_type (str, optional): Not used in this context, but can be included for consistency.
429430
description (str, optional): Not used in this context, but can be included for consistency.
431+
**kwargs: Additional keyword arguments (not used here).
430432
431433
Raises:
432434
IOError: If the file already exists and is not empty.

pycardano/key.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def to_primitive(self) -> bytes:
7373
def from_primitive(cls: Type["Key"], value: bytes) -> Key:
7474
return cls(value)
7575

76-
def to_json(self, **kwargs) -> str:
76+
def to_json(self, **kwargs) -> str: # type: ignore
7777
"""Serialize the key to JSON.
7878
7979
The json output has three fields: "type", "description", and "cborHex".
@@ -90,7 +90,7 @@ def to_json(self, **kwargs) -> str:
9090
)
9191

9292
@classmethod
93-
def from_json(cls: Type[Key], data: str, validate_type=False) -> Key:
93+
def from_json(cls: Type[Key], data: str, validate_type=False) -> Key: # type: ignore
9494
"""Restore a key from a JSON string.
9595
9696
Args:

pycardano/plutus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def _dfs(obj):
652652

653653
return _dfs(self)
654654

655-
def to_json(self, **kwargs) -> str:
655+
def to_json(self, **kwargs) -> str: # type: ignore
656656
"""Convert to a json string
657657
658658
Args:
@@ -847,7 +847,7 @@ def _dfs(obj):
847847

848848
return _dfs(RawPlutusData.to_primitive(self))
849849

850-
def to_json(self, **kwargs) -> str:
850+
def to_json(self, **kwargs) -> str: # type: ignore
851851
"""Convert to a json string
852852
853853
Args:

pycardano/serialization.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,12 @@ def json_description(self) -> str:
561561
"""
562562
return self.__class__.__doc__ or "Generated with PyCardano"
563563

564-
def to_json(self, key_type: Optional[str] = None, description: Optional[str] = None) -> str:
564+
def to_json(
565+
self,
566+
key_type: Optional[str] = None,
567+
description: Optional[str] = None,
568+
**kwargs,
569+
) -> str:
565570
"""
566571
Convert the CBORSerializable object to a JSON string containing type, description, and CBOR hex.
567572
@@ -570,17 +575,21 @@ def to_json(self, key_type: Optional[str] = None, description: Optional[str] = N
570575
Args:
571576
key_type (str): The type to use in the JSON output. Defaults to the class name.
572577
description (str): The description to use in the JSON output. Defaults to the class docstring.
578+
**kwargs: Extra key word arguments to be passed to `json.dumps()`
573579
574580
Returns:
575581
str: The JSON string representation of the object.
576582
"""
583+
if "indent" not in kwargs:
584+
kwargs["indent"] = 2
585+
577586
return json.dumps(
578587
{
579588
"type": key_type or self.json_type,
580589
"description": description or self.json_description,
581590
"cborHex": self.to_cbor_hex(),
582591
},
583-
indent=2,
592+
**kwargs,
584593
)
585594

586595
@classmethod
@@ -613,6 +622,7 @@ def save(
613622
path: str,
614623
key_type: Optional[str] = None,
615624
description: Optional[str] = None,
625+
**kwargs,
616626
):
617627
"""
618628
Save the CBORSerializable object to a file in JSON format.
@@ -624,14 +634,15 @@ def save(
624634
path (str): The file path to save the object to.
625635
key_type (str, optional): The type to use in the JSON output. Defaults to the class name.
626636
description (str, optional): The description to use in the JSON output. Defaults to the class docstring.
637+
**kwargs: Extra key word arguments to be passed to `json.dumps()`
627638
628639
Raises:
629640
IOError: If the file already exists and is not empty.
630641
"""
631642
if os.path.isfile(path) and os.stat(path).st_size > 0:
632643
raise IOError(f"File {path} already exists!")
633644
with open(path, "w") as f:
634-
f.write(self.to_json(key_type=key_type, description=description))
645+
f.write(self.to_json(key_type=key_type, description=description, **kwargs))
635646

636647
@classmethod
637648
def load(cls, path: str):

0 commit comments

Comments
 (0)