Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 3.8 syntax #41

Merged
merged 4 commits into from
Nov 13, 2024
Merged

Remove 3.8 syntax #41

merged 4 commits into from
Nov 13, 2024

Conversation

ChristianGeng
Copy link
Member

@ChristianGeng ChristianGeng commented Nov 12, 2024

Closes #40

Summary by Sourcery

Update type annotations across the codebase to use Python 3.9+ syntax, replacing 'typing.Union' with the '|' operator and updating sequence types to use 'collections.abc'. Adjust the project configuration to require Python 3.9 or higher.

Enhancements:

  • Replace usage of 'typing.Union' with the more concise '|' operator for type annotations, improving code readability and aligning with Python 3.9+ syntax.
  • Update type annotations to use 'collections.abc' for sequence types, enhancing code clarity and consistency.

Build:

  • Update 'pyproject.toml' to require Python 3.9 or higher, ensuring compatibility with the new type annotation syntax.

Copy link

sourcery-ai bot commented Nov 12, 2024

Reviewer's Guide by Sourcery

This PR updates the type hint syntax throughout the codebase to use the new Python 3.9+ pipe operator syntax (|) instead of typing.Union. It also adds collections.abc imports to replace typing.Sequence and other typing collection types.

Class diagram for updated type hints

classDiagram
    class Base {
        +__init__(bypass_prob: float | observe.Base, unit: str, preserve_level: bool | observe.Base, aux: str | observe.Base | np.ndarray | Base, transform: Base, num_repeat: int)
    }

    class AMRNB {
        +__init__(bit_rate: int | observe.Base, dtx: bool | observe.Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class Append {
        +__init__(aux: str | observe.Base | np.ndarray | Base, read_pos_aux: int | float | observe.Base | Time, read_dur_aux: int | float | observe.Base | Time, unit: str, transform: Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class AppendValue {
        +__init__(duration: int | float | observe.Base | Time, value: float | observe.Base, unit: str, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class BabbleNoise {
        +__init__(speech: collections.abc.Sequence[str | np.ndarray], num_speakers: int | observe.Base, gain_db: float | observe.Base, snr_db: float | observe.Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class BandPass {
        +__init__(center: float | observe.Base, bandwidth: float | observe.Base, order: int | observe.Base, design: str, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class BandStop {
        +__init__(center: float | observe.Base, bandwidth: float | observe.Base, order: int | observe.Base, design: str, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class Clip {
        +__init__(threshold: float | observe.Base, soft: bool | observe.Base, normalize: bool | observe.Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class ClipByRatio {
        +__init__(ratio: float | observe.Base, soft: bool | observe.Base, normalize: bool | observe.Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class Compose {
        +__init__(transforms: collections.abc.Sequence[observe.Base], preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class CompressDynamicRange {
        +__init__(threshold_db: float | observe.Base, ratio: float | observe.Base, attack_time: float | observe.Base, release_time: float | observe.Base, knee_radius_db: float | observe.Base, makeup_db: None | float | observe.Base, clip: bool | observe.Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class Fade {
        +__init__(in_dur: int | float | observe.Base | Time, out_dur: int | float | observe.Base | Time, in_shape: str, out_shape: str, in_db: float, out_db: float, unit: str, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class FFTConvolve {
        +__init__(aux: str | observe.Base | np.ndarray | Base, keep_tail: bool | observe.Base, transform: Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class GainStage {
        +__init__(gain_db: float | observe.Base, max_peak_db: float | observe.Base, clip: bool | observe.Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class HighPass {
        +__init__(cutoff: float | observe.Base, order: int | observe.Base, design: str, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class LowPass {
        +__init__(cutoff: float | observe.Base, order: int | observe.Base, design: str, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class Mix {
        +__init__(aux: str | observe.Base | np.ndarray | Base, gain_base_db: float | observe.Base, gain_aux_db: float | observe.Base, snr_db: float | observe.Base, write_pos_base: int | float | observe.Base | Time, read_pos_aux: int | float | observe.Base | Time, read_dur_aux: int | float | observe.Base | Time, clip_mix: bool | observe.Base, loop_aux: bool | observe.Base, extend_base: bool | observe.Base, num_repeat: int | observe.Base, unit: str, transform: Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class NormalizeByPeak {
        +__init__(peak_db: float | observe.Base, clip: bool | observe.Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class PinkNoise {
        +__init__(gain_db: float | observe.Base, snr_db: float | observe.Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class Prepend {
        +__init__(aux: str | observe.Base | np.ndarray | Base, read_pos_aux: int | float | observe.Base | Time, read_dur_aux: int | float | observe.Base | Time, unit: str, transform: Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class PrependValue {
        +__init__(duration: int | float | observe.Base | Time, value: float | observe.Base, unit: str, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class Resample {
        +__init__(target_rate: int | observe.List, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class Select {
        +__init__(transforms: collections.abc.Sequence[Base], preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class Shift {
        +__init__(duration: int | float | observe.Base | Time, unit: str, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class Tone {
        +__init__(freq: float | observe.Base, gain_db: float | observe.Base, snr_db: float | observe.Base, shape: str | observe.Base, lfo_rate: float | observe.Base, lfo_range: float | observe.Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class Trim {
        +__init__(start_pos: int | float | observe.Base | Time, end_pos: int | float | observe.Base | Time, duration: int | float | observe.Base | Time, fill: str, fill_pos: str, unit: str, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class WhiteNoiseGaussian {
        +__init__(gain_db: float | observe.Base, snr_db: float | observe.Base, stddev: float | observe.Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class WhiteNoiseUniform {
        +__init__(gain_db: float | observe.Base, snr_db: float | observe.Base, preserve_level: bool | observe.Base, bypass_prob: float | observe.Base)
    }

    class ArrayResolver {
        +decode(value: object) object
        +encode(value: object) object
    }

    class ObservableListResolver {
        +decode(value: object) object
        +encode(value: collections.abc.MutableSequence[object]) object
    }

    class List {
        +__init__(elements: collections.abc.MutableSequence[object], shuffle: bool, draw: bool)
        +_draw() object
        +_next() object
        +__call__() object
    }

    class Interface {
        +__init__(sampling_rate: int, resample: bool, channels: int | collections.abc.Sequence[int], mixdown: bool, keep_nat: bool, num_workers: int | None, multiprocessing: bool, seed: int, verbose: bool)
        +augment(data: pd.Index | pd.Series | pd.DataFrame, cache_root: str, data_root: str, modified_only: bool, num_variants: int, force: bool) pd.Index | pd.Series | pd.DataFrame
    }

    class Utils {
        +from_db(x_db: float | observe.Base) float
        +to_db(x: float | observe.Base) float
        +to_samples(value: int | float | observe.Base | time.Time, sampling_rate: int, length: int)
    }

    class Time {
        +__init__(value: int | float | observe.Base, unit: str)
    }
Loading

File-Level Changes

Change Details Files
Updated type hint syntax to use Python 3.9+ pipe operator
  • Replaced typing.Union[T1, T2] with T1
T2 syntax
  • Added Python version requirement >=3.9 in pyproject.toml
  • Removed unused typing imports
  • Updated collection type hints to use collections.abc
    • Replaced typing.Sequence with collections.abc.Sequence
    • Replaced typing.MutableSequence with collections.abc.MutableSequence
    • Replaced typing.Any with object type
    auglib/core/resolver.py
    auglib/core/observe.py
    auglib/core/interface.py

    Assessment against linked issues

    Issue Objective Addressed Explanation
    #40 Remove use of Union type hints from typing module
    #40 Replace Union type hints with syntax (Python 3.9+)
    #40 Add requires-python = '>=3.9' to pyproject.toml

    Possibly linked issues


    Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time. You can also use
      this command to specify where the summary should be inserted.

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    Copy link

    @sourcery-ai sourcery-ai bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Hey @ChristianGeng - I've reviewed your changes - here's some feedback:

    Overall Comments:

    • The PR uses the | union operator syntax which requires Python 3.10+, but pyproject.toml specifies Python >=3.9. This will cause errors for users on Python 3.9. Either keep using typing.Union for 3.9 compatibility or update the Python requirement to >=3.10.
    Here's what I looked at during the review
    • 🟡 General issues: 1 issue found
    • 🟢 Security: all looks good
    • 🟢 Testing: all looks good
    • 🟢 Complexity: all looks good
    • 🟢 Documentation: all looks good

    Sourcery is free for open source - if you like our reviews please consider sharing them ✨
    Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

    auglib/core/transform.py Outdated Show resolved Hide resolved
    auglib/core/interface.py Show resolved Hide resolved
    Copy link

    codecov bot commented Nov 12, 2024

    Codecov Report

    All modified and coverable lines are covered by tests ✅

    Project coverage is 100.0%. Comparing base (ae5b35c) to head (2e868fc).
    Report is 1 commits behind head on main.

    Additional details and impacted files
    Files with missing lines Coverage Δ
    auglib/core/interface.py 100.0% <100.0%> (ø)
    auglib/core/observe.py 100.0% <100.0%> (ø)
    auglib/core/resolver.py 100.0% <100.0%> (ø)
    auglib/core/time.py 100.0% <100.0%> (ø)
    auglib/core/transform.py 100.0% <100.0%> (ø)
    auglib/core/utils.py 100.0% <100.0%> (ø)

    @ChristianGeng
    Copy link
    Member Author

    Hey @ChristianGeng - I've reviewed your changes - here's some feedback:

    Overall Comments:

    • The PR uses the | union operator syntax which requires Python 3.10+, but pyproject.toml specifies Python >=3.9. This will cause errors for users on Python 3.9. Either keep using typing.Union for 3.9 compatibility or update the Python requirement to >=3.10.

    Here's what I looked at during the review

    • 🟡 General issues: 1 issue found
    • 🟢 Security: all looks good
    • 🟢 Testing: all looks good
    • 🟢 Complexity: all looks good
    • 🟢 Documentation: all looks good

    Sourcery is free for open source - if you like our reviews please consider sharing them ✨

    Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

    I am not so sure. Can this not be fetched from future like having the following in the first line of code?

    from __future__ import annotations
    

    @ChristianGeng ChristianGeng self-assigned this Nov 12, 2024
    @ChristianGeng ChristianGeng requested a review from hagenw November 12, 2024 12:11
    Copy link
    Member

    @hagenw hagenw left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Great, beside my single comment, it all looks good.

    auglib/core/transform.py Outdated Show resolved Hide resolved
    @ChristianGeng ChristianGeng merged commit b26e916 into main Nov 13, 2024
    9 checks passed
    @ChristianGeng ChristianGeng deleted the remove-3.8-syntax branch November 13, 2024 08:56
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    Title: Remove Python 3.8 Language Constructs from Files
    2 participants