[Python-ideas] Re: Auto dedent -c arguments.
On 05Apr2023 10:01, Lucas Wiman wrote: On Tue, Apr 4, 2023 at 7:19 AM Jonathan Crall wrote: Would there be any downside to the Python CLI automatically dedenting the input string given to -c? I can't think of any case off the top of my head where it would make a previously valid program invalid. Unless I'm missing something this would strictly make previously invalid strings valid. Very strong +1 to this. Me too, on reflection. +1 ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/TEPTRZVDKBFDDVRQXQK6V3APPGXB6DXM/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Auto dedent -c arguments.
On Tue, Apr 4, 2023 at 7:19 AM Jonathan Crall wrote: > Would there be any downside to the Python CLI automatically dedenting the > input string given to -c? I can't think of any case off the top of my head > where it would make a previously valid program invalid. Unless I'm missing > something this would strictly make previously invalid strings valid. > > Thoughts? > Very strong +1 to this. That would be useful and it doesn't seem like there's a downside. I often make bash functions that pipe files or database queries to Python for post-processing. I also sometimes resort to Ruby because it's easy to write one-liners in Ruby and annoying to write one-liners in python/bash. I suppose there's some ambiguity in the contents of multi-line """strings""". Should indentation be stripped at all in that case? E.g. python -c " ''' some text " But it seems simpler and easier to understand/document if you pre-process the input like using an algorithm like this: * If the first nonempty line has indentation, and all subsequent lines either start with the same indentation characters or are empty, then remove that prefix from those lines. I think that handles cases where editors strip trailing spaces or the first line is blank. So e.g.: python -c " some_code_here() " Then python receives something like "\nsome_code_here\n" python -c " some_code here() if some_some_other_code(): still_more_code() " Then python receives something like "\nsome_code_here\n\nif ..." This wouldn't handle cases where indentation is mixed and there is a first line, e.g.: python -c "first_thing() if second_thing(): third_thing() " That seems simple enough to avoid, and raising a syntax error is reasonable in that case. Best wishes, Lucas ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/YQNYNGO4LI2537HU6SET4LIIINNDHHUO/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: len(Enum) should raise TypeError
mypy does not detect this as a problem because EnumMeta has a `.__len__` method https://github.com/python/typeshed/blob/60939b00afede13feeec3cee6f6dfe6eb2df1593/stdlib/enum.pyi#L121 what would the type hints look like if len(Enum) failed but class Foo(Enum): pass len(Foo) succeeds? ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/RTAF57ZHKB2B75T3OJ73WBNT6JRUQF44/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: len(Enum) should raise TypeError
> Can any Python linting tools (such as pylint) detect a potential > problem with the code? Hey, I checked mypy, flake8, pylint, all did not see this as a problem. My native IDE ( PyCharm ) also saw no problem with it. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/W42HLCKELCO2OT6VVMK46EGYNGG7HY44/ Code of Conduct: http://python.org/psf/codeofconduct/