google / pytype

A static type analyzer for Python code
https://google.github.io/pytype
Other
4.77k stars 278 forks source link

Couldn't import pyi for 'xml.dom.minidom' [pyi-error] #1130

Open PhilippWendler opened 2 years ago

PhilippWendler commented 2 years ago

When using the xml.dom.minidom API, pytype 2022.02.17 fails. With 2022.2.8 this still worked.

Minimal example:

import xml.dom.minidom

xml.dom.minidom.parseString("")

Output from pytype:

Computing dependencies
Analyzing 1 sources with 0 local dependencies
ninja: Entering directory `.pytype'
[1/1] check test
FAILED: /tmp/.pytype/pyi/test.pyi 
/home/wendler/.local/pipx/venvs/pytype/bin/python -m pytype.single --imports_info /tmp/.pytype/imports/test.imports --module-name test -V 3.9 -o /tmp/.pytype/pyi/test.pyi --analyze-annotated --nofail --quick /tmp/test.py
File "/tmp/test.py", line 3, in <module>: Couldn't import pyi for 'xml.dom.minidom' [pyi-error]
  No Node.TEXT_NODE in module xml.dom.minidom, referenced from 'xml.dom.expatbuilder'

For more details, see https://google.github.io/pytype/errors.html#pyi-error
ninja: build stopped: subcommand failed.
Leaving directory '.pytype'

xml.dom.minidom.Node.TEXT_NODE exists in the stdlib, it is an int constant and referred to here. However, it is not in minidom.pyi.

I guess this is caused by the recent typeshed update, which brought https://github.com/python/typeshed/commit/6b2218846ccc368059142640b469ee80169050c3.

Tested on Python 3.7 and Python 3.9.

rchen152 commented 2 years ago

Thanks for the report! I'll send a PR to typeshed.

rchen152 commented 2 years ago

Ah, nevermind, it looks like TEXT_NODE is indeed defined in the parent xml.dom.Node class. So this is a pytype bug of some sort in pyi lookup.

bernhardkaindl commented 9 months ago

@rchen152 wrote:

Ah, nevermind, it looks like TEXT_NODE is indeed defined in the parent xml.dom.Node class. So this is a pytype bug of some sort in pyi lookup.

@rchen152 Can you fix it? I see this error aborting pytype-2024.1.24 installed on Python 3.10.12 of Ubuntu 22.04 with the same error:

pytype scripts/examples/python/provision.py
Computing dependencies
Analyzing 1 sources with 2 local dependencies
ninja: Entering directory `.pytype'
[2/2] check provision
FAILED: /home/bkaindl/git/github/review/5427/xen-api/.pytype/pyi/provision.pyi
/usr/bin/python3 -m pytype.single --disable import-error,ignored-abstractmethod,ignored-metaclass --imports_info /home/bkaindl/git/github/review/5427/xen-api/.pytype/imports/provision.imports --module-name provision --platform linux -V 3.10 -o /home/bkaindl/git/github/review/5427/xen-api/.pytype/pyi/provision.pyi --analyze-annotated --nofail --quick /home/bkaindl/git/github/review/5427/xen-api/scripts/examples/python/provision.py
File "/home/bkaindl/git/github/review/5427/xen-api/scripts/examples/python/provision.py", line 65, in parseProvisionSpec: Couldn't import pyi for 'xml.dom.minidom' [pyi-error]
  No Node.TEXT_NODE in module xml.dom.minidom, referenced from 'xml.dom.expatbuilder'
File "/home/bkaindl/git/github/review/5427/xen-api/scripts/examples/python/provision.py", line 77, in printProvisionSpec: Couldn't import pyi for 'xml.dom.minidom' [pyi-error]
  No Node.TEXT_NODE in module xml.dom.minidom, referenced from 'xml.dom.expatbuilder'

For more details, see https://google.github.io/pytype/errors.html#pyi-error
ninja: build stopped: subcommand failed.
Leaving directory '.pytype'

Disabled pyi-error now...