python-overpy icon indicating copy to clipboard operation
python-overpy copied to clipboard

Replace sentinel value with an enumerator.

Open noenandre opened this issue 3 years ago • 2 comments

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.

noenandre avatar Dec 06 '21 22:12 noenandre

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

phibos avatar Dec 10 '21 12:12 phibos

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.

noenandre avatar Dec 14 '21 18:12 noenandre