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 @final/Final type hints #477

Merged
merged 2 commits into from
Jul 19, 2020
Merged
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
1 change: 1 addition & 0 deletions CHANGES/477.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``@final``/``Final`` type hints
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ black-check:
black --check $(SRC)

mypy:
mypy yarl tests
mypy --show-error-codes yarl tests

lint: flake8 black-check mypy

Expand Down
2 changes: 1 addition & 1 deletion tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def test_inheritance():
with pytest.raises(TypeError) as ctx:

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

assert (
Expand Down
2 changes: 1 addition & 1 deletion yarl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def build(
return url

def __init_subclass__(cls):
raise TypeError("Inheritance a class {!r} from URL " "is forbidden".format(cls))
raise TypeError("Inheritance a class {!r} from URL is forbidden".format(cls))

def __str__(self):
val = self._val
Expand Down
49 changes: 25 additions & 24 deletions yarl/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
from typing import overload, Any, Tuple, Optional, Mapping, Union, Sequence, Type
from typing_extensions import TypedDict
from typing_extensions import TypedDict, Final, final
import multidict
from functools import _CacheInfo

_QueryVariable = Union[str, int]
_Query = Union[
None, str, Mapping[str, _QueryVariable], Sequence[Tuple[str, _QueryVariable]]
]

@final
class URL:
scheme: str
raw_user: str
user: Optional[str]
raw_password: Optional[str]
password: Optional[str]
raw_host: Optional[str]
host: Optional[str]
port: Optional[int]
raw_path: str
path: str
raw_query_string: str
query_string: str
path_qs: str
raw_path_qs: str
raw_fragment: str
fragment: str
query: multidict.MultiDict[str]
raw_name: str
name: str
raw_parts: Tuple[str, ...]
parts: Tuple[str, ...]
parent: URL
scheme: Final[str]
raw_user: Final[str]
user: Final[Optional[str]]
raw_password: Final[Optional[str]]
password: Final[Optional[str]]
raw_host: Final[Optional[str]]
host: Final[Optional[str]]
port: Final[Optional[int]]
raw_path: Final[str]
path: Final[str]
raw_query_string: Final[str]
query_string: Final[str]
path_qs: Final[str]
raw_path_qs: Final[str]
raw_fragment: Final[str]
fragment: Final[str]
query: Final[multidict.MultiDict[str]]
raw_name: Final[str]
name: Final[str]
raw_parts: Final[Tuple[str, ...]]
parts: Final[Tuple[str, ...]]
parent: Final[URL]
def __init__(
self, val: Union[str, "URL"] = ..., *, encoded: bool = ...
) -> None: ...
Expand Down Expand Up @@ -85,6 +85,7 @@ class URL:
@classmethod
def _normalize_path(cls, path: str) -> str: ...

@final
class cached_property:
def __init__(self, wrapped: Any) -> None: ...
def __get__(self, inst: URL, owner: Type[URL]) -> Any: ...
Expand Down