Skip to content

Commit

Permalink
Add a validator to Distribution.from_name
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jun 23, 2022
1 parent a4ae953 commit 71cec30
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from importlib import import_module
from importlib.abc import MetaPathFinder
from itertools import starmap
from pydantic import Field, validate_arguments
from pydantic.typing import Annotated
from typing import List, Mapping, Optional, Union


Expand Down Expand Up @@ -548,7 +550,8 @@ def locate_file(self, path):
"""

@classmethod
def from_name(cls, name):
@validate_arguments
def from_name(cls, name: Annotated[str, Field(min_length=1)]):
"""Return the Distribution for the given package name.
:param name: The name of the distribution package to search for.
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ python_requires = >=3.7
install_requires =
zipp>=0.5
typing-extensions>=3.6.4; python_version < "3.8"
pydantic

[options.packages.find]
exclude =
Expand Down
2 changes: 0 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re
import json
import pickle
import pytest
import unittest
import warnings
import importlib
Expand Down Expand Up @@ -51,7 +50,6 @@ def test_new_style_classes(self):
self.assertIsInstance(Distribution, type)
self.assertIsInstance(MetadataPathFinder, type)

@pytest.mark.xfail(reason="Not implemented")
@fixtures.parameterize(
dict(name=None),
dict(name=''),
Expand Down

0 comments on commit 71cec30

Please sign in to comment.