Remove redundant attrs from exception classes
MODIFY
src/urllib3/exceptions.py
src/urllib3/exceptions.py
@@ -32,8 +32,6 @@ _TYPE_REDUCE_RESULT = Tuple[Callable[..., object], Tuple[object, ...]]
class PoolError(HTTPError):
"""Base exception for errors caused within a pool."""
- pool: "ConnectionPool"
-
def __init__(self, pool: "ConnectionPool", message: str) -> None:
self.pool = pool
super().__init__(f"{pool}: {message}")
@@ -46,8 +44,6 @@ class PoolError(HTTPError):
class RequestError(PoolError):
"""Base exception for PoolErrors that have associated URLs."""
- url: str
-
def __init__(self, pool: "ConnectionPool", url: str, message: str) -> None:
self.url = url
super().__init__(pool, message)
@@ -109,8 +105,6 @@ class MaxRetryError(RequestError):
"""
- reason: Optional[Exception]
-
def __init__(
self, pool: "ConnectionPool", url: str, reason: Optional[Exception] = None
) -> None:
@@ -124,8 +118,6 @@ class MaxRetryError(RequestError):
class HostChangedError(RequestError):
"""Raised when an existing pool gets a request for a foreign host."""
- retries: Union["Retry", int]
-
def __init__(
self, pool: "ConnectionPool", url: str, retries: Union["Retry", int] = 3
) -> None:
@@ -167,8 +159,6 @@ class ConnectTimeoutError(TimeoutError):
class NewConnectionError(ConnectTimeoutError, HTTPError):
"""Raised when we fail to establish a new connection. Usually ECONNREFUSED."""
- conn: "HTTPConnection"
-
def __init__(self, conn: "HTTPConnection", message: str) -> None:
self.conn = conn
super().__init__(f"{conn}: {message}")
@@ -220,8 +210,6 @@ class LocationValueError(ValueError, HTTPError):
class LocationParseError(LocationValueError):
"""Raised when get_host or similar fails to parse the URL input."""
- location: str
-
def __init__(self, location: str) -> None:
message = f"Failed to parse: {location}"
super().__init__(message)
@@ -232,8 +220,6 @@ class LocationParseError(LocationValueError):
class URLSchemeUnknown(LocationValueError):
"""Raised when a URL input has an unsupported scheme."""
- scheme: str
-
def __init__(self, scheme: str):
message = f"Not supported URL scheme {scheme}"
super().__init__(message)
@@ -310,9 +296,6 @@ class IncompleteRead(HTTPError, httplib_IncompleteRead):
for ``partial`` to avoid creating large objects on streamed reads.
"""
- partial: int
- expected: int
-
def __init__(self, partial: int, expected: int) -> None:
self.partial = partial
self.expected = expected
@@ -327,14 +310,9 @@ class IncompleteRead(HTTPError, httplib_IncompleteRead):
class InvalidChunkLength(HTTPError, httplib_IncompleteRead):
"""Invalid chunk length in a chunked response."""
- partial: int
- expected: Optional[int]
- response: "HTTPResponse"
- length: int
-
def __init__(self, response: "HTTPResponse", length: int) -> None:
- self.partial = response.tell()
- self.expected = response.length_remaining
+ self.partial: int = response.tell()
+ self.expected: Optional[int] = response.length_remaining
self.response = response
self.length = length

Remove redundant attrs from exception classes (#2376)