Giter Club home page Giter Club logo

Comments (4)

JFoederer avatar JFoederer commented on June 20, 2024

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.

pekkaklarck avatar pekkaklarck commented on June 20, 2024

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.

borutzki avatar borutzki commented on June 20, 2024

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.

JFoederer avatar JFoederer commented on June 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.