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

bump: min Python 3.9 [blocked] #331

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions .github/scripts/find-unused-caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import os
from datetime import timedelta
from typing import List


def fetch_all_caches(repository: str, token: str, per_page: int = 100, max_pages: int = 100) -> List[dict]:
def fetch_all_caches(repository: str, token: str, per_page: int = 100, max_pages: int = 100) -> list[dict]:
"""Fetch list of al caches from a given repository.

Args:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ on:
default: |
{
"os": ["ubuntu-20.04", "macos-11", "windows-2022"],
"python-version": ["3.8", "3.9"]
"python-version": ["3.9", "3.12"]
}
env-vars:
description: "custom environment variables in json format"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-22.04", "macos-13", "windows-2022"]
python-version: ["3.8", "3.10", "3.12"]
python-version: ["3.9", "3.10", "3.12"]
requires: ["oldest", "latest"]
exclude:
- { requires: "oldest", python-version: "3.12" }
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-use-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
testing-matrix: |
{
"os": ["ubuntu-22.04", "macos-13", "windows-2022"],
"python-version": ["3.8", "3.12"]
"python-version": ["3.9", "3.12"]
}

check-package-extras:
Expand Down
3 changes: 1 addition & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import glob
import os
import re
from typing import List

import pt_lightning_sphinx_theme

Expand Down Expand Up @@ -272,7 +271,7 @@ def setup(app):

# Ignoring Third-party packages
# https://stackoverflow.com/questions/15889621/sphinx-how-to-exclude-imports-in-automodule
def _package_list_from_file(file: str) -> List[str]:
def _package_list_from_file(file: str) -> list[str]:
list_pkgs = []
with open(file) as fp:
lines = fp.readlines()
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires = [
]

[tool.ruff]
target-version = "py38"
target-version = "py39"

line-length = 120
format.preview = true
Expand Down Expand Up @@ -152,4 +152,3 @@ files = [
"src/lightning_utilities",
]
disallow_untyped_defs = true
ignore_missing_imports = true
2 changes: 2 additions & 0 deletions requirements/typing.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mypy>=1.0.0

types-setuptools

fire
8 changes: 4 additions & 4 deletions scripts/adjust-torch-versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import re
import sys
from typing import Dict, List, Optional
from typing import Optional


def _determine_torchaudio(torch_version: str) -> str:
Expand Down Expand Up @@ -103,7 +103,7 @@ def _determine_torchvision(torch_version: str) -> str:
return ".".join(map(str, tv_ver_array))


def find_latest(ver: str) -> Dict[str, str]:
def find_latest(ver: str) -> dict[str, str]:
"""Find the latest version.

>>> from pprint import pprint
Expand Down Expand Up @@ -136,7 +136,7 @@ def find_latest(ver: str) -> Dict[str, str]:
}


def adjust(requires: List[str], pytorch_version: Optional[str] = None) -> List[str]:
def adjust(requires: list[str], pytorch_version: Optional[str] = None) -> list[str]:
"""Adjust the versions to be paired within pytorch ecosystem.

>>> from pprint import pprint
Expand Down Expand Up @@ -175,7 +175,7 @@ def adjust(requires: List[str], pytorch_version: Optional[str] = None) -> List[s
return requires_


def _offset_print(reqs: List[str], offset: str = "\t|\t") -> str:
def _offset_print(reqs: list[str], offset: str = "\t|\t") -> str:
"""Adding offset to each line for the printing requirements."""
reqs = [offset + r for r in reqs]
return os.linesep.join(reqs)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _requirement_extras(path_req: str = _PATH_REQUIRE) -> dict:
include_package_data=True,
zip_safe=False,
keywords=["Utilities", "DevOps", "CI/CD"],
python_requires=">=3.8",
python_requires=">=3.9",
setup_requires=[],
install_requires=requirements,
extras_require=_requirement_extras(),
Expand Down
3 changes: 2 additions & 1 deletion src/lightning_utilities/cli/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#
import glob
import os.path
from collections.abc import Sequence
from pprint import pprint
from typing import Sequence, Union
from typing import Union

REQUIREMENT_ROOT = "requirements.txt"
REQUIREMENT_FILES_ALL: list = glob.glob(os.path.join("requirements", "*.txt"))
Expand Down
17 changes: 9 additions & 8 deletions src/lightning_utilities/core/apply_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#
import dataclasses
from collections import OrderedDict, defaultdict
from collections.abc import Mapping, Sequence
from copy import deepcopy
from typing import Any, Callable, List, Mapping, Optional, Sequence, Tuple, Union
from typing import Any, Callable, Optional, Union


def is_namedtuple(obj: object) -> bool:
Expand All @@ -22,10 +23,10 @@ def is_dataclass_instance(obj: object) -> bool:

def apply_to_collection(
data: Any,
dtype: Union[type, Any, Tuple[Union[type, Any]]],
dtype: Union[type, Any, tuple[Union[type, Any]]],
function: Callable,
*args: Any,
wrong_dtype: Optional[Union[type, Tuple[type, ...]]] = None,
wrong_dtype: Optional[Union[type, tuple[type, ...]]] = None,
include_none: bool = True,
allow_frozen: bool = False,
**kwargs: Any,
Expand Down Expand Up @@ -83,10 +84,10 @@ def apply_to_collection(

def _apply_to_collection_slow(
data: Any,
dtype: Union[type, Any, Tuple[Union[type, Any]]],
dtype: Union[type, Any, tuple[Union[type, Any]]],
function: Callable,
*args: Any,
wrong_dtype: Optional[Union[type, Tuple[type, ...]]] = None,
wrong_dtype: Optional[Union[type, tuple[type, ...]]] = None,
include_none: bool = True,
allow_frozen: bool = False,
**kwargs: Any,
Expand Down Expand Up @@ -181,10 +182,10 @@ def _apply_to_collection_slow(
def apply_to_collections(
data1: Optional[Any],
data2: Optional[Any],
dtype: Union[type, Any, Tuple[Union[type, Any]]],
dtype: Union[type, Any, tuple[Union[type, Any]]],
function: Callable,
*args: Any,
wrong_dtype: Optional[Union[type, Tuple[type]]] = None,
wrong_dtype: Optional[Union[type, tuple[type]]] = None,
**kwargs: Any,
) -> Any:
"""Zips two collections and applies a function to their items of a certain dtype.
Expand Down Expand Up @@ -252,7 +253,7 @@ def apply_to_collections(
# but do not deepcopy mapped fields since the computation would
# be wasted on values that likely get immediately overwritten
data = [data1, data2]
fields: List[dict] = [{}, {}]
fields: list[dict] = [{}, {}]
memo: dict = {}
for i in range(len(data)):
for field in dataclasses.fields(data[i]):
Expand Down
4 changes: 2 additions & 2 deletions src/lightning_utilities/core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
import warnings
from enum import Enum
from typing import List, Optional
from typing import Optional

from typing_extensions import Literal

Expand Down Expand Up @@ -67,7 +67,7 @@ def try_from_str(cls, value: str, source: Literal["key", "value", "any"] = "key"
return None

@classmethod
def _allowed_matches(cls, source: str) -> List[str]:
def _allowed_matches(cls, source: str) -> list[str]:
keys, vals = [], []
for enum_key, enum_val in cls.__members__.items():
keys.append(enum_key)
Expand Down
6 changes: 3 additions & 3 deletions src/lightning_utilities/core/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from importlib.metadata import version as _version
from importlib.util import find_spec
from types import ModuleType
from typing import Any, Callable, List, Optional, TypeVar
from typing import Any, Callable, Optional, TypeVar

from packaging.requirements import Requirement
from packaging.version import InvalidVersion, Version
Expand Down Expand Up @@ -187,7 +187,7 @@ def _check_extras_available(self, requirement: Requirement) -> bool:

return True

def _get_extra_requirements(self, requirement: Requirement) -> List[Requirement]:
def _get_extra_requirements(self, requirement: Requirement) -> list[Requirement]:
dist = distribution(requirement.name)
# Get the required dependencies for the specified extras
extra_requirements = dist.metadata.get_all("Requires-Dist") or []
Expand Down Expand Up @@ -272,7 +272,7 @@ def __getattr__(self, item: str) -> Any:

return getattr(self._module, item)

def __dir__(self) -> List[str]:
def __dir__(self) -> list[str]:
"""Overwrite attribute access for dictionary."""
if self._module is None:
self._import_module()
Expand Down
8 changes: 4 additions & 4 deletions src/lightning_utilities/core/inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# http://www.apache.org/licenses/LICENSE-2.0
#
from typing import Iterator, Set, Type
from collections.abc import Iterator


def get_all_subclasses_iterator(cls: Type) -> Iterator[Type]:
def get_all_subclasses_iterator(cls: type) -> Iterator[type]:
"""Iterate over all subclasses."""

def recurse(cl: Type) -> Iterator[Type]:
def recurse(cl: type) -> Iterator[type]:
for subclass in cl.__subclasses__():
yield subclass
yield from recurse(subclass)

yield from recurse(cls)


def get_all_subclasses(cls: Type) -> Set[Type]:
def get_all_subclasses(cls: type) -> set[type]:
"""List all subclasses of a class."""
return set(get_all_subclasses_iterator(cls))
3 changes: 1 addition & 2 deletions src/lightning_utilities/core/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
from functools import partial
from typing import Type
from unittest.mock import Mock


def is_overridden(method_name: str, instance: object, parent: Type[object]) -> bool:
def is_overridden(method_name: str, instance: object, parent: type[object]) -> bool:
"""Check if a method of a given object was overwritten."""
instance_attr = getattr(instance, method_name, None)
if instance_attr is None:
Expand Down
7 changes: 4 additions & 3 deletions src/lightning_utilities/docs/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import os
import re
import sys
from typing import Iterable, List, Optional, Tuple, Union
from collections.abc import Iterable
from typing import Optional, Union


def _transform_changelog(path_in: str, path_out: str) -> None:
Expand Down Expand Up @@ -41,7 +42,7 @@ def _linkcode_resolve(
main_branch: str = "master",
stable_branch: str = "release/stable",
) -> str:
def find_source() -> Tuple[str, int, int]:
def find_source() -> tuple[str, int, int]:
# try to find the file and line number, based on code from numpy:
# https://github.com/numpy/numpy/blob/master/doc/source/conf.py#L286
obj = sys.modules[info["module"]]
Expand Down Expand Up @@ -76,7 +77,7 @@ def find_source() -> Tuple[str, int, int]:
return f"https://github.com/{github_user}/{github_repo}/blob/{filename}"


def _load_pypi_versions(package_name: str) -> List[str]:
def _load_pypi_versions(package_name: str) -> list[str]:
"""Load the versions of the package from PyPI.

>>> _load_pypi_versions("numpy") # doctest: +ELLIPSIS
Expand Down
5 changes: 2 additions & 3 deletions src/lightning_utilities/docs/retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import os
import re
from typing import List, Tuple

import requests

Expand All @@ -23,7 +22,7 @@ def _download_file(file_url: str, folder: str) -> str:
return fname


def _search_all_occurrences(list_files: List[str], pattern: str) -> List[str]:
def _search_all_occurrences(list_files: list[str], pattern: str) -> list[str]:
"""Search for all occurrences of specific pattern in a collection of files.

Args:
Expand All @@ -40,7 +39,7 @@ def _search_all_occurrences(list_files: List[str], pattern: str) -> List[str]:
return collected


def _replace_remote_with_local(file_path: str, docs_folder: str, pairs_url_path: List[Tuple[str, str]]) -> None:
def _replace_remote_with_local(file_path: str, docs_folder: str, pairs_url_path: list[tuple[str, str]]) -> None:
"""Replace all URL with local files in a given file.

Args:
Expand Down
5 changes: 3 additions & 2 deletions src/lightning_utilities/install/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
import re
from collections.abc import Iterable, Iterator
from distutils.version import LooseVersion
from pathlib import Path
from typing import Any, Iterable, Iterator, List, Optional, Union
from typing import Any, Optional, Union

from pkg_resources import Requirement, yield_lines

Expand Down Expand Up @@ -103,7 +104,7 @@ def _parse_requirements(strs: Union[str, Iterable[str]]) -> Iterator[_Requiremen
pip_argument = None


def load_requirements(path_dir: str, file_name: str = "base.txt", unfreeze: str = "all") -> List[str]:
def load_requirements(path_dir: str, file_name: str = "base.txt", unfreeze: str = "all") -> list[str]:
"""Load requirements from a file.

>>> import os
Expand Down
5 changes: 3 additions & 2 deletions src/lightning_utilities/test/warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#
import re
import warnings
from collections.abc import Generator
from contextlib import contextmanager
from typing import Generator, Optional, Type
from typing import Optional


@contextmanager
def no_warning_call(expected_warning: Type[Warning] = Warning, match: Optional[str] = None) -> Generator:
def no_warning_call(expected_warning: type[Warning] = Warning, match: Optional[str] = None) -> Generator:
"""Check that no warning was raised/emitted under this context manager."""
with warnings.catch_warnings(record=True) as record:
yield
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/core/test_apply_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numbers
from collections import OrderedDict, defaultdict, namedtuple
from dataclasses import InitVar
from typing import Any, ClassVar, List, Optional
from typing import Any, ClassVar, Optional

import pytest
from unittests.mocks import torch
Expand All @@ -27,7 +27,7 @@ def __eq__(self, o: object) -> bool:

@dataclasses.dataclass
class ModelExample:
example_ids: List[str]
example_ids: list[str]
feature: Feature
label: torch.Tensor
some_constant: int = dataclasses.field(init=False)
Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/mocks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Iterable
from collections.abc import Iterable
from typing import Any

from lightning_utilities.core.imports import package_available

Expand Down
Loading
Loading