Skip to content

show_none_errors causes invalid behavior for descriptors #6514

Closed
@Elscouta

Description

@Elscouta

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*]'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions