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
pre-commit mypy additional dependencies when pre-commit-config.yaml is inside child directory #174
Comments
seems to work fine for me? $ cat t.py
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
user = User(id=42, name='foo')
reveal_type(user.id)
$ cat .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.782
hooks:
- id: mypy
$ pre-commit run --all-files
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
t.py:6: error: Variable "t.Base" is not valid as a type
t.py:6: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
t.py:6: error: Invalid base class "Base"
t.py:12: note: Revealed type is 'Any'
Found 2 errors in 1 file (checked 1 source file)
$ echo $'[mypy]\nplugins = sqlmypy' > setup.cfg
$ echo ' additional_dependencies: [sqlalchemy-stubs]' >> .pre-commit-config.yaml
$ pre-commit run --all-files
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
t.py:12: note: Revealed type is 'builtins.int*'
note that |
When running
However, when I run
Posting this first to give some context - but I'll continue trying to debug as well. |
this is ~roughly what pre-commit would do: virtualenv venv
venv/bin/pip install mypy sqlalchemy-stubs
venv/bin/mypy ... $(git ls-files -- '*.py') also a general tip for open source, don't post images of output or code, they are inaccessible (can't be searched, can't be viewed in the viewers preferred contrast/accessibility settings, etc.) -- post text of text |
Thanks for the tip to post text only. I reproduced the problem and found that my error only happens specifically when my entire python project (including |
you could try sharing a reproducible example, so fare we're just guessing at your problem |
https://repl.it/@AjitZK/directory-broken-mypy ^ Here's an accessible example |
can you put a repo on github, I'm not sure what to do with repl it |
https://github.com/AjitZK/directory-broken-mypy ^ as a repo |
and translating what I told you above, here's a reproduction without pre-commit: $ rm -rf venv && virtualenv venv >& /dev/null && venv/bin/pip install mypy sqlalchemy-stubs >& /dev/null && venv/bin/mypy --ignore-missing-imports --scripts-are-modules $(git ls-files -- '*.py')
backend/alembic/env.py:3: error: "Type[Base]" has no attribute "metadata"
Found 1 error in 1 file (checked 9 source files) an aside, pre-commit's configuration is conventionally at the root of the repository and git hooks execute from the root of the repository |
telling mypy where your configuration is seems to work though: $ venv/bin/mypy --config backend/setup.cfg --ignore-missing-imports --scripts-are-modules $(git ls-files -- '*.py')
Success: no issues found in 9 source files |
Ok, then I'm changing my
This fixes my issue. Will need to refactor to properly set up |
Currently my
.pre-commit-config.yaml
looks like the above. However, addingsqlalchemy-stubs
to theadditional_dependencies
doesn't do anything to change the behaviour. Addingsqlmypy
tosetup.cfg
works just fine however.If someone on the team or @asottile can help, that'd be much appreciated.
The text was updated successfully, but these errors were encountered: