[issue44896] AttributeError in ast.unparse

2021-12-17 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

#46073 may be a duplicate of this and perhaps should have the same resolution.

--
nosy: +terry.reedy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44896] AttributeError in ast.unparse

2021-12-14 Thread Batuhan Taskaya


Change by Batuhan Taskaya :


--
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44896] AttributeError in ast.unparse

2021-09-29 Thread Łukasz Langa

Łukasz Langa  added the comment:

Sorry, I think we shouldn't be changing `ast.py` this way. To reiterate my 
review comment from the PR:

I think we should just let this go and instead advertise that if you put new 
synthetic nodes in a tree, you have to either:
- provide `lineno` and `col_offset` yourself; or
- use `fix_missing_locations()` to fill out the information for you.

The problem with the logic that I commented on twice now (on the PR) is one 
reason for my opinion. Another is bigger though:

Suppose user code is replacing nodes or just inserting new ones. This operation 
not only creates nodes without location attributes. It also in all likelihood 
*moves* locations of type comments and those aren't updated (for example, 
`_type_ignores[123]` should now really be `_type_ignores[125]` to still point 
at the same tokens). So user code shouldn't be naive when it comes to missing 
locations, and we definitely shouldn't paper over missing locations.

--
nosy: +lukasz.langa
resolution:  -> rejected
stage: patch review -> resolved

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44896] AttributeError in ast.unparse

2021-08-16 Thread Łukasz Langa

Change by Łukasz Langa :


--
versions: +Python 3.10, Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44896] AttributeError in ast.unparse

2021-08-14 Thread Batuhan Taskaya


Change by Batuhan Taskaya :


--
keywords: +patch
pull_requests: +26245
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/27770

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44896] AttributeError in ast.unparse

2021-08-14 Thread Batuhan Taskaya


Batuhan Taskaya  added the comment:

I don't think this is really an issue considering some other functionalities 
that consumes AST code (e.g `compile`) will expect it to be annotated with 
location metadata. This is why the `ast` module already comes bundled with a 
utility function called `fix_missing_locations` which in your example would 
work;

> print(ast.unparse(bad))
> print(ast.unparse(ast.fix_missing_locations(bad)))

Though I recall seeing this error once before, and since there also some 
counter examples (e.g ast.increment_lineno) that assume an AST node might lack 
of these attributes even though the nodes declare them makes it worth to fix.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44896] AttributeError in ast.unparse

2021-08-13 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
title: Issue with unparse in ast module -> AttributeError in ast.unparse

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com