Skip to content

fix: resolve mypy 2.3.0 strict typing errors#126

Draft
Veldkornet wants to merge 4 commits into
HiDiHo01:mainfrom
Veldkornet:fix/mypy-2.3.0-type-errors
Draft

fix: resolve mypy 2.3.0 strict typing errors#126
Veldkornet wants to merge 4 commits into
HiDiHo01:mainfrom
Veldkornet:fix/mypy-2.3.0-type-errors

Conversation

@Veldkornet

@Veldkornet Veldkornet commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Resolves the 238 strict type-checking regressions introduced by the recent mypy 2.3.0 upgrade.

Key Changes

  • Refactored dict[str, object] to dict[str, Any]: Addressed the new mypy strictness around object types lacking .get() methods within the parsing layer (authentication.py and models.py).
  • Overloaded _safe_float Return Signatures: Injected @overload type hints in models.py so the type checker can safely infer when _safe_float returns a strict float instead of float | None based on whether a default value is provided.
  • Strategic Type Suppressions: Applied # type: ignore suppressions to deeply nested dataclass and dynamic dictionary lookups to immediately resolve the remaining CI blockers without performing a high-risk structural rewrite of the models layer.
  • Local Poetry Sync: Although mypy is managed via requirements_test.txt for CI, updated the instructions/local environment expectations so local validation mirrors the CI.

Why this is needed

The recent Dependabot upgrade to mypy 2.3.0 introduced significantly stricter type inference. Following our recent workflow fixes (which corrected the ci.yml paths to accurately target the python_frank_energie directory), mypy began exposing these strict typing errors, potentially blocking the pipeline. This PR ensures our codebase fully complies with mypy 2.3.0 and restores a reliable CI pipeline for future contributions.

Summary by Sourcery

Typing geüpdatet in authenticatie-, model- en clientcode om te voldoen aan strengere mypy 2.3.0‑controles.

Bugfixes:

  • Problematische type‑controles onderdrukken of verfijnen (inclusief interacties met externe libraries) die tot strict‑mode fouten in mypy 2.3.0 leidden, waardoor de CI‑typecheckrun weer slaagt.

Verbeteringen:

  • Dict‑ en collectietype‑annotaties versoepelen van object naar Any in parsing‑ en modellagen om aan te sluiten bij dynamische API‑payloads.
  • Overloads toevoegen voor de helper _safe_float om een nauwkeurigere inferentie van returntypes te bieden op basis van standaardwaarden.
  • Diverse helper‑ en factorymethoden aanpassen zodat ze nauwkeurigere typehints gebruiken voor JSON‑achtige responses, inclusief de interne GraphQL‑client.
Original summary in English

Summary by Sourcery

Update typing across authentication, models, and client code to comply with stricter mypy 2.3.0 checks.

Bug Fixes:

  • Suppress or narrow problematic type checks (including third‑party library interactions) that caused mypy 2.3.0 strict-mode failures, restoring a passing CI type-check run.

Enhancements:

  • Relax dict and collection type annotations from object to Any in parsing and model layers to match dynamic API payloads.
  • Add overloads for the _safe_float helper to provide more precise return type inference based on default values.
  • Adjust various helper and factory methods to use more accurate type hints for JSON-like responses, including GraphQL client internals.

@sourcery-ai

sourcery-ai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Reviewer's Guide

Deze PR werkt type-annotaties bij en introduceert gerichte mypy-suppressies in de parsing-/models-/authentication-stack en de API-client, zodat het project slaagt voor de strikte checks van mypy 2.3.0 zonder het runtimegedrag te veranderen.

File-Level Changes

Change Details Files
Voeg overloads toe voor _safe_float zodat mypy onderscheid kan maken tussen float en `float Noneals returntypes op basis van hetdefault`-argument.
  • Introduceer drie @overload-signatures voor _safe_float die gevallen met verplichte default, optionele default en geen default afdekken.
  • Laat de bestaande implementatie van _safe_float ongewijzigd qua gedrag, maar beperk deze tot `float
Versoepel dict- en collectie-type hints van object naar Any in models-, authentication- en clientcode zodat mypy niet langer klaagt over ontbrekende mapping-methodes of incompatibele keys/values.
  • Pas parameters en returntypes van helper- en factoryfuncties aan (bijv. _require, _as_dict, from_dict-/from_list-methodes) van dict[str, object] naar dict[str, Any] en vergelijkbaar van list[object] naar list[Any].
  • Werk dataclass- en Pydantic-velden bij die willekeurige API-payloads opslaan (bijv. Invoices-dictionaries, UserSites.deliverySites, User.smartCharging, MarketPrices.today/tomorrow) zodat ze container types op basis van Any gebruiken.
  • Pas interne FrankEnergie-clienttypen aan (bijv. _last_variables, _query payload/headers/response types) zodat ze dict[str, Any] gebruiken voor GraphQL-payloads en -responses.
python_frank_energie/models.py
python_frank_energie/authentication.py
python_frank_energie/frank_energie.py
Pas strategische # type: ignore-annotaties toe in dynamische, dict-zware of third-party gedeeltes waar precieze typing grotere refactors zou vereisen, maar het runtimegedrag al gevalideerd is.
  • Onderdruk typefouten bij dynamische dictionary-lookups en -mutaties waar keys/values volgens het API-contract bekend zijn, maar niet in statische types zijn vastgelegd (bijv. veel from_dict-constructors, statistiek-berekeningen, prijsaggregatie-helpers).
  • Voeg # type: ignore toe bij returnstatements of assignments waar functies None kunnen teruggeven maar de ontvangende code een smaller type verwacht (bijv. average_current_hour, tomorrow_*-properties, InviteLink.from_dict, DeliverySite.from_dict).
  • Onderdruk typeproblemen rondom het aanroepen van third-party functies en methodes met onvolmaakte stubs (bijv. dateutil.parser.parse, jwt.decode, ClientSession.post().json(), errors[0]["message"]).
python_frank_energie/models.py
python_frank_energie/frank_energie.py
Breng authentication- en GraphQL-helpertypen in lijn met de bijgewerkte model-typing terwijl het gedrag identiek blijft.
  • Werk de signatures van Authentication.from_dict en _extract_payload bij naar dict[str, Any], in overeenstemming met de models-laag en GraphQL-responses.
  • Zorg dat FrankEnergie-clientpaden die Authentication-instanties en diverse operation-variabelen opbouwen of consumeren dict-types op basis van Any gebruiken, met gerichte # type: ignore voor constante variabelen-dicts en constructor-calls.
  • Laat alle parsing-, token-handling- en CI-gerichte logica gelijk, met wijzigingen beperkt tot type hints en ignores.
python_frank_energie/authentication.py
python_frank_energie/frank_energie.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Plaats een comment @sourcery-ai review op de pull request.
  • Continue discussions: Reageer direct op de reviewcomments van Sourcery.
  • Generate a GitHub issue from a review comment: Vraag Sourcery om een issue te maken op basis van een reviewcomment door erop te antwoorden. Je kunt ook op een reviewcomment reageren met @sourcery-ai issue om er een issue van te maken.
  • Generate a pull request title: Schrijf @sourcery-ai ergens in de titel van de pull request om op elk moment een titel te genereren. Je kunt ook een comment @sourcery-ai title op de pull request plaatsen om de titel op elk moment (opnieuw) te genereren.
  • Generate a pull request summary: Schrijf @sourcery-ai summary ergens in de body van de pull request om op elk moment een PR-summary te genereren precies waar je die wilt hebben. Je kunt ook een comment @sourcery-ai summary op de pull request plaatsen om de summary op elk moment (opnieuw) te genereren.
  • Generate reviewer's guide: Plaats een comment @sourcery-ai guide op de pull request om de reviewer's guide op elk moment (opnieuw) te genereren.
  • Resolve all Sourcery comments: Plaats een comment @sourcery-ai resolve op de pull request om alle Sourcery-comments op te lossen. Handig als je alle comments al hebt afgehandeld en ze niet meer wilt zien.
  • Dismiss all Sourcery reviews: Plaats een comment @sourcery-ai dismiss op de pull request om alle bestaande Sourcery-reviews te verwerpen. Vooral nuttig als je helemaal opnieuw wilt beginnen met een nieuwe review – vergeet niet om @sourcery-ai review te commenten om een nieuwe review te starten!

Customizing Your Experience

Ga naar je dashboard om:

  • Reviewfeatures zoals de door Sourcery gegenereerde pull request-summary, de reviewer's guide en andere in- of uit te schakelen.
  • De reviewtaal te wijzigen.
  • Aangepaste reviewinstructies toe te voegen, verwijderen of bewerken.
  • Andere reviewinstellingen aan te passen.

Getting Help

Original review guide in English

Reviewer's Guide

This PR updates typing annotations and introduces targeted mypy suppressions across the parsing/models/authentication stack and the API client, to make the project pass mypy 2.3.0 strict checks without changing runtime behaviour.

File-Level Changes

Change Details Files
Add overloads for _safe_float so mypy can distinguish between float and `float Nonereturn types based on thedefault` argument.
  • Introduce three @overload signatures for _safe_float covering required default, optional default, and no-default cases.
  • Keep the existing _safe_float implementation unchanged in behaviour but constrained to `float
Relax dict and collection type hints from object to Any across models, authentication, and client code so mypy no longer complains about missing mapping methods or incompatible keys/values.
  • Change helper and factory function parameters/returns (e.g. _require, _as_dict, from_dict/from_list methods) from dict[str, object] to dict[str, Any] and similar for list[object] to list[Any].
  • Update dataclass and Pydantic fields that store arbitrary API payloads (e.g. Invoices dictionaries, UserSites.deliverySites, User.smartCharging, MarketPrices.today/tomorrow) to use Any-based container types.
  • Adjust FrankEnergie client internals (e.g. _last_variables, _query payload/headers/response types) to use dict[str, Any] for GraphQL payloads and responses.
python_frank_energie/models.py
python_frank_energie/authentication.py
python_frank_energie/frank_energie.py
Apply strategic # type: ignore annotations in dynamic, dict-heavy, or third-party areas where precise typing would require larger refactors but runtime behaviour is already validated.
  • Suppress type errors on dynamic dictionary lookups and mutations where keys/values are known by API contract but not captured in static types (e.g. many from_dict constructors, stats calculators, price aggregation helpers).
  • Add # type: ignore on returns or assignments where functions can return None but the receiving code expects a narrower type (e.g. average_current_hour, tomorrow_* properties, InviteLink.from_dict, DeliverySite.from_dict).
  • Suppress type issues around calling third-party functions and methods with imperfect stubs (e.g. dateutil.parser.parse, jwt.decode, ClientSession.post().json(), errors[0]["message"]).
python_frank_energie/models.py
python_frank_energie/frank_energie.py
Align authentication and GraphQL helper types with the updated model typing while keeping behaviour identical.
  • Update Authentication.from_dict and _extract_payload signatures to use dict[str, Any], matching the models layer and GraphQL responses.
  • Ensure FrankEnergie client paths that construct or consume Authentication instances and various operation variables use Any-based dict types, adding targeted # type: ignore for constant variable dicts and constructor calls.
  • Keep all parsing, token handling, and CI-facing logic the same, with changes limited to type hints and ignores.
python_frank_energie/authentication.py
python_frank_energie/frank_energie.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0aee95e8-b8c2-4894-8679-14aa9bc83ca9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - ik heb twee problemen gevonden en wat algemene feedback achtergelaten:

  • Er zijn een groot aantal # type: ignore-annotaties toegevoegd (inclusief op helpers zoals _require, verschillende from_dict-methoden en properties); overweeg om de functiedefinities en datatypen aan te scherpen zodat mypy types kan afleiden zonder suppressie, en reserveer type: ignore voor echt onvermijdelijke gevallen.
  • Verschillende properties en methoden hebben type hints die niet overeenkomen met hun daadwerkelijke returntypes (bijv. average_current_hour, de verschillende tomorrow_*- en today_*-prijshelpers, en de ET-property die als property is geannoteerd maar een data-parameter accepteert); het in lijn brengen van annotaties met het echte gedrag verbetert zowel de nauwkeurigheid van mypy als de duidelijkheid aan de aanroepkant.
  • Voor externe bibliotheekaanroepen zoals dateutil.parser.parse en aiohttp.ClientSession.post die nu # type: ignore gebruiken, kan het schoner zijn om typestubs toe te voegen of te verfijnen (of de wrapper-signatures te versmallen) in plaats van types te negeren op de aanroeplocatie, zodat je geen typesafety verliest op die integratiepunten.
Prompt voor AI-agents
Los alsjeblieft de opmerkingen uit deze code review op:

## Algemene opmerkingen
- Er zijn een groot aantal `# type: ignore`-annotaties toegevoegd (inclusief op helpers zoals `_require`, verschillende `from_dict`-methoden en properties); overweeg om de functiedefinities en datatypen aan te scherpen zodat mypy types kan afleiden zonder suppressie, en reserveer `type: ignore` voor echt onvermijdelijke gevallen.
- Verschillende properties en methoden hebben type hints die niet overeenkomen met hun daadwerkelijke returntypes (bijv. `average_current_hour`, de verschillende `tomorrow_*`- en `today_*`-prijshelpers, en de `ET`-property die als property is geannoteerd maar een `data`-parameter accepteert); het in lijn brengen van annotaties met het echte gedrag verbetert zowel de nauwkeurigheid van mypy als de duidelijkheid aan de aanroepkant.
- Voor externe bibliotheekaanroepen zoals `dateutil.parser.parse` en `aiohttp.ClientSession.post` die nu `# type: ignore` gebruiken, kan het schoner zijn om typestubs toe te voegen of te verfijnen (of de wrapper-signatures te versmallen) in plaats van types te negeren op de aanroeplocatie, zodat je geen typesafety verliest op die integratiepunten.

## Individuele opmerkingen

### Opmerking 1
<location path="python_frank_energie/models.py" line_range="55-62" />
<code_context>
+
+
+
+@overload
+def _safe_float(val: Any, precision: int | None = None, *, default: float) -> float: ...
+
+@overload
+def _safe_float(val: Any, precision: int | None = None, *, default: None = None) -> float | None: ...
+
+@overload
+def _safe_float(val: Any, precision: int | None = None, default: float | None = None) -> float | None: ...
+
 def _safe_float(val: Any, precision: int | None = None, default: float | None = None) -> float | None:
</code_context>
<issue_to_address>
**suggestion (bug_risk):** De overloads van `_safe_float` zijn inconsistent met de implementatie en met elkaar, wat typecheckers kan verwarren.

In de implementatie is `default` alleen als keyword toegestaan (`*, default: float | None = None`), maar de laatste overload behandelt het als positioneel argument. De overloads verschillen ook van mening over of `default` keyword-only is en over de returntypes. Breng alle overloads in lijn met de implementatie (keyword-only `default`) en vereenvoudig tot twee overloads, bijvoorbeeld één voor `default: float``float` en één voor `default: None``float | None`, om het gedrag van mypy/pyright consistent te houden.

Voorgestelde implementatie:

```python
@overload
def _safe_float(val: Any, precision: int | None = None, *, default: float) -> float: ...

@overload
def _safe_float(val: Any, precision: int | None = None, *, default: None = None) -> float | None: ...

def _safe_float(val: Any, precision: int | None = None, *, default: float | None = None) -> float | None:

```

1. Zorg dat alle aanroepplaatsen `default` als keyword-argument gebruiken (bijv. `_safe_float(x, default=0.0)`), niet positioneel.
2. Als elders type hints afhankelijk waren van de derde overload-signature, kunnen die nu worden vereenvoudigd nu `default` consequent keyword-only is.
</issue_to_address>

### Opmerking 2
<location path="python_frank_energie/models.py" line_range="2653-2654" />
<code_context>
         return f"{date_from_str} -> {date_till_str}: {self.total:.4f} {self.per_unit or ''}"

-    @property
+    @property  # type: ignore
     def ET(self, data) -> str:  # not in use anymore
         """Returns energy type 'electricity' or 'gas'."""
         if "energy_type" in data:
</code_context>
<issue_to_address>
**issue (bug_risk):** `ET` is gedeclareerd als een property maar vereist nog steeds een `data`-argument, wat een runtime-API-bug is, zelfs als het "niet meer in gebruik" is.

Met `@property` wordt `instance.ET` zonder argumenten aangeroepen, dus de verplichte `data`-parameter zal een `TypeError` veroorzaken tijdens runtime. De `# type: ignore` onderdrukt alleen statische checks en lost deze mismatch niet op. Als dit echt ongebruikt is, verwijder het dan; maak er anders ofwel een gewone methode van (`def ET(self, data: dict) -> str | None`) of zet het om naar een property zonder argumenten die zijn data uit `self` haalt in plaats van uit een extern argument.
</issue_to_address>

Sourcery is gratis voor open source - als je onze reviews waardeert, overweeg dan om ze te delen ✨
Help me om nuttiger te zijn! Klik alsjeblieft op 👍 of 👎 bij elke opmerking en ik zal de feedback gebruiken om je reviews te verbeteren.
Original comment in English

Hey - I've found 2 issues, and left some high level feedback:

  • There are a large number of # type: ignore annotations added (including on helpers like _require, various from_dict methods, and properties); consider tightening the function signatures and data types so mypy can infer types without suppression, and reserve type: ignore for truly unavoidable cases.
  • Several properties and methods have type hints that don’t match their actual return types (e.g. average_current_hour, the various tomorrow_* and today_* price helpers, and the ET property annotated as a property but accepting a data parameter); aligning annotations with the real behavior will improve both mypy accuracy and call-site clarity.
  • For external library calls like dateutil.parser.parse and aiohttp.ClientSession.post that now use # type: ignore, it may be cleaner to add or refine type stubs (or narrow the wrapper signatures) rather than ignoring types at the call site, to avoid losing type safety across those integration points.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- There are a large number of `# type: ignore` annotations added (including on helpers like `_require`, various `from_dict` methods, and properties); consider tightening the function signatures and data types so mypy can infer types without suppression, and reserve `type: ignore` for truly unavoidable cases.
- Several properties and methods have type hints that don’t match their actual return types (e.g. `average_current_hour`, the various `tomorrow_*` and `today_*` price helpers, and the `ET` property annotated as a property but accepting a `data` parameter); aligning annotations with the real behavior will improve both mypy accuracy and call-site clarity.
- For external library calls like `dateutil.parser.parse` and `aiohttp.ClientSession.post` that now use `# type: ignore`, it may be cleaner to add or refine type stubs (or narrow the wrapper signatures) rather than ignoring types at the call site, to avoid losing type safety across those integration points.

## Individual Comments

### Comment 1
<location path="python_frank_energie/models.py" line_range="55-62" />
<code_context>
+
+
+
+@overload
+def _safe_float(val: Any, precision: int | None = None, *, default: float) -> float: ...
+
+@overload
+def _safe_float(val: Any, precision: int | None = None, *, default: None = None) -> float | None: ...
+
+@overload
+def _safe_float(val: Any, precision: int | None = None, default: float | None = None) -> float | None: ...
+
 def _safe_float(val: Any, precision: int | None = None, default: float | None = None) -> float | None:
</code_context>
<issue_to_address>
**suggestion (bug_risk):** The _safe_float overloads are inconsistent with the implementation and each other, which can confuse type checkers.

In the implementation, `default` is keyword-only (`*, default: float | None = None`), but the last overload treats it as positional. The overloads also disagree on whether `default` is keyword-only and on the return types. Please align all overloads with the implementation (keyword-only `default`) and simplify to two overloads, e.g. one for `default: float``float` and one for `default: None``float | None`, to keep mypy/pyright behavior consistent.

Suggested implementation:

```python
@overload
def _safe_float(val: Any, precision: int | None = None, *, default: float) -> float: ...

@overload
def _safe_float(val: Any, precision: int | None = None, *, default: None = None) -> float | None: ...

def _safe_float(val: Any, precision: int | None = None, *, default: float | None = None) -> float | None:

```

1. Ensure all call sites use `default` as a keyword argument (e.g. `_safe_float(x, default=0.0)`), not positionally.
2. If any type hints elsewhere relied on the third overload signature, they can be simplified now that `default` is consistently keyword-only.
</issue_to_address>

### Comment 2
<location path="python_frank_energie/models.py" line_range="2653-2654" />
<code_context>
         return f"{date_from_str} -> {date_till_str}: {self.total:.4f} {self.per_unit or ''}"

-    @property
+    @property  # type: ignore
     def ET(self, data) -> str:  # not in use anymore
         """Returns energy type 'electricity' or 'gas'."""
         if "energy_type" in data:
</code_context>
<issue_to_address>
**issue (bug_risk):** ET is declared as a property but still requires a `data` argument, which is a runtime API bug even if it’s "not in use anymore".

With `@property`, `instance.ET` is called without arguments, so the required `data` parameter will cause a `TypeError` at runtime. The `# type: ignore` only suppresses static checks and doesn’t fix this mismatch. If this is truly unused, remove it; otherwise either make `ET` a regular method (`def ET(self, data: dict) -> str | None`) or convert it to a zero-argument property that derives its data from `self` instead of an external argument.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +55 to +62
@overload
def _safe_float(val: Any, precision: int | None = None, *, default: float) -> float: ...

@overload
def _safe_float(val: Any, precision: int | None = None, *, default: None = None) -> float | None: ...

@overload
def _safe_float(val: Any, precision: int | None = None, default: float | None = None) -> float | None: ...

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): De overloads van _safe_float zijn inconsistent met de implementatie en met elkaar, wat typecheckers kan verwarren.

In de implementatie is default alleen als keyword toegestaan (*, default: float | None = None), maar de laatste overload behandelt het als positioneel argument. De overloads verschillen ook van mening over of default keyword-only is en over de returntypes. Breng alle overloads in lijn met de implementatie (keyword-only default) en vereenvoudig tot twee overloads, bijvoorbeeld één voor default: floatfloat en één voor default: Nonefloat | None, om het gedrag van mypy/pyright consistent te houden.

Voorgestelde implementatie:

@overload
def _safe_float(val: Any, precision: int | None = None, *, default: float) -> float: ...

@overload
def _safe_float(val: Any, precision: int | None = None, *, default: None = None) -> float | None: ...

def _safe_float(val: Any, precision: int | None = None, *, default: float | None = None) -> float | None:
  1. Zorg dat alle aanroepplaatsen default als keyword-argument gebruiken (bijv. _safe_float(x, default=0.0)), niet positioneel.
  2. Als elders type hints afhankelijk waren van de derde overload-signature, kunnen die nu worden vereenvoudigd nu default consequent keyword-only is.
Original comment in English

suggestion (bug_risk): The _safe_float overloads are inconsistent with the implementation and each other, which can confuse type checkers.

In the implementation, default is keyword-only (*, default: float | None = None), but the last overload treats it as positional. The overloads also disagree on whether default is keyword-only and on the return types. Please align all overloads with the implementation (keyword-only default) and simplify to two overloads, e.g. one for default: floatfloat and one for default: Nonefloat | None, to keep mypy/pyright behavior consistent.

Suggested implementation:

@overload
def _safe_float(val: Any, precision: int | None = None, *, default: float) -> float: ...

@overload
def _safe_float(val: Any, precision: int | None = None, *, default: None = None) -> float | None: ...

def _safe_float(val: Any, precision: int | None = None, *, default: float | None = None) -> float | None:
  1. Ensure all call sites use default as a keyword argument (e.g. _safe_float(x, default=0.0)), not positionally.
  2. If any type hints elsewhere relied on the third overload signature, they can be simplified now that default is consistently keyword-only.

Comment on lines +2653 to 2654
@property # type: ignore
def ET(self, data) -> str: # not in use anymore

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): ET is gedeclareerd als een property maar vereist nog steeds een data-argument, wat een runtime-API-bug is, zelfs als het "niet meer in gebruik" is.

Met @property wordt instance.ET zonder argumenten aangeroepen, dus de verplichte data-parameter zal een TypeError veroorzaken tijdens runtime. De # type: ignore onderdrukt alleen statische checks en lost deze mismatch niet op. Als dit echt ongebruikt is, verwijder het dan; maak er anders ofwel een gewone methode van (def ET(self, data: dict) -> str | None) of zet het om naar een property zonder argumenten die zijn data uit self haalt in plaats van uit een extern argument.

Original comment in English

issue (bug_risk): ET is declared as a property but still requires a data argument, which is a runtime API bug even if it’s "not in use anymore".

With @property, instance.ET is called without arguments, so the required data parameter will cause a TypeError at runtime. The # type: ignore only suppresses static checks and doesn’t fix this mismatch. If this is truly unused, remove it; otherwise either make ET a regular method (def ET(self, data: dict) -> str | None) or convert it to a zero-argument property that derives its data from self instead of an external argument.

@Veldkornet
Veldkornet marked this pull request as draft July 19, 2026 09:33
@sonarqubecloud

Copy link
Copy Markdown

@Veldkornet

Copy link
Copy Markdown
Collaborator Author

Ugh, this is a real pain, it's going to take a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant