Skip to content

Commit 46bf316

Browse files
committed
Add type annotations for neo4j.
1 parent bf6ff4b commit 46bf316

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

neo4j/testcontainers/neo4j/__init__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import os
1515

16-
from neo4j import GraphDatabase
16+
from neo4j import Driver, GraphDatabase
1717

1818
from testcontainers.core.generic import DbContainer
1919
from testcontainers.core.waiting_utils import wait_container_is_ready, wait_for_logs
@@ -38,37 +38,33 @@ class Neo4jContainer(DbContainer):
3838

3939
# The official image requires a change of password on startup.
4040
NEO4J_ADMIN_PASSWORD = os.environ.get("NEO4J_ADMIN_PASSWORD", "password")
41-
4241
# Default port for the binary Bolt protocol.
4342
DEFAULT_BOLT_PORT = 7687
44-
4543
AUTH_FORMAT = "neo4j/{password}"
46-
4744
NEO4J_STARTUP_TIMEOUT_SECONDS = 10
48-
4945
NEO4J_USER = "neo4j"
5046

51-
def __init__(self, image="neo4j:latest", **kwargs):
47+
def __init__(self, image: str = "neo4j:latest", **kwargs) -> None:
5248
super(Neo4jContainer, self).__init__(image, **kwargs)
5349
self.bolt_port = Neo4jContainer.DEFAULT_BOLT_PORT
5450
self.with_exposed_ports(self.bolt_port)
5551
self._driver = None
5652

57-
def _configure(self):
53+
def _configure(self) -> None:
5854
self.with_env(
5955
"NEO4J_AUTH",
6056
Neo4jContainer.AUTH_FORMAT.format(password=Neo4jContainer.NEO4J_ADMIN_PASSWORD)
6157
)
6258

63-
def get_connection_url(self):
59+
def get_connection_url(self) -> str:
6460
return "{dialect}://{host}:{port}".format(
6561
dialect="bolt",
6662
host=self.get_container_host_ip(),
6763
port=self.get_exposed_port(self.bolt_port),
6864
)
6965

7066
@wait_container_is_ready()
71-
def _connect(self):
67+
def _connect(self) -> None:
7268
# First we wait for Neo4j to say it's listening
7369
wait_for_logs(
7470
self,
@@ -83,7 +79,7 @@ def _connect(self):
8379
with driver.session() as session:
8480
session.run("RETURN 1").single()
8581

86-
def get_driver(self, **kwargs):
82+
def get_driver(self, **kwargs) -> Driver:
8783
return GraphDatabase.driver(
8884
self.get_connection_url(),
8985
auth=(Neo4jContainer.NEO4J_USER, Neo4jContainer.NEO4J_ADMIN_PASSWORD),

0 commit comments

Comments
 (0)