Skip to content

Commit

Permalink
NamedTuple → dataclass
Browse files Browse the repository at this point in the history
Helps maintainability. For example, it can help use mutable default values
during class initialisation.
  • Loading branch information
DimitriPapadopoulos committed May 18, 2024
1 parent 2970397 commit e781452
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/pipx/package_specifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import logging
import re
import urllib.parse
from dataclasses import dataclass
from pathlib import Path
from typing import List, NamedTuple, Optional, Set, Tuple
from typing import List, Optional, Set, Tuple

from packaging.requirements import InvalidRequirement, Requirement
from packaging.specifiers import SpecifierSet
Expand All @@ -24,7 +25,8 @@
ARCHIVE_EXTENSIONS = (".whl", ".tar.gz", ".zip")


class ParsedPackage(NamedTuple):
@dataclass(frozen=True)
class ParsedPackage:
valid_pep508: Optional[Requirement]
valid_url: Optional[str]
valid_local_path: Optional[str]
Expand Down
5 changes: 3 additions & 2 deletions src/pipx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import subprocess
import sys
import textwrap
from dataclasses import dataclass
from pathlib import Path
from typing import (
Any,
Dict,
List,
NamedTuple,
NoReturn,
Optional,
Pattern,
Expand All @@ -36,7 +36,8 @@ def __init__(self, message: str, wrap_message: bool = True):
super().__init__(message)


class RelevantSearch(NamedTuple):
@dataclass(frozen=True)
class RelevantSearch:
pattern: Pattern[str]
category: str

Expand Down

0 comments on commit e781452

Please sign in to comment.