Skip to content

Commit

Permalink
Begin requiring error codes in all # type: ignore (#3134)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Nov 23, 2023
1 parent ac6ca99 commit 4ece59b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,6 @@ warn_redundant_casts = true
warn_return_any = true
warn_unused_configs = true
warn_unused_ignores = true
enable_error_code = [
"ignore-without-code",
]
5 changes: 0 additions & 5 deletions src/urllib3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ def __init__(
self._tunnel_port: int | None = None
self._tunnel_scheme: str | None = None

# https://github.com/python/mypy/issues/4125
# Mypy treats this as LSP violation, which is considered a bug.
# If `host` is made a property it violates LSP, because a writeable attribute is overridden with a read-only one.
# However, there is also a `host` setter so LSP is not violated.
# Potentially, a `@host.deleter` might be needed depending on how this issue will be fixed.
@property
def host(self) -> str:
"""
Expand Down
4 changes: 2 additions & 2 deletions src/urllib3/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,8 @@ def urlopen( # type: ignore[override]
# have to copy the headers dict so we can safely change it without those
# changes being reflected in anyone else's copy.
if not http_tunnel_required:
headers = headers.copy() # type: ignore[attr-defined]
headers.update(self.proxy_headers) # type: ignore[union-attr]
headers = HTTPHeaderDict(headers)
headers.update(self.proxy_headers)

# Must keep the exception bound to a separate variable or else Python 3
# complains about UnboundLocalError.
Expand Down
4 changes: 2 additions & 2 deletions test/with_dummyserver/test_connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def test_upload(self) -> None:
"upload_filename": "lolcat.txt",
"filefield": ("lolcat.txt", data),
}
fields["upload_size"] = len(data) # type: ignore
fields["upload_size"] = len(data) # type: ignore[assignment]

with HTTPConnectionPool(self.host, self.port) as pool:
r = pool.request("POST", "/upload", fields=fields)
Expand Down Expand Up @@ -274,7 +274,7 @@ def test_unicode_upload(self) -> None:
"upload_filename": filename,
fieldname: (filename, data),
}
fields["upload_size"] = size # type: ignore
fields["upload_size"] = size # type: ignore[assignment]
with HTTPConnectionPool(self.host, self.port) as pool:
r = pool.request("POST", "/upload", fields=fields)
assert r.status == 200, r.data
Expand Down

0 comments on commit 4ece59b

Please sign in to comment.