Comments (4)
Illustrating some of the downsides of current available constructs:
Function reassignment
Can only be used on discovered keywords. breaks down when using @keyword
decorator
def do_action(self):
"""docu for both singular and plural version goes here"""
pass
do_actions = do_action
Regular expression
Yields an extra unused argument and looks very ugly in libdoc: Shout ${n} cheer${s:s?} for
@keyword("Shout ${n} cheer${s:s?} for")
def hurray(self, n:int, plural_s, person:str):
Redirection
Works, but fully duplicates all docu in libdoc and there is no way to actually know they are aliases other than writing it in the docu.
@keyword("Shout ${n} cheers for")
def hurray(self, n:int, person:str):
"""Cheer them on as much as you like!
Example:
| `Shout 1 cheer for` | Python |
| `Shout 3 cheers for` | Robot |
"""
def shout_1_cheer(self, person:str):
return self.hurray(1, person)
shout_1_cheer.__doc__ = hurray.__doc__
from robotframework.
It's true that creating aliases doesn't work with assignment if the keyword has a name set using the @keyword
decorator. If aliases were to be supported in that case, I'd prefer adding a separate aliases=None
to @keyword
instead of adding a separate @alias
decorator.
For some reason I'd prefer a possibility to specify the whole keyword name as a regexp instead of using an alias. We could allow something like regexp=True
with the @keyword
decorator, but that syntax wouldn't work with user keywords. A more generic solution would be considering names surrounded by forward slashes as regexps like /Shout \d cheers?/
. We then needed to decide how to mark arguments. With libraries using normal regexp groups like /Shout (\d) cheers?/
would work, but with user keywords these groups need names and using Robot variables as we do nowadays like /Shout ${n} cheers?/
or /Shout ${n:\d} cheers?/
would probably be better.
from robotframework.
Apart from the regex part described above, maybe there's a possibility to somehow rewrite @keyword
decorator in such a way that it might be used multiple times?
It might be easier to use and comprehend I think:
@keyword("Shout ${n} cheers for")
@keyword("Shout ${n} cheer for")
def hurray(self, n:int, person:str):
"""Cheer them on as much as you like!
Example:
| `Shout 1 cheer for` | Python |
| `Shout 3 cheers for` | Robot |
"""
One potential issue I see here is the "recursive" character of such decorator that would either call wrapper from wrapper from wrapper or must be implemented as quite weird structure trying to differentiate base function / method from one already decorated.
from robotframework.
Having a regex as keyword specifier is more flexible than an alias, but, as is often the case with higher flexibility, usability can suffer. Before opting for this high degree of flexibility I would like to get clear what the impact will be on things like documentation and auto-completion of keywords.
Potential issues I see so far:
- When regexes are kept in the documentation, the user now needs to understand regexes as well
- Expanding the variants can become a huge list
- Higher risk of missing a variant when doing updates
- Accidentally creating duplicate keywords
from robotframework.
Related Issues (20)
- Named-only arguments are not trace logged with user keywords HOT 1
- Collections: Value of `ignore_case` argument accidentally logged HOT 1
- Remove confusing debug statement HOT 1
- Error Encountered When Running BDD Example (https://docs.robotframework.org/docs/testcase_styles/bdd) HOT 3
- Add new section about style to User Guide HOT 1
- Add support for time strings containing "week" values HOT 2
- Extended variable syntax does not take effect HOT 1
- Logging doesn't work propertly if Robot is running on thread HOT 4
- list the IP addresses of all connected devices HOT 1
- Embedded argument support for examples in libdoc
- Python global variables not visible if class is created HOT 1
- ExecutionResult is returning a wrong start_time, end_time and elapsed. HOT 5
- Support using named arguments with non-string values programmatically HOT 1
- Warning with page screen shot HOT 1
- More events for Listener interface ? HOT 1
- Update Dutch language file
- Enhance BDD support (GIVEN/WHEN/THEN) for French language
- Evaluate keyword fails with NameError is not defined nor importable as module
- testdoc do not print Template Keyword used in doc
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from robotframework.