From 9260cbe704396082e62246a2067b080abe2374a2 Mon Sep 17 00:00:00 2001 From: Bill Fisher Date: Wed, 6 Nov 2024 21:05:57 -0700 Subject: [PATCH 1/3] Try re-introducing cancel method. --- examples/tests/test_basic.py | 2 +- examples/tests/test_flowcache.py | 2 +- examples/tests/test_gnmi.py | 4 ++-- examples/tests/test_hello.py | 6 +++--- examples/tests/test_int.py | 2 +- examples/tests/test_l2switch.py | 2 +- examples/tests/test_ngsdn.py | 4 ++-- examples/tests/test_tls_demo.py | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/tests/test_basic.py b/examples/tests/test_basic.py index 75d973a8..4e2ddd21 100644 --- a/examples/tests/test_basic.py +++ b/examples/tests/test_basic.py @@ -17,7 +17,7 @@ async def test_demo(demonet, python): async with python(BASIC_DIR / "demo.py") as demo: await asyncio.sleep(0.5) await demonet.send("pingall", expect="(12/12 received)") - raise asyncio.CancelledError() + demo.cancel() async def test_read_tables(demonet): diff --git a/examples/tests/test_flowcache.py b/examples/tests/test_flowcache.py index 233e4ef8..03c9bf06 100644 --- a/examples/tests/test_flowcache.py +++ b/examples/tests/test_flowcache.py @@ -18,7 +18,7 @@ async def test_demo(demonet, python): await asyncio.sleep(0.5) await demonet.send("h1 ping -c 1 -W .25 h2", expect="100% packet loss") await demonet.send("h2 ping -c 1 -W .25 h1", expect="100% packet loss") - raise asyncio.CancelledError() + demo.cancel() async def test_read_tables(demonet): diff --git a/examples/tests/test_gnmi.py b/examples/tests/test_gnmi.py index df74da34..d1765858 100644 --- a/examples/tests/test_gnmi.py +++ b/examples/tests/test_gnmi.py @@ -28,7 +28,7 @@ async def test_demo2(demonet, python): await asyncio.sleep(0.5) await demonet.send("h1 ifconfig eth0 up") await asyncio.sleep(0.5) - raise asyncio.CancelledError() + demo2.cancel() assert ( result.decode() @@ -42,7 +42,7 @@ async def test_demo3(demonet, python): async with python(GNMI_DIR / "demo3.py") | result as demo3: await asyncio.sleep(6.5) - raise asyncio.CancelledError() + demo3.cancel() assert result.decode().startswith( "initial: s1-eth1 is UP\nupdate: s1-eth1 is DOWN\nupdate: s1-eth1 is UP\nupdate: s1-eth1 is DOWN" diff --git a/examples/tests/test_hello.py b/examples/tests/test_hello.py index 3a866452..ae982b69 100644 --- a/examples/tests/test_hello.py +++ b/examples/tests/test_hello.py @@ -41,7 +41,7 @@ async def test_demo1(demonet, python): async with python(HELLO_DIR / "demo1.py") as demo1: await asyncio.sleep(0.25) await demonet.send("pingall", expect="(6/6 received)") - raise asyncio.CancelledError() + demo1.cancel() async def test_demo2(demonet, python): @@ -50,7 +50,7 @@ async def test_demo2(demonet, python): await asyncio.sleep(0.5) await demonet.send("pingall") await demonet.send("pingall", expect="(6/6 received)") - raise asyncio.CancelledError() + demo2.cancel() async def test_read_tables(demonet): @@ -90,7 +90,7 @@ async def test_demo3(demonet, python): await asyncio.sleep(0.5) await demonet.send("pingall") await demonet.send("pingall", expect="(6/6 received)") - raise asyncio.CancelledError() + demo3.cancel() @pytest.mark.skipif(not testlib.has_pygraphviz(), reason="Requires pygraphviz") diff --git a/examples/tests/test_int.py b/examples/tests/test_int.py index 55e93203..0d9f3ea6 100644 --- a/examples/tests/test_int.py +++ b/examples/tests/test_int.py @@ -18,7 +18,7 @@ async def test_demo(demonet, python): await asyncio.sleep(0.25) await demonet.send("h1 echo 'abc' | socat - udp:192.168.0.48:5555") await asyncio.sleep(1.0) - raise asyncio.CancelledError() + demo.cancel() async def test_read_tables(demonet): diff --git a/examples/tests/test_l2switch.py b/examples/tests/test_l2switch.py index 7d02a903..6c2f8b5e 100644 --- a/examples/tests/test_l2switch.py +++ b/examples/tests/test_l2switch.py @@ -17,7 +17,7 @@ async def test_demo(demonet, python): async with python(L2SWITCH_DIR / "demo.py") as demo: await asyncio.sleep(0.5) await demonet.send("pingall", expect="(6/6 received)") - raise asyncio.CancelledError() + demo.cancel() async def test_read_tables(demonet): diff --git a/examples/tests/test_ngsdn.py b/examples/tests/test_ngsdn.py index 2856b040..89204931 100644 --- a/examples/tests/test_ngsdn.py +++ b/examples/tests/test_ngsdn.py @@ -26,7 +26,7 @@ async def test_ngsdn_oneshot(demonet, python): await demonet.send("h3 ping -c 1 h1a") await demonet.send("h1a ping -c 1 h3", expect=" 0% packet loss") - raise asyncio.CancelledError() + demo.cancel() async def test_leaf2(demonet): @@ -163,7 +163,7 @@ async def test_ngsdn_actionprofile(demonet, python): await demonet.send("h3 ping -c 2 h1a") await demonet.send("h1a ping -c 1 h3", expect=" 0% packet loss") - raise asyncio.CancelledError() + demo.cancel() async def test_read_tables_actionprofile(demonet, caplog): diff --git a/examples/tests/test_tls_demo.py b/examples/tests/test_tls_demo.py index f6abadf3..653e6e26 100644 --- a/examples/tests/test_tls_demo.py +++ b/examples/tests/test_tls_demo.py @@ -16,4 +16,4 @@ async def test_demo1(demonet, python): async with python(TLSDEMO_DIR / "demo1.py") as demo1: await asyncio.sleep(0.25) await demonet.send("pingall", expect="(2/2 received)") - raise asyncio.CancelledError() + demo1.cancel() From ed20be84bd6f3fd5bc3bed942379c049d6aaa14d Mon Sep 17 00:00:00 2001 From: Bill Fisher Date: Thu, 7 Nov 2024 09:35:52 -0700 Subject: [PATCH 2/3] Update dev. dependencies. --- ci/requirements-demonet.txt | 2 +- ci/requirements-dev.txt | 8 ++++---- ci/requirements.txt | 2 +- poetry.lock | 8 ++++---- pyproject.toml | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ci/requirements-demonet.txt b/ci/requirements-demonet.txt index be85ed66..cdff17d1 100644 --- a/ci/requirements-demonet.txt +++ b/ci/requirements-demonet.txt @@ -1,3 +1,3 @@ -# Poetry (version 1.8.4) export at Tue Nov 5 11:42:39 MST 2024 +# Poetry (version 1.8.4) export at Thu Nov 7 09:33:40 MST 2024 pygraphviz==1.14 ; python_version >= "3.10" and python_version < "4.0" \ --hash=sha256:c10df02377f4e39b00ae17c862f4ee7e5767317f1c6b2dfd04cea6acc7fc2bea diff --git a/ci/requirements-dev.txt b/ci/requirements-dev.txt index 8fe80413..78678fe7 100644 --- a/ci/requirements-dev.txt +++ b/ci/requirements-dev.txt @@ -1,4 +1,4 @@ -# Poetry (version 1.8.4) export at Tue Nov 5 11:42:39 MST 2024 +# Poetry (version 1.8.4) export at Thu Nov 7 09:33:40 MST 2024 astroid==3.3.5 ; python_version >= "3.10" and python_version < "4.0" \ --hash=sha256:5cfc40ae9f68311075d27ef68a4841bdc5cc7f6cf86671b49f00607d30188e2d \ --hash=sha256:a9d1c946ada25098d790e079ba2a1b112157278f3fb7e718ae6a9252f5835dc8 @@ -311,9 +311,9 @@ pygments==2.18.0 ; python_version >= "3.10" and python_version < "4.0" \ pylint==3.3.1 ; python_version >= "3.10" and python_version < "4.0" \ --hash=sha256:2f846a466dd023513240bc140ad2dd73bfc080a5d85a710afdb728c420a5a2b9 \ --hash=sha256:9f3dcc87b1203e612b78d91a896407787e708b3f189b5fa0b307712d49ff0c6e -pyright==1.1.387 ; python_version >= "3.10" and python_version < "4.0" \ - --hash=sha256:577de60224f7fe36505d5b181231e3a395d427b7873be0bbcaa962a29ea93a60 \ - --hash=sha256:6a1f495a261a72e12ad17e20d1ae3df4511223c773b19407cfa006229b1b08a5 +pyright==1.1.388 ; python_version >= "3.10" and python_version < "4.0" \ + --hash=sha256:0166d19b716b77fd2d9055de29f71d844874dbc6b9d3472ccd22df91db3dfa34 \ + --hash=sha256:c7068e9f2c23539c6ac35fc9efac6c6c1b9aa5a0ce97a9a8a6cf0090d7cbf84c pytest-asyncio==0.24.0 ; python_version >= "3.10" and python_version < "4.0" \ --hash=sha256:a811296ed596b69bf0b6f3dc40f83bcaf341b155a269052d82efa2b25ac7037b \ --hash=sha256:d081d828e576d85f875399194281e92bf8a68d60d72d1a2faf2feddb6c46b276 diff --git a/ci/requirements.txt b/ci/requirements.txt index d5f768a5..d1bbf31b 100644 --- a/ci/requirements.txt +++ b/ci/requirements.txt @@ -1,4 +1,4 @@ -# Poetry (version 1.8.4) export at Tue Nov 5 11:42:39 MST 2024 +# Poetry (version 1.8.4) export at Thu Nov 7 09:33:40 MST 2024 grpcio==1.67.1 ; python_version >= "3.10" and python_version < "4.0" \ --hash=sha256:01f616a964e540638af5130469451cf580ba8c7329f45ca998ab66e0c7dcdb04 \ --hash=sha256:0489063974d1452436139501bf6b180f63d4977223ee87488fe36858c5725292 \ diff --git a/poetry.lock b/poetry.lock index fd7bc9cf..e5a32afd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -642,13 +642,13 @@ testutils = ["gitpython (>3)"] [[package]] name = "pyright" -version = "1.1.387" +version = "1.1.388" description = "Command line wrapper for pyright" optional = false python-versions = ">=3.7" files = [ - {file = "pyright-1.1.387-py3-none-any.whl", hash = "sha256:6a1f495a261a72e12ad17e20d1ae3df4511223c773b19407cfa006229b1b08a5"}, - {file = "pyright-1.1.387.tar.gz", hash = "sha256:577de60224f7fe36505d5b181231e3a395d427b7873be0bbcaa962a29ea93a60"}, + {file = "pyright-1.1.388-py3-none-any.whl", hash = "sha256:c7068e9f2c23539c6ac35fc9efac6c6c1b9aa5a0ce97a9a8a6cf0090d7cbf84c"}, + {file = "pyright-1.1.388.tar.gz", hash = "sha256:0166d19b716b77fd2d9055de29f71d844874dbc6b9d3472ccd22df91db3dfa34"}, ] [package.dependencies] @@ -795,4 +795,4 @@ demonet = ["shellous"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "7fde133746422cb0604d23dc6d99f4c6d1145d585106164eaa4b655dbef5eebe" +content-hash = "26e49837be74c7b0b3605de7866f4e9082443a0eb3e8be200dee331da9d77dfa" diff --git a/pyproject.toml b/pyproject.toml index a1dd4772..ddd84510 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,7 @@ mypy = "^1.13.0" pdoc = "^15.0.0" prometheus-client = "^0.21.0" pylint = "^3.3.1" -pyright = "^1.1.383" +pyright = "^1.1.388" pytest = "^8.3.3" pytest-asyncio = "^0.24.0" pytest-cov = "^5.0.0" From 671748ce989d44e019b4ec042c6d95bf8556b6f3 Mon Sep 17 00:00:00 2001 From: Bill Fisher Date: Thu, 7 Nov 2024 10:40:25 -0700 Subject: [PATCH 3/3] Fix pylint/pyright warnings. --- finsy/p4schema.py | 6 +++++- finsy/stringutil.py | 3 +++ pyproject.toml | 6 +++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/finsy/p4schema.py b/finsy/p4schema.py index 8b62e783..8667fad6 100644 --- a/finsy/p4schema.py +++ b/finsy/p4schema.py @@ -2030,10 +2030,12 @@ def data_type_spec(self) -> p4t.P4DataTypeSpec: @property def bitwidth(self) -> int: + "Width of serializable enum in bits." return self.pbuf.underlying_type.bitwidth @property def members(self) -> dict[str, int]: + "Dictionary of enum members." return self._members def encode_data(self, value: Any) -> p4d.P4Data: @@ -2176,10 +2178,12 @@ def __init__( @property def extern_type_id(self) -> int: + "ID of the extern's type." return self._extern_type_id @property def extern_type_name(self) -> str: + "Name of the extern's type." return self._extern_type_name @property @@ -2208,7 +2212,7 @@ def __getitem__(self, key: tuple[str, str] | tuple[int, int]) -> P4ExternInstanc value = self.get(key) if value is None: self._key_error(key) - return value # pyright: ignore[reportReturnType] + return value def __iter__(self) -> Iterator[P4ExternInstance]: return iter(self._by_name.values()) diff --git a/finsy/stringutil.py b/finsy/stringutil.py index 3e19fb9f..d3d7f34e 100644 --- a/finsy/stringutil.py +++ b/finsy/stringutil.py @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Don't use min() builtin in performance-critical loops. +# pylint: disable=consider-using-min-builtin + def minimum_edit_distance(str1: str, str2: str) -> int: """Compute the minimum edit distance between two strings. diff --git a/pyproject.toml b/pyproject.toml index ddd84510..ee3c8721 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -132,14 +132,14 @@ ignored-modules = ["finsy.proto"] good-names = ["i", "j", "k", "v", "ex", "Run", "_", "m", "s", "ee", "up", "id", "vt"] [tool.pylint.design] -max-attributes = 15 +max-attributes = 17 min-public-methods = 0 -max-public-methods = 25 +max-public-methods = 27 max-branches = 15 max-returns = 10 [tool.pylint.format] -max-module-lines = 2500 +max-module-lines = 2700 max-line-length = 120 [tool.pylint."messages control"]