Skip to content

show_none_errors causes invalid behavior for descriptors #6514

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
Elscouta opened this issue Mar 6, 2019 · 2 comments · Fixed by #13507
Closed

show_none_errors causes invalid behavior for descriptors #6514

Elscouta opened this issue Mar 6, 2019 · 2 comments · Fixed by #13507
Labels
bug mypy got something wrong priority-2-low

Comments

@Elscouta
Copy link

Elscouta commented Mar 6, 2019

Setting show_none_errors in the config file causes descriptor-based attributes to no longer be detected. Instead, even when called on an instance, they return the type of the property itself.

Minimal code for reproduction:

test.py

from typing import Generic, TypeVar, overload, Any, Union
import datetime as dt

T = TypeVar('T')

class Column(Generic[T]):
    @overload
    def __get__(self, instance: None, owner: Any) -> "Column[T]": ...
    @overload
    def __get__(self, instance: object, owner: Any) -> T: ...

    def __get__(self, instance: Union[None, object], owner: Any) -> "Union[Column[T], T]": ...

class MyClass:
    prop: Column[dt.date] = Column()

reveal_type(MyClass.prop)
reveal_type(MyClass().prop)

mypy.ini:

[mypy]
python_version = 3.6
#show_none_errors = False

This yields the following (expected) result:

test.py:17: error: Revealed type is 'test3.Column[datetime.date*]'
test.py:18: error: Revealed type is 'datetime.date*'

However, uncommenting the show_none_errors line modifies the output into:

test.py:17: error: Revealed type is 'test3.Column[datetime.date*]'
test.py:18: error: Revealed type is 'test3.Column[datetime.date*]'
@gvanrossum gvanrossum added bug mypy got something wrong priority-2-low labels Mar 6, 2019
@gvanrossum
Copy link
Member

That's definitely a bug; when show_none_errors is set, apparently some part of the type analysis is wrongly skipped.

But why are you using that flag? Shouldn't you use strict_optional? IIRC show_none_errors is part of a very old and buggy way to work around the errors caused by introducing strict Optional checking in a code base that was annotated before mypy supported that.

@Elscouta
Copy link
Author

Elscouta commented Mar 6, 2019

Thanks for the quick reply.

We tested with strict_optional instead and the error reporting is indeed much more accurate.

hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Aug 25, 2022
These are somewhat buggy and modern per-module options should be
preferred. I can't find any use of strict_optional_whitelist.
There is some use of show_none_errors, but it's all set to True;
I think people are just worried and cargo culting and want mypy to
really, actually give them all the errors.

Fixes python#6514, fixes python#2396
hauntsaninja added a commit that referenced this issue Aug 25, 2022
These are somewhat buggy and modern per-module options should be
preferred. I can't find any use of strict_optional_whitelist.
There is some use of show_none_errors, but it's all set to True;
I think people are just worried and cargo culting and want mypy to
really, actually give them all the errors.

Fixes #6514, fixes #2396
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-2-low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants