-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Support passing custom filters with the same name as built-in flags #413
base: main
Are you sure you want to change the base?
Conversation
c986edb
to
8945ad2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey there!
lots of comments. mostly looking to clean up variable names and integrate better in the filter logic, can you review a refactoring I'm proposing? I did it step by step but I'm not 100% sure i didnt miss something, tests pass for each refactor step.
Thank you for taking the time and giving me so many suggestions and comments! I'm on a short trip and don't have a computer with me at the moment. I should be back home in two days to revise the current submission again🙏🙏 |
The latest code has been updated. Previously, it might have been because I was concerned that making too many alterations to the code would impact other functions. Thus, I attempted to refrain from modifying the original logic and merely added some patch codes to it. |
I continued to test the efficiency issue regarding text replacement. The added import itertools
import re
from faker import Faker
PREFIX = "__SOME_PREFIX_"
PREFIX_REG = re.compile(r"^__SOME_PREFIX")
class MyFaker(Faker):
def prefix_name(self):
return f"{PREFIX}{self.name()}"
fake = MyFaker()
data_num = 10000
escape_percent = 0.5
escape_num = int(data_num * escape_percent)
prefix_texts = [fake.prefix_name() for _ in range(escape_num)]
normal_texts = [fake.name() for _ in range(data_num - escape_num)]
def test_and_replace():
for text in itertools.chain(prefix_texts, normal_texts):
if text.startswith(PREFIX):
res = text.replace(PREFIX, "")
return res
def just_replace():
for text in itertools.chain(prefix_texts, normal_texts):
res = text.replace(PREFIX, "")
return res
def remove_prefix():
for text in itertools.chain(prefix_texts, normal_texts):
res = text.removeprefix(PREFIX)
return res
def re_replace():
for text in itertools.chain(prefix_texts, normal_texts):
res = PREFIX_REG.sub(text, "")
return res
__benchmarks__ = [
(test_and_replace, just_replace, "just_replace"),
(test_and_replace, remove_prefix, "remove_prefix"),
(test_and_replace, re_replace, "re_replace")
] benchmark res:
|
mainly I wanted to show that we can just have a single line with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision 5e64e05 of this pull request into gerrit so we can run tests and reviews and stuff
New Gerrit review created for change 5e64e05: https://gerrit.sqlalchemy.org/c/sqlalchemy/mako/+/5557 |
Fix: #140
During the lexical analysis phase, add an additional prefix for undeclared identifiers that have the same name as built-in flags, and determine the final filter to be used during the code generation phase based on the context provided by the user.
This code can now be rendered correctly.