Skip to content

Commit

Permalink
Remove unecessary typing fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed May 7, 2024
1 parent 034a1f0 commit 08d6862
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 47 deletions.
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ python_requires = >=3.8
# new major versions. This works if the required packages follow Semantic Versioning.
# For more information, check out https://semver.org/.
install_requires =
importlib-metadata; python_version<"3.8"
importlib-resources; python_version<"3.7"
fastjsonschema>=2.16.2,<=3


Expand Down
8 changes: 1 addition & 7 deletions src/validate_pyproject/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import sys

if sys.version_info[:2] >= (3, 8):
# TODO: Import directly (no need for conditional) when `python_requires = >= 3.8`
from importlib.metadata import PackageNotFoundError, version # pragma: no cover
else:
from importlib_metadata import PackageNotFoundError, version # pragma: no cover
from importlib.metadata import PackageNotFoundError, version # pragma: no cover

try:
# Change here if project is renamed and does not equal the package name
Expand Down
6 changes: 1 addition & 5 deletions src/validate_pyproject/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import json
import logging
import sys
import typing
from enum import Enum
from functools import partial, reduce
Expand Down Expand Up @@ -35,10 +34,7 @@


try: # pragma: no cover
if sys.version_info[:2] < (3, 7) or typing.TYPE_CHECKING: # See #22
from importlib_resources import files
else:
from importlib.resources import files
from importlib.resources import files

def read_text(package: Union[str, ModuleType], resource: str) -> str:
""":meta private:"""
Expand Down
24 changes: 6 additions & 18 deletions src/validate_pyproject/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,14 @@
.. _entry point: https://setuptools.readthedocs.io/en/latest/userguide/entry_point.html
"""

import sys
import typing
from importlib.metadata import EntryPoint, entry_points
from string import Template
from textwrap import dedent
from typing import Any, Callable, Iterable, List, Optional
from typing import Any, Callable, Iterable, List, Optional, Protocol

from .. import __version__

if sys.version_info[:2] >= (3, 8): # pragma: no cover
# TODO: Import directly (no need for conditional) when `python_requires = >= 3.8`
from importlib.metadata import EntryPoint, entry_points
else: # pragma: no cover
from importlib_metadata import EntryPoint, entry_points

if typing.TYPE_CHECKING:
from typing import Protocol

from ..types import Plugin, Schema
else:
Protocol = object
from ..types import Plugin, Schema

ENTRYPOINT_GROUP = "validate_pyproject.tool_schema"

Expand All @@ -37,7 +25,7 @@ def id(self) -> str: ...
def tool(self) -> str: ...

@property
def schema(self) -> "Schema": ...
def schema(self) -> Schema: ...

@property
def help_text(self) -> str: ...
Expand All @@ -47,7 +35,7 @@ def fragment(self) -> str: ...


class PluginWrapper:
def __init__(self, tool: str, load_fn: "Plugin"):
def __init__(self, tool: str, load_fn: Plugin):
self._tool = tool
self._load_fn = load_fn

Expand All @@ -60,7 +48,7 @@ def tool(self) -> str:
return self._tool

@property
def schema(self) -> "Schema":
def schema(self) -> Schema:
return self._load_fn(self.tool)

@property
Expand Down
7 changes: 1 addition & 6 deletions src/validate_pyproject/pre_compile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os
import sys
from importlib import metadata as _M
from pathlib import Path
from types import MappingProxyType
from typing import TYPE_CHECKING, Dict, Mapping, Optional, Sequence, Union
Expand All @@ -9,11 +9,6 @@

from .. import api, dist_name, types

if sys.version_info[:2] >= (3, 8): # pragma: no cover
from importlib import metadata as _M
else: # pragma: no cover
import importlib_metadata as _M

if TYPE_CHECKING: # pragma: no cover
from ..plugins import PluginProtocol

Expand Down
10 changes: 1 addition & 9 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# The code in this module is mostly borrowed/adapted from PyScaffold and was originally
# published under the MIT license
# The original PyScaffold license can be found in 'NOTICE.txt'

import sys
from importlib.metadata import EntryPoint # pragma: no cover

import pytest

Expand All @@ -15,13 +14,6 @@
)


if sys.version_info[:2] >= (3, 8):
# TODO: Import directly (no need for conditional) when `python_requires = >= 3.8`
from importlib.metadata import EntryPoint # pragma: no cover
else:
from importlib_metadata import EntryPoint # pragma: no cover


def test_load_from_entry_point__error():
# This module does not exist, so Python will have some trouble loading it
# EntryPoint(name, value, group)
Expand Down

0 comments on commit 08d6862

Please sign in to comment.