Skip to content

Commit

Permalink
Add typing to URL (#1084)
Browse files Browse the repository at this point in the history
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <webknjaz@redhat.com>
Co-authored-by: Sam Bull <git@sambull.org>
  • Loading branch information
3 people authored Sep 3, 2024
1 parent d4e7601 commit e70f9d4
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 258 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ coverage:
status:
patch:
default:
target: 100%
target: 99.11% # 100%
flags:
- pytest
project:
Expand Down
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ source =
*/Lib/site-packages/yarl

[report]
fail_under = 98.97
fail_under = 98.95
skip_covered = true
skip_empty = true
show_missing = true
Expand Down
1 change: 1 addition & 0 deletions CHANGES/1084.contrib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Covered the :class:`~yarl.URL` object with types -- by :user:`bdraco`.
1 change: 1 addition & 0 deletions CHANGES/1084.feature.rst
2 changes: 1 addition & 1 deletion tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def test_inheritance():
with pytest.raises(TypeError) as ctx:

class MyURL(URL): # type: ignore[misc]
class MyURL(URL):
pass

assert (
Expand Down
131 changes: 0 additions & 131 deletions yarl/__init__.pyi

This file was deleted.

7 changes: 6 additions & 1 deletion yarl/_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from typing import TYPE_CHECKING

__all__ = ("cached_property",)

Expand All @@ -10,7 +11,11 @@


# isort: off
if not NO_EXTENSIONS: # pragma: no branch
if TYPE_CHECKING:
from ._helpers_py import cached_property as cached_property_py

cached_property = cached_property_py
elif not NO_EXTENSIONS: # pragma: no branch
try:
from ._helpers_c import cached_property as cached_property_c # type: ignore[attr-defined, unused-ignore] # noqa: E501

Expand Down
4 changes: 2 additions & 2 deletions yarl/_quoting_c.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class _Quoter:
qs: bool = ...,
requote: bool = ...
) -> None: ...
def __call__(self, val: Optional[str] = ...) -> Optional[str]: ...
def __call__(self, val: str = ...) -> str: ...

class _Unquoter:
def __init__(
self, *, ignore: str = ..., unsafe: str = ..., qs: bool = ...
) -> None: ...
def __call__(self, val: Optional[str] = ...) -> Optional[str]: ...
def __call__(self, val: str = ...) -> str: ...
6 changes: 3 additions & 3 deletions yarl/_quoting_py.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import codecs
import re
from string import ascii_letters, ascii_lowercase, digits
from typing import Optional, cast
from typing import cast

BASCII_LOWERCASE = ascii_lowercase.encode("ascii")
BPCT_ALLOWED = {f"%{i:02X}".encode("ascii") for i in range(256)}
Expand Down Expand Up @@ -33,7 +33,7 @@ def __init__(
self._qs = qs
self._requote = requote

def __call__(self, val: Optional[str]) -> Optional[str]:
def __call__(self, val: str) -> str:
if val is None:
return None
if not isinstance(val, str):
Expand Down Expand Up @@ -123,7 +123,7 @@ def __init__(self, *, ignore: str = "", unsafe: str = "", qs: bool = False) -> N
self._quoter = _Quoter()
self._qs_quoter = _Quoter(qs=True)

def __call__(self, val: Optional[str]) -> Optional[str]:
def __call__(self, val: str) -> str:
if val is None:
return None
if not isinstance(val, str):
Expand Down
Loading

0 comments on commit e70f9d4

Please sign in to comment.