In cleaning up my working code, I’m trying to understand if I should add some sort of type hint.
The simplified code sample below works as intended to sort the array by date in the dict, but PyCharm 2024.1.4 adds this warning:
Unexpected type(s):((x: Any) -> Any)Possible type(s):(None)(Callable[Any, SupportsDunderLT | SupportsDunderGT])
Code sample:
app_list = [
{
"version": "0.2.1",
"date": "2024-02-13",
},
{
"version": "0.1.2",
"date": "2024-01-15",
},
{
"version": "0.1.5",
"date": "2024-01-21",
},
]
app_list.sort(key=lambda x: x["date"])
print(app_list)
when testing in the console or running, output is as expected:
[{'version': '0.1.2', 'date': '2024-01-15'}, {'version': '0.1.5', 'date': '2024-01-21'}, {'version': '0.2.1', 'date': '2024-02-13'}]
but I haven’t yet found out how to avoid the warning, or if it is best to do so.
Is there anything I can do to improve the code and avoid this warning? or is this PyCharm inspection too strict?