Skip to content

Commit 1f456e3

Browse files
committed
Add the npfl138.first_time method.
1 parent e947b0b commit 1f456e3

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

labs/npfl138/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from . import rl_utils
2525

2626
# Utils
27+
from .first_time import first_time
2728
from .initializers_override import global_keras_initializers
2829
from .startup import startup
2930
from .version import __version__, require_version

labs/npfl138/docs/utilities.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
The `npfl138` package also provides a few utilities for startup initialization,
44
parameter initialization override, and for version management.
55

6-
::: npfl138.startup.startup
6+
::: npfl138.first_time.first_time
77
options:
8-
heading: npfl138.startup
8+
heading: npfl138.first_time
99

1010
::: npfl138.global_keras_initializers
1111

@@ -15,4 +15,8 @@ parameter initialization override, and for version management.
1515
options:
1616
show_root_members_full_path: true
1717

18+
::: npfl138.startup.startup
19+
options:
20+
heading: npfl138.startup
21+
1822
::: npfl138.__version__

labs/npfl138/first_time.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file is part of NPFL138 <http://github.com/ufal/npfl138/>.
2+
#
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
seen_tags: set[str] = set()
8+
9+
10+
def first_time(tag: str) -> bool:
11+
"""Returns `True` when first called with the given `tag`."""
12+
if tag in seen_tags:
13+
return False
14+
15+
seen_tags.add(tag)
16+
return True

0 commit comments

Comments
 (0)