[issue46078] `ast.unparse` fails on `class C: i: int`… convert broken from `ast.AnnAssign` to `ast.Assign`

2021-12-14 Thread Samuel Marks


Samuel Marks  added the comment:

Just fixed the issue by using this value:
```py
"```(None)```" if sys.version_info[:2] >= (3, 9) else "```None```"
```

--
stage:  -> resolved
status: open -> closed

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



[issue46078] `ast.unparse` fails on `class C: i: int`… convert broken from `ast.AnnAssign` to `ast.Assign`

2021-12-14 Thread Samuel Marks

New submission from Samuel Marks :

astor fails with:
```
  File "python3.8/site-packages/astor/code_gen.py", line 63, in to_source
generator.visit(node)
  File "python3.8/site-packages/astor/node_util.py", line 143, in visit
return visitor(node)
  File "python3.8/site-packages/astor/code_gen.py", line 878, in visit_Module
self.write(*node.body)
  File "python3.8/site-packages/astor/code_gen.py", line 178, in write
visit(item)
  File "python3.8/site-packages/astor/node_util.py", line 143, in visit
return visitor(node)
  File "python3.8/site-packages/astor/code_gen.py", line 364, in visit_ClassDef
self.body(node.body)
  File "python3.8/site-packages/astor/code_gen.py", line 226, in body
self.write(*statements)
  File "python3.8/site-packages/astor/code_gen.py", line 178, in write
visit(item)
  File "python3.8/site-packages/astor/node_util.py", line 143, in visit
return visitor(node)
  File "python3.8/site-packages/astor/code_gen.py", line 293, in visit_Assign
self.visit(node.value)
  File "python3.8/site-packages/astor/node_util.py", line 143, in visit
return visitor(node)
  File "python3.8/site-packages/astor/node_util.py", line 137, in abort_visit
raise AttributeError(msg % node.__class__.__name__)
AttributeError: No defined handler for node of type NoneType
```

Whereas the now builtin to Python (3.9+) `ast.unparse` gives:
```
File "3.10/lib/python3.10/ast.py", line 1673, in unparse
return unparser.visit(ast_obj)
  File "3.10/lib/python3.10/ast.py", line 807, in visit
self.traverse(node)
  File "3.10/lib/python3.10/ast.py", line 798, in traverse
super().visit(node)
  File "3.10/lib/python3.10/ast.py", line 410, in visit
return visitor(node)
  File "3.10/lib/python3.10/ast.py", line 822, in visit_Module
self._write_docstring_and_traverse_body(node)
  File "3.10/lib/python3.10/ast.py", line 815, in 
_write_docstring_and_traverse_body
self.traverse(node.body)
  File "3.10/lib/python3.10/ast.py", line 796, in traverse
self.traverse(item)
  File "3.10/lib/python3.10/ast.py", line 798, in traverse
super().visit(node)
  File "3.10/lib/python3.10/ast.py", line 410, in visit
return visitor(node)
  File "3.10/lib/python3.10/ast.py", line 1001, in visit_ClassDef
self._write_docstring_and_traverse_body(node)
  File "3.10/lib/python3.10/ast.py", line 815, in 
_write_docstring_and_traverse_body
self.traverse(node.body)
  File "3.10/lib/python3.10/ast.py", line 796, in traverse
self.traverse(item)
  File "3.10/lib/python3.10/ast.py", line 798, in traverse
super().visit(node)
  File "3.10/lib/python3.10/ast.py", line 410, in visit
return visitor(node)
  File "3.10/lib/python3.10/ast.py", line 863, in visit_Assign
self.traverse(node.value)
  File "3.10/lib/python3.10/ast.py", line 798, in traverse
super().visit(node)
  File "3.10/lib/python3.10/ast.py", line 410, in visit
return visitor(node)
  File "3.10/lib/python3.10/ast.py", line 414, in generic_visit
for field, value in iter_fields(node):
  File "3.10/lib/python3.10/ast.py", line 252, in iter_fields
for field in node._fields:
AttributeError: 'NoneType' object has no attribute '_fields'
```

Found it when I tried to unparse previously parsed:
```py
class C:
i: int
```

Found in reality when trying to parse then emit:
- 
https://github.com/tensorflow/tensorflow/blob/ba146843/tensorflow/compiler/xla/python/xla_client.py#L402-L413


Which is creating this:
```
ast.Assign(targets=[ast.Name(id="interior_padding")],
   type_comment="int",
   value=None)
```

(one thing my library does is convert betwixt `ast.Assign` and `ast.AnnAssign`… 
later I'll be doing more interesting variable type tracing to generate big 
`typing.Union` of all possible types each variable may have… but if it finds 
`None` then it will infer `typing.Optional`.)

Here is my `ast.NodeTransformer` override for `visit_AnnAssign`: 
https://github.com/offscale/cdd-python/blob/968507e/cdd/doctrans_utils.py#L111-L131

Is there some way of rewriting an `ast.AnnAssign` to `ast.Assign` without 
losing type information?

--
messages: 408580
nosy: samuelmarks
priority: normal
severity: normal
status: open
title: `ast.unparse` fails on `class C: i: int`… convert broken from 
`ast.AnnAssign` to `ast.Assign`
versions: Python 3.10, Python 3.11, Python 3.8, Python 3.9

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



[issue44825] node.annotation is not a str in `ast`'s `class _Unparser(NodeVisitor)`

2021-08-04 Thread Samuel Marks


Samuel Marks  added the comment:

Fixed with https://github.com/offscale/cdd-python/commit/079dc28

--
stage:  -> resolved
status: open -> closed

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



[issue44825] node.annotation is not a str in `ast`'s `class _Unparser(NodeVisitor)`

2021-08-04 Thread Samuel Marks


Samuel Marks  added the comment:

Hmm, debugging my test and I was able to replicate it with this smaller one:

```
from ast import FunctionDef, arguments, Load, Name, AnnAssign, Store, BinOp, 
Add, unparse
unparse(FunctionDef(args=arguments(args=[],
   defaults=[],
   kw_defaults=[],
   kwarg=None,
   kwonlyargs=[],
   posonlyargs=[],
   vararg=None),
body=[AnnAssign(annotation='int',
simple=1,
target=Name(ctx=Store(),
id='res'),
value=BinOp(left=Name(ctx=Load(),
  id='a'),
op=Add(),
right=Name(ctx=Load(),
   id='b')))],
decorator_list=[],
name='sum',
returns=None,
lineno=None,
type_comment=None))
```

Which for some reason has made the `annotation` a `str` rather than `Name`. So 
I think it's my bug then?

--

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



[issue44825] node.annotation is not a str in `ast`'s `class _Unparser(NodeVisitor)`

2021-08-04 Thread Samuel Marks


New submission from Samuel Marks :

I tried making `node.annotation` an `ast.Name("str", ast.Load())`, which worked 
but when the AST was unparsed to a string it shows as `# type: `.
https://github.com/offscale/cdd-python/runs/3213864077

Replicate with:
```
unparse(Assign(annotation=None, simple=1, targets=[Name("foo", Store())], 
value=Constant(value=5, kind=None), expr=None, expr_targe
   ...: t=None, expr_annotation=None, type_comment=Name('str', Load()), 
lineno=None))
```

Checking what it expects, it does expect a str. E.g.,:
```
$ python3.9 -c 'import ast; tc=ast.parse("foo = 5 # type: int", 
type_comments=True).body[0].type_comment; print("type_comment is a", 
type(tc).__name__, "with value", tc)'
type_comment is a str with value int
```

But when I do make it a str and unparse it, I get:
```
File "/opt/python3.10/lib/python3.10/ast.py", line 1674, in unparse
return unparser.visit(ast_obj)
  File "/opt/python3.10/lib/python3.10/ast.py", line 808, in visit
self.traverse(node)
  File "/opt/python3.10/lib/python3.10/ast.py", line 799, in traverse
super().visit(node)
  File "/opt/python3.10/lib/python3.10/ast.py", line 410, in visit
return visitor(node)
  File "/opt/python3.10/lib/python3.10/ast.py", line 1005, in visit_FunctionDef
self._function_helper(node, "def")
  File "/opt/python3.10/lib/python3.10/ast.py", line 1023, in _function_helper
self._write_docstring_and_traverse_body(node)
  File "/opt/python3.10/lib/python3.10/ast.py", line 816, in 
_write_docstring_and_traverse_body
self.traverse(node.body)
  File "/opt/python3.10/lib/python3.10/ast.py", line 797, in traverse
self.traverse(item)
  File "/opt/python3.10/lib/python3.10/ast.py", line 799, in traverse
super().visit(node)
  File "/opt/python3.10/lib/python3.10/ast.py", line 410, in visit
return visitor(node)
  File "/opt/python3.10/lib/python3.10/ast.py", line 879, in visit_AnnAssign
self.traverse(node.annotation)
  File "/opt/python3.10/lib/python3.10/ast.py", line 799, in traverse
super().visit(node)
  File "/opt/python3.10/lib/python3.10/ast.py", line 410, in visit
return visitor(node)
  File "/opt/python3.10/lib/python3.10/ast.py", line 414, in generic_visit
for field, value in iter_fields(node):
  File "/opt/python3.10/lib/python3.10/ast.py", line 252, in iter_fields
for field in node._fields:
AttributeError: 'str' object has no attribute '_fields'
```

--
messages: 398878
nosy: samuelmarks
priority: normal
severity: normal
status: open
title: node.annotation is not a str in `ast`'s `class _Unparser(NodeVisitor)`
versions: Python 3.10, Python 3.11, Python 3.9

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



[issue44470] 3.11 docs.python.org in Polish not English?

2021-06-24 Thread Samuel Marks

Samuel Marks  added the comment:

Yep exactly like my screenshot but now the Polish has turned Korean… my family 
was never Korean!

--

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



[issue44470] 3.11 docs.python.org in Polish not English?

2021-06-21 Thread Samuel Marks


New submission from Samuel Marks :

It's been too long since my family have been Polish!

(see screenshot of https://docs.python.org/3.11/library/parser.html )

My computer is only configured for English. Running Firefox 90.0b9 (64-bit) on 
macOS 11.4 (20F71).

--
assignee: docs@python
components: Documentation
files: Screen Shot 2021-06-21 at 4.49.27 pm.png
messages: 396207
nosy: docs@python, samuelmarks
priority: normal
severity: normal
status: open
title: 3.11 docs.python.org in Polish not English?
type: behavior
versions: Python 3.11
Added file: https://bugs.python.org/file50122/Screen Shot 2021-06-21 at 4.49.27 
pm.png

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



[issue44402] Python 3.9 and 3.10 fails to install in WINE

2021-06-11 Thread Samuel Marks

New submission from Samuel Marks :

What works:
- python-3.7.9.exe  python-3.8.9.exe

What fails:
- python-3.10.0b2.exe  python-3.9.5.exe

(I'm debugging some regressions on my test suite… macOS and Linux [incl. in 
Docker] work, Windows fails)

How to reproduce (macOS):
0. Install WINE (crossover) 
https://github.com/Gcenx/homebrew-wine#how-to-install-using-brew
1. wine python-.exe /quiet /passive /log c:/p.log 
TargetDir=C:/python- InstallAllUsers=1 Include_doc=0 Include_debug=0 
Include_dev=0 Include_exe=1 Include_launcher=0 Include_lib=1 Include_pip=1 
Include_symbols=0 Include_tcltk=0 Include_test=0 Include_tools=0
2. curl https://bootstrap.pypa.io/get-pip.py -o http://get-pip.py
3. wine "C:\\python-\\python.exe" http://get-pip.py

(replacing ``; obviously)

Error:
```
000b:fixme:thread:create_user_shared_data_thread Creating user shared data 
update thread.
000d:fixme:thread:create_user_shared_data_thread Creating user shared data 
update thread.
0010:fixme:thread:create_user_shared_data_thread Creating user shared data 
update thread.
0017:fixme:thread:create_user_shared_data_thread Creating user shared data 
update thread.
001d:err:plugplay:process_IOService_Device object 0x9203
001d:err:plugplay:process_IOService_Device Unable to create plug in interface 
for USB deviceobject 0x9207
001f:fixme:thread:create_user_shared_data_thread Creating user shared data 
update thread.
0009:fixme:heap:RtlSetHeapInformation 0x0 1 0x0 0 stub
0025:fixme:thread:create_user_shared_data_thread Creating user shared data 
update thread.
0009:fixme:ntdll:NtQueryInformationToken QueryInformationToken( ..., 
TokenElevation, ...) semi-stub
0009:fixme:ntdll:NtQueryInformationToken QueryInformationToken( ..., 
TokenElevation, ...) semi-stub
0009:fixme:advapi:DecryptFileW 
(L"C:\\windows\\Temp\\{FDB2F91C-29EE-4A75-AAA5-39F402CF12ED}\\", ): stub
002b:fixme:heap:RtlSetHeapInformation 0x0 1 0x0 0 stub
002b:fixme:ntdll:NtQueryInformationToken QueryInformationToken( ..., 
TokenElevation, ...) semi-stub
002b:fixme:ntdll:NtQueryInformationToken QueryInformationToken( ..., 
TokenElevation, ...) semi-stub
002b:fixme:advapi:DecryptFileW 
(L"C:\\windows\\Temp\\{3F224591-5EEC-4431-8291-2450B9ECC110}\\", ): stub
002e:fixme:shell:SHAutoComplete stub
002b:fixme:ver:GetCurrentPackageId (0x31fd04 0x0): stub
0009:fixme:ver:GetCurrentPackageId (0x31fd04 0x0): stub
```

Expected (`uniq` output of a successful install of 3.8):
```
000b:fixme:thread:create_user_shared_data_thread Creating user shared data 
update thread.
000d:fixme:thread:create_user_shared_data_thread Creating user shared data 
update thread.
0010:fixme:thread:create_user_shared_data_thread Creating user shared data 
update thread.
0017:fixme:thread:create_user_shared_data_thread Creating user shared data 
update thread.
001d:err:plugplay:process_IOService_Device object 0x6a03
001d:err:plugplay:process_IOService_Device Unable to create plug in interface 
for USB deviceobject 0x6a07
001f:fixme:thread:create_user_shared_data_thread Creating user shared data 
update thread.
0009:fixme:heap:RtlSetHeapInformation 0x0 1 0x0 0 stub
0025:fixme:thread:create_user_shared_data_thread Creating user shared data 
update thread.
0009:fixme:ntdll:NtQueryInformationToken QueryInformationToken( ..., 
TokenElevation, ...) semi-stub
0009:fixme:advapi:DecryptFileW 
(L"C:\\windows\\Temp\\{86717C64-3933-4B4D-9283-CEA5CD0F5EBB}\\", ): stub
002b:fixme:heap:RtlSetHeapInformation 0x0 1 0x0 0 stub
002b:fixme:ntdll:NtQueryInformationToken QueryInformationToken( ..., 
TokenElevation, ...) semi-stub
002b:fixme:advapi:DecryptFileW 
(L"C:\\windows\\Temp\\{9A024DD0-BF6A-4DF1-A034-C61E89E6F711}\\", ): stub
002e:fixme:shell:SHAutoComplete stub
002b:fixme:advapi:DecryptFileW 
(L"C:\\windows\\Temp\\{9A024DD0-BF6A-4DF1-A034-C61E89E6F711}\\", ): stub
002b:fixme:exec:SHELL_execute flags ignored: 0x0100
0030:fixme:heap:RtlSetHeapInformation 0x0 1 0x0 0 stub
0030:fixme:ntdll:NtQueryInformationToken QueryInformationToken( ..., 
TokenElevation, ...) semi-stub
0030:fixme:ole:CoInitializeSecurity 
(0031F458,-1,,,6,2,,12288,) - stub!
0030:fixme:wuapi:automatic_updates_Pause 
0030:fixme:sfc:SRSetRestorePointW 0031F320 0031F530
0033:fixme:advapi:DecryptFileW (L"C:\\ProgramData\\Package 
Cache\\{3854F8D0-6FA6-4227-8047-8DE95B0A7DE7}v3.8.9150.0\\core.msi", ): 
stub
0030:fixme:ntdll:NtLockFile I/O completion on lock not implemented yet
0033:fixme:advapi:DecryptFileW (L"C:\\ProgramData\\Package 
Cache\\{A3ED59F7-FC59-4793-AEBC-9D3813922BE1}v3.8.9150.0\\exe.msi", ): 
stub
0030:fixme:ntdll:NtQuerySystemInformation info_class 
SYSTEM_PERFORMANCE_INFORMATION
0030:err:mscoree:LoadLibraryShim error reading registry key for installroot
0033:fixme:advapi:DecryptFileW (L"C:\\ProgramData\\Package 
Cache\\{D12B4386-129A-4C17-AB8D-45FD90C6EB0D}v3.8.9150.0\\lib.msi

[issue44321] os.EX_OK for Windows

2021-06-06 Thread Samuel Marks


Samuel Marks  added the comment:

`EXIT_SUCCESS` is defined in `stdlib.h`, as per 
https://docs.microsoft.com/en-us/cpp/c-runtime-library/exit-success-exit-failure
 (following the standard 
https://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdlib.h.html)

There are also 
https://docs.microsoft.com/en-us/cpp/c-runtime-library/errno-constants which 
has many equivalents to the `` (in ``).

Kinda related: https://bugs.python.org/issue24053

--

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



[issue44321] os.EX_OK for Windows

2021-06-06 Thread Samuel Marks


Change by Samuel Marks :


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

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



[issue44321] os.EX_OK for Windows

2021-06-06 Thread Samuel Marks

New submission from Samuel Marks :

Since Python 2.3 alpha 2 [19-Feb-2003] `EX_OK` has existed… but only for Unix. 
This adds support for Windows.

--
components: Windows
messages: 395203
nosy: paul.moore, samuelmarks, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: os.EX_OK for Windows
type: enhancement

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



[issue43339] Could not build the ssl module! | macOS with `CPPFLAGS` and `LDFLAGS` set

2021-02-27 Thread Samuel Marks

Samuel Marks  added the comment:

Nevermind it actually was that missing `PKG_CONFIG_PATH` line…

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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



[issue43339] Could not build the ssl module! | macOS with `CPPFLAGS` and `LDFLAGS` set

2021-02-27 Thread Samuel Marks


New submission from Samuel Marks :

I was on 3.10a4 on macOS 11.1 for ages, finally decided to upgrade to a5, 
building from source. With latest `brew install openssl zlib`.
```
$ export LDFLAGS='-L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/zlib/lib'
$ export CPPFLAGS='-I/usr/local/opt/openssl@1.1/include 
-I/usr/local/opt/zlib/include'
$ ./configure --enable-optimizations --prefix /opt/python3.10
```

I suppose I could set this which I forgot, but I doubt it's the problem, unless 
pkg_config is how the CPython build system find OpenSSL?
```
export PKG_CONFIG_PATH='/usr/local/opt/openssl@1.1/lib/pkgconfig'
```

Error:
```
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_hashlib  _ssl  ossaudiodev
spwd   
To find the necessary bits, look in setup.py in detect_modules() for the 
module's name.


The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc  pwd   time   


Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with 
X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, 
https://github.com/libressl-portable/portable/issues/381
```

Happy to test alternative configurations

--
components: Build
messages: 38
nosy: samuelmarks
priority: normal
severity: normal
status: open
title: Could not build the ssl module! | macOS with `CPPFLAGS` and `LDFLAGS` set
versions: Python 3.10

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



[issue43203] Default value incorrectly read with unittests on Windows & macOS but not Linux

2021-02-11 Thread Samuel Marks

New submission from Samuel Marks :

Had a couple of commits to try and fix it on GitHub Actions (as I was unable to 
replicate locally), ended up with this very easy fix for Windows:
https://github.com/SamuelMarks/doctrans/commit/98203e9fee3e0a888ab1f4128011dde5fad98f63

To completely remove the default value. The only thing I can assume happened is 
that a different test in the same class—which set the default value to 
something else—changed the default value of the function.

This was all very confusing, and I can only think it to be a bug on python, or 
in GitHub Actions deployment thereof.

PS: The macOS builds are still failing with the previous issue :\

--
components: Windows, macOS
messages: 386845
nosy: ned.deily, paul.moore, ronaldoussoren, samuelmarks, steve.dower, 
tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Default value incorrectly read with unittests on Windows & macOS but not 
Linux
versions: Python 3.10, Python 3.7, Python 3.8, Python 3.9

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



[issue42699] Use `.join(k for k in g)` instead of `.join([k for k in g])`

2020-12-21 Thread Samuel Marks


Samuel Marks  added the comment:

There were only 12k occurrences, I'm sure I could manually go through that
in an afternoon. Would you accept it then?

On Tue, 22 Dec 2020, 12:22 am Eric V. Smith,  wrote:

>
> Eric V. Smith  added the comment:
>
> See https://github.com/ikamensh/flynt#dangers-of-conversion for reasons.
>
> Would I like to see all string literal formatting done with f-strings? Yes!
>
> Would I accept the risk and hassle of doing it blindly? No.
>
> --
>
> ___
> Python tracker 
> <https://bugs.python.org/issue42699>
> ___
>

--
nosy: +SamuelMarks

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



[issue42699] Use `.join(k for k in g)` instead of `.join([k for k in g])`

2020-12-21 Thread Samuel Marks


Samuel Marks  added the comment:

EDIT: Just found https://github.com/ikamensh/flynt

--

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



[issue42699] Use `.join(k for k in g)` instead of `.join([k for k in g])`

2020-12-21 Thread Samuel Marks

Samuel Marks  added the comment:

I suppose that's a good justification to never improve/upgrade the syntax and 
quality of the codebase.

In terms of automatic upgrades of the codebase, one could always replicate the 
approach I use in doctrans—i.e., use of `ast` and/or `inspect`—to automatically 
upgrade syntax from `%` and `.format` to use f-strings.

Would that be acceptable?

--

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



[issue42699] Use `.join(k for k in g)` instead of `.join([k for k in g])`

2020-12-21 Thread Samuel Marks


Samuel Marks  added the comment:

Wait I don't understand why you wouldn't accept a wholesale replacement of all 
`%` and `format` with f-strings through the entire CPython codebase [master 
branch]?

BTW: Kinda unrelated, but would be great to have perspective on this little 
project - https://github.com/SamuelMarks/doctrans - I'm interested in wholesale 
enforcement of code consistency and translating between constructs (e.g., 
dataclass to/fro argparse to/fro class method; ReST to/fro Google to/fro NumPy 
dostrings; inline types to/fro types in docstrings; with more planned)

--

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



[issue42699] Use `.join(k for k in g)` instead of `.join([k for k in g])`

2020-12-21 Thread Samuel Marks

Samuel Marks  added the comment:

Yeah I hear ya, was just trying for the most concise issue title. I tend to 
[over]use `map`, `filter`, `filterfalse` and other `itertools` and `operator` 
methods in my own codebase.

Surprised with that result, that using an explicit list is actually faster. 
Seems like an obvious* micro-optimisation. *But don't want to say that unless 
I'm actually maintaining/contributing-to your C code.

It's also surprising—last time I checked—that lists are faster to construct 
than tuples. When I create codebases or maintain other peoples, I try and:
- remove all unnecessary mutability (incl. replacing lists with tuples);
- flatten `.append` occurrences into generator comprehensions or map;
- remove all indentation creating for-loops, replacing with comprehensions or 
map and functions or lambdas
- combine generators rather than concatenate lists;

The general idea here is to evaluate at the time of computation, and be lazy 
everywhere else. So searching the whole codebase for lists and other mutable 
structures is a good first step.

But maybe with efficiency losses, like shown here, means that this would only 
aid [maybe] in readability, understandability, traceability & whatever other 
functional -ility; but not performance?

:(

--

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



[issue42699] Use `.join(k for k in g)` instead of `.join([k for k in g])`

2020-12-20 Thread Samuel Marks


Samuel Marks  added the comment:

@eric.smith No benchmarks offhand, but I'd expect it to be a very minor 
improvement (if detectable).

If this gets accepted I'll probably do a bunch of little changes like this, to 
improve things, e.g., replace '%' with '.format' (or f-strings, whatever you 
prefer), ensure `.iterkeys()`/`.iteritems()` validity, and collapse some 
obvious `.append` cases with list comprehensions.

The idea I'm going off is that when one is debugging their Python code, and it 
goes across to the Python source, that that Python source code quality is 
better or equal to the one the higher-level Python developer is creating.

Constructing unnecessary lists is one such code quality issue.

--

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



[issue42699] Use `.join(k for k in g)` instead of `.join([k for k in g])`

2020-12-20 Thread Samuel Marks

New submission from Samuel Marks :

This is an extremely minor improvement. Rather than create a `list`—using a 
comprehension—then have it consumed by `.join`, one can skip the list 
construction entirely.

(I remember this working from at least Python 2.7… probably earlier also)

--
messages: 383474
nosy: samuelmarks
priority: normal
pull_requests: 22737
severity: normal
status: open
title: Use `.join(k for k in g)` instead of `.join([k for k in g])`
type: performance
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

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



[issue41810] Consider reintroducing `types.EllipsisType` for the sake of typing

2020-11-05 Thread Samuel Marks

Samuel Marks  added the comment:

Since we're bringing these back, would you accept a backport of these types?

[I'm writing a bunch of parsers/emitters—and starting to maintain an old 
runtime type-checker—for 3.6+]

--
nosy: +samuelmarks

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



[issue42242] Backport SQLite trace API v2

2020-11-02 Thread Samuel Marks


Samuel Marks  added the comment:

Done, thanks for the how-to:
- https://github.com/python/cpython/pull/23103 [3.8]
- https://github.com/python/cpython/pull/23102 [3.9]

--

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



[issue40318] Migrate to SQLite3 trace v2 API

2020-11-02 Thread Samuel Marks


Change by Samuel Marks :


--
pull_requests: +22020
pull_request: https://github.com/python/cpython/pull/23103

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



[issue40318] Migrate to SQLite3 trace v2 API

2020-11-02 Thread Samuel Marks


Change by Samuel Marks :


--
nosy: +samuelmarks
nosy_count: 4.0 -> 5.0
pull_requests: +22019
pull_request: https://github.com/python/cpython/pull/23102

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



[issue42229] Fix SQLite warnings on macOS

2020-11-01 Thread Samuel Marks


Samuel Marks  added the comment:

Opened two issues and two PRs for 3.8 and 3.8:
- https://bugs.python.org/issue42241
- https://bugs.python.org/issue42242

--

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



[issue42242] Backport SQLite trace API v2

2020-11-01 Thread Samuel Marks


New submission from Samuel Marks :

Backports https://github.com/python/cpython/pull/19581 
https://bugs.python.org/issue40318 as per https://bugs.python.org/issue42229

See also 3.9 backporting: https://bugs.python.org/issue42241

[not sure if this is how you do backporting, a new issue and GH PR for each 
supported release tag?]

--
components: Build
messages: 380186
nosy: samuelmarks
priority: normal
pull_requests: 22013
severity: normal
status: open
title: Backport SQLite trace API v2
type: compile error
versions: Python 3.8

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



[issue42241] Backport SQLite trace API v2

2020-11-01 Thread Samuel Marks


New submission from Samuel Marks :

Backports https://github.com/python/cpython/pull/19581 
https://bugs.python.org/issue40318 as per https://bugs.python.org/issue42229

--
components: Build
messages: 380185
nosy: samuelmarks
priority: normal
pull_requests: 22011
severity: normal
status: open
title: Backport SQLite trace API v2
type: compile error
versions: Python 3.9

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



[issue42229] Fix SQLite warnings on macOS

2020-11-01 Thread Samuel Marks


Change by Samuel Marks :


--
stage:  -> resolved
status: open -> closed

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



[issue42229] Fix SQLite warnings on macOS

2020-11-01 Thread Samuel Marks

Samuel Marks  added the comment:



--

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



[issue42229] Fix SQLite warnings on macOS

2020-11-01 Thread Samuel Marks

Samuel Marks  added the comment:

@erlendaasland Hmm… just double-checked, and this issue is present on Python 
3.8.6 and 3.9.0 but not master [d3b4e068077dd26927ae7485bd0303e09d962c02] as 
you referenced.

Should I close this issue—and PR—then? - Backport from master to these?

--

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



[issue42229] Fix SQLite warnings on macOS

2020-11-01 Thread Samuel Marks

Samuel Marks  added the comment:

Yes, this commit extends his changes to include macOS support (for some reason 
that SQLite version check doesn’t work properly on macOS; so this checks the 
macOS version, knowing AOT when SQLite trace v1 APIs were deprecated.

Curious that `sqlite3_enable_shared_cache` is in the ‘wontfix’ category… why is 
this?

--

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



[issue42229] Fix SQLite warnings on macOS

2020-11-01 Thread Samuel Marks

New submission from Samuel Marks :

Planned to fix all the compiler warnings on macOS. Ended up just fixing this 
SQLite one:
```
Python-3.9.0/Modules/_sqlite/connection.c:1066:9: warning: 'sqlite3_trace' is 
deprecated: first deprecated in macOS 10.12
  [-Wdeprecated-declarations]
sqlite3_trace(self->db, 0, (void*)0);
^
sqlite3_trace_v2
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sqlite3.h:3022:36:
 note: 'sqlite3_trace' has
  been explicitly marked deprecated here
SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(
   ^
Python-3.9.0/Modules/_sqlite/connection.c:1069:9: warning: 'sqlite3_trace' is 
deprecated: first deprecated in macOS 10.12
  [-Wdeprecated-declarations]
sqlite3_trace(self->db, _trace_callback, trace_callback);
^
sqlite3_trace_v2
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sqlite3.h:3022:36:
 note: 'sqlite3_trace' has
  been explicitly marked deprecated here
SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(
   ^
```

Note that: `sqlite3_enable_shared_cache` should be removed from 
`Modules/_sqlite/module.c` also, as warning and guide says: 
https://www.sqlite.org/c3ref/enable_shared_cache.html
```
Python-3.9.0/Modules/_sqlite/module.c:147:10: warning: 
'sqlite3_enable_shared_cache' is deprecated: first deprecated in macOS
  10.7 - Not supported [-Wdeprecated-declarations]
```

But I think that would require a major version change, so let's keep that 
warning fix to one side.

Same with the tk issues, as per https://bugs.python.org/issue41016 ; although I 
suspect there's a way to quiet the warnings here…

--
components: Build
messages: 380126
nosy: samuelmarks
priority: normal
pull_requests: 21992
severity: normal
status: open
title: Fix SQLite warnings on macOS
type: compile error
versions: Python 3.9

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



[issue41819] Fix some compiler warnings

2020-09-20 Thread Samuel Marks


Change by Samuel Marks :


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

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



[issue41819] Fix some compiler warnings

2020-09-20 Thread Samuel Marks

Samuel Marks  added the comment:

Okay I'll redo it on master, here is my config, on macOS 10.15.6:
```
$ export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
$ export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
$ export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
$ export CPPFLAGS="-I/usr/local/opt/zlib/include $CPPFLAGS"
$ export LDFLAGS="-L/usr/local/opt/zlib/lib $LDFLAGS"
$ gcc --version && clang --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr 
--with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ ./configure --enable-optimizations --prefix /opt/python3-master
$ ./configure --enable-optimizations --prefix /opt/python3-master
checking for git... found
checking build system type... x86_64-apple-darwin19.6.0
checking host system type... x86_64-apple-darwin19.6.0
checking for python3.10... no
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "darwin"
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr 
--with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
[… omitted for brevity]
$ make
```

With these warnings being addressed by this bug report and PR:
```
gcc -c -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv 
-O3 -Wall-std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter 
-Wno-missing-field-initializers -Wstrict-prototypes 
-Werror=implicit-function-declaration -fvisibility=hidden 
-fprofile-instr-generate -I./Include/internal  -I. -I./Include 
-I/usr/local/opt/zlib/include -I/usr/local/opt/openssl@1.1/include 
-I/usr/local/opt/zlib/include -I/usr/local/opt/openssl@1.1/include  
-DPy_BUILD_CORE \
-DPLATLIBDIR='"lib"' \
-o Python/initconfig.o ./Python/initconfig.c
./Python/initconfig.c:2677:38: warning: format specifies type 'wint_t' (aka 
'int') but the argument has type 'unsigned int' [-Wformat]
PySys_WriteStderr("%lc", ch);
   ~~~   ^~
   %c
1 warning generated.
```

Looks like someone else has already picked up the other bug. So opened a new PR 
for this.

--

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



[issue41819] Fix some compiler warnings

2020-09-20 Thread Samuel Marks


New submission from Samuel Marks :

https://github.com/SamuelMarks/cpython/tree/3.9-compiler-fixes

--
components: Build
messages: 377205
nosy: samuelmarks
priority: normal
pull_requests: 21373
severity: normal
status: open
title: Fix some compiler warnings
type: compile error
versions: Python 3.9

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



[issue22240] argparse support for "python -m module" in help

2019-10-04 Thread Samuel Marks


Samuel Marks  added the comment:

See https://bugs.python.org/msg353987 for manual test

--
Added file: https://bugs.python.org/file48643/prog-module-name-handler.patch

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



[issue22240] argparse support for "python -m module" in help

2019-10-04 Thread Samuel Marks


Samuel Marks  added the comment:

Until this is accepted, I've modified my codebase:
```
from argparse import ArgumentParser

ArgumentParser(
  prog=None if globals().get('__spec__') is None else 'python -m 
{}'.format(__spec__.name.partition('.')[0])
)
```

--
nosy: +samuelmarks

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



[issue21014] `1` = `True`; for tutorial docs

2014-03-21 Thread Samuel Marks

New submission from Samuel Marks:

Particularly for new programmers `True` makes more sense than `1` when doing 
boolean logic.

If you aren't going to accept this patch; at least add in a sentence explaining 
that: ` 1 == True`.

Best,

Samuel Marks

--
assignee: docs@python
components: Documentation
files: Use_`True`_instead_of_`1`_.patch
hgrepos: 229
keywords: patch
messages: 214430
nosy: SamuelMarks, docs@python
priority: normal
severity: normal
status: open
title: `1` = `True`; for tutorial docs
type: enhancement
versions: Python 2.7
Added file: http://bugs.python.org/file34559/Use_`True`_instead_of_`1`_.patch

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