From e7a5e1d324e237955510147161b8838f804e6538 Mon Sep 17 00:00:00 2001 From: kclowes Date: Thu, 13 Apr 2023 12:06:07 -0600 Subject: [PATCH 1/2] Fix typing for get_ipc_path and get_dev_ipc_path --- web3/providers/ipc.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/web3/providers/ipc.py b/web3/providers/ipc.py index 1031a48b22..ae749b355c 100644 --- a/web3/providers/ipc.py +++ b/web3/providers/ipc.py @@ -14,6 +14,7 @@ ) from typing import ( Any, + Optional, Type, Union, ) @@ -85,24 +86,26 @@ def reset(self) -> socket.socket: return self.sock -# type ignored b/c missing return statement is by design here -def get_default_ipc_path() -> str: # type: ignore +def get_default_ipc_path() -> Optional[str]: if sys.platform == "darwin": ipc_path = os.path.expanduser( os.path.join("~", "Library", "Ethereum", "geth.ipc") ) if os.path.exists(ipc_path): return ipc_path + return None elif sys.platform.startswith("linux") or sys.platform.startswith("freebsd"): ipc_path = os.path.expanduser(os.path.join("~", ".ethereum", "geth.ipc")) if os.path.exists(ipc_path): return ipc_path + return None elif sys.platform == "win32": ipc_path = os.path.join("\\\\", ".", "pipe", "geth.ipc") if os.path.exists(ipc_path): return ipc_path + return None else: raise ValueError( @@ -111,22 +114,25 @@ def get_default_ipc_path() -> str: # type: ignore ) -# type ignored b/c missing return statement is by design here -def get_dev_ipc_path() -> str: # type: ignore +def get_dev_ipc_path() -> Optional[str]: if os.environ.get("WEB3_PROVIDER_URI", ""): ipc_path = os.environ.get("WEB3_PROVIDER_URI") if os.path.exists(ipc_path): return ipc_path + return None + elif sys.platform == "darwin": tmpdir = os.environ.get("TMPDIR", "") ipc_path = os.path.expanduser(os.path.join(tmpdir, "geth.ipc")) if os.path.exists(ipc_path): return ipc_path + return None elif sys.platform.startswith("linux") or sys.platform.startswith("freebsd"): ipc_path = os.path.expanduser(os.path.join("/tmp", "geth.ipc")) if os.path.exists(ipc_path): return ipc_path + return None elif sys.platform == "win32": ipc_path = os.path.join("\\\\", ".", "pipe", "geth.ipc") From 559f4d7d557ef6867007863aaed636ddaabb7f31 Mon Sep 17 00:00:00 2001 From: kclowes Date: Wed, 19 Apr 2023 14:20:54 -0600 Subject: [PATCH 2/2] Add newsfragment --- newsfragments/2917.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/2917.bugfix.rst diff --git a/newsfragments/2917.bugfix.rst b/newsfragments/2917.bugfix.rst new file mode 100644 index 0000000000..495cf61e7a --- /dev/null +++ b/newsfragments/2917.bugfix.rst @@ -0,0 +1 @@ +Typing was being ignored for the ``get_ipc_path`` and ``get_dev_ipc_path`` functions because of a missing ``None`` return. Those two methods now explicitly return ``None`` and have an ``Optional`` in their type definition.