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

linkcheck: constrain status code types to LiteralString #13039

Conversation

jayaddison
Copy link
Contributor

Feature or Bugfix

  • Refactoring

Purpose

  • Begin adding some code-symbol safety measures around the use of status codes in the linkcheck builder.
  • Prepares for a subsequent refactor to use a StrEnum (Py3.11+) to declare the available status codes.

Detail

  • Add LiteralString typing to status code variables.

Relates

@AA-Turner
Copy link
Member

Why LiteralString over Literal[...]?

@jayaddison
Copy link
Contributor Author

Ah; to be honest, I'd forgotten about Literal and didn't notice it despite double-checking some usage details for LiteralString (which is what I misread your suggestion to be..).

Assuming that I had opened a PR with the intended change instead, using Literal[...]: that would be a nice low-overhead type safety mechanism, but wouldn't provide much runtime assurance, if I understand it correctly. Additionally, the diff from here to StrEnum introduction might be slightly unusual -- it would involve complete replacement of the Literal-based type alias approach with a StrEnum alternative (that does provide runtime safety).

@jayaddison
Copy link
Contributor Author

Note: from a readability point of view, I do find the dotted-attribute format (for example, LinkStatus.WORKING) an improvement, so I would like to migrate to StrEnum.

(the reason I mention this is because Literal[...] almost seems like it could solve my refactoring goals entirely, without using StrEnum at all.. except that I don't think standalone constants are ideal; grouping them logically within a parent container is helpful, I think)

@jayaddison
Copy link
Contributor Author

Superseded by #13040.

@jayaddison jayaddison closed this Oct 19, 2024
@jayaddison jayaddison deleted the refactor/1-of-3-linkcheck-status-code-literals branch October 19, 2024 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants