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

Replace sentinel value with an enumerator. #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

noenandre
Copy link

Issue type
  • Feature
Summary

Replace XML_PARSER_DOM and XML_PARSER_SAX with an enumerator.
If this is not a perfect use case for a enum class, I don't what is.

@phibos
Copy link
Member

phibos commented Dec 10, 2021

Looks like this would break backward compatibility. Are there any advantages besides the improved code completion?

@phibos phibos self-assigned this Dec 10, 2021
@noenandre
Copy link
Author

Better type hints than just integer was really what I was trying to achieved here. Of course that can be achieved with a literal type (Literal[1, 2]), but a enum makes a better connection between the sentinel value and their function, and gives better auto code completion, as you said.
I went specifically with enum.IntEnum in an attempt to not brake anything. XMLParser.DOM==1 and XMLParser.SAX==2 will evaluate to true, so you can still pass a literal 1 or 2 too the methods, as opposed to a enum.Enum class.
I can of course reintroduce the constants XML_PARSER_DOM and XML_PARSER_SAX as both as 1 and 2 or as XMLParser.DOM and XMLParser.SAX respectably.

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