AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 15 Bitcoin

type hints: (trivial) add missing "Optional" qualifiers

Public commit record

What the developer wrote

Authored by SomberNight

93/100 · Strong
type hints: (trivial) add missing "Optional" qualifiers

In many cases with our type hinting, we do not explicitly specify that variables are allowed to be None when they have a default value of None.
This PR now adds the missing explicit "Optional" markers.

-----

Consider:
```
class Foo(NamedTuple):
field: str = None
```
This type-hinting is technically incorrect, we should type hint it as either one of these options:
- `field: Optional[str] = None`
- `field: str | None = None`

PyCharm has had soft-warnings about these lines for quite a while,
however when doing type-inference, it used to internally "fix" the type by allowing None.
Recently however it seems it is not doing the internal inference-fixing anymore, but assume that `path` has type `str` (as we specified) and then make "incorrect" inferences:

```
class Foo(NamedTuple):
field: str = None

def func(foo: Foo):
assert foo.field is None
print("function body") # <<< PyCharm now says this code is unreachable
```
I have whole function bodies grayed out and marked as dead code due to this.

Example: https://github.com/spesmilo/electrum/blob/c82a0d12ef1e03a96d6180839f215c05efe9efe3/electrum/lnpeer.py#L2320, where htlc_set.parent_set_key is type-hinted as str, so the assert "must" always fail
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit only fixes type hints in the source code. It changes annotations such as `name: str = None` to `name: str | None = None` so that developer tools correctly understand that these variables may be empty. No actual program behavior, logic, or security checks are changed.

Recommended action

No security action required. Treat as a normal code-quality/type-hint maintenance commit.

Security signals we found

No strong security signals were identified.

Risk score

Why this scored 15/100

Our methodology →
Potential impact 0/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 0/15
Confidence 10/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.