Skip to content

snakecase isConnected #2643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ virtualenv for smoke testing:
$ pip install ipython
$ ipython
>>> from web3.auto import w3
>>> w3.isConnected()
>>> w3.is_connected()
>>> ...


Expand Down
2 changes: 1 addition & 1 deletion docs/internals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ setting the middlewares the provider should use.
the JSON-RPC method being called.


.. py:method:: BaseProvider.isConnected()
.. py:method:: BaseProvider.is_connected()

This function should return ``True`` or ``False`` depending on whether the
provider should be considered *connected*. For example, an IPC socket
Expand Down
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ following built-in providers:
# WebsocketProvider:
>>> w3 = Web3(Web3.WebsocketProvider('ws://127.0.0.1:8546'))

>>> w3.isConnected()
>>> w3.is_connected()
True

For more information, (e.g., connecting to remote nodes, provider auto-detection,
Expand Down
6 changes: 3 additions & 3 deletions docs/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ For example, the following retrieves the client enode endpoint for both geth and

from web3.auto import w3

connected = w3.isConnected()
connected = w3.is_connected()

if connected and w3.clientVersion.startswith('Parity'):
enode = w3.parity.enode
Expand Down Expand Up @@ -186,7 +186,7 @@ an optional secret key, set the environment variable ``WEB3_INFURA_API_SECRET``:
>>> from web3.auto.infura import w3

# confirm that the connection succeeded
>>> w3.isConnected()
>>> w3.is_connected()
True

Geth dev Proof of Authority
Expand All @@ -199,7 +199,7 @@ To connect to a ``geth --dev`` Proof of Authority instance with defaults:
>>> from web3.auto.gethdev import w3

# confirm that the connection succeeded
>>> w3.isConnected()
>>> w3.is_connected()
True

Built In Providers
Expand Down
6 changes: 3 additions & 3 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Web3.py makes this test provider available via ``EthereumTesterProvider``:

>>> from web3 import Web3, EthereumTesterProvider
>>> w3 = Web3(EthereumTesterProvider())
>>> w3.isConnected()
>>> w3.is_connected()
True


Expand All @@ -73,7 +73,7 @@ to this local node can be done as follows:
# WebsocketProvider:
>>> w3 = Web3(Web3.WebsocketProvider('wss://127.0.0.1:8546'))

>>> w3.isConnected()
>>> w3.is_connected()
True

If you stick to the default ports or IPC file locations, you can utilize a
Expand All @@ -83,7 +83,7 @@ and save a few keystrokes:
.. code-block:: python

>>> from web3.auto import w3
>>> w3.isConnected()
>>> w3.is_connected()
True


Expand Down
6 changes: 3 additions & 3 deletions docs/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Ethereum network. An example configuration, if you're connecting to a locally ru
>>> w3 = Web3(Web3.HTTPProvider('http://localhost:8545'))

# now `w3` is available to use:
>>> w3.isConnected()
>>> w3.is_connected()
True
>>> w3.eth.send_transaction(...)

Expand All @@ -66,11 +66,11 @@ Refer to the :ref:`providers` documentation for further help with configuration.

Why isn't my web3 instance connecting to the network?
-----------------------------------------------------
You can check that your instance is connected via the ``isConnected`` method:
You can check that your instance is connected via the ``is_connected`` method:

.. code-block:: python

>>> w3.isConnected()
>>> w3.is_connected()
False

There's a variety of explanations for why you may see ``False`` here. If you're
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2643.breaking-change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Snakecase the `isConnected` method
2 changes: 1 addition & 1 deletion tests/core/providers/test_async_tester_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@pytest.mark.asyncio
async def test_async_tester_provider_is_connected() -> None:
provider = AsyncEthereumTesterProvider()
connected = await provider.isConnected()
connected = await provider.is_connected()
assert connected


Expand Down
4 changes: 2 additions & 2 deletions tests/core/providers/test_ipc_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def jsonrpc_ipc_pipe_path():

def test_ipc_no_path():
"""
IPCProvider.isConnected() returns False when no path is supplied
IPCProvider.is_connected() returns False when no path is supplied
"""
ipc = IPCProvider(None)
assert ipc.isConnected() is False
assert ipc.is_connected() is False


def test_ipc_tilda_in_path():
Expand Down
18 changes: 9 additions & 9 deletions tests/core/providers/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@


class ConnectedProvider(BaseProvider):
def isConnected(self):
def is_connected(self):
return True


class DisconnectedProvider(BaseProvider):
def isConnected(self):
def is_connected(self):
return False


def test_isConnected_connected():
def test_is_connected_connected():
"""
Web3.isConnected() returns True when connected to a node.
Web3.is_connected() returns True when connected to a node.
"""
w3 = Web3(ConnectedProvider())
assert w3.isConnected() is True
assert w3.is_connected() is True


def test_isConnected_disconnected():
def test_is_connected_disconnected():
"""
Web3.isConnected() returns False when configured with a provider
Web3.is_connected() returns False when configured with a provider
that's not connected to a node.
"""
w3 = Web3(DisconnectedProvider())
assert w3.isConnected() is False
assert w3.is_connected() is False


def test_autoprovider_detection():
Expand All @@ -50,6 +50,6 @@ def must_not_call():

w3 = Web3(auto)

assert w3.isConnected()
assert w3.is_connected()

assert isinstance(auto._active_provider, ConnectedProvider)
2 changes: 1 addition & 1 deletion tests/core/utilities/test_attach_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_attach_external_modules_multiple_levels_deep(
},
)

assert w3.isConnected()
assert w3.is_connected()

# assert instantiated with default modules
assert hasattr(w3, "geth")
Expand Down
4 changes: 2 additions & 2 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ async def test_eth_gas_price(self, async_w3: "Web3") -> None:
assert gas_price > 0

@pytest.mark.asyncio
async def test_isConnected(self, async_w3: "Web3") -> None:
is_connected = await async_w3.isConnected() # type: ignore
async def test_is_connected(self, async_w3: "Web3") -> None:
is_connected = await async_w3.is_connected() # type: ignore
assert is_connected is True

@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion web3/_utils/module_testing/web3_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,4 @@ def test_solidityKeccak_same_number_of_types_and_values(
w3.solidityKeccak(types, values)

def test_is_connected(self, w3: "Web3") -> None:
assert w3.isConnected()
assert w3.is_connected()
4 changes: 2 additions & 2 deletions web3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ def attach_modules(
"""
_attach_modules(self, modules)

def isConnected(self) -> Union[bool, Coroutine[Any, Any, bool]]:
return self.provider.isConnected()
def is_connected(self) -> Union[bool, Coroutine[Any, Any, bool]]:
return self.provider.is_connected()

def is_encodable(self, _type: TypeStr, value: Any) -> bool:
return self.codec.is_encodable(_type, value)
Expand Down
4 changes: 2 additions & 2 deletions web3/providers/async_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def _generate_request_func(
async def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse:
raise NotImplementedError("Providers must implement this method")

async def isConnected(self) -> bool:
async def is_connected(self) -> bool:
raise NotImplementedError("Providers must implement this method")


Expand All @@ -104,7 +104,7 @@ def decode_rpc_response(self, raw_response: bytes) -> RPCResponse:
text_response = to_text(raw_response)
return cast(RPCResponse, FriendlyJsonSerde().json_decode(text_response))

async def isConnected(self) -> bool:
async def is_connected(self) -> bool:
try:
response = await self.make_request(RPCEndpoint("web3_clientVersion"), [])
except OSError:
Expand Down
6 changes: 3 additions & 3 deletions web3/providers/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse:
except OSError:
return self._proxy_request(method, params, use_cache=False)

def isConnected(self) -> bool:
def is_connected(self) -> bool:
provider = self._get_active_provider(use_cache=True)
return provider is not None and provider.isConnected()
return provider is not None and provider.is_connected()

def _proxy_request(
self, method: RPCEndpoint, params: Any, use_cache: bool = True
Expand All @@ -117,7 +117,7 @@ def _get_active_provider(self, use_cache: bool) -> Optional[BaseProvider]:

for Provider in self._potential_providers:
provider = Provider()
if provider is not None and provider.isConnected():
if provider is not None and provider.is_connected():
self._active_provider = provider
return provider

Expand Down
4 changes: 2 additions & 2 deletions web3/providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _generate_request_func(
def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse:
raise NotImplementedError("Providers must implement this method")

def isConnected(self) -> bool:
def is_connected(self) -> bool:
raise NotImplementedError("Providers must implement this method")


Expand All @@ -104,7 +104,7 @@ def encode_rpc_request(self, method: RPCEndpoint, params: Any) -> bytes:
encoded = FriendlyJsonSerde().json_encode(rpc_dict)
return to_bytes(text=encoded)

def isConnected(self) -> bool:
def is_connected(self) -> bool:
try:
response = self.make_request(RPCEndpoint("web3_clientVersion"), [])
except OSError:
Expand Down
4 changes: 2 additions & 2 deletions web3/providers/eth_tester/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse:
"result": response,
}

async def isConnected(self) -> Literal[True]:
async def is_connected(self) -> Literal[True]:
return True


Expand Down Expand Up @@ -157,5 +157,5 @@ def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse:
"result": response,
}

def isConnected(self) -> Literal[True]:
def is_connected(self) -> Literal[True]:
return True