-
Notifications
You must be signed in to change notification settings - Fork 1
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
Suggestion for refactoring #1
Comments
Hi there! Thanks for the suggestions.
The
The = spaces are a stylistic choice. I always put spaces around keyword arguments in all my python code (even if that's not what pep8 suggests I find it more readable). WrapConstraintsAnd has two arguments because of performance. It's unusual to have single keys with more than two constraints so I optimize for the common case, avoiding a loop at runtime when possible. There are actually two places when all/any would be reasonable though, ConstraintSuffixAll and ConstraintSuffixAny.
In it's current form, yes. I didn't do it because I was thinking about the possibility of adding compiler options such as comparing string in a case-insensitive way. That would have to be added here: if isinstance(pattern, str):
if 'case-insensitive' in self.options:
do_something()
else:
do_another_thing() The rationale is that if an user creates a subclass of the Compiler and overrides compile_str, the options are still honored.
The idea about Pattern and JSONPattern is that the user doesn't need to care about the internals, thus I don't return the compiled pattern in the compile() method. But seriously, thanks a lot for your suggestions, I appreciate them. I'm pretty sure I sound waaaay more pedantic than you with all those explanations. Sorry for that, I'm incredibly picky about my style choices. I hope that at least I don't sound like a complete jerk that refuses every advice no matter what. |
👍 understood, just two different approaches to the same problem IMHO. |
Apologies if I sound a bit blocky and bot-like in my comment, it's like 12:33AM where I am. See MQLite.py:425, a conditional is not needed as you have already stated all of the possible conditions in the
__init__
function. Also in line 438, not wanting to sound like a pendant it is generally not recommended to put spaces after equals sign in function arguments. ForWrapConstraintAnd
you may implement it as the following which would be more intuitive:The long block of conditionals at line 529 may also be refactored into a dict:
Also for caching classes like
Pattern
I usually implement the caching like the following:The text was updated successfully, but these errors were encountered: