Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Chris Angelico via Python-list
On Sat, 9 Mar 2024 at 03:42, Grant Edwards via Python-list wrote: > > On 2024-03-08, Chris Angelico via Python-list wrote: > > On Sat, 9 Mar 2024 at 00:51, Grant Edwards via Python-list > > wrote: > > > >> One might argue that "global" isn't a good choice for what to call the > >> scope in

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Grant Edwards via Python-list
On 2024-03-08, Chris Angelico via Python-list wrote: > On Sat, 9 Mar 2024 at 00:51, Grant Edwards via Python-list > wrote: > >> One might argue that "global" isn't a good choice for what to call the >> scope in question, since it's not global. It's limited to that source >> file. It doesn't make

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Chris Angelico via Python-list
On Sat, 9 Mar 2024 at 00:51, Grant Edwards via Python-list wrote: > One might argue that "global" isn't a good choice for what to call the > scope in question, since it's not global. It's limited to that source > file. It doesn't make sense to me to call a binding "global", when > there can be

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Grant Edwards via Python-list
On 2024-03-07, Cameron Simpson via Python-list wrote: > Yes. Note that the "global" namespace is the module in which the > function is defined. One might argue that "global" isn't a good choice for what to call the scope in question, since it's not global. It's limited to that source file. It

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-07 Thread Cameron Simpson via Python-list
lobal. If a variable is assigned a value anywhere within the function’s body, it’s assumed to be a local unless explicitly declared as global." So, I would then assume that if I explicitly include a variable name inside the global statement, then even just assigning it a new value should update th

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-07 Thread Jacob Kruger via Python-list
Thanks again, all. I think the python -i scoping2.py would have given me a good beginning as well - will archive that one for use. And, to maybe explain how I work - not an excuse at all - but, I am actually 100% blind, so a lot of the IDE's, or their common means/methods of interaction

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Grant Edwards via Python-list
On 2024-03-07, dn via Python-list wrote: > The idea of importing a module into the REPL and then (repeatedly) > manually entering the code to set-up and execute is unusual (surely type > such into a script (once), and run that (repeatedly). As you say, most > of us would be working from an

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread dn via Python-list
On 7/03/24 05:28, Jacob Kruger via Python-list wrote: ... So, yes, know this comes across like some form of a scam/joke, or list-garbage, since it doesn't make any sense to me at all, but still just wondering if missing something, or should I shift over to 3.12 to see if if works differently,

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Roel Schroeven via Python-list
Grant Edwards via Python-list schreef op 6/03/2024 om 18:59: On 2024-03-06, Roel Schroeven via Python-list wrote: > Op 6/03/2024 om 17:40 schreef Jacob Kruger via Python-list: >> >>> from scoping2 import * > > [...] > > I would advice not to use 'import *', if at all possible, for multiple

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Grant Edwards via Python-list
On 2024-03-06, Roel Schroeven via Python-list wrote: > Op 6/03/2024 om 17:40 schreef Jacob Kruger via Python-list: >> >>> from scoping2 import * > > [...] > > I would advice not to use 'import *', if at all possible, for multiple > reasons, one of which is to prevent problems like this.

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Roel Schroeven via Python-list
Op 6/03/2024 om 17:40 schreef Jacob Kruger via Python-list: >>> from scoping2 import * Ah yes, that explains what's happening. After that statement, the name dt_expiry in the current namespace is bound to the same object that the name dt_expiry in the namespace of module scoping2

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
Ok, Ethan, that makes sense - I generally work with modules in folders, etc., but, this was just test code, but, 'see' if I instead import scoping2 as sc2, and then refer to sc2.dt_expiry and sc2.do_it, then it does operate as it should - thanks, again. Jacob Kruger +2782 413 4791

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Ethan Furman via Python-list
On 3/6/24 08:28, Jacob Kruger via Python-list wrote: > C:\temp\py_try>python > Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec 4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> from scoping2 import * And it becomes

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
You'll see more details in other mail, but, here I am firing up standard python interpreter from within windows terminal, and then executing following line: from scoping2 import * And, this is under windows 11 windows terminal, which is where I generally interact with my python code, via

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
est=[1, 2, 3, 1, 2, 3, 99], id(l_test)=140153285385856 after: l_test=[1, 2, 3, 1, 2, 3, 99], id(l_test)=140153285385856 It's the same list object, as you can see by the id values. And the list is updating as expected. And... you don't need the global statement for l_test. As it's mutable, you can mutat

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
4-03-06 08:57 outside after: 2024-03-06 08:57 List after: [1, 2, 3, 99] As an aside, you have gone to some trouble to copy, clear, and reconstruct l_test.  It would be simpler like this (and you wouldn't have to import the "copy" library):     l_temp = l_test[:]     l_test = [] Instead of t

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Roel Schroeven via Python-list
Op 6/03/2024 om 16:39 schreef Roel Schroeven via Python-list: Op 6/03/2024 om 13:55 schreef Jacob Kruger via Python-list: If you import the contents of that file into the python interpreter, [...] What exactly to you mean by "import the contents of that file into the python interpreter"?

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Roel Schroeven via Python-list
Op 6/03/2024 om 13:55 schreef Jacob Kruger via Python-list: If you import the contents of that file into the python interpreter, [...] What exactly to you mean by "import the contents of that file into the python interpreter"? Other people have put your code in a script, executed it, and saw

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Thomas Passin via Python-list
l_test[:] l_test = [] Instead of those lines and then this: for i in l_temp: l_test.append(i) you could achieve the same thing with this single statement: l_test = l_test[:] If I take out the line that removes values from l_test # l_test.clear() # before appending new value to it,

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Thomas Passin via Python-list
On 3/6/2024 5:59 AM, Alan Gauld via Python-list wrote: On 05/03/2024 22:46, Grant Edwards via Python-list wrote: Unfortunately (presumably thanks to SEO) the enshittification of Google has reached the point where searching for info on things like Python name scope, the first page of links are

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Mats Wichmann via Python-list
And... you don't need the global statement for l_test. As it's mutable, you can mutate it in the function; the global only acts on assignment. Using "global" for that may make your intent more clear to readers though, although static checkers will grumble at you. You must be doing

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
ithin the function’s body, it’s assumed to be a local unless explicitly declared as global." So, I would then assume that if I explicitly include a variable name inside the global statement, then even just assigning it a new value should update the variable in the global context, outside th

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
start with a small experiment: - after l_servers is created, print its id() - after the global statement, print its id() - after the clear/reassignment, print its id() Is Python always working with the same list? Please advise... On 6/03/24 07:13, Jacob Kruger via Python-list wrote: Hi there Wor

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Alan Gauld via Python-list
On 05/03/2024 22:46, Grant Edwards via Python-list wrote: > Unfortunately (presumably thanks to SEO) the enshittification of > Google has reached the point where searching for info on things like > Python name scope, the first page of links are to worthless sites like > geeksforgeeks. And not just

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread Grant Edwards via Python-list
cal variable. _Regardless_ of whether that > assignment has been executed, or gets executed at all (eg in an > if-statement branch which doesn't fire). Unfortunately, crap "information" sites like geeksforgeeks often describe this either incorrectly or so vaguely as to be wor

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread Cameron Simpson via Python-list
in Python, when you write a function Python does a static analysis of it to decide which variables are local and which are not. If there's an assignment to a variable, it is a local variable. _Regardless_ of whether that assignment has been executed, or gets executed at all (eg in an if-statement

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread dn via Python-list
is the ultimate description! Perhaps start with a small experiment: - after l_servers is created, print its id() - after the global statement, print its id() - after the clear/reassignment, print its id() Is Python always working with the same list? Please advise... On 6/03/24 07:13, Jacob Kruger

Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread Jacob Kruger via Python-list
Hi there Working with python 3.11, and, issue that confused me for a little while, trying to figure out what was occurring - unless am completely confused, or missing something - was that, for example, when having pre-defined a variable, and then included it in the global statement inside

Re: Match statement with literal strings

2023-06-07 Thread Jason Friedman via Python-list
> > The bytecode compiler doesn't know that you intend RANGE > to be a constant -- it thinks it's a variable to bind a > value to. > > To make this work you need to find a way to refer to the > value that isn't just a bare name. One way would be to > define your constants using an enum: > > class

Re: Match statement with literal strings

2023-06-07 Thread Chris Angelico via Python-list
On Thu, 8 Jun 2023 at 08:19, Jason Friedman via Python-list wrote: > > This gives the expected results: > > with open(data_file, newline="") as reader: > csvreader = csv.DictReader(reader) > for row in csvreader: > #print(row) > match row[RULE_TYPE]: > case "RANGE": > print("range") > case

Re: Match statement with literal strings

2023-06-07 Thread Greg Ewing via Python-list
On 8/06/23 10:18 am, Jason Friedman wrote: SyntaxError: name capture 'RANGE' makes remaining patterns unreachable The bytecode compiler doesn't know that you intend RANGE to be a constant -- it thinks it's a variable to bind a value to. To make this work you need to find a way to refer to the

Match statement with literal strings

2023-06-07 Thread Jason Friedman via Python-list
This gives the expected results: with open(data_file, newline="") as reader: csvreader = csv.DictReader(reader) for row in csvreader: #print(row) match row[RULE_TYPE]: case "RANGE": print("range") case "MANDATORY": print("mandatory") case _: print("nothing to do") This: RANGE = "RANGE"

Re: Single line if statement with a continue

2022-12-19 Thread Peter J. Holzer
On 2022-12-18 16:49:27 +, Stefan Ram wrote: > Dennis Lee Bieber writes: > >>for idx, thing in enumerate(things): > >>if idx == 103: > >>continue > >>do_something_with(thing) > >> > > For this example, I'd probably reverse the condition. > > if idx != 103: > >

Re: Single line if statement with a continue

2022-12-18 Thread Tony Oliver
On Saturday, 17 December 2022 at 23:58:11 UTC, avi.e...@gmail.com wrote: > Is something sort of taboo when using something like a computer language to > write a program? With what else would you write a program? -- https://mail.python.org/mailman/listinfo/python-list

Re: Single line if statement with a continue

2022-12-18 Thread Dennis Lee Bieber
continue >do_something_with(thing) > For this example, I'd probably reverse the condition. if idx != 103: do_something_with(thing) and hence completely drop the "continue" -- after all, if idx is 103, the if statement falls through, and the end

Re: Single line if statement with a continue

2022-12-17 Thread Chris Angelico
On Sun, 18 Dec 2022 at 10:59, wrote: > > If a compiler or interpreter HAPPILY (as happy as machines/code get) compiles > or interprets your code without errors every time you use it a certain way, > then it is not wrong to use it. Of course if it subject to change or already > deprecated, ...

Re: Single line if statement with a continue

2022-12-17 Thread Thomas Passin
er but perhaps should be discouraged in other circumstances. So back to computer languages. Many languages using grouping with something like "{...}" often do not care where you break your lines albeit some get touchy about an else statement placed improperly. It is perfectly le

RE: Single line if statement with a continue

2022-12-17 Thread avi.e.gross
o back to computer languages. Many languages using grouping with something like "{...}" often do not care where you break your lines albeit some get touchy about an else statement placed improperly. It is perfectly legal to write: If (condition) { first; second; third } The grammar ba

Re: Single line if statement with a continue

2022-12-17 Thread dn
On 16/12/2022 02.30, Rob Cliffe via Python-list wrote: On 15/12/2022 04:35, Chris Angelico wrote: On Thu, 15 Dec 2022 at 14:41, Aaron P wrote: I occasionally run across something like: for idx, thing in enumerate(things): if idx == 103: continue do_something_with(thing)

Re: Single line if statement with a continue

2022-12-17 Thread Abdullah Nafees
Just wanted to say that a silent reader like me learnt more about PEP-8 solely from this thread than my mentor at work or any other course I have taken earlier this year. Thank you so much. On Sun, 18 Dec 2022, 00:16 Rob Cliffe via Python-list, < python-list@python.org> wrote: > > > On

Re: Single line if statement with a continue

2022-12-17 Thread Rob Cliffe via Python-list
On 15/12/2022 04:35, Chris Angelico wrote: On Thu, 15 Dec 2022 at 14:41, Aaron P wrote: I occasionally run across something like: for idx, thing in enumerate(things): if idx == 103: continue do_something_with(thing) It seems more succinct and cleaner to use: if idx ==

Re: Single line if statement with a continue

2022-12-15 Thread Grant Edwards
On 2022-12-15, MRAB wrote: > A problem with having a single return is that it can lead to excessive > indentation: > > if test_1: > ... > > if test_2: > ... > > if test_3: > ... > > return I sometimes have to work on code

Re: Single line if statement with a continue

2022-12-15 Thread Thomas Passin
On 12/15/2022 3:58 AM, Chris Green wrote: Thomas Passin wrote: I personally tend to use if test: return even inside larger blocks. I always try to avoid multiple returns from functions/methods, as soon as things get complex it's all to easy to miss clean-up etc. "No

Re: Single line if statement with a continue

2022-12-15 Thread MRAB
to skip further processing so the program then slides down to a single return statement. If done properly, it boils down to the same result if VERY carefully done but with lots of sometimes complex IF statements that may be not be updated well if the logic changes a bit. In such cases, I vastly

Re: Single line if statement with a continue

2022-12-15 Thread Weatherby,Gerard
is easily handled by the try / finally construct. From: Python-list on behalf of avi.e.gr...@gmail.com Date: Thursday, December 15, 2022 at 2:07 PM To: python-list@python.org Subject: RE: Single line if statement with a continue *** Attention: This is an external email. Use caution responding

RE: Single line if statement with a continue

2022-12-15 Thread avi.e.gross
then slides down to a single return statement. If done properly, it boils down to the same result if VERY carefully done but with lots of sometimes complex IF statements that may be not be updated well if the logic changes a bit. In such cases, I vastly prefer clean and unambiguous returns from

Re: Single line if statement with a continue

2022-12-15 Thread Cecil Westerhof via Python-list
easurably slower. (It should not > with an optimizing compiler, but it did due to those > measurements. Can't find that article now, though.) That makes me think about the quote from Edsger W. Dijkstra about the go to statement: Please do not fall into the trap of believing that I am

Re: Single line if statement with a continue

2022-12-15 Thread Chris Green
Thomas Passin wrote: >I personally tend to use > > if test: return > > even inside larger blocks. I always try to avoid multiple returns from functions/methods, as soon as things get complex it's all to easy to miss clean-up etc. "No multiple returns" is often found in

RE: Single line if statement with a continue

2022-12-14 Thread avi.e.gross
and where they can be skipped in a one liner like "if (condition) statement" rather than the style some use on multiple lines like: If (condition) { Statement } Or even: If (condition) { Statement } Of course, once you have additional parts following like an "else" th

Re: Single line if statement with a continue

2022-12-14 Thread Chris Angelico
"While sometimes it’s okay to put an if/for/while with a small body on > the same line, never do this for multi-clause statements. > ... > # Wrong: > if foo == 'blah': do_blah_thing() > for x in lst: total += x > while t < 10: t = delay() > " > > If the one-liner

Re: Single line if statement with a continue

2022-12-14 Thread Thomas Passin
line, never do this for multi-clause statements. ... # Wrong: if foo == 'blah': do_blah_thing() for x in lst: total += x while t < 10: t = delay() " If the one-liner were not in a multi-statement block, it would be all right with PEP-8. OTOH, there is nothing that says one has to

Re: Single line if statement with a continue

2022-12-14 Thread dn
On 15/12/2022 07.53, Aaron P wrote: I occasionally run across something like: for idx, thing in enumerate(things): if idx == 103: continue do_something_with(thing) It seems more succinct and cleaner to use: if idx == 103: continue. Of course this would be considered an

Re: Single line if statement with a continue

2022-12-14 Thread Chris Angelico
On Thu, 15 Dec 2022 at 14:41, Aaron P wrote: > > I occasionally run across something like: > > for idx, thing in enumerate(things): > if idx == 103: > continue > do_something_with(thing) > > It seems more succinct and cleaner to use: > > if idx == 103: continue. > > Of course this

Single line if statement with a continue

2022-12-14 Thread Aaron P
I occasionally run across something like: for idx, thing in enumerate(things): if idx == 103: continue do_something_with(thing) It seems more succinct and cleaner to use: if idx == 103: continue. Of course this would be considered an anti-pattern, and Flake8 will complain.

Re: SyntaxError: multiple statements found while compiling a single statement

2022-08-07 Thread Joe Pfeiffer
Sohail Ahmad writes: > kindly please help me about issues > SyntaxError: multiple statements found while compiling a single statement > how to solve this issues Please post the code that got the error. Preferably several lines before the actual error, and the line with the err

on a statement followed by an expression

2022-06-04 Thread Meredith Montgomery
(*) Question How can I, in a single line, write a statement followed by an expression? For example, if /d/ is a dicionary, how can I write d["key"] = value # and somehow making this line end up with d (*) Where does the question come from? >From the following experi

Re: on a statement followed by an expression

2022-06-04 Thread Alan Bawden
Meredith Montgomery writes: How can I execute a statement followed by a value in a single line? def roberry_via_reduce(rs): return my_reduce(rs, lambda d, r: ``increment and return d'', {}) The grammar or Python is deliberately designed so that the body of a lambda expression cannot

[issue532467] 6.9 The raise statement is confusing

2022-04-10 Thread admin
Change by admin : -- github: None -> 36289 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue512497] multi-line print statement

2022-04-10 Thread admin
Change by admin : -- github: None -> 36025 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue217377] API docs, 7.2.1, too restrictive statement

2022-04-10 Thread admin
Change by admin : ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue518989] Import statement Index ref. broken

2022-04-10 Thread admin
Change by admin : -- github: None -> 36118 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue491246] problem with imports in an if-statement

2022-04-10 Thread admin
Change by admin : -- github: None -> 35711 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue481118] 'switch'/'case'/'else' statement

2022-04-10 Thread admin
Change by admin : -- github: None -> 35514 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue467381] print statement and exception

2022-04-10 Thread admin
Change by admin : -- github: None -> 35269 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue401071] whichdb.py: add missing "try:" statement

2022-04-10 Thread admin
Change by admin : ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue400970] extended print statement

2022-04-10 Thread admin
Change by admin : ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue217377] API docs, 7.2.1, too restrictive statement

2022-04-10 Thread admin
Change by admin : -- github: None -> 33378 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue401071] whichdb.py: add missing "try:" statement

2022-04-10 Thread admin
Change by admin : -- github: None -> 32882 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue400970] extended print statement

2022-04-10 Thread admin
Change by admin : -- github: None -> 32648 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46033] Duplicated sentence in for statement documentation

2022-04-02 Thread Terry J. Reedy
Change by Terry J. Reedy : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed type: -> enhancement ___ Python tracker ___

[issue46033] Duplicated sentence in for statement documentation

2022-04-02 Thread Terry J. Reedy
Terry J. Reedy added the comment: New changeset 281f980d354d1709018a2dc77f79388faf3e56c0 by Michał D in branch 'main': bpo-46033: Clarify for-statement execution (GH-30025) https://github.com/python/cpython/commit/281f980d354d1709018a2dc77f79388faf3e56c0 -- nosy: +terry.reedy

Do you support The #Python Software Foundation making a statement in support of peace?

2022-03-13 Thread René Dudfield
hey hey, Do you support The Python Software Foundation making a statement in support of peace? Vote here: https://twitter.com/pygame_org/status/1502989885296238593 cheerio, -- https://mail.python.org/mailman/listinfo/python-list

[issue41879] Outdated description of async iterables in documentation of async for statement

2022-03-12 Thread Andrew Svetlov
Change by Andrew Svetlov : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue46980] ast.FunctionDef cannot find functions under if statement

2022-03-10 Thread Ruishi
Ruishi added the comment: I see. It's my misunderstanding. Thank you for your help! -- ___ Python tracker ___ ___ Python-bugs-list

[issue46980] ast.FunctionDef cannot find functions under if statement

2022-03-10 Thread Jelle Zijlstra
Jelle Zijlstra added the comment: This is the right place to file an issue. Your code is incorrect; it will find only top-level functions. Functions within an `if` statement will be nested inside an `ast.If` node. To find all functions in a file, you'll need to recurse into nested nodes

[issue46980] ast.FunctionDef cannot find functions under if statement

2022-03-10 Thread Ruishi
Ruishi added the comment: I'm not sure whether I should file this issue here or on Github and I'm not an expert on this so I think I cannot contribute to this but only report to you. -- ___ Python tracker

[issue46980] ast.FunctionDef cannot find functions under if statement

2022-03-10 Thread Ruishi
New submission from Ruishi : When I use the Python ast package to get the functions of Python files, I find the functions defined in the body of `if` statement cannot be recognized. Here is my code: with open(py_file, 'r') as f: data = f.read() module = ast.parse(data) func_def

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2022-01-09 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: I created a PEP to formally propose the change: https://www.python.org/dev/peps/pep-0679/ -- ___ Python tracker ___

[issue46274] backslash creating statement out of nothing

2022-01-06 Thread Pablo Galindo Salgado
Change by Pablo Galindo Salgado : -- nosy: -pablogsal ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46274] backslash creating statement out of nothing

2022-01-05 Thread Jeremy
tokens INDENT, NEWLINE, DEDENT, ENDMARKER. Whereas the source (with spaces) ``` ``` produces the tokens NL, ENDMARKER. -- components: Parser messages: 409811 nosy: lys.nikolaou, pablogsal, ucodery priority: normal severity: normal status: open title: backslash creating statement out of

[issue46033] Duplicated sentence in for statement documentation

2022-01-03 Thread Vedran Čačić
Vedran Čačić added the comment: Yes, it's ok. The only slight problem is that is suggests that first item is somehow special, but later it is explained that in fact it is not. :-) I would say "_Each_ item ..." (instead of "First") and without the "this is repeated for every item..." at the

[issue46033] Duplicated sentence in for statement documentation

2022-01-03 Thread Michał D
Michał D added the comment: Please see the changes I suggested in my PR. -- ___ Python tracker ___ ___ Python-bugs-list mailing

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-24 Thread Guido van Rossum
Guido van Rossum added the comment: You don’t have to use the new feature. But people expect it to work. -- ___ Python tracker ___

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: For very long expression or very long message you can add parentheses around the expression or message. Black will format it as: assert ( very very long expression ), ( "very very long " "message" ) With the proposed feature it will be:

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Pablo Galindo Salgado
Change by Pablo Galindo Salgado : -- keywords: +patch pull_requests: +28465 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30247 ___ Python tracker

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Guido van Rossum
Guido van Rossum added the comment: I like the lookahead. We could also make the comma and the message mandatory when inside parentheses: | 'assert' '(' a=expression ',' b=expression [','] ')' &(NEWLINE | ';') | 'assert' a=expression b=[',' z=expression { z }] (And probably add an

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: Another possibility is actually handled this in the compiler: if we see an assert with a tuple of two elements, we can assume is basically in the form that we want and proceed as if is in the form assert A, B This also feels a bit hacky because the

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: We could do this, but feels a bit hacky: | 'assert' '(' a=expression b=[',' z=expression { z }] ')' &(NEWLINE | ';') | 'assert' a=expression b=[',' z=expression { z }] -- ___ Python tracker

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: > We managed to do this for 'with' so it should be possible here too, I'd > think. The "committing" token would be the newline following the close > parenthesis. I am not so sure is that inmediate. Changing the assert statem

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Guido van Rossum
Guido van Rossum added the comment: We managed to do this for 'with' so it should be possible here too, I'd think. The "committing" token would be the newline following the close parenthesis. Serhiy: the benefit is when you want to split it across two lines, e.g. assert

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: > can we finally get rid of this language wart Yes, please. This is a pretty bad pitfall. I've seen this happen to people who've been conditioned by other languages to think of assert() as a macro or function: assert(sometest, somemessage)

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +gvanrossum, serhiy.storchaka ___ Python tracker ___ ___ Python-bugs-list mailing

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Gregory P. Smith
Gregory P. Smith added the comment: It's not about an advantage, it's about removing the problem of what edit to make when working on assert thing_that_has_a_meaningful_name.methods_have_good_names(value_from_somewhere) == other_thing_that_is_meaningful, "Description of what the issue is

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: I can try to prototype something in the parser to see how it looks and work on the pep if everything looks ok. Parentheses are a bit tricky in general as backtracking ends causing all sorts of tricky situations with custom syntax errors as the parser

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It does not need any change in parser, it can be done in the code generator which currently explicitly warns about such ambiguity. Although it needs changes in formal grammar which will be more complex. But what is a benefit? What is an advantage of

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Sergei Lebedev
Change by Sergei Lebedev : -- nosy: +slebedev ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Gregory P. Smith
or description beyond a single line on assert statements as () are the natural way to do that and as it is with assert being a statement, knowing specifically where to place the ()s to not fall into the pit of snakes of unintentionally nerfing your assertion to be an always true tuple is hard

[issue46059] Typo in match Statement example

2021-12-14 Thread Vivek Vashist
Vivek Vashist added the comment: Thanks for sorting this out Alex :) -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue46059] Typo in match Statement example

2021-12-14 Thread Alex Waygood
Alex Waygood added the comment: Thanks for the bug report, Vivek! It should be fixed now -- it might take a day or two for the online docs to update. -- ___ Python tracker

[issue46059] Typo in match Statement example

2021-12-14 Thread Ken Jin
Change by Ken Jin : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

  1   2   3   4   5   6   7   8   9   10   >