Skip to content

Commit

Permalink
Use typing.NamedTuple instead of collections.namedtuple
Browse files Browse the repository at this point in the history
Inheriting from `typing.NamedTuple` creates a custom `tuple` subclass
in the same way as using the `collections.namedtuple` factory function.
However, using `typing.NamedTuple` allows you to provide a type annotation
for each field in the class.
  • Loading branch information
DimitriPapadopoulos committed Aug 4, 2024
1 parent 3bfc5b0 commit 603f94a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions tests/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.

import collections
import itertools
import os
import platform
import sys
from typing import cast
from typing import NamedTuple, cast
from unittest import mock

import pytest
Expand Down Expand Up @@ -94,7 +93,7 @@ def test_allows_prerelease(self):
)


FakeVersionInfo = collections.namedtuple(
FakeVersionInfo = NamedTuple(
"FakeVersionInfo", ["major", "minor", "micro", "releaselevel", "serial"]
)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_musllinux.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import collections
import pathlib
import subprocess
from typing import NamedTuple

import pretend
import pytest
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_parse_musl_version(output, version):
)
def test_get_musl_version(monkeypatch, executable, output, version, ld_musl):
def mock_run(*args, **kwargs):
return collections.namedtuple("Proc", "stderr")(output)
return NamedTuple("Proc", "stderr")(output)

run_recorder = pretend.call_recorder(mock_run)
monkeypatch.setattr(_musllinux.subprocess, "run", run_recorder)
Expand Down

0 comments on commit 603f94a

Please sign in to comment.