Skip to content

Commit

Permalink
Ruff: ensure all functions have type hints (microsoft#2217)
Browse files Browse the repository at this point in the history
* Ensure all functions have type hints

* Fix Callable

* Undo notebook changes
  • Loading branch information
adamjstewart authored Aug 12, 2024
1 parent 96ef481 commit e973c1e
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions docs/tutorials/custom_raster_dataset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,12 @@
"outputs": [],
"source": [
"class Downloadable(RasterDataset):\n",
" def __init__(self, root, crs, res, transforms, cache, download=False):\n",
" def __init__(self, paths, crs, res, bands, transforms, cache, download=False):\n",
" if download:\n",
" # download the dataset\n",
" ...\n",
"\n",
" super().__init__(root, crs, res, transforms, cache)"
" super().__init__(paths, crs, res, bands, transforms, cache)"
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,11 @@ quote-style = "single"
skip-magic-trailing-comma = true

[tool.ruff.lint]
extend-select = ["D", "I", "NPY201", "UP"]
extend-select = ["ANN", "D", "I", "NPY201", "UP"]
ignore = ["ANN101", "ANN102", "ANN401"]

[tool.ruff.lint.per-file-ignores]
"docs/**" = ["D"]
"docs/**" = ["ANN", "D"]
"experiments/**" = ["D"]
"tests/**" = ["D"]

Expand Down
2 changes: 1 addition & 1 deletion tests/data/cbf/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import shutil


def create_geojson():
def create_geojson() -> dict[object, object]:
geojson = {
'type': 'FeatureCollection',
'crs': {
Expand Down
2 changes: 1 addition & 1 deletion tests/data/cropharvest/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
]


def create_geojson():
def create_geojson() -> dict[object, object]:
geojson = {
'type': 'FeatureCollection',
'crs': {},
Expand Down
4 changes: 2 additions & 2 deletions tests/data/eurocrops/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
SIZE = 1280


def create_data_file(dataname):
def create_data_file(dataname: str) -> None:
schema = {'geometry': 'Polygon', 'properties': {'EC_hcat_c': 'str'}}
with fiona.open(
dataname, 'w', crs=CRS.from_epsg(32616), driver='ESRI Shapefile', schema=schema
Expand All @@ -33,7 +33,7 @@ def create_data_file(dataname):
shpfile.write({'geometry': mapping(polygon), 'properties': properties})


def create_csv(fname):
def create_csv(fname: str) -> None:
with open(fname, 'w') as f:
writer = csv.DictWriter(f, fieldnames=['HCAT2_code'])
writer.writeheader()
Expand Down
2 changes: 1 addition & 1 deletion tests/data/nccm/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
files = ['CDL2017_clip.tif', 'CDL2018_clip1.tif', 'CDL2019_clip.tif']


def create_file(path: str, dtype: str):
def create_file(path: str, dtype: str) -> None:
"""Create the testing file."""
profile = {
'driver': 'GTiff',
Expand Down
2 changes: 1 addition & 1 deletion tests/data/nlcd/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"""


def create_file(path: str, dtype: str):
def create_file(path: str, dtype: str) -> None:
"""Create the testing file."""
profile = {
'driver': 'GTiff',
Expand Down
6 changes: 3 additions & 3 deletions tests/data/openbuildings/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
SIZE = 0.05


def create_meta_data_file(zipfilename):
def create_meta_data_file(zipfilename: str) -> dict[object, object]:
meta_data = {
'type': 'FeatureCollection',
'features': [
Expand All @@ -38,7 +38,7 @@ def create_meta_data_file(zipfilename):
return meta_data


def create_csv_data_row(lat, long):
def create_csv_data_row(lat: float, long: float) -> dict[object, object]:
width, height = SIZE / 10, SIZE / 10
minx = long - 0.5 * width
maxx = long + 0.5 * width
Expand All @@ -59,7 +59,7 @@ def create_csv_data_row(lat, long):
return data_row


def create_buildings_data():
def create_buildings_data() -> list[dict[object, object]]:
fourth = SIZE / 4
# pandas df
dict_data = [
Expand Down
2 changes: 1 addition & 1 deletion tests/data/south_america_soybean/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
files = ['SouthAmerica_Soybean_2002.tif', 'SouthAmerica_Soybean_2021.tif']


def create_file(path: str, dtype: str):
def create_file(path: str, dtype: str) -> None:
"""Create the testing file."""
profile = {
'driver': 'GTiff',
Expand Down
2 changes: 1 addition & 1 deletion tests/data/ssl4eo_benchmark_landsat/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def create_mask_directory(
create_mask(path.replace('all_bands', f'{mask_product}_{year}'))


def create_tarballs(directories) -> None:
def create_tarballs(directories: str) -> None:
for directory in directories:
# Create tarballs
shutil.make_archive(directory, 'gztar', '.', directory)
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/models/changestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(
inner_channels: int = 16,
num_convs: int = 4,
scale_factor: float = 4.0,
):
) -> None:
"""Initializes a new ChangeMixin module.
Args:
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/models/fcsiam.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
in_channels: int = 3,
classes: int = 1,
activation: str | Callable[[Tensor], Tensor] | None = None,
):
) -> None:
"""Initialize a new FCSiamConc model.
Args:
Expand Down

0 comments on commit e973c1e

Please sign in to comment.