Skip to content

Commit

Permalink
Add type hint for create method (#377)
Browse files Browse the repository at this point in the history
Add type hint to create method

Create is an important method. By adding type hinting the workflow is
improved a lot.

Co-authored-by: Christian.Wickboldt <[email protected]>
  • Loading branch information
noootch and Christian.Wickboldt authored Jul 23, 2024
1 parent 1d3608f commit b0218ae
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pylatex/base_classes/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
.. :copyright: (c) 2014 by Jelte Fennema.
:license: MIT, see License for more details.
"""
from __future__ import annotations

from collections import UserList
from contextlib import contextmanager
from typing import TypeVar
from collections.abc import Generator

from pylatex.utils import dumps_list

Expand Down Expand Up @@ -95,7 +98,7 @@ def dumps_packages(self):
return super().dumps_packages()

@contextmanager
def create(self, child):
def create(self, child: T) -> Generator[T, None, None]:
"""Add a LaTeX object to current container, context-manager style.
Args
Expand All @@ -113,6 +116,9 @@ def create(self, child):
self.append(child)


T = TypeVar("T", bound=Container)


class Environment(Container):
r"""A base class for LaTeX environments.
Expand Down

0 comments on commit b0218ae

Please sign in to comment.