Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ on:

concurrency:
group: tag-and-release-${{ github.ref }}
cancel-in-progress: true
cancel-in-progress:
${{ ! startsWith(github.event.head_commit.message, 'bump:') }}

jobs:
black:
Expand All @@ -35,7 +36,7 @@ jobs:

release:
needs: test
if: ${{ !startsWith(github.event.head_commit.message, 'bump:') }}
if: ${{ ! startsWith(github.event.head_commit.message, 'bump:') }}
# Don't run 'bump:'
permissions:
contents: write
Expand Down
26 changes: 13 additions & 13 deletions src/cmudict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import re
from contextlib import ExitStack
from importlib import metadata, resources
from typing import IO, Dict, List, Optional, Tuple
from typing import IO, Dict, Optional

__version__ = metadata.version(__name__)

Expand All @@ -34,7 +34,7 @@ def _string(resource_name: str) -> str:

def _entries(
stream: IO[bytes], comment_string: Optional[str] = None
) -> List[Tuple[str, List[str]]]:
) -> list[tuple[str, list[str]]]:
cmudict_entries = []
for line in stream:
parts = []
Expand All @@ -48,13 +48,13 @@ def _entries(


# pylint: disable-next=redefined-builtin
def dict() -> Dict[str, List[List[str]]]:
def dict() -> Dict[str, list[list[str]]]:
"""
Compatibility with NLTK.
Returns the cmudict lexicon as a dictionary, whose keys are
lowercase words and whose values are lists of pronunciations.
"""
default: Dict[str, List[List[str]]] = {}
default: Dict[str, list[list[str]]] = {}
for key, value in entries():
if key not in default:
default[key] = []
Expand All @@ -80,9 +80,9 @@ def license_string() -> str:
return string


def phones() -> List[Tuple[str, List[str]]]:
def phones() -> list[tuple[str, list[str]]]:
"""Return a list of phones used in the main dict."""
cmu_phones: List[Tuple[str, List[str]]] = []
cmu_phones: list[tuple[str, list[str]]] = []
for line in phones_stream():
parts = line.decode("utf-8").strip().split()
cmu_phones.append((parts[0], parts[1:]))
Expand All @@ -101,9 +101,9 @@ def phones_string() -> str:
return string


def symbols() -> List[str]:
def symbols() -> list[str]:
"""Return a list of symbols."""
cmu_symbols: List[str] = []
cmu_symbols: list[str] = []
for line in symbols_stream():
cmu_symbols.append(line.decode("utf-8").strip())
return cmu_symbols
Expand All @@ -122,9 +122,9 @@ def symbols_string() -> str:


# pylint: disable-next=invalid-name
def vp() -> Dict[str, List[List[str]]]:
def vp() -> Dict[str, list[list[str]]]:
"""Return a list of punctuation pronounciations."""
cmu_vp: Dict[str, List[List[str]]] = {}
cmu_vp: Dict[str, list[list[str]]] = {}
with vp_stream() as stream:
for key, value in _entries(stream):
if not key in cmu_vp:
Expand All @@ -147,14 +147,14 @@ def vp_string() -> str:

# The .entries(), .raw(), and .words() functions
# maintain compatability with NTLK.
def entries() -> List[Tuple[str, List[str]]]:
def entries() -> list[tuple[str, list[str]]]:
"""
Compatibility with NLTK.
Returns the cmudict lexicon as a list of entries
containing (word, transcriptions) tuples.
"""
with dict_stream() as stream:
cmu_entries: List[Tuple[str, List[str]]] = _entries(stream, "#")
cmu_entries: list[tuple[str, list[str]]] = _entries(stream, "#")
return cmu_entries


Expand All @@ -167,7 +167,7 @@ def raw() -> str:
return string


def words() -> List[str]:
def words() -> list[str]:
"""
Compatibility with NLTK.
Returns a list of all words defined in the cmudict lexicon.
Expand Down