8000 Add a validator to Distribution.from_name · python/importlib_metadata@f905645 · GitHub
[go: up one dir, main page]

Skip to content

Commit f905645

Browse files
committed
Add a validator to Distribution.from_name
1 parent 2fe689e commit f905645

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

importlib_metadata/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
from importlib import import_module
3030
from importlib.abc import MetaPathFinder
3131
from itertools import starmap
32+
from pydantic import Field, validate_arguments
33+
from pydantic.typing import Annotated
3234
from typing import List, Mapping, Optional, Union
3335

3436

@@ -548,7 +550,8 @@ def locate_file(self, path):
548550
"""
549551

550552
@classmethod
551-
def from_name(cls, name):
553+
@validate_arguments
554+
def from_name(cls, name: Annotated[str, Field(min_length=1)]):
552555
"""Return the Distribution for the given package name.
553556
554557
:param name: The name of the distribution package to search for.

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ python_requires = >=3.7
1919
install_requires =
2020
zipp>=0.5
2121
typing-extensions>=3.6.4; python_version < "3.8"
22+
pydantic
2223

2324
[options.packages.find]
2425
exclude =

tests/test_main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
22
import json
33
import pickle
4-
import pytest
54
import unittest
65
import warnings
76
import importlib
@@ -51,7 +50,6 @@ def test_new_style_classes(self):
5150
self.assertIsInstance(Distribution, type)
5251
self.assertIsInstance(MetadataPathFinder, type)
5352

54-
@pytest.mark.xfail(reason="Not implemented")
5553
@fixtures.parameterize(
5654
dict(name=None),
5755
dict(name=''),

0 commit comments

Comments
 (0)
0