diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eb64f3838..51d07a3b3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,11 +7,11 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/psf/black-pre-commit-mirror - rev: 25.12.0 + rev: 26.1.0 hooks: - id: black - repo: https://github.com/pycqa/isort - rev: 7.0.0 + rev: 8.0.0 hooks: - id: isort args: ["--profile", "black", "--filter-files"] @@ -21,7 +21,7 @@ repos: - id: flake8 args: ["--max-line-length=88", "--ignore=E20,W503"] # black compatible - repo: https://github.com/pre-commit/mirrors-eslint - rev: v10.0.0-beta.0 + rev: v10.0.1 hooks: - id: eslint additional_dependencies: diff --git a/api/actions.py b/api/actions.py index 32c0eb31b..d8a715b54 100644 --- a/api/actions.py +++ b/api/actions.py @@ -1001,7 +1001,7 @@ def __change_rows( sa_table = table_obj.get_oedb_table_proxy()._main_table.get_sa_table() - pks = [c for c in sa_table.columns if c.primary_key] # type:ignore + pks = [c for c in sa_table.columns if c.primary_key] # type: ignore inserts = [] cursor = load_cursor_from_context(context) @@ -1333,11 +1333,11 @@ def add_type(d, type): engine = _get_engine() artificial_connection = False - connection: DBAPIConnection = engine.raw_connection() # type:ignore TODO + connection: DBAPIConnection = engine.raw_connection() # type: ignore TODO if cursor is None: artificial_connection = True - cursor = cast(AbstractCursor, connection.cursor()) # type:ignore TODO + cursor = cast(AbstractCursor, connection.cursor()) # type: ignore TODO try: columns = list(describe_columns(table_obj).keys()) @@ -1545,7 +1545,7 @@ def set_table_metadata(table: str, metadata): # --------------------------------------- django_table_obj = Table.objects.get(name=table) - django_table_obj.oemetadata = metadata_obj # type:ignore + django_table_obj.oemetadata = metadata_obj # type: ignore django_table_obj.save() # --------------------------------------- @@ -1570,8 +1570,7 @@ def get_single_table_size(table_obj: Table) -> dict | None: Return size details for one table or None if not found. """ - sql = text( - """ + sql = text(""" SELECT :schema AS table_schema, :table AS table_name, @@ -1581,8 +1580,7 @@ def get_single_table_size(table_obj: Table) -> dict | None: pg_size_pretty(pg_relation_size(format('%I.%I', :schema, :table))) AS table_pretty, pg_size_pretty(pg_indexes_size(format('%I.%I', :schema, :table))) AS index_pretty, pg_size_pretty(pg_total_relation_size(format('%I.%I', :schema, :table))) AS total_pretty - """ # noqa: E501 - ) + """) # noqa: E501 sess = _create_oedb_session() try: @@ -1605,8 +1603,7 @@ def list_table_sizes() -> list[dict]: List table sizes """ oedb_schema = SCHEMA_DATA - sql = text( - f""" + sql = text(f""" SELECT table_schema, table_name, @@ -1618,8 +1615,7 @@ def list_table_sizes() -> list[dict]: WHERE table_schema='{oedb_schema}' AND table_type = 'BASE TABLE' ORDER BY pg_total_relation_size(format('%I.%I', table_schema, table_name)) DESC - """ # noqa: E501 - ) + """) # noqa: E501 sess = _create_oedb_session() try: @@ -1637,14 +1633,12 @@ def list_table_sizes() -> list[dict]: def table_has_row_with_id(table: Table, id: int | str, id_col: str = "id") -> bool: - query = text( - f""" + query = text(f""" SELECT count(*) FROM "{table.oedb_schema}"."{table.name}" WHERE {id_col} = :id ; - """ - ) + """) engine = _get_engine() with engine.connect() as conn: @@ -1656,13 +1650,11 @@ def table_has_row_with_id(table: Table, id: int | str, id_col: str = "id") -> bo def table_get_row_count(table: Table) -> int: - query = text( - f""" + query = text(f""" SELECT count(*) FROM "{table.oedb_schema}"."{table.name}" ; - """ - ) + """) engine = _get_engine() with engine.connect() as conn: @@ -1689,14 +1681,12 @@ def table_get_approx_row_count(table: Table, precise_below: int = 0) -> int: # table name. but its validated by constraints # on django table.name field - query = text( - f""" + query = text(f""" SELECT reltuples::bigint AS approx_row_count FROM pg_class WHERE oid = '"{table.oedb_schema}"."{table.name}"'::regclass ; - """ - ) + """) with engine.connect() as conn: resp = _execute(conn, query) @@ -2118,7 +2108,7 @@ def _execute( *args, **kwargs, ) -> ResultProxy: - response = con.execute(sql, *args, **kwargs) # type:ignore + response = con.execute(sql, *args, **kwargs) # type: ignore # Note: cast is only for type checking, # should disappear once we migrate to sqlalchemy >= 1.4 response = cast(ResultProxy, response) diff --git a/api/parser.py b/api/parser.py index e08722e54..fcd196d0e 100644 --- a/api/parser.py +++ b/api/parser.py @@ -128,7 +128,7 @@ def get_column_definition_query(d: dict) -> Column: if d.get("character_maximum_length"): max_len = int(d["character_maximum_length"]) - dt = dt(max_len) # type:ignore + dt = dt(max_len) # type: ignore _assert_valid_identifier_name(name) c = Column(name, dt, *args, **kwargs) @@ -483,11 +483,11 @@ def _parse_from_item(d): on_clause = None if "on" in d: on_clause = parse_condition(d["on"]) - sa_table = left.join( # type:ignore + sa_table = left.join( # type: ignore right, onclause=on_clause, - isouter=is_outer, # type:ignore - full=full, # type:ignore + isouter=is_outer, # type: ignore + full=full, # type: ignore ) else: raise APIError("Unknown from-item: " + dtype) diff --git a/api/sessions.py b/api/sessions.py index 672013149..a65d96e49 100644 --- a/api/sessions.py +++ b/api/sessions.py @@ -54,7 +54,7 @@ def __init__(self, connection_id=None, owner: AbstractUser | None = None): ) engine = _get_engine() - self.connection: DBAPIConnection = engine.connect().connection # type:ignore + self.connection: DBAPIConnection = engine.connect().connection # type: ignore if connection_id is None: connection_id = _add_entry(self, _SESSION_CONTEXTS) elif connection_id not in _SESSION_CONTEXTS: diff --git a/base/tests/__init__.py b/base/tests/__init__.py index 7c188d8f7..87048f9e9 100644 --- a/base/tests/__init__.py +++ b/base/tests/__init__.py @@ -36,7 +36,7 @@ def get_urlpattern_params(pattern: URLPattern) -> list[str]: if isinstance(pattern2, RegexPattern): regex = re.compile( # TODO: better way than using protected attribute? - pattern2._regex # type:ignore + pattern2._regex # type: ignore ) return list(regex.groupindex.keys()) elif isinstance(pattern2, RoutePattern): diff --git a/dataedit/management/commands/create_example_tables.py b/dataedit/management/commands/create_example_tables.py index 022b8f1a5..5092aed6b 100644 --- a/dataedit/management/commands/create_example_tables.py +++ b/dataedit/management/commands/create_example_tables.py @@ -115,7 +115,7 @@ def handle(self, *args, **opts): Table.create_with_oedb_table( name=table_name, is_sandbox=True, # tests ALWAYS in sandbox - user=user, # type:ignore + user=user, # type: ignore column_definitions=column_defs, constraints_definitions=constraint_defs, ) diff --git a/dataedit/management/commands/migrate_tags.py b/dataedit/management/commands/migrate_tags.py index a1a99198b..84eb62d64 100644 --- a/dataedit/management/commands/migrate_tags.py +++ b/dataedit/management/commands/migrate_tags.py @@ -30,13 +30,11 @@ def handle(self, *args, **options): color, usage_tracked_since, ) in con.execute( - text( - """ + text(""" select id, name_normalized, usage_count, name, color, usage_tracked_since from public.tags - """ - ) + """) ).fetchall(): tag_names[id] = name_normalized # convert to timezone aware @@ -51,15 +49,11 @@ def handle(self, *args, **options): usage_tracked_since=usage_tracked_since, ) - for table_name, tag_id in con.execute( - text( - """ + for table_name, tag_id in con.execute(text(""" select table_name, tag from public.table_tags - """ - ) - ).fetchall(): + """)).fetchall(): table = TableOEP.objects.filter(name=table_name).first() if not table: print(f"Warning: table does not exist: {table_name}") diff --git a/dataedit/management/commands/migrate_tags2.py b/dataedit/management/commands/migrate_tags2.py index 4e36c1c0b..41d761393 100644 --- a/dataedit/management/commands/migrate_tags2.py +++ b/dataedit/management/commands/migrate_tags2.py @@ -36,14 +36,12 @@ def handle(self, *args, **options): usage_tracked_since, category, ) in con.execute( - text( - """ + text(""" select id, name_normalized, usage_count, name, color, usage_tracked_since, category from public.tags - """ - ) + """) ).fetchall(): tag_names[tag_id] = tag_name_normalized tag = TagOEP.objects.filter(name_normalized=tag_name_normalized).first() @@ -61,18 +59,18 @@ def handle(self, *args, **options): ) else: if category: - tag.category = category # type:ignore + tag.category = category # type: ignore tag.save() # update factsheets for factsheet_class in [BasicFactsheet, Energymodel, Energyframework]: for factsheet in factsheet_class.objects.all(): - tag_int_ids = factsheet.tags_TODO_deprecated # type:ignore + tag_int_ids = factsheet.tags_TODO_deprecated # type: ignore for tag_int_id in tag_int_ids: if tag_int_id not in tag_names: print(f"Missing tag: {tag_int_id}") continue tag_name_normalized = tag_names[tag_int_id] tag = TagOEP.objects.get(name_normalized=tag_name_normalized) - factsheet.tags.add(tag) # type:ignore + factsheet.tags.add(tag) # type: ignore factsheet.save() diff --git a/dataedit/views.py b/dataedit/views.py index cb7544bf6..f0b157e18 100644 --- a/dataedit/views.py +++ b/dataedit/views.py @@ -728,7 +728,7 @@ def iter_oem_key_order(metadata: dict): opr_result_context = {} if reviews.exists(): - latest_review: PeerReview = reviews.last() # type:ignore (reviews.exists()) + latest_review: PeerReview = reviews.last() # type: ignore (reviews.exists()) opr_manager.update_open_since(opr=latest_review) current_reviewer = opr_manager.load(latest_review).current_reviewer opr_context.update( @@ -1432,8 +1432,8 @@ def post(self, request: HttpRequest, table: str, review_id=None) -> HttpResponse # Set new review values and update existing review active_peer_review.review = merged_review_data - active_peer_review.reviewer = user # type:ignore TODO why type warning? - active_peer_review.contributor = contributor # type:ignore TODO + active_peer_review.reviewer = user # type: ignore TODO why type warning? + active_peer_review.contributor = contributor # type: ignore TODO active_peer_review.update(review_type=review_post_type) else: error_msg = ( diff --git a/factsheet/helper.py b/factsheet/helper.py index b265c2c08..13d677370 100644 --- a/factsheet/helper.py +++ b/factsheet/helper.py @@ -192,7 +192,7 @@ def build_sector_dropdowns_from_oeo(g: Graph): # sector individuals: ?sector oeo:is_defined_by ?sd for sector in g.subjects(PROP_DEFINED_BY, sd): - sec_label = _label(g, sector) # type:ignore + sec_label = _label(g, sector) # type: ignore definition = g.value(sector, PROP_DEFINITION) sectors_list.append( diff --git a/login/models.py b/login/models.py index 5659f30c9..d4137b256 100644 --- a/login/models.py +++ b/login/models.py @@ -236,7 +236,7 @@ class myuser(AbstractBaseUser, PermissionHolder): ] # related_name, for static type checking USERNAME_FIELD = "name" - REQUIRED_FIELDS = [name] # type:ignore TODO: why do we need this? + REQUIRED_FIELDS = [name] # type: ignore TODO: why do we need this? objects = OEPUserManager() diff --git a/login/tests/test_utils.py b/login/tests/test_utils.py index af94d9060..26d94752a 100644 --- a/login/tests/test_utils.py +++ b/login/tests/test_utils.py @@ -19,10 +19,10 @@ class TestUtils(TestCase): def test_user_get_tables_queryset(self): - user_a: User = User.objects.create_user( # type:ignore + user_a: User = User.objects.create_user( # type: ignore name="A", email="a@test.test", affiliation="test" ) - user_b: User = User.objects.create_user( # type:ignore + user_b: User = User.objects.create_user( # type: ignore name="B", email="b@test.test", affiliation="test" ) diff --git a/login/views.py b/login/views.py index 99203b38d..90a295026 100644 --- a/login/views.py +++ b/login/views.py @@ -855,5 +855,5 @@ def metadata_review_badge_indicator_icon_file_view(request, user_id, table_name) return render( request, "login/partials/badge_icon.html", - context=context, # type:ignore (we have Literals in type signature) + context=context, # type: ignore (we have Literals in type signature) ) diff --git a/modelview/forms.py b/modelview/forms.py index 2994688a7..0b8fe17c4 100644 --- a/modelview/forms.py +++ b/modelview/forms.py @@ -24,7 +24,7 @@ def __init__(self, *args, **kwargs): self.fields[key].required = False else: f = [not f.null for f in Energymodel._meta.fields if f.name == key][0] - cls_name = self.fields[key].widget.__class__.__name__ # type:ignore + cls_name = self.fields[key].widget.__class__.__name__ # type: ignore self.fields[key].required = f and cls_name != "CheckboxInput" class Meta: @@ -42,7 +42,7 @@ def __init__(self, *args, **kwargs): f = [not f.null for f in Energyframework._meta.fields if f.name == key][ 0 ] - cls_name = self.fields[key].widget.__class__.__name__ # type:ignore + cls_name = self.fields[key].widget.__class__.__name__ # type: ignore self.fields[key].required = f and cls_name != "CheckboxInput" if "help_text" in self.fields[key].__dict__: self.fields[key].help_text = self.fields[key].help_text.replace( diff --git a/modelview/templatetags/modelview_extras.py b/modelview/templatetags/modelview_extras.py index 1d0770b58..853cf6a28 100644 --- a/modelview/templatetags/modelview_extras.py +++ b/modelview/templatetags/modelview_extras.py @@ -52,9 +52,7 @@ def checktable(model, label, prefix, suffixes, separator="_"): {2} - """.format( - label, header, "" - ) + """.format(label, header, "") @register.simple_tag diff --git a/modelview/views.py b/modelview/views.py index 3474873ea..f1a153621 100644 --- a/modelview/views.py +++ b/modelview/views.py @@ -149,7 +149,7 @@ def model_to_csv_view(request, sheettype): tag_ids = tag_ids.split(",") header = list( - field.attname # type:ignore because hasattr(field, "attname") + field.attname # type: ignore because hasattr(field, "attname") for field in c._meta.get_fields() if hasattr(field, "attname") ) diff --git a/oedb/env.py b/oedb/env.py index d84ca1d25..780612596 100644 --- a/oedb/env.py +++ b/oedb/env.py @@ -20,7 +20,7 @@ from oedb.connection import __get_connection_string, _get_engine # noqa: E402 from oedb.structures import Base # noqa: E402 -target_metadata = Base.metadata # type:ignore +target_metadata = Base.metadata # type: ignore alembic_cfg = Config() db_url = __get_connection_string() @@ -33,7 +33,7 @@ # Interpret the config file for Python logging. # This line sets up loggers basically. -fileConfig(config.config_file_name) # type:ignore +fileConfig(config.config_file_name) # type: ignore # add your model's MetaData object here # for 'autogenerate' support diff --git a/oedb/utils.py b/oedb/utils.py index 59b8d8c76..16aceeed9 100644 --- a/oedb/utils.py +++ b/oedb/utils.py @@ -132,14 +132,14 @@ def get_sa_table(self, shared_metadata: bool = False) -> SATable: metadata = MetaData(bind=_get_engine()) key = f"{self._validated_schema_name}.{self._validated_table_name}" - if key not in metadata.tables: # type:ignore + if key not in metadata.tables: # type: ignore SATable( self._validated_table_name, metadata, autoload=True, schema=self._validated_schema_name, ) - return metadata.tables[key] # type:ignore + return metadata.tables[key] # type: ignore def _execute(self, query, requires_permission: int = ADMIN_PERM): if self._permission_level < requires_permission: @@ -163,7 +163,7 @@ def _create( *constraints_definitions, schema=self._validated_schema_name, ) - sa_table.create(self._engine) # type:ignore + sa_table.create(self._engine) # type: ignore return sa_table diff --git a/oedb/versions/3c2369dfcc55_tags_name_normalized.py b/oedb/versions/3c2369dfcc55_tags_name_normalized.py index b9e074dd1..0b80a9372 100644 --- a/oedb/versions/3c2369dfcc55_tags_name_normalized.py +++ b/oedb/versions/3c2369dfcc55_tags_name_normalized.py @@ -30,8 +30,7 @@ def upgrade(): ) # create normalized names - op.execute( - """ + op.execute(""" -- create normalized names UPDATE public.tags SET name_normalized = @@ -92,8 +91,7 @@ def upgrade(): -- drop temporary table ALTER TABLE public.tags DROP COLUMN id_normalized ; - """ - ) + """) # change column to unique not null op.alter_column( diff --git a/oekg/sparqlQuery.py b/oekg/sparqlQuery.py index a83a82fbc..a136a6e14 100644 --- a/oekg/sparqlQuery.py +++ b/oekg/sparqlQuery.py @@ -52,7 +52,7 @@ def bundle_scenarios_filter(bundle_uri: Union[str, URIRef], return_format=JSON) sparql.setReturnFormat(return_format) sparql.setQuery(sparql_query) - return sparql.query().convert() # type:ignore (if json, convert() -> dict) + return sparql.query().convert() # type: ignore (if json, convert() -> dict) def scenario_in_bundle(bundle_uuid: UUID, scenario_uuid: UUID) -> bool: @@ -72,7 +72,7 @@ def scenario_in_bundle(bundle_uuid: UUID, scenario_uuid: UUID) -> bool: sparql.setReturnFormat(JSON) response: dict = ( sparql.query().convert() - ) # type:ignore (if json, convert() -> dict) + ) # type: ignore (if json, convert() -> dict) return response.get( "boolean", False @@ -100,7 +100,7 @@ def dataset_exists(scenario_uuid: UUID, dataset_url: str) -> bool: sparql.setReturnFormat(JSON) response: dict = ( sparql.query().convert() - ) # type:ignore (if json, convert() -> dict) + ) # type: ignore (if json, convert() -> dict) return response.get("boolean", False) # Returns True if dataset exists @@ -147,7 +147,7 @@ def add_datasets_to_scenario(oekgDatasetConfig: DatasetConfig) -> bool: response = sparql_wrapper_update.query() http_response: HTTPResponse = ( response.response - ) # type:ignore (according to documentation) + ) # type: ignore (according to documentation) if not http_response.status == 200: return False # Return False if any query fails except Exception as e: @@ -307,7 +307,7 @@ def scenario_bundle_filter_oekg(criteria: dict, return_format=JSON) -> dict: # Run query sparql.setReturnFormat(return_format) sparql.setQuery(query_structure) - return sparql.query().convert() # type:ignore (if json, convert() -> dict) + return sparql.query().convert() # type: ignore (if json, convert() -> dict) # --- filter helpers (reusable) ------------------------------------- @@ -480,7 +480,7 @@ def list_factsheets_oekg(criteria: dict, return_format=JSON) -> dict: sparql.setReturnFormat(return_format) sparql.setQuery(sparql_query) - return sparql.query().convert() # type:ignore (if json, convert() -> dict) + return sparql.query().convert() # type: ignore (if json, convert() -> dict) def normalize_factsheets_rows(res_json: dict) -> list[dict]: diff --git a/oeo_ext/utils.py b/oeo_ext/utils.py index 6c1601cdc..1ec7f7797 100644 --- a/oeo_ext/utils.py +++ b/oeo_ext/utils.py @@ -45,7 +45,7 @@ def automated_label_generator(new_unit_class: type): prefix_label = None for sub_class in target_class.Classes: if isinstance(sub_class, ThingClass): # The unit part - unit_label = sub_class.label[0] # type:ignore ? + unit_label = sub_class.label[0] # type: ignore ? elif ( isinstance(sub_class, Restriction) and sub_class.property == has_unit_prefix diff --git a/ontology/utils.py b/ontology/utils.py index 0d894f008..4bd3da6ed 100644 --- a/ontology/utils.py +++ b/ontology/utils.py @@ -59,7 +59,7 @@ def collect_modules(path): # Execute the SPARQL query for comment comment_results: Iterable[ResultRow] = g.query( comment_query - ) # type:ignore + ) # type: ignore # Update the comment in the modules dictionary if found for row in comment_results: @@ -78,7 +78,7 @@ def collect_modules(path): # Execute the SPARQL query for description description_results: Iterable[ResultRow] = g.query( description_query - ) # type:ignore + ) # type: ignore # Update the comment in the modules dictionary if found for row in description_results: @@ -93,28 +93,22 @@ def read_oeo_context_information(path, file, ontology=None): g = Graph() g.parse(Ontology_URI.as_posix()) - q_global = g.query( - """ + q_global = g.query(""" SELECT DISTINCT ?s ?o WHERE { ?s rdfs:subClassOf ?o filter(!isBlank(?o)) } - """ - ) + """) - q_label: Iterable[ResultRow] = g.query( - """ + q_label: Iterable[ResultRow] = g.query(""" SELECT DISTINCT ?s ?o WHERE { ?s rdfs:label ?o } - """ - ) # type:ignore + """) # type: ignore - q_main_description: Iterable[ResultRow] = g.query( - """ + q_main_description: Iterable[ResultRow] = g.query(""" SELECT ?s ?o WHERE { ?s dc:description ?o } - """ - ) # type:ignore + """) # type: ignore classes_name = {} for row in q_label: @@ -127,19 +121,15 @@ def read_oeo_context_information(path, file, ontology=None): ontology_description = row.o if ontology in [OPEN_ENERGY_ONTOLOGY_NAME]: - q_definition: Iterable[ResultRow] = g.query( - """ + q_definition: Iterable[ResultRow] = g.query(""" SELECT DISTINCT ?s ?o WHERE { ?s obo:IAO_0000115 ?o } - """ - ) # type:ignore + """) # type: ignore - q_note: Iterable[ResultRow] = g.query( - """ + q_note: Iterable[ResultRow] = g.query(""" SELECT DISTINCT ?s ?o WHERE { ?s obo:IAO_0000116 ?o } - """ - ) # type:ignore + """) # type: ignore classes_definitions = defaultdict(list) for row in q_definition: