Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixed

- Allow `DateTime.astimezone()` to use the local timezone when no timezone argument is supplied, matching `datetime.datetime`.

- Fix valid TOML being rejected when an out-of-order table reopens an implicit super-table with a dotted key: `[a.b.c]` then `[a]` with `b.z = 1` extends the implicit `a.b` super-table rather than redefining it (stdlib `tomllib` accepts it), so it now parses and round-trips instead of raising `Redefinition of an existing table`. The concrete-table case (`[a.b]` then `[a]` `b.z = 1`) stays rejected. ([#565](https://github.com/python-poetry/tomlkit/pull/565))
- Fix appending a key to a parsed inline table that uses `", "` separators emitting a bare `","` for the new entry, leaving the table inconsistently spaced (e.g. `{x = 1, y = 2,z = 3}`). ([#595](https://github.com/python-poetry/tomlkit/pull/595))

Expand Down
12 changes: 12 additions & 0 deletions tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,18 @@ def test_datetimes_behave_like_datetimes(tz_utc: tzinfo, tz_pst: tzinfo) -> None
assert doc.as_string() == "dt = 2018-07-23T12:34:56-05:00"


def test_datetime_astimezone_defaults_to_local_timezone() -> None:
value = parse("time = 1979-05-27T07:32:00Z # birthday\n")["time"]
expected = datetime(1979, 5, 27, 7, 32, tzinfo=timezone.utc).astimezone()

result = value.astimezone()

assert isinstance(result, DateTime)
assert result.unwrap() == expected
assert result.as_string() == expected.isoformat()
assert result == value.astimezone(None)


@pytest.mark.parametrize("fold", [0, 1])
def test_datetime_subtraction_preserves_input_fold(tz_fold: tzinfo, fold: int) -> None:
value = datetime(2018, 11, 4, 1, 30, tzinfo=tz_fold, fold=fold)
Expand Down
2 changes: 1 addition & 1 deletion tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ def __sub__(self, other: timedelta | datetime) -> DateTime | timedelta:
def replace(self, *args: object, **kwargs: object) -> DateTime:
return self._new(super().replace(*args, **kwargs)) # type: ignore[arg-type]

def astimezone(self, tz: tzinfo) -> DateTime: # type: ignore[override]
def astimezone(self, tz: tzinfo | None = None) -> DateTime:
result = super().astimezone(tz)
if PY38:
return result
Expand Down
Loading