Skip to content

Commit

Permalink
🐝 Upgrade pyright to match VSCode errors (#3148)
Browse files Browse the repository at this point in the history
* 🐝 update pyright to version 1.1.373
  • Loading branch information
Marigold authored Aug 22, 2024
1 parent 5ecc3c2 commit e614831
Show file tree
Hide file tree
Showing 87 changed files with 270 additions and 221 deletions.
2 changes: 1 addition & 1 deletion apps/backport/datasync/datasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def upload_gzip_string(s: str, s3_path: str, private: bool = False) -> None:
retry=retry_if_exception_type((EndpointConnectionError, SSLError)),
):
with attempt:
client.put_object(
client.put_object( # type: ignore[reportAttributeAccessIssue]
Bucket=bucket,
Body=body_gzip,
Key=key,
Expand Down
8 changes: 4 additions & 4 deletions apps/metadata_migrate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,22 +324,22 @@ def _create_origin_from_source(ds: Dataset, source: Source, license: Optional[Li
description += source.description

origin = Origin(
title=ds.metadata.title,
producer=source.name,
title=ds.metadata.title, # type: ignore[reportArgumentType]
producer=source.name, # type: ignore[reportArgumentType]
citation_full=source.published_by,
license=license,
description=description,
url_main=source.url,
url_download=source.source_data_url,
date_accessed=source.date_accessed,
date_published=source.publication_date or source.publication_year,
date_published=source.publication_date or source.publication_year, # type: ignore[reportArgumentType]
)

if not origin.date_published:
log.warning(
f"missing publication_date and publication_year in source, using date_accessed: {origin.date_accessed}"
)
origin.date_published = origin.date_accessed
origin.date_published = origin.date_accessed # type: ignore
return origin


Expand Down
2 changes: 1 addition & 1 deletion apps/metagpt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def main(path_to_file: str, output_dir: str, overwrite: bool, model: str) -> Non
class MetadataGPTUpdater:
"""Update metadata file using Chat GPT."""

def __init__(self: Self, path_to_file: str, model: str) -> None:
def __init__(self: Self, path_to_file: str, model: str) -> None: # type: ignore[reportInvalidTypeVarUse]
"""Initialize the metadata updater."""
# Name of the model
self.model: str = model
Expand Down
6 changes: 3 additions & 3 deletions apps/utils/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class GPTResponse(ChatCompletion):

message_content_dix: Optional[Dict[str, Any]] = field(default_factory=dict)

def __init__(self: Self, chat_completion_instance: ChatCompletion | None = None, **kwargs) -> None:
def __init__(self: Self, chat_completion_instance: ChatCompletion | None = None, **kwargs) -> None: # type: ignore[reportInvalidTypeVarUse]
"""Initialize OpenAI API wrapper."""
if chat_completion_instance:
super().__init__(**chat_completion_instance.dict())
Expand Down Expand Up @@ -102,7 +102,7 @@ def message_content_as_dict(self: Self) -> Dict[str, Any]:
self.message_content_dix = yaml.safe_load(self.message_content)
else:
raise ValueError("`message_content` is empty!")
return self.message_content_dix
return self.message_content_dix # type: ignore[reportReturnType]

@property
def cost(self) -> float | None:
Expand Down Expand Up @@ -167,7 +167,7 @@ def to_dict(self: Self) -> Dict[str, Any]:
class OpenAIWrapper(OpenAI):
"""Wrapper for OpenAI API."""

def __init__(self: Self, **kwargs) -> None:
def __init__(self: Self, **kwargs) -> None: # type: ignore[reportInvalidTypeVarUse]
"""Initialize OpenAI API wrapper."""
super().__init__(**kwargs)

Expand Down
2 changes: 1 addition & 1 deletion apps/utils/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def cli(step: str, cpu: bool, mem: bool, functions: tuple[str]) -> None:

# Profile the run function
if mem:
memory_usage((mem_profile(lp_wrapper), [dest_dir]))
memory_usage((mem_profile(lp_wrapper), [dest_dir])) # type: ignore[reportArgumentType]
else:
lp_wrapper(dest_dir)

Expand Down
4 changes: 2 additions & 2 deletions apps/wizard/app_pages/fasttrack/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def parse_metadata_from_csv(
date_published=str(dt.date.today()), # type: ignore
)

return DatasetMeta(**dataset_dict), {k: VariableMeta(**v) for k, v in variables_dict.items()}, origin
return DatasetMeta(**dataset_dict), {k: VariableMeta(**v) for k, v in variables_dict.items()}, origin # type: ignore


###################################
Expand Down Expand Up @@ -301,7 +301,7 @@ def _parse_sources(sources_meta_df: pd.DataFrame) -> Optional[Source]:
# short_name is not used anymore
source.pop("short_name", None)

return Source(**source)
return Source(**source) # type: ignore[reportCallIssue]


def _parse_origins(origins_meta_df: pd.DataFrame) -> Optional[Origin]:
Expand Down
10 changes: 5 additions & 5 deletions apps/wizard/app_pages/owidle.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def load_data(placeholder: str) -> Tuple[pd.DataFrame, gpd.GeoDataFrame]:
].drop_duplicates()
# df_geo = df_geo.to_crs(3310)

return tb_indicator, df_geo
return tb_indicator, df_geo # type: ignore[reportReturnType]


@st.cache_data
Expand Down Expand Up @@ -827,16 +827,16 @@ def plot_chart_gdp_pc(countries_guessed: List[str], years_guessed: List[str], so
countries_guessed,
years_guessed=years_guessed,
solution=solution,
column_indicator=GDP_INDICATOR,
title=gdp_indicator_titles[GDP_INDICATOR],
column_indicator=GDP_INDICATOR, # type: ignore[reportArgumentType]
title=gdp_indicator_titles[GDP_INDICATOR], # type: ignore[reportArgumentType]
column_country="location",
)
else:
_plot_chart(
countries_guessed,
solution=solution,
column_indicator=GDP_INDICATOR,
title=gdp_indicator_titles[GDP_INDICATOR],
column_indicator=GDP_INDICATOR, # type: ignore[reportArgumentType]
title=gdp_indicator_titles[GDP_INDICATOR], # type: ignore[reportArgumentType]
column_country="location",
)

Expand Down
4 changes: 2 additions & 2 deletions apps/wizard/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@click.command(cls=RichCommand, context_settings=dict(show_default=True))
@click.argument(
"phase",
type=click.Choice(WIZARD_PHASES.__args__), # type: ignore
type=click.Choice(WIZARD_PHASES),
default="all",
)
@click.option(
Expand All @@ -52,7 +52,7 @@
help="Application port.",
)
def cli(
phase: Iterable[WIZARD_PHASES],
phase: Iterable[str],
run_checks: bool,
dummy_data: bool,
port: int,
Expand Down
3 changes: 1 addition & 2 deletions apps/wizard/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
It basically reads the configuration from .wizard.yml and renders the home page and other details.
"""
from typing import Literal

import yaml

Expand Down Expand Up @@ -106,7 +105,7 @@ def _check_wizard_config(config: dict):
_aliases.append(app["alias"])
## Add aliases from etl steps and 'all'
_aliases = tuple(_aliases + list(WIZARD_CONFIG["etl"]["steps"].keys()) + ["all"])
WIZARD_PHASES = Literal[_aliases] # type: ignore
WIZARD_PHASES = _aliases

# Get all pages by alias
_pages = [ww for w in WIZARD_CONFIG["sections"] for ww in w["apps"]]
Expand Down
2 changes: 1 addition & 1 deletion apps/wizard/etl_steps/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ExpressForm(utils.StepForm):
namespace_custom: str | None = None
update_period_date: date

def __init__(self: Self, **data: str | date | bool | int) -> None:
def __init__(self: Self, **data: str | date | bool | int) -> None: # type: ignore[reportInvalidTypeVarUse]
"""Construct class."""
data["add_to_dag"] = data["dag_file"] != utils.ADD_DAG_OPTIONS[0]

Expand Down
2 changes: 1 addition & 1 deletion apps/wizard/etl_steps/garden.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class GardenForm(utils.StepForm):
update_period_days: int
topic_tags: List[str]

def __init__(self: Self, **data: str | bool) -> None:
def __init__(self: Self, **data: str | bool) -> None: # type: ignore[reportInvalidTypeVarUse]
"""Construct class."""
data["add_to_dag"] = data["dag_file"] != utils.ADD_DAG_OPTIONS[0]

Expand Down
2 changes: 1 addition & 1 deletion apps/wizard/etl_steps/grapher.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GrapherForm(utils.StepForm):
dag_file: str
is_private: bool

def __init__(self: Self, **data: str | bool) -> None:
def __init__(self: Self, **data: str | bool) -> None: # type: ignore[reportInvalidTypeVarUse]
"""Construct class."""
data["add_to_dag"] = data["dag_file"] != utils.ADD_DAG_OPTIONS[0]

Expand Down
2 changes: 1 addition & 1 deletion apps/wizard/etl_steps/meadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class MeadowForm(utils.StepForm):
generate_notebook: bool
is_private: bool

def __init__(self: Self, **data: str | bool) -> None:
def __init__(self: Self, **data: str | bool) -> None: # type: ignore[reportInvalidTypeVarUse]
"""Construct class."""
data["add_to_dag"] = data["dag_file"] != utils.ADD_DAG_OPTIONS[0]

Expand Down
4 changes: 2 additions & 2 deletions apps/wizard/etl_steps/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SnapshotForm(utils.StepForm):
license_url: str
license_name: str

def __init__(self: Self, **data: str | int) -> None:
def __init__(self: Self, **data: str | int) -> None: # type: ignore[reportInvalidTypeVarUse]
"""Construct form."""
# Change name for certain fields (and remove old ones)
data["license_url"] = data["origin.license.url"]
Expand Down Expand Up @@ -177,7 +177,7 @@ def validate(self: "SnapshotForm") -> None:
self.errors["origin.attribution_custom"] = "Please introduce the name of the custom attribute!"

@property
def metadata(self: Self) -> Dict[str, Any]:
def metadata(self: Self) -> Dict[str, Any]: # type: ignore[reportIncompatibleMethodOverride]
"""Define metadata for easy YAML-export."""
license_field = {
"name": self.license_name,
Expand Down
2 changes: 1 addition & 1 deletion apps/wizard/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def create_card(
# text=f"Press {i + 1}",
# text=["This is a test card", "This is a subtext"],
styles=styles,
on_click=lambda: None,
on_click=lambda: None, # type: ignore[reportArgumentType]
)
if go_to_page:
st.switch_page(entrypoint)
Expand Down
2 changes: 1 addition & 1 deletion apps/wizard/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def remove_from_dag(step: str, dag_path: Path = DAG_WIZARD_PATH) -> None:
class classproperty(property):
"""Decorator."""

def __get__(self, owner_self: Self, owner_cls: Self):
def __get__(self, owner_self: Self, owner_cls: Self): # type: ignore[reportIncompatibleMethodOverride]
return self.fget(owner_cls) # type: ignore


Expand Down
4 changes: 2 additions & 2 deletions apps/wizard/utils/step_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StepForm(BaseModel):
errors: Dict[str, Any] = {}
step_name: str

def __init__(self: Self, **kwargs: str | int) -> None:
def __init__(self: Self, **kwargs: str | int) -> None: # type: ignore[reportInvalidTypeVarUse]
"""Construct parent class."""
super().__init__(**kwargs)
self.validate()
Expand All @@ -36,7 +36,7 @@ def from_state(cls: Type[Self]) -> Self:
# st.write(data)
return cls(**data)

def validate(self: Self) -> None:
def validate(self: Self) -> None: # type: ignore[reportIncompatibleMethodOverride]
"""Validate form fields."""
raise NotImplementedError("Needs to be implemented in the child class!")

Expand Down
13 changes: 9 additions & 4 deletions etl/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import rich
from dotenv import dotenv_values
from owid import catalog
from owid.catalog import CHANNEL
from owid.repack import repack_frame
from rich import print
from rich_click.rich_command import RichCommand
Expand Down Expand Up @@ -116,7 +117,7 @@ def diff_print(
@click.pass_context
def etl_catalog(
ctx: click.core.Context,
channel: str,
channel: CHANNEL,
namespace: str,
dataset: str,
table: str,
Expand All @@ -140,7 +141,11 @@ def etl_catalog(
"""
try:
remote_df = catalog.find_latest(
table=table, namespace=namespace, dataset=dataset, channels=[channel], version=version
table=table,
namespace=namespace,
dataset=dataset,
channels=[channel],
version=version, # type: ignore[reportArgumentType]
)
except Exception as e:
if debug:
Expand All @@ -157,7 +162,7 @@ def etl_catalog(
namespace=namespace,
dataset=dataset,
channel=cast(catalog.CHANNEL, channel),
version=version,
version=version, # type: ignore[reportArgumentType]
)
except ValueError as e:
# try again after reindexing
Expand All @@ -168,7 +173,7 @@ def etl_catalog(
namespace=namespace,
dataset=dataset,
channel=cast(catalog.CHANNEL, channel),
version=version,
version=version, # type: ignore[reportArgumentType]
)
else:
raise e
Expand Down
7 changes: 4 additions & 3 deletions etl/data_helpers/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import warnings
from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List, Literal, Optional, Set, TypeVar, Union, cast
from typing import Any, Dict, Hashable, List, Literal, Optional, Set, TypeVar, Union, cast

import numpy as np
import owid.catalog.processing as pr
Expand Down Expand Up @@ -848,7 +848,8 @@ def add_gdp_to_table(
def create_table_of_regions_and_subregions(ds_regions: Dataset, subregion_type: str = "members") -> Table:
# Subregion type can be "members" or "successors" (or in principle also "related").
# Get the main table from the regions dataset.
tb_regions = ds_regions["regions"][["name", subregion_type]]
tb_regions = ds_regions["regions"]
tb_regions = tb_regions.loc[:, ["name", subregion_type]]

# Get a mapping from code to region name.
mapping = tb_regions["name"].to_dict()
Expand Down Expand Up @@ -1002,7 +1003,7 @@ def list_members_of_region(
def detect_overlapping_regions(
df: TableOrDataFrame,
index_columns: List[str],
regions_and_members: Dict[str, List[str]],
regions_and_members: Dict[Hashable, List[str]],
country_col: str = "country",
year_col: str = "year",
ignore_overlaps_of_zeros: bool = True,
Expand Down
4 changes: 2 additions & 2 deletions etl/data_helpers/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def add_origins_to_mortality_database(tb_who: Table) -> Table:
producer="World Health Organisation",
url_main="https://platform.who.int/mortality/themes/theme-details/MDB/all-causes",
date_accessed="2023-08-01",
date_published="2023-08-01",
date_published="2023-08-01", # type: ignore
citation_full="Mortality Database, World Health Organization. Licence: CC BY-NC-SA 3.0 IGO.",
description="The WHO mortality database is a collection death registration data including cause-of-death information from member states. Where they are collected, death registration data are the best source of information on key health indicators, such as life expectancy, and death registration data with cause-of-death information are the best source of information on mortality by cause, such as maternal mortality and suicide mortality. WHO requests from all countries annual data by age, sex, and complete ICD code (e.g., 4-digit code if the 10th revision of ICD was used). Countries have reported deaths by cause of death, year, sex, and age for inclusion in the WHO Mortality Database since 1950. Data are included only for countries reporting data properly coded according to the International Classification of Diseases (ICD). Today the database is maintained by the WHO Division of Data, Analytics and Delivery for Impact (DDI) and contains data from over 120 countries and areas. Data reported by member states and selected areas are displayed in this portal’s interactive visualizations if the data are reported to the WHO mortality database in the requested format and at least 65% of deaths were recorded in each country and year.",
license=License(name="CC BY 4.0"),
Expand Down Expand Up @@ -197,7 +197,7 @@ def add_origins_to_global_burden_of_disease(tb_gbd: Table) -> Table:
producer="Institute of Health Metrics and Evaluation",
url_main="https://vizhub.healthdata.org/gbd-results/",
date_accessed="2021-12-01",
date_published="2020-10-17",
date_published="2020-10-17", # type: ignore
citation_full="Global Burden of Disease Collaborative Network. Global Burden of Disease Study 2019 (GBD 2019). Seattle, United States: Institute for Health Metrics and Evaluation (IHME), 2020.",
description="The Global Burden of Disease (GBD) provides a comprehensive picture of mortality and disability across countries, time, age, and sex. It quantifies health loss from hundreds of diseases, injuries, and risk factors, so that health systems can be improved and disparities eliminated. GBD research incorporates both the prevalence of a given disease or risk factor and the relative harm it causes. With these tools, decision-makers can compare different health issues and their effects.",
license=License(
Expand Down
2 changes: 1 addition & 1 deletion etl/datadiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def _diff_tables(self, ds_a: Dataset, ds_b: Dataset, table_name: str):
changed.append("changed [u]metadata[/u]")
if new_index.any():
changed.append("new [u]data[/u]")
if (~eq_data[~new_index]).any():
if (~eq_data[~new_index]).any(): # type: ignore[reportCallIssue]
changed.append("changed [u]data[/u]")

if changed:
Expand Down
6 changes: 3 additions & 3 deletions etl/git_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def ensure_cloned(self, shallow: bool = True) -> None:
if not dest_dir.is_dir():
dest_dir.parent.mkdir(parents=True, exist_ok=True)
if shallow:
sh.git("clone", "--depth=1", self.github_url, dest_dir.as_posix(), _fg=True)
sh.git("clone", "--depth=1", self.github_url, dest_dir.as_posix(), _fg=True) # type: ignore[reportCallIssue]
else:
sh.git("clone", self.github_url, dest_dir.as_posix(), _fg=True)
sh.git("clone", self.github_url, dest_dir.as_posix(), _fg=True) # type: ignore[reportCallIssue]
else:
self.update_and_reset()

Expand Down Expand Up @@ -86,7 +86,7 @@ def _git(self, *args: str, **kwargs: Any) -> str:
"Execute a git command in the context of this repo."
return cast(
str,
sh.git("--no-pager", *args, _cwd=self.cache_dir.as_posix(), **kwargs).stdout.decode("utf8").strip(),
sh.git("--no-pager", *args, _cwd=self.cache_dir.as_posix(), **kwargs).stdout.decode("utf8").strip(), # type: ignore[reportCallIssue]
)

def is_up_to_date(self) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions etl/grapher_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,11 @@ def country_to_entity_id(
assert by == "name", "create_entities works only with `by='name'`"
ix = entity_id.isnull()
# cast to float to fix issues with categories
entity_id[ix] = (
country[ix].map(_get_and_create_entities_in_db(set(country[ix].unique()), engine=engine)).astype(float)
entity_id[ix] = ( # type: ignore[reportCallIssue]
country[ix].map(_get_and_create_entities_in_db(set(country[ix].unique()), engine=engine)).astype(float) # type: ignore[reportCallIssue]
)

assert not entity_id.isnull().any(), f"Some countries have not been mapped: {set(country[entity_id.isnull()])}"
assert not entity_id.isnull().any(), f"Some countries have not been mapped: {set(country[entity_id.isnull()])}" # type: ignore[reportCallIssue]

return cast(pd.Series, entity_id.astype(int))

Expand Down
Loading

0 comments on commit e614831

Please sign in to comment.