Skip to content

Commit 229bb2b

Browse files
authored
Fix typing for get_ipc_path and get_dev_ipc_path (#2917)
* Fix typing for get_ipc_path and get_dev_ipc_path * Add newsfragment
1 parent 824ba41 commit 229bb2b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

newsfragments/2917.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

web3/providers/ipc.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515
from typing import (
1616
Any,
17+
Optional,
1718
Type,
1819
Union,
1920
)
@@ -85,24 +86,26 @@ def reset(self) -> socket.socket:
8586
return self.sock
8687

8788

88-
# type ignored b/c missing return statement is by design here
89-
def get_default_ipc_path() -> str: # type: ignore
89+
def get_default_ipc_path() -> Optional[str]:
9090
if sys.platform == "darwin":
9191
ipc_path = os.path.expanduser(
9292
os.path.join("~", "Library", "Ethereum", "geth.ipc")
9393
)
9494
if os.path.exists(ipc_path):
9595
return ipc_path
96+
return None
9697

9798
elif sys.platform.startswith("linux") or sys.platform.startswith("freebsd"):
9899
ipc_path = os.path.expanduser(os.path.join("~", ".ethereum", "geth.ipc"))
99100
if os.path.exists(ipc_path):
100101
return ipc_path
102+
return None
101103

102104
elif sys.platform == "win32":
103105
ipc_path = os.path.join("\\\\", ".", "pipe", "geth.ipc")
104106
if os.path.exists(ipc_path):
105107
return ipc_path
108+
return None
106109

107110
else:
108111
raise ValueError(
@@ -111,22 +114,25 @@ def get_default_ipc_path() -> str: # type: ignore
111114
)
112115

113116

114-
# type ignored b/c missing return statement is by design here
115-
def get_dev_ipc_path() -> str: # type: ignore
117+
def get_dev_ipc_path() -> Optional[str]:
116118
if os.environ.get("WEB3_PROVIDER_URI", ""):
117119
ipc_path = os.environ.get("WEB3_PROVIDER_URI")
118120
if os.path.exists(ipc_path):
119121
return ipc_path
122+
return None
123+
120124
elif sys.platform == "darwin":
121125
tmpdir = os.environ.get("TMPDIR", "")
122126
ipc_path = os.path.expanduser(os.path.join(tmpdir, "geth.ipc"))
123127
if os.path.exists(ipc_path):
124128
return ipc_path
129+
return None
125130

126131
elif sys.platform.startswith("linux") or sys.platform.startswith("freebsd"):
127132
ipc_path = os.path.expanduser(os.path.join("/tmp", "geth.ipc"))
128133
if os.path.exists(ipc_path):
129134
return ipc_path
135+
return None
130136

131137
elif sys.platform == "win32":
132138
ipc_path = os.path.join("\\\\", ".", "pipe", "geth.ipc")

0 commit comments

Comments
 (0)