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

[Typing][B-92] Add type annotations for python/paddle/batch.py #66295

Merged
merged 12 commits into from
Jul 23, 2024
13 changes: 11 additions & 2 deletions python/paddle/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__all__ = []
from __future__ import annotations

from typing import TYPE_CHECKING, Generator, List, TypeVar

if TYPE_CHECKING:
from types import ModuleType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是干啥用的?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是没有用的,在新的提交中已经将其删除。


T = TypeVar('T')
Caogration marked this conversation as resolved.
Show resolved Hide resolved
__all__ = []

def batch(reader, batch_size, drop_last=False):
def batch(
reader: Generator[T, None, None], batch_size: int, drop_last: bool = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上面定义了 _T,这里肯定也要改啊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

) -> Generator[List[T], None, None]:
Caogration marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reader: Generator[T, None, None], batch_size: int, drop_last: bool = False
) -> Generator[List[T], None, None]:
reader: Callable[[], Generator[_T, None, None]], batch_size: int, drop_last: bool = False
) -> Callable[[], Generator[list[_T], None, None]]:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""
This operator creates a batched reader which combines the data from the
input reader to batched data.
Expand Down