google / pytype

A static type analyzer for Python code

Home Page:https://google.github.io/pytype

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

False positive for dictionary entries in version 2023.11.21

fsiola opened this issue · comments

The following sample code did not failed before version 2023.11.21.

from datetime import datetime

def do_log(log: dict) -> None:
    log['time'] = datetime.strptime(log['time'], '%Y-%m-%dT%H:%M:%S.%fZ')
    log['str'] = log['str'].split(':')

Current output:

FAILED: /tmp/.pytype/pyi/test.pyi 
/bin/python -m pytype.single --imports_info /tmp/.pytype/imports/test.imports --module-name test --platform darwin -V 3.8 -o /tmp/.pytype/pyi/test.pyi --analyze-annotated --nofail --quick --use-enum-overlay /tmp/test.py
File "/tmp/test.py", line 5, in split_log: No attribute 'split' on datetime.datetime [attribute-error]
  In Union[Any, datetime.datetime]

Expected output:
No errors

Interestingly, this seems to have been caused by 5692420.