Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more typing details #1204

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/zeep/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class Client:

def __init__(
self,
wsdl,
wsdl: typing.Union[typing.IO, str],
wsse=None,
transport=None,
service_name=None,
port_name=None,
plugins=None,
settings=None,
settings: typing.Optional[Settings] = None,
):
if not wsdl:
raise ValueError("No URL given for the wsdl")
Expand Down
10 changes: 5 additions & 5 deletions src/zeep/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Error(Exception):
def __init__(self, message=""):
def __init__(self, message: str = ""):
super(Exception, self).__init__(message)
self.message = message

Expand All @@ -19,7 +19,7 @@ def __init__(self, *args, **kwargs):
self.sourceline = kwargs.pop("sourceline", None)
super().__init__(*args, **kwargs)

def __str__(self):
def __str__(self) -> str:
location = None
if self.filename and self.sourceline:
location = "%s:%s" % (self.filename, self.sourceline)
Expand All @@ -37,7 +37,7 @@ class WsdlSyntaxError(Error):


class TransportError(Error):
def __init__(self, message="", status_code=0, content=None):
def __init__(self, message: str = "", status_code=0, content=None):
super().__init__(message)
self.status_code = status_code
self.content = content
Expand All @@ -56,7 +56,7 @@ class NamespaceError(Error):


class Fault(Error):
def __init__(self, message, code=None, actor=None, detail=None, subcodes=None):
def __init__(self, message: str, code=None, actor=None, detail=None, subcodes=None):
super().__init__(message)
self.message = message
self.code = code
Expand All @@ -74,7 +74,7 @@ def __init__(self, *args, **kwargs):
self.path = kwargs.pop("path", [])
super().__init__(*args, **kwargs)

def __str__(self):
def __str__(self) -> str:
if self.path:
path = ".".join(str(x) for x in self.path)
return "%s (%s)" % (self.message, path)
Expand Down
2 changes: 1 addition & 1 deletion src/zeep/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from urllib.parse import urlparse

import requests
from requests import Response
from requests import Response as Response
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows using the Response type without directly depending on requests (which avoids any issues if the underlying library were ever changed).

Used like:

from zeep.transports import Response
resp: Response = client_with_raw_response.service.Foo()

from requests_file import FileAdapter

from zeep.exceptions import TransportError
Expand Down
6 changes: 5 additions & 1 deletion src/zeep/wsdl/wsdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ class Document:
"""

def __init__(
self, location, transport: typing.Type["Transport"], base=None, settings=None
self,
location: typing.Union[typing.IO, str],
transport: typing.Type["Transport"],
base=None,
settings=None
):
"""Initialize a WSDL document.

Expand Down