Skip to content

Commit

Permalink
Reproduce #91
Browse files Browse the repository at this point in the history
  • Loading branch information
kedder committed Mar 24, 2023
1 parent 6945ee0 commit c178b6b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions mypy-zope.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[mypy]
namespace_packages=True
warn_unreachable=True
plugins=mypy_zope:plugin
31 changes: 31 additions & 0 deletions tests/samples/dmr_unreachable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import Optional

from zope.interface import Interface, implementer


class IFoo(Interface):
pass


@implementer(IFoo)
class BaseFoo:
pass


class ChildFoo(BaseFoo):
pass


class IFooFactory(Interface):
def build() -> Optional[IFoo]:
pass


def build_and_use_foo(client_factory: IFooFactory) -> None:
client_protocol = client_factory.build()
assert isinstance(client_protocol, ChildFoo)
print("Hello")


"""
"""
29 changes: 29 additions & 0 deletions tests/samples/isinstance_impl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Optional
from zope.interface import implementer, Interface


class IFoo(Interface):
...


@implementer(IFoo)
class MyFoo:
...


def make_foo() -> Optional[IFoo]:
return MyFoo()


x = make_foo()
reveal_type(x)
assert isinstance(x, MyFoo)

# The code below should not be considered unreachable
print("hello")

"""
<output>
isinstance_impl.py:19: note: Revealed type is "Union[__main__.IFoo, None]"
</output>
"""
1 change: 1 addition & 0 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_samples(samplefile, mypy_cache_dir):
opts.show_traceback = True
opts.namespace_packages = True
opts.hide_error_codes = True
opts.warn_unreachable = True
opts.plugins = ['mypy_zope:plugin']
# Config file is needed to load plugins, it doesn't not exist and is not
# supposed to.
Expand Down

0 comments on commit c178b6b

Please sign in to comment.