Skip to content

Internal error with custom module #8561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nkakouros opened this issue Mar 20, 2020 · 1 comment
Closed

Internal error with custom module #8561

nkakouros opened this issue Mar 20, 2020 · 1 comment

Comments

@nkakouros
Copy link

nkakouros commented Mar 20, 2020

  • Are you reporting a bug, or opening a feature request?
    BUG

In my project, I have lib folder where I have placed some custom modules. The directory looks like this:

src/lib/python/
├── canvas
│   ├── announcements.py
│   ├── api_interface.py
│   ├── canvas_config.py
│   ├── course.py
│   ├── groups.py
│   ├── independent_group_discussions.py
│   ├── __init__.py
│   └── pages.py
├── cds
│   ├── canary
│   │   ├── canary_trap.py
│   │   └── __init__.py
│   ├── executor
│   │   ├── executor.py
│   │   └── __init__.py
│   ├── querier
│   │   ├── backends
│   │   │   ├── elasticsearch
│   │   │   │   ├── es_querier.py
│   │   │   │   └── queries
│   │   │   │       ├── canary
│   │   │   │       │   ├── command.py
│   │   │   │       │   └── packet.py
│   │   │   │       ├── __init__.py
│   │   │   │       ├── misc.py
│   │   │   │       └── player.py
│   │   │   └── stub
│   │   │       ├── queries
│   │   │       │   └── __init__.py
│   │   │       └── stub_querier.py
│   │   ├── __init__.py
│   │   ├── querier.py
│   │   ├── queries.py
│   │   └── query.py
│   └── splicer.py
├── twmn
│   ├── player.py
│   ├── scenario.py
│   ├── scoreboard
│   │   ├── backends
│   │   │   ├── canvas.py
│   │   │   └── mock.py
│   │   ├── __init__.py
│   │   └── scoreboard.py
│   ├── system.py
│   ├── theme.py
│   └── world.py
└── twmn_helpers
    ├── cdag.py
    ├── dotdict.py
    ├── errors.py
    └── logging.py

I have set PYTHONPATH to:

export PYTHONPATH="$PYTHONPATH:$PWD/src/lib/python"

Similarly, I have set MYPYPATH to:

export MYPYPATH="$PWD/src/lib/python/"

Without setting MYPYPATH, I do not get proper warnings for type mismatches for my custom modules.

The file cds/querier/query.py contains:

#!/usr/bin/env python

from abc import ABCMeta, abstractmethod


class Query(ABCMeta):
    @abstractmethod
    def __init__(self, query):
        pass

Then, I copy this file to /tmp/shadow.py and run:

mypy --config-file mypy.cfg /absolute/path/to/src/lib/python/cds/querier/query.py  --shadow-file /absolute/or/relative/path/to/src/lib/python/cds/querier/query.py /tmp/shadow.py

(I am replicating how my editor calls mypy to perform linting.)

This gives an internal error:

src/lib/python/cds/querier/query.py:8: error: Function is missing a type annotation
/absolute/path/to/src/lib/python/cds/querier/query.py:7: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.770
Traceback (most recent call last):
  File "mypy/checker.py", line 401, in accept
  File "mypy/nodes.py", line 766, in accept
  File "mypy/checker.py", line 3516, in visit_decorator
  File "mypy/checker.py", line 792, in check_func_item
  File "mypy/checker.py", line 835, in check_func_def
  File "mypy/checker.py", line 1060, in check_for_missing_annotations
  File "mypy/checker.py", line 4767, in fail
  File "mypy/messages.py", line 180, in fail
  File "mypy/messages.py", line 165, in report
  File "mypy/errors.py", line 319, in report
  File "mypy/errors.py", line 350, in add_error_info
  File "mypy/errors.py", line 322, in _add_error_info
AssertionError: 
/absolute/path/to/src/lib/python/cds/querier/query.py:7: : note: use --pdb to drop into pdb

If I replace in the mypy command the absolute path to the file with the relative path, then mypy works ok:

mypy --config-file mypy.cfg src/lib/python/cds/querier/query.py  --shadow-file /absolute/or/relative/path/to/src/lib/python/cds/querier/query.py /tmp/shadow.py

I have tried with the latest development version and I get the same behavior.

@msullivan
Copy link
Collaborator

The issue is probably that your MYPYPATH overlaps with the files you are passing to the command line, which triggers a crash. The issue is #4881, so I'm closing this as a dupe of that.

There was a PR to fix that (#7567) that stalled out for no particularly good reason. I'll try to get that merged since it is pretty bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants