Skip to content

Commit ef3a765

Browse files
committed
fix: lints
1 parent aaec1a6 commit ef3a765

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/firebase_functions/logger.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Logger module for Firebase Functions.
3+
"""
4+
15
import enum as _enum
26
import json as _json
37
import sys as _sys
@@ -7,7 +11,8 @@
711

812
class LogSeverity(str, _enum.Enum):
913
"""
10-
`LogSeverity` indicates the detailed severity of the log entry. See [LogSeverity](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity).
14+
`LogSeverity` indicates the detailed severity of the log entry. See
15+
[LogSeverity](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity).
1116
"""
1217

1318
DEBUG = "DEBUG"
@@ -45,12 +50,15 @@ def _entry_from_args(severity: LogSeverity, **kwargs) -> LogEntry:
4550
return {"severity": severity, "message": message}
4651

4752

48-
def _remove_circular(obj: _typing.Any, refs: _typing.Set[_typing.Any] = set()):
53+
def _remove_circular(obj: _typing.Any, refs: _typing.Set[_typing.Any] | None = None):
4954
"""
5055
Removes circular references from the given object and replaces them with "[CIRCULAR]".
5156
"""
5257

53-
if (id(obj) in refs):
58+
if refs is None:
59+
refs = set()
60+
61+
if id(obj) in refs:
5462
return "[CIRCULAR]"
5563

5664
if not isinstance(obj, (str, int, float, bool, type(None))):
@@ -74,7 +82,7 @@ def _get_write_file(severity: LogSeverity) -> _typing.TextIO:
7482

7583

7684
def write(entry: LogEntry) -> None:
77-
write_file = _get_write_file(entry['severity'])
85+
write_file = _get_write_file(entry["severity"])
7886
print(_json.dumps(_remove_circular(entry)), file=write_file)
7987

8088

tests/test_logger.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
"""
2+
Logger module tests.
3+
"""
4+
15
import pytest
26
import json
37
from firebase_functions import logger
48

59

610
class TestLogger:
11+
"""
12+
Tests for the logger module.
13+
"""
714
def test_format_should_be_valid_json(self, capsys: pytest.CaptureFixture[str]):
815
logger.log(foo="bar")
916
raw_log_output = capsys.readouterr().out

0 commit comments

Comments
 (0)