Compare commits
17 Commits
v1.140.0rc
...
dmr/test-m
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6554988888 | ||
|
|
0c09fccab1 | ||
|
|
f031e406d7 | ||
|
|
af0145bf27 | ||
|
|
baca8eb43e | ||
|
|
d4a608e8bb | ||
|
|
c3aa80ca9d | ||
|
|
9b985cf8a8 | ||
|
|
ecc1084654 | ||
|
|
af2f251ace | ||
|
|
b306fa579d | ||
|
|
a7636881cc | ||
|
|
31b5b619c9 | ||
|
|
df8e0b9dbc | ||
|
|
0df5d132e7 | ||
|
|
024c8df013 | ||
|
|
5830b7a986 |
1
changelog.d/15313.misc
Normal file
1
changelog.d/15313.misc
Normal file
@@ -0,0 +1 @@
|
||||
Dummy changelog.
|
||||
18
poetry.lock
generated
18
poetry.lock
generated
@@ -1520,24 +1520,28 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "mypy-zope"
|
||||
version = "0.9.1"
|
||||
version = "0.9.1.dev0"
|
||||
description = "Plugin for mypy to support zope interfaces"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "mypy-zope-0.9.1.tar.gz", hash = "sha256:4c87dbc71fec35f6533746ecdf9d400cd9281338d71c16b5676bb5ed00a97ca2"},
|
||||
{file = "mypy_zope-0.9.1-py3-none-any.whl", hash = "sha256:733d4399affe9e61e332ce9c4049418d6775c39b473e4b9f409d51c207c1b71a"},
|
||||
]
|
||||
files = []
|
||||
develop = false
|
||||
|
||||
[package.dependencies]
|
||||
mypy = ">=1.0.0,<1.1.0"
|
||||
mypy = "1.0.0"
|
||||
"zope.interface" = "*"
|
||||
"zope.schema" = "*"
|
||||
|
||||
[package.extras]
|
||||
test = ["lxml", "pytest (>=4.6)", "pytest-cov"]
|
||||
|
||||
[package.source]
|
||||
type = "git"
|
||||
url = "https://github.com/Shoobx/mypy-zope.git"
|
||||
reference = "fix-unreachable"
|
||||
resolved_reference = "282269e484cdece7aa024639f763927015cfdac5"
|
||||
|
||||
[[package]]
|
||||
name = "myst-parser"
|
||||
version = "1.0.0"
|
||||
@@ -3426,4 +3430,4 @@ user-search = ["pyicu"]
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.7.1"
|
||||
content-hash = "0a1dd4be3dff3c8cc71bd57a4eb48e1d92f155db7230e61fbb54f8af03619509"
|
||||
content-hash = "6991931764c913db1be84bc4c684bcf8b9d1855d49a297f21c1a56a5119dc68a"
|
||||
|
||||
@@ -315,7 +315,8 @@ ruff = "0.0.252"
|
||||
|
||||
# Typechecking
|
||||
mypy = "*"
|
||||
mypy-zope = "*"
|
||||
mypy-zope = {git = "https://github.com/Shoobx/mypy-zope.git", rev = "fix-unreachable"}
|
||||
|
||||
types-bleach = ">=4.1.0"
|
||||
types-commonmark = ">=0.9.2"
|
||||
types-jsonschema = ">=3.2.0"
|
||||
@@ -350,7 +351,6 @@ towncrier = ">=18.6.0rc1"
|
||||
# Used for checking the Poetry lockfile
|
||||
tomli = ">=1.2.3"
|
||||
|
||||
|
||||
# Dependencies for building the development documentation
|
||||
[tool.poetry.group.dev-docs]
|
||||
optional = true
|
||||
|
||||
27
tests/http/federation/dmr_reproduce_mypy_zope_pain.py
Normal file
27
tests/http/federation/dmr_reproduce_mypy_zope_pain.py
Normal file
@@ -0,0 +1,27 @@
|
||||
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")
|
||||
@@ -63,7 +63,7 @@ from tests.http import (
|
||||
get_test_ca_cert_file,
|
||||
)
|
||||
from tests.server import FakeTransport, ThreadedMemoryReactorClock
|
||||
from tests.utils import checked_cast, default_config
|
||||
from tests.utils import default_config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -147,9 +147,8 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||
# Normally this would be done by the TCP socket code in Twisted, but we are
|
||||
# stubbing that out here.
|
||||
# NB: we use a checked_cast here to workaround https://github.com/Shoobx/mypy-zope/issues/91)
|
||||
client_protocol = checked_cast(
|
||||
_WrappingProtocol, client_factory.buildProtocol(dummy_address)
|
||||
)
|
||||
client_protocol = client_factory.buildProtocol(dummy_address)
|
||||
assert isinstance(client_protocol, _WrappingProtocol)
|
||||
client_protocol.makeConnection(
|
||||
FakeTransport(server_protocol, self.reactor, client_protocol)
|
||||
)
|
||||
@@ -467,7 +466,8 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||
assert isinstance(proxy_server_transport, FakeTransport)
|
||||
client_protocol = proxy_server_transport.other
|
||||
assert isinstance(client_protocol, Protocol)
|
||||
c2s_transport = checked_cast(FakeTransport, client_protocol.transport)
|
||||
c2s_transport = client_protocol.transport
|
||||
assert isinstance(c2s_transport, FakeTransport)
|
||||
c2s_transport.other = server_ssl_protocol
|
||||
|
||||
self.reactor.advance(0)
|
||||
|
||||
@@ -43,7 +43,6 @@ from tests.http import (
|
||||
)
|
||||
from tests.server import FakeTransport, ThreadedMemoryReactorClock
|
||||
from tests.unittest import TestCase
|
||||
from tests.utils import checked_cast
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -645,7 +644,8 @@ class MatrixFederationAgentTests(TestCase):
|
||||
assert isinstance(proxy_server_transport, FakeTransport)
|
||||
client_protocol = proxy_server_transport.other
|
||||
assert isinstance(client_protocol, Protocol)
|
||||
c2s_transport = checked_cast(FakeTransport, client_protocol.transport)
|
||||
c2s_transport = client_protocol.transport
|
||||
assert isinstance(c2s_transport, FakeTransport)
|
||||
c2s_transport.other = server_ssl_protocol
|
||||
|
||||
self.reactor.advance(0)
|
||||
@@ -763,9 +763,12 @@ class MatrixFederationAgentTests(TestCase):
|
||||
# https://github.com/Shoobx/mypy-zope/issues/91 .
|
||||
# We also double-checked these casts at runtime (test-time) because I found it
|
||||
# quite confusing to deduce these types in the first place!
|
||||
s2c_transport = checked_cast(FakeTransport, proxy_server.transport)
|
||||
client_protocol = checked_cast(_WrappingProtocol, s2c_transport.other)
|
||||
c2s_transport = checked_cast(FakeTransport, client_protocol.transport)
|
||||
s2c_transport = proxy_server.transport
|
||||
assert isinstance(s2c_transport, FakeTransport)
|
||||
client_protocol = s2c_transport.other
|
||||
assert isinstance(client_protocol, _WrappingProtocol)
|
||||
c2s_transport = client_protocol.transport
|
||||
assert isinstance(c2s_transport, FakeTransport)
|
||||
|
||||
# the FakeTransport is async, so we need to pump the reactor
|
||||
self.reactor.advance(0)
|
||||
@@ -825,7 +828,8 @@ class MatrixFederationAgentTests(TestCase):
|
||||
@patch.dict(os.environ, {"http_proxy": "proxy.com:8888"})
|
||||
def test_proxy_with_no_scheme(self) -> None:
|
||||
http_proxy_agent = ProxyAgent(self.reactor, use_proxy=True)
|
||||
proxy_ep = checked_cast(HostnameEndpoint, http_proxy_agent.http_proxy_endpoint)
|
||||
proxy_ep = http_proxy_agent.http_proxy_endpoint
|
||||
assert isinstance(proxy_ep, HostnameEndpoint)
|
||||
self.assertEqual(proxy_ep._hostStr, "proxy.com")
|
||||
self.assertEqual(proxy_ep._port, 8888)
|
||||
|
||||
@@ -837,14 +841,16 @@ class MatrixFederationAgentTests(TestCase):
|
||||
@patch.dict(os.environ, {"http_proxy": "http://proxy.com:8888"})
|
||||
def test_proxy_with_http_scheme(self) -> None:
|
||||
http_proxy_agent = ProxyAgent(self.reactor, use_proxy=True)
|
||||
proxy_ep = checked_cast(HostnameEndpoint, http_proxy_agent.http_proxy_endpoint)
|
||||
proxy_ep = http_proxy_agent.http_proxy_endpoint
|
||||
assert isinstance(proxy_ep, HostnameEndpoint)
|
||||
self.assertEqual(proxy_ep._hostStr, "proxy.com")
|
||||
self.assertEqual(proxy_ep._port, 8888)
|
||||
|
||||
@patch.dict(os.environ, {"http_proxy": "https://proxy.com:8888"})
|
||||
def test_proxy_with_https_scheme(self) -> None:
|
||||
https_proxy_agent = ProxyAgent(self.reactor, use_proxy=True)
|
||||
proxy_ep = checked_cast(_WrapperEndpoint, https_proxy_agent.http_proxy_endpoint)
|
||||
proxy_ep = https_proxy_agent.http_proxy_endpoint
|
||||
assert isinstance(proxy_ep, _WrapperEndpoint)
|
||||
self.assertEqual(proxy_ep._wrappedEndpoint._hostStr, "proxy.com")
|
||||
self.assertEqual(proxy_ep._wrappedEndpoint._port, 8888)
|
||||
|
||||
|
||||
30
tests/isinstance_impl.py
Normal file
30
tests/isinstance_impl.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# Per https://github.com/Shoobx/mypy-zope/pull/92#issuecomment-1483266683
|
||||
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>
|
||||
"""
|
||||
@@ -21,7 +21,6 @@ from synapse.logging import RemoteHandler
|
||||
from tests.logging import LoggerCleanupMixin
|
||||
from tests.server import FakeTransport, get_clock
|
||||
from tests.unittest import TestCase
|
||||
from tests.utils import checked_cast
|
||||
|
||||
|
||||
def connect_logging_client(
|
||||
@@ -57,7 +56,8 @@ class RemoteHandlerTestCase(LoggerCleanupMixin, TestCase):
|
||||
client, server = connect_logging_client(self.reactor, 0)
|
||||
|
||||
# Trigger data being sent
|
||||
client_transport = checked_cast(FakeTransport, client.transport)
|
||||
client_transport = client.transport
|
||||
assert isinstance(client_transport, FakeTransport)
|
||||
client_transport.flush()
|
||||
|
||||
# One log message, with a single trailing newline
|
||||
@@ -90,7 +90,8 @@ class RemoteHandlerTestCase(LoggerCleanupMixin, TestCase):
|
||||
|
||||
# Allow the reconnection
|
||||
client, server = connect_logging_client(self.reactor, 0)
|
||||
client_transport = checked_cast(FakeTransport, client.transport)
|
||||
client_transport = client.transport
|
||||
assert isinstance(client_transport, FakeTransport)
|
||||
client_transport.flush()
|
||||
|
||||
# Only the 7 infos made it through, the debugs were elided
|
||||
@@ -124,7 +125,8 @@ class RemoteHandlerTestCase(LoggerCleanupMixin, TestCase):
|
||||
|
||||
# Allow the reconnection
|
||||
client, server = connect_logging_client(self.reactor, 0)
|
||||
client_transport = checked_cast(FakeTransport, client.transport)
|
||||
client_transport = client.transport
|
||||
assert isinstance(client_transport, FakeTransport)
|
||||
client_transport.flush()
|
||||
|
||||
# The 10 warnings made it through, the debugs and infos were elided
|
||||
@@ -149,7 +151,8 @@ class RemoteHandlerTestCase(LoggerCleanupMixin, TestCase):
|
||||
|
||||
# Allow the reconnection
|
||||
client, server = connect_logging_client(self.reactor, 0)
|
||||
client_transport = checked_cast(FakeTransport, client.transport)
|
||||
client_transport = client.transport
|
||||
assert isinstance(client_transport, FakeTransport)
|
||||
client_transport.flush()
|
||||
|
||||
# The first five and last five warnings made it through, the debugs and
|
||||
|
||||
@@ -82,7 +82,7 @@ from tests.server import (
|
||||
)
|
||||
from tests.test_utils import event_injection, setup_awaitable_errors
|
||||
from tests.test_utils.logging_setup import setup_logging
|
||||
from tests.utils import checked_cast, default_config, setupdb
|
||||
from tests.utils import default_config, setupdb
|
||||
|
||||
setupdb()
|
||||
setup_logging()
|
||||
@@ -296,9 +296,11 @@ class HomeserverTestCase(TestCase):
|
||||
|
||||
from tests.rest.client.utils import RestHelper
|
||||
|
||||
reactor = self.hs.get_reactor()
|
||||
assert isinstance(reactor, MemoryReactorClock)
|
||||
self.helper = RestHelper(
|
||||
self.hs,
|
||||
checked_cast(MemoryReactorClock, self.hs.get_reactor()),
|
||||
reactor,
|
||||
self.site,
|
||||
getattr(self, "user_id", None),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user