Skip to content
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

0.800: Unable to configure subdirectories #10045

Open
Dreamsorcerer opened this issue Feb 7, 2021 · 10 comments
Open

0.800: Unable to configure subdirectories #10045

Dreamsorcerer opened this issue Feb 7, 2021 · 10 comments
Labels
bug mypy got something wrong topic-configuration Configuration files and flags

Comments

@Dreamsorcerer
Copy link
Contributor

In Mypy 0.800, it now checks files in subdirectories without __init__.py files.

The problem is that the config still only works on modules containing __init__.py, meaning there is no way to change the config for these subdirectories.

e.g.
untyped-def errors have started appearing in test/foo/bar.py

Adding this to config has no effect:

[mypy-tests.*]
disallow_untyped_defs = False

This only works if tests/__init__.py and tests/foo/__init__.py are created.

Expected behaviour is that the above config will ignore the errors, or an alternative syntax is available to do so (e.g. [mypy-tests/*].

@Dreamsorcerer Dreamsorcerer added the bug mypy got something wrong label Feb 7, 2021
@Dreamsorcerer
Copy link
Contributor Author

I marked this as a bug, as it's kind of a regression from 0.790, in that files checked by default cannot be configured.

@Dreamsorcerer Dreamsorcerer changed the title per-directory config 0.800: per-directory config Feb 8, 2021
@Dreamsorcerer Dreamsorcerer changed the title 0.800: per-directory config 0.800: Unable to configure subdirectories Feb 8, 2021
@JelleZijlstra
Copy link
Member

I reported something similar in #9974.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Feb 8, 2021

You can (as previously) use the module name mypy associates with the file, so e.g. [mypy-bar] will let you ignore tests/foo/bar.py. Exactly as if you'd run mypy tests/foo/bar.py with mypy 0.790.
So fwiw I'd classify this as a feature request. Do see #9974 though :-)

@Dreamsorcerer
Copy link
Contributor Author

I think if --namespace-packages is made default as mentioned in that issue, that would resolve the "regression".

This would still be useful to support though as it makes it easier to include tests and examples in the checks (which normally need less strict options configured). Currently this requires adding a bunch of __init__.py files which don't really make sense in this context, they are added purely to make Mypy work.

@Dreamsorcerer
Copy link
Contributor Author

Dreamsorcerer commented Feb 11, 2021

Is this likely to get implemented in an upcoming release? Or is the recommendation to litter the codebase with __init__.py for now? (Just figuring out if it's worth waiting a bit longer before upgrading or not).

@hauntsaninja
Copy link
Collaborator

--namespace-packages is the default in the next release

@Dreamsorcerer
Copy link
Contributor Author

I'm not sure this quite resolves the situation. It seems that I can still only configure directories if there is a __init__.py in the top-level directory.

I'm figuring out how to configure https://github.com/aio-libs/aiohttp-demos/
But, the default behaviour means that I can only configure individual paths with the presence of __init__.py in demos/. Which then gets more complicated as you end with Source file found twice under different module names errors.
So, it seems you still can't do configuration for all paths that mypy reports errors on in 0.800+.

@Dreamsorcerer
Copy link
Contributor Author

It seems to me like module discovery for imports and configuration paths are intertwined. So, I'm struggling to get mypy to check the files for individual demos and recognise the import aiohttpdemo_blog etc. imports and be able to configure strictness for individual demos/paths.

@hauntsaninja hauntsaninja reopened this Nov 7, 2022
@Dreamsorcerer
Copy link
Contributor Author

If anybody has any ideas how to make this work currently, that would be great. My initial attempt is at: https://github.com/aio-libs/aiohttp-demos/pull/210/files

I'd like mypy to type check all the demos, while being able to configure the settings for each demo individually. This just seems to be impossible currently.

@Kludex
Copy link

Kludex commented Jul 6, 2023

Can someone point me out what I need to look code wise to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-configuration Configuration files and flags
Projects
None yet
Development

No branches or pull requests

5 participants