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

6.0.0rc1 pytest.skip mypy error: Attribute function "__call__" ... does not accept self argument #7495

Closed
1 of 4 tasks
simonjayhawkins opened this issue Jul 14, 2020 · 8 comments · Fixed by #7531
Closed
1 of 4 tasks
Labels
topic: typing type-annotation issue
Milestone

Comments

@simonjayhawkins
Copy link

simonjayhawkins commented Jul 14, 2020

  • a detailed description of the bug or suggestion
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible
import pytest


def valid_config():
    return False


def test_function():
    if not valid_config():
        pytest.skip("unsupported configuration")
$ pytest ~/pytest-mypy.py 
=========================================================================== test session starts ============================================================================
platform win32 -- Python 3.8.3, pytest-6.0.0rc1, py-1.9.0, pluggy-0.13.1
rootdir: C:\Users\simon
plugins: hypothesis-5.16.3, asyncio-0.12.0, cov-2.10.0, forked-1.1.2, xdist-1.32.0
collected 1 item

..\pytest-mypy.py s                                                                                                                                                   [100%] 

============================================================================ 1 skipped in 0.12s ============================================================================ 
$ mypy ~/pytest-mypy.py
C:\Users\simon\pytest-mypy.py:10: error: Attribute function "__call__" with type "Callable[[str, DefaultNamedArg(bool, 'allow_module_level')], NoReturn]" does not accept self argument
C:\Users\simon\pytest-mypy.py:10: error: Too many positional arguments for "skip"
C:\Users\simon\pytest-mypy.py:10: error: Argument 1 to "skip" has incompatible type "str"; expected "bool"
Found 3 errors in 1 file (checked 1 source file)

skip is decorated with @_with_exception(Skipped), will look soon but assuming decorator is not preserving signature

@bluetech
Copy link
Member

There is some trickery there but I can't reproduce it here, pytest.skip is type-checked correctly.

If you can provide steps for creating a standalone venv which reproduce this (package versions + configs) that'd be great.

@bluetech
Copy link
Member

In particular, I suspect it's maybe an older mypy version -- which versions are you using, and if using an older version, can you reproduce with latest mypy?

@simonjayhawkins
Copy link
Author

Thanks @bluetech for looking into this. we are pinned to mypy 0.730 at the moment. I'll get back to you on using different versions

@nicoddemus nicoddemus added the topic: typing type-annotation issue label Jul 14, 2020
@simonjayhawkins
Copy link
Author

@bluetech I can confirm that I don't get this error from mypy 0.750 onwards but not sure which mypy commit fixed this. maybe as a result of 'more powerful self types'. What confuses me is that this issue looks a bit like python/mypy#6910 which is still open.

Looking at the pytest code the annotation for __call__ in _WithException is annotated as _F which doesn't account for the self argument, so I think the error message being raised by mypy does make sense.

However, from a pandas standpoint, I'm happy to add #type: ignore to the few pystest.skip uses we have for now since we should be thinking about bumping our version of mypy anyhow.

cc @WillAyd

One thing i've not checked is the Python version. I am using Python 3.8.3 and so Protocol is being used for _WithException whereas for earlier versions, Protocol is an alias to Generic.

@simonjayhawkins
Copy link
Author

ahh, just noticed the code comment

# Elaborate hack to work around https://github.com/python/mypy/issues/2087.
# Ideally would just be `exit.Exception = Exit` etc.

that's interesting. in pandas we normally just add an ignore for these cases. maybe python/mypy#2087 (comment) is relevant.

@The-Compiler The-Compiler added this to the 6.0 milestone Jul 22, 2020
@Zac-HD
Copy link
Member

Zac-HD commented Jul 22, 2020

we are pinned to mypy 0.730 at the moment... I can confirm that I don't get this error from mypy 0.750 onwards

As noted in the changelog, our type hints are developed against mypy 0.780 - and I think it's reasonable to require a recent version of mypy to use with the forthcoming major version of pytest.

@The-Compiler @nicoddemus I suggest that we close this without action, save perhaps noting in the changelog that mypy versions before 0.750 are known to be incompatible.

@nicoddemus
Copy link
Member

nicoddemus commented Jul 22, 2020

@Zac-HD I agree we should only support versions >=X of mypy, and need to make that explicit somewhere (changelog is fine for now).

WDYT @bluetech?

@simonjayhawkins
Copy link
Author

I suggest that we close this without action

i'm OK with that from pandas perspective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: typing type-annotation issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants