Skip to content
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

Snakecase fromWeb3 #2703

Merged
merged 4 commits into from
Nov 2, 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
4 changes: 2 additions & 2 deletions docs/ens_overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Create an :class:`~ens.ENS` object (named ``ns`` below) in one of three ways:
# Note: This inherits the w3 middlewares from the w3 instance and adds a stalecheck middleware to the middleware onion
from ens import ENS
w3 = Web3(...)
ns = ENS.fromWeb3(w3)
ns = ENS.from_web3(w3)


Asynchronous support is available via the ``AsyncENS`` module:
Expand All @@ -49,7 +49,7 @@ Asynchronous support is available via the ``AsyncENS`` module:

Note that an ``ens`` module instance is also avaliable on the ``w3`` instance.
The first time it's used, Web3.py will create the ``ens`` instance using
``ENS.fromWeb3(w3)`` or ``AsyncENS.fromWeb3(w3)`` as appropriate.
``ENS.from_web3(w3)`` or ``AsyncENS.from_web3(w3)`` as appropriate.

.. code-block:: python

Expand Down
2 changes: 1 addition & 1 deletion ens/async_ens.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(
)

@classmethod
def fromWeb3(cls, w3: "Web3", addr: ChecksumAddress = None) -> "AsyncENS":
def from_web3(cls, w3: "Web3", addr: ChecksumAddress = None) -> "AsyncENS":
"""
Generate an AsyncENS instance with web3

Expand Down
2 changes: 1 addition & 1 deletion ens/ens.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(
)

@classmethod
def fromWeb3(cls, w3: "Web3", addr: ChecksumAddress = None) -> "ENS":
def from_web3(cls, w3: "Web3", addr: ChecksumAddress = None) -> "ENS":
"""
Generate an ENS instance with web3

Expand Down
2 changes: 1 addition & 1 deletion ethpm/backends/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def parse_registry_uri(uri: str) -> RegistryURI:
address_or_ens, chain_id = parsed_uri.netloc.split(":")
else:
address_or_ens, chain_id = parsed_uri.netloc, "1"
ns = ENS.fromWeb3(w3)
ns = ENS.from_web3(w3)
if is_address(address_or_ens):
address = address_or_ens
ens = None
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2703.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Snakecase the fromWeb3 method
4 changes: 2 additions & 2 deletions tests/core/pm-module/test_ens_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def ens_setup(deployer):
ens_contract.functions.setSubnodeOwner(
b"\0" * 32, eth_labelhash, eth_registrar.address
).transact({"from": ens_key})
return ENS.fromWeb3(w3, ens_contract.address)
return ENS.from_web3(w3, ens_contract.address)


@pytest.fixture
Expand All @@ -124,7 +124,7 @@ def test_ens_must_be_set_before_ens_methods_can_be_used(ens):
@pytest.mark.xfail(reason="Need to properly add authorization as of 8/10/2022")
def test_web3_ens(ens):
w3 = ens.w3
ns = ENS.fromWeb3(w3, ens.ens.address)
ns = ENS.from_web3(w3, ens.ens.address)
w3.ens = ns
registry = SimpleRegistry.deploy_new_instance(w3)
w3.ens.setup_address("tester.eth", registry.address)
Expand Down
4 changes: 2 additions & 2 deletions tests/ens/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def ens_setup():
reverse_tld_namehash, w3.keccak(text="addr"), reverse_registrar.address
).transact({"from": ens_key})

return ENS.fromWeb3(w3, ens_contract.address)
return ENS.from_web3(w3, ens_contract.address)


@pytest.fixture()
Expand Down Expand Up @@ -645,7 +645,7 @@ async def async_ens_setup(async_w3):
reverse_tld_namehash, async_w3.keccak(text="addr"), reverse_registrar.address
).transact({"from": ens_key})

return AsyncENS.fromWeb3(async_w3, ens_contract.address)
return AsyncENS.from_web3(async_w3, ens_contract.address)


@pytest_asyncio.fixture
Expand Down
8 changes: 4 additions & 4 deletions tests/ens/test_ens.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
)


def test_fromWeb3_inherits_web3_middlewares(w3):
def test_from_web3_inherits_web3_middlewares(w3):
test_middleware = pythonic_middleware
w3.middleware_onion.add(test_middleware, "test_middleware")

ns = ENS.fromWeb3(w3)
ns = ENS.from_web3(w3)
assert ns.w3.middleware_onion.get("test_middleware") == test_middleware


# -- async -- #


@pytest.mark.asyncio
async def test_async_fromWeb3_inherits_web3_middlewares(async_w3):
async def test_async_from_web3_inherits_web3_middlewares(async_w3):
test_middleware = async_validation_middleware
async_w3.middleware_onion.add(test_middleware, "test_middleware")

ns = AsyncENS.fromWeb3(async_w3)
ns = AsyncENS.from_web3(async_w3)
assert ns.w3.middleware_onion.get("test_middleware") == test_middleware
4 changes: 3 additions & 1 deletion web3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ def is_encodable(self, _type: TypeStr, value: Any) -> bool:
@property
def ens(self) -> Union[ENS, AsyncENS, "Empty"]:
if self._ens is empty:
return AsyncENS.fromWeb3(self) if self.eth.is_async else ENS.fromWeb3(self)
return (
AsyncENS.from_web3(self) if self.eth.is_async else ENS.from_web3(self)
)

return self._ens

Expand Down