Skip to content

Conversation

@jjotero
Copy link
Contributor

@jjotero jjotero commented Feb 23, 2021

This PR implements the attribute access to variables and parameters directly from the class body. Prior to this PR, an attempt to access either variables or parameters from the class body resulted in a NameError since none of these built-ins are stored in the public namespace from the class. This PR not only implements the access to these items, but also provides a more robust error handling in case of erroneous user input:

  • Accessing a required (undefined) variable in the class body will raise a ValueError:
class Foo(rfm.RegressionMixin):
    v = variable(str)
    x = f'{v}' # This will raise an error because `v` has no value
  • Accessing a defined variable will return its default value:
class Foo(rfm.RegressionMixin):
    v = variable(int, value=4)
    x = v + 1 # this sets x to 5
  • Accessing a parameter directly from the class body is disallowed.
class Foo(rfm.RegressionMixin):
    p = parameter([1, 2, 3])
    x = f'{p}' # This raises an error. Here `P` is a TestParam object, not a test parameter.

@jjotero jjotero added this to the ReFrame 3.5.0 milestone Feb 23, 2021
@jjotero jjotero requested review from ekouts, teojgo and vkarak February 23, 2021 14:40
@jjotero jjotero self-assigned this Feb 23, 2021
@codecov-io
Copy link

Codecov Report

Merging #1806 (0e31e60) into master (9d02ba4) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1806      +/-   ##
==========================================
+ Coverage   87.57%   87.59%   +0.02%     
==========================================
  Files          49       49              
  Lines        7922     7935      +13     
==========================================
+ Hits         6938     6951      +13     
  Misses        984      984              
Impacted Files Coverage Δ
reframe/core/meta.py 100.00% <100.00%> (ø)
reframe/core/pipeline.py 91.72% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d02ba4...0e31e60. Read the comment docs.

Copy link
Contributor

@vkarak vkarak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@vkarak vkarak merged commit 0fdf619 into reframe-hpc:master Feb 24, 2021
@jjotero jjotero deleted the feature/namespace-access branch February 24, 2021 10:13
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.

5 participants