Skip to content

Commit

Permalink
force a default of None
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Abraham <[email protected]>
  • Loading branch information
jabraham17 committed Oct 31, 2024
1 parent 9063d24 commit 3f5084a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions test/chplcheck/RuleSettings/RuleSettings.1.good
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
In One: Local=None, Global='default'
In Two: Local=None, Global='different default'
In One: Local=None, Global=None
In Two: Local=None, Global=None
4 changes: 2 additions & 2 deletions test/chplcheck/RuleSettings/RuleSettings.2.good
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
In One: Local='x', Global='default'
In Two: Local=None, Global='different default'
In One: Local='x', Global=None
In Two: Local=None, Global=None
4 changes: 2 additions & 2 deletions test/chplcheck/RuleSettings/RuleSettings.3.good
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
In One: Local=None, Global='default'
In Two: Local='y', Global='different default'
In One: Local=None, Global=None
In Two: Local='y', Global=None
4 changes: 2 additions & 2 deletions test/chplcheck/RuleSettings/RuleSettings.8.good
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
In One: Local='y', Global='default'
In Two: Local=None, Global='different default'
In One: Local='y', Global=None
In Two: Local=None, Global=None
10 changes: 4 additions & 6 deletions test/chplcheck/RuleSettings/rules.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@

from chapel import AstNode
from typing import Optional


def var_string(**kwargs):
s = []
for k, v in kwargs.items():
val = v if v is None else f"'{v}'"
s.append(f"{k}={val}")
return ", ".join(s)


def rules(driver):

@driver.basic_rule(AstNode, settings=[".Local", "Global"])
def One(context, node, Local: Optional[str]=None, Global: str="default"):

def One(c, n, Local: Optional[str] = None, Global: Optional[str] = None):
print(f"In One:", var_string(Local=Local, Global=Global))
return True

@driver.advanced_rule(settings=[".Local", "Global"])
def Two(context, node, Local: Optional[str]=None, Global: str="different default"):

def Two(c, n, Local: Optional[str] = None, Global: Optional[str] = None):
print(f"In Two:", var_string(Local=Local, Global=Global))
yield from []

2 changes: 2 additions & 0 deletions tools/chplcheck/src/rule_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def get_settings_kwargs(self):
# either they have no specific rule name, or they match this rule
setting_kwargs = {}
for setting in self.settings:
# default to None if the setting is not in the driver's settings
setting_kwargs[setting.setting_name] = None
# if setting is in the driver's settings, use that value
# otherwise, use the default value (ie pass nothing in the kwargs)
driver_setting = self.driver.config.rule_settings.get(setting)
Expand Down

0 comments on commit 3f5084a

Please sign in to comment.