Skip to content

Commit

Permalink
Fix: Fix type hints for pretty_print function
Browse files Browse the repository at this point in the history
The file can be str or bytes IO. For example sys.stdout is str IO
(TextIO).
  • Loading branch information
bjoernricks authored and greenbonebot committed Jun 14, 2024
1 parent 38ccca4 commit 14e9bf2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions gvm/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import sys
from io import IOBase
from typing import List, Optional, Union
from typing import List, Optional, TextIO, Union

import defusedxml.lxml as secET
from defusedxml import DefusedXmlException
Expand Down Expand Up @@ -68,7 +68,7 @@ def __init__(self, name):

def pretty_print(
xml: Union[str, List[Union[Element, str]], Element],
file: IOBase = sys.stdout,
file: Union[TextIO, IOBase] = sys.stdout,
):
"""Prints beautiful XML-Code
Expand All @@ -85,9 +85,9 @@ def pretty_print(
A IOBase type. Can be a File, StringIO, ...
"""
if not isinstance(file, IOBase):
if not isinstance(file, (IOBase, TextIO)):
raise TypeError(
f"Type needs to be from IOBase, not {type(file)}."
f"Type needs to be from IOBase or TextIO, not {type(file)}."
) from None

if isinstance(xml, list):
Expand Down

0 comments on commit 14e9bf2

Please sign in to comment.