python / python/mypy

New semantic analyzer: Namespace package with __init__.py breaks analysis

Open
#7,029 19 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug false-positive needs discussion semantic-analyzer topic-usability
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

I'm getting a lot of errors reported that are not errors.

  • Classes are reported as invalid types
  • Calls to methods are reported as modules not having those attributes
  • Instances of classes are reported as modules not callable
  • Types passed to, e.g., isinstance are reported as incompatible type Module (suggests that all custom types are treated as type Module)
  • Base classes are reported as invalid base classes
  • Calls to instances of classes are reported as not having the specified attributes
  • Package imports in __init__.py are reported as already defined

I am not sure whether these are issues are caused by the new semantic analyzer or by the Mypy plugin for PyCharm which has not been updated yet.

In comparison, with the new semantic analyzer disabled, there are no errors. The application works correctly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests. Start by reproducing the reported false positives with a namespace package containing init.py, comparing the new semantic analyzer with it disabled and considering the PyCharm plugin distinction. Done means the listed class, method, instance, inheritance, and package-import errors are no longer reported for the reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.