Skip to content

Add type hints to pancake_sort function - #15122

Closed
villenaderic wants to merge 2 commits into
TheAlgorithms:masterfrom
villenaderic:add-type-hints-pancake-sort
Closed

Add type hints to pancake_sort function#15122
villenaderic wants to merge 2 commits into
TheAlgorithms:masterfrom
villenaderic:add-type-hints-pancake-sort

Conversation

@villenaderic

@villenaderic villenaderic commented Aug 30, 2026

Copy link
Copy Markdown

Describe your change:

Added type hints to the pancake_sort function's parameter and return value, as requested in the linked issue.

Fixes #14737

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes add type hints to pancake_sort function #14737".

@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Aug 30, 2026
Comment thread sorts/pancake_sort.py Outdated


def pancake_sort(arr):
def pancake_sort(arr: list[int]) -> list[int]:

@cclauss cclauss Aug 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would arr="Python" fail?!? arr=[1.5, 1.3, 1.0]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch floats should be supported since the docstring says "comparable items," not just ints. I have updated it to use a generic type parameter (def pancake_sort[T: (int, float)](arr: list[T]) -> list[T]) so it correctly supports both, and mypy/ruff both pass now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@cclauss cclauss closed this Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add type hints to pancake_sort function

2 participants