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

Replace all Optional with Union #1095

Merged
merged 8 commits into from
Sep 6, 2024
Merged
Changes from 1 commit
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
34 changes: 17 additions & 17 deletions yarl/_url.py
bdraco marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def __new__(
raise TypeError("Constructor parameter should be str")

if not encoded:
host: Optional[str]
host: Union[str, None]
if not val[1]: # netloc
netloc = ""
host = ""
Expand Down Expand Up @@ -231,8 +231,8 @@ def build(
*,
scheme: str = "",
authority: str = "",
user: Optional[str] = None,
password: Optional[str] = None,
user: Union[str, None] = None,
password: Union[str, None] = None,
host: str = "",
port: Optional[int] = None,
path: str = "",
Expand Down Expand Up @@ -492,7 +492,7 @@ def authority(self) -> str:
)

@property
def raw_user(self) -> Optional[str]:
def raw_user(self) -> Union[str, None]:
"""Encoded user part of URL.

None if user is missing.
Expand All @@ -502,7 +502,7 @@ def raw_user(self) -> Optional[str]:
return self._val.username or None

@cached_property
def user(self) -> Optional[str]:
def user(self) -> Union[str, None]:
"""Decoded user part of URL.

None if user is missing.
Expand All @@ -514,7 +514,7 @@ def user(self) -> Optional[str]:
return self._UNQUOTER(raw_user)

@property
def raw_password(self) -> Optional[str]:
def raw_password(self) -> Union[str, None]:
"""Encoded password part of URL.

None if password is missing.
Expand All @@ -523,7 +523,7 @@ def raw_password(self) -> Optional[str]:
return self._val.password

@cached_property
def password(self) -> Optional[str]:
def password(self) -> Union[str, None]:
"""Decoded password part of URL.

None if password is missing.
Expand All @@ -535,7 +535,7 @@ def password(self) -> Optional[str]:
return self._UNQUOTER(raw_password)

@cached_property
def raw_host(self) -> Optional[str]:
def raw_host(self) -> Union[str, None]:
"""Encoded host part of URL.

None for relative URLs.
Expand All @@ -546,7 +546,7 @@ def raw_host(self) -> Optional[str]:
return self._val.hostname

@cached_property
def host(self) -> Optional[str]:
def host(self) -> Union[str, None]:
"""Decoded host part of URL.

None for relative URLs.
Expand Down Expand Up @@ -842,9 +842,9 @@ def _encode_host(cls, host: str, human: bool = False) -> str:
@classmethod
def _make_netloc(
cls,
user: Optional[str],
password: Optional[str],
host: Optional[str],
user: Union[str, None],
password: Union[str, None],
host: Union[str, None],
port: Optional[int],
encode: bool = False,
encode_host: bool = True,
Expand Down Expand Up @@ -883,7 +883,7 @@ def with_scheme(self, scheme: str) -> "URL":
raise ValueError("scheme replacement is not allowed for relative URLs")
return URL(self._val._replace(scheme=scheme.lower()), encoded=True)

def with_user(self, user: Optional[str]) -> "URL":
def with_user(self, user: Union[str, None]) -> "URL":
"""Return a new URL with user replaced.

Autoencode user if needed.
Expand All @@ -909,7 +909,7 @@ def with_user(self, user: Optional[str]) -> "URL":
encoded=True,
)

def with_password(self, password: Optional[str]) -> "URL":
def with_password(self, password: Union[str, None]) -> "URL":
"""Return a new URL with password replaced.

Autoencode password if needed.
Expand Down Expand Up @@ -1026,7 +1026,7 @@ def _query_var(v: _QueryVariable) -> str:
"of type {}".format(v, cls)
)

def _get_str_query(self, *args: Any, **kwargs: Any) -> Optional[str]:
def _get_str_query(self, *args: Any, **kwargs: Any) -> Union[str, None]:
query: Optional[Union[str, Mapping[str, _QueryVariable]]]
if kwargs:
if len(args) > 0:
Expand Down Expand Up @@ -1112,7 +1112,7 @@ def update_query(self, *args: Any, **kwargs: Any) -> "URL":
self._val._replace(query=self._get_str_query(query) or ""), encoded=True
)

def with_fragment(self, fragment: Optional[str]) -> "URL":
def with_fragment(self, fragment: Union[str, None]) -> "URL":
"""Return a new URL with fragment replaced.

Autoencode fragment if needed.
Expand Down Expand Up @@ -1229,7 +1229,7 @@ def human_repr(self) -> str:
return urlunsplit(val)


def _human_quote(s: Optional[str], unsafe: str) -> Optional[str]:
def _human_quote(s: Union[str, None], unsafe: str) -> Union[str, None]:
if not s:
return s
for c in "%" + unsafe:
Expand Down
Loading