Skip to content

Commit

Permalink
fix: replace deprecated package with Python 3.13 deprecated decorator (
Browse files Browse the repository at this point in the history
…#537)

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii authored Nov 21, 2023
1 parent 791d652 commit 20d7430
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:

- name: Test docstrings with doctest
if: "runner.os == 'Linux' && matrix.python-version == 3.11"
run: python -m pytest --doctest-modules src/particle --ignore-glob="src/particle/particle/convert.py"
run: python -m pytest --doctest-modules src/particle --ignore=src/particle/particle/convert.py

notebooks:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repos:
hooks:
- id: mypy
files: src
additional_dependencies: [attrs==21.4.0, hepunits>=2.2.0, importlib_resources, types-deprecated]
additional_dependencies: [attrs==21.4.0, hepunits>=2.2.0, importlib_resources]
args: [--show-error-codes]

- repo: https://github.com/codespell-project/codespell
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ dependencies = [
"attrs>=19.2",
"hepunits>=2.0.0",
"importlib-resources>=2.0;python_version<\"3.9\"",
"typing-extensions;python_version<\"3.8\"",
"deprecated"
"typing-extensions>=4.5;python_version<\"3.13\"",
]
dynamic = ["version"]

Expand Down
Empty file.
28 changes: 28 additions & 0 deletions src/particle/_compat/typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2018-2023, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.


from __future__ import annotations

import sys

if sys.version_info < (3, 8):
from typing_extensions import Protocol, runtime_checkable
else:
from typing import Protocol, runtime_checkable

if sys.version_info < (3, 9):
from importlib_resources.abc import Traversable
elif sys.version_info < (3, 11):
from importlib.abc import Traversable
else:
from importlib.resources.abc import Traversable


__all__ = (
"Protocol",
"runtime_checkable",
"Traversable",
)
10 changes: 10 additions & 0 deletions src/particle/_compat/warnings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import annotations

import sys

if sys.version_info < (3, 13):
from typing_extensions import deprecated
else:
from warnings import deprecated

__all__ = ["deprecated"]
3 changes: 2 additions & 1 deletion src/particle/particle/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@
import pandas as pd

from .. import data
from .._compat.typing import Traversable
from ..pdgid import PDGID, is_baryon
from ..typing import StringOrIO, Traversable
from ..typing import StringOrIO
from .enums import (
Charge,
Charge_mapping,
Expand Down
11 changes: 5 additions & 6 deletions src/particle/particle/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

# External dependencies
import attr
from deprecated import deprecated
from hepunits.constants import c_light

from .. import data
from .._compat.typing import Traversable
from .._compat.warnings import deprecated
from ..converters.evtgen import EvtGenName2PDGIDBiMap
from ..pdgid import PDGID, is_valid
from ..pdgid.functions import Location, _digit
from ..typing import HasOpen, HasRead, StringOrIO, Traversable
from ..typing import HasOpen, HasRead, StringOrIO
from .enums import (
Charge,
Charge_mapping,
Expand Down Expand Up @@ -1240,8 +1241,7 @@ def findall(

@classmethod
@deprecated(
version="0.22",
reason="This method is deprecated and will be removed from version 0.23.0. Use finditer or findall instead.",
"This method is deprecated and will be removed from version 0.23.0. Use finditer or findall instead.",
)
def from_string(cls: type[Self], name: str) -> Self:
"Get a particle from a PDG style name - returns the best match."
Expand All @@ -1252,8 +1252,7 @@ def from_string(cls: type[Self], name: str) -> Self:

@classmethod
@deprecated(
version="0.22",
reason="This method is deprecated and will be removed from version 0.23.0. Use finditer or findall instead.",
"This method is deprecated and will be removed from version 0.23.0. Use finditer or findall instead.",
)
def from_string_list(cls: type[Self], name: str) -> list[Self]:
"Get a list of particles from a PDG style name."
Expand Down
15 changes: 1 addition & 14 deletions src/particle/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,11 @@

from __future__ import annotations

import sys
from typing import Any, TextIO, Union

if sys.version_info < (3, 8):
from typing_extensions import Protocol, runtime_checkable
else:
from typing import Protocol, runtime_checkable

if sys.version_info < (3, 9):
from importlib_resources.abc import Traversable
else:
from importlib.abc import Traversable

from ._compat.typing import Protocol, Traversable, runtime_checkable

__all__ = (
"Protocol",
"runtime_checkable",
"Traversable",
"StringOrIO",
"HasOpen",
"HasRead",
Expand Down

0 comments on commit 20d7430

Please sign in to comment.