PyCharm raises false alarm on datetime module
Here's a sample code that I'm having a problem with.
The code just above function and in the function is the same except for variable names.

I'm not sure why PyCharm is giving a warning for the same lines of code within the function but when not in function.
Here's the code in text format for the reference.
datetime1 = datetime.datetime.now()
datetime_after_20_days1 = datetime1 + timedelta(days=20)
d1 = datetime_after_20_days1 - datetime.datetime.now()
def func(datetime2: datetime):
datetime_after_20_days2 = datetime2 + timedelta(days=20)
d2 = datetime_after_20_days2 - datetime.datetime.now()
return d2
请先登录再写评论。
Hi,
Yes, the issue seems to exist and I've reported it to our tracker just in case: https://youtrack.jetbrains.com/issue/PY-39495
Meanwhile, you can resolve the issue by refactoring the code, see the example below: