Describe the bug
PlainSerializer when_used literal giving PyCharm inspection false positive of: "unresolved reference 'json'".
This doesn't reproduce in a scratch file for some reason. This is a weird bug and may be upstream.
Is there anything I can do to help determine if this is a plugin issue or upstream issue?
To Reproduce
from datetime import datetime
from typing import Annotated, TypeAlias
from pydantic import PlainSerializer
def datetime_to_epoch_ms(timestamp: datetime) -> int:
if timestamp.tzinfo is None:
timestamp = timestamp.astimezone()
return int(timestamp.timestamp() * 1000)
Timestamp: TypeAlias = Annotated[
datetime,
PlainSerializer(
# when_used="json" is giving PyCharm inspection false positive of: "unresolved reference 'json'"
lambda timestamp: 0 if timestamp is None else datetime_to_epoch_ms(timestamp),
return_type=int,
when_used="json",
),
]
Expected behavior
when_used value should be recognized as acceptable literal as in the scratch file.
Environments (please complete the following information):
Additional context
I already tried Invalidate Caches feature (all boxes checked) and it didn't help.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too