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

pyupgrade --py38-plus #1553

Merged
merged 2 commits into from
Oct 5, 2024
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
2 changes: 1 addition & 1 deletion radicale/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def load(paths: Optional[Iterable[Tuple[str, bool]]] = None
config_source = "config file %r" % path
config: types.CONFIG
try:
with open(path, "r") as f:
with open(path) as f:
parser.read_file(f)
config = {s: {o: parser[s][o] for o in parser.options(s)}
for s in parser.sections()}
Expand Down
2 changes: 1 addition & 1 deletion radicale/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def server_bind(self) -> None:
if name == "certificate_authority" and not filename:
continue
try:
open(filename, "r").close()
open(filename).close()
except OSError as e:
raise RuntimeError(
"Invalid %s value for option %r in section %r in %s: %r "
Expand Down
25 changes: 11 additions & 14 deletions radicale/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.

import contextlib
import sys
from typing import (Any, Callable, ContextManager, Iterator, List, Mapping,
MutableMapping, Sequence, Tuple, TypeVar, Union)
MutableMapping, Protocol, Sequence, Tuple, TypeVar, Union,
runtime_checkable)

WSGIResponseHeaders = Union[Mapping[str, str], Sequence[Tuple[str, str]]]
WSGIResponse = Tuple[int, WSGIResponseHeaders, Union[None, str, bytes]]
Expand All @@ -41,20 +41,17 @@ def contextmanager(func: Callable[..., Iterator[_T]]
return result


if sys.version_info >= (3, 8):
from typing import Protocol, runtime_checkable
@runtime_checkable
class InputStream(Protocol):
def read(self, size: int = ...) -> bytes: ...

@runtime_checkable
class InputStream(Protocol):
def read(self, size: int = ...) -> bytes: ...

@runtime_checkable
class ErrorStream(Protocol):
def flush(self) -> object: ...
def write(self, s: str) -> object: ...
else:
ErrorStream = Any
InputStream = Any
@runtime_checkable
class ErrorStream(Protocol):
def flush(self) -> object: ...

def write(self, s: str) -> object: ...


from radicale import item, storage # noqa:E402 isort:skip

Expand Down
10 changes: 1 addition & 9 deletions radicale/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@
# You should have received a copy of the GNU General Public License
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.

import sys
from importlib import import_module
from importlib import import_module, metadata
from typing import Callable, Sequence, Type, TypeVar, Union

from radicale import config
from radicale.log import logger

if sys.version_info < (3, 8):
import pkg_resources
else:
from importlib import metadata

_T_co = TypeVar("_T_co", covariant=True)


Expand All @@ -52,6 +46,4 @@ def load_plugin(internal_types: Sequence[str], module_name: str,


def package_version(name):
if sys.version_info < (3, 8):
return pkg_resources.get_distribution(name).version
return metadata.version(name)
Loading