(Mar-15-2020, 10:51 PM)Gribouillis Wrote:Skaperen Wrote:is this valid?…why not?This is not valid because there is a syntax definition that forbids it. Have a look at the railroad diagram of python 3.8's syntax that I uploaded recently. You will clearly see that this construct is not possible. You will also see that you can not handle all the cases with a regex because the following is valid for example
def spam(ham=[n for n in range(1, dividend+1) if dividend % n == 0]): ...One way to check that it is valid would be to add a line of function body with a simple 'pass' statement and call the 'compile' function to see if it can build an AST tree with this code.
so, would it be possible to check all possible cases for validity with parser code? yeah, silly question. i guess that one way to do this is add on a dummy body (maybe a solo return) and see what a call to something that parses python code (exec(), maybe) does with in.
(Mar-20-2020, 03:09 PM)Gribouillis Wrote: Notice the following, which is syntactically correct but the : at the end of the first line is not what you thinkcases like this are what i was worried about.
>>> def foo(ages= { 'pam': ... 24, ... 'jim': 24, ... }, a = ... print('spam') ... ): pass ... spam >>>
i will only have the "first line". but a dictionary in the arg list can let the "first line" be on more than one text line. i need to thing out this more in terms of what code i am getting.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.