feat(nano): use decorator to export a Blueprint#1395
Merged
Conversation
1a13e0d to
663c694
Compare
|
| Branch | feat/nano/blueprint-export-decorator |
| Testbed | ubuntu-22.04 |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result minutes (m) (Result Δ%) | Lower Boundary minutes (m) (Limit %) | Upper Boundary minutes (m) (Limit %) |
|---|---|---|---|---|
| sync-v2 (up to 20000 blocks) | 📈 view plot 🚷 view threshold | 1.84 m(+9.18%)Baseline: 1.68 m | 1.51 m (82.43%) | 2.02 m (90.98%) |
663c694 to
e1cd544
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1395 +/- ##
==========================================
- Coverage 85.87% 85.86% -0.02%
==========================================
Files 431 431
Lines 32700 32733 +33
Branches 5096 5102 +6
==========================================
+ Hits 28082 28105 +23
- Misses 3598 3608 +10
Partials 1020 1020 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
e1cd544 to
156555c
Compare
glevco
reviewed
Sep 8, 2025
Comment on lines
+281
to
+308
| def export(cls: B) -> B: | ||
| """Decorator to export the main Blueprint of a Python module.""" | ||
| current_frame = inspect.currentframe() | ||
| assert current_frame is not None | ||
| module_frame = current_frame.f_back | ||
| assert module_frame is not None | ||
| module_globals = module_frame.f_globals | ||
| if BLUEPRINT_EXPORT_NAME in module_globals: | ||
| raise TypeError('A Blueprint has already been registered') | ||
| module_globals[BLUEPRINT_EXPORT_NAME] = cls | ||
| return cls |
Contributor
There was a problem hiding this comment.
Using global or globals() doesn't work?
Member
Author
There was a problem hiding this comment.
It doesn't work because it would refer to the hathor.nanocontracts.types's globals, not the module that uses @export's globals.
msbrogli
previously approved these changes
Sep 8, 2025
df2898c to
492dcf5
Compare
492dcf5 to
eb235f2
Compare
glevco
approved these changes
Sep 10, 2025
msbrogli
approved these changes
Sep 10, 2025
This was referenced Sep 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The current method of assigning to
__blueprint__has some drawbacks. This proposal uses a decorator which should already be familiar because of@viewand@publicdecorators.Acceptance Criteria
hathor.nanocontracts.on_chain_blueprints.BLUEPRINT_CLASS_NAMEtohathor.nanocontracts.types.BLUEPRINT_EXPORT_NAMEhathor.nanocontracts.exportwhich just sets__blueprint__at the module where it is called, which means it is backwards compatible:Checklist
master, confirm this code is production-ready and can be included in future releases as soon as it gets merged