[issue38627] Add copy() method to pathlib
Sebastian Linke added the comment: Docstring could be: Copy file content and permission bits of this path to the target path and return a new Path instance pointing to the target path. If target is a directory, the base filename of this path is added to the target and a new file corresponding to the target is created. If target points to an existing file, that file is overwritten. -- ___ Python tracker <https://bugs.python.org/issue38627> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38627] Add copy() method to pathlib
New submission from Sebastian Linke : pathlib.Path() could wrap shutil.copy() with something like this: def copy(self, target): if not self.is_file(): # No support for directories here raise ValueError("Path must point to a regular file") # copy() appends filename when Path is copied to a directory # see shutil.copy() docstring and source for details target = shutil.copy(self, target) return self.__class__(target) -- components: Library (Lib) messages: 355616 nosy: seblin priority: normal severity: normal status: open title: Add copy() method to pathlib type: enhancement versions: Python 3.9 ___ Python tracker <https://bugs.python.org/issue38627> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue35494] Inaccurate error message for f-string
Sebastian Linke added the comment: The same behavior applies to f'{spam[}' and f'{spam(}'. Also to f'{spam{}', but that might be expected. This message is more clear: >>> f'{spam(' File "", line 1 SyntaxError: f-string: mismatched '(', '{', or '[' Perhaps you want to apply that to the above error cases. Then you wouldn't have to catch any type of bracket. :-) -- ___ Python tracker <https://bugs.python.org/issue35494> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue35494] Inaccurate error message for f-string
New submission from Sebastian Linke : Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> spam = 'spam' >>> f'{spam[0}' File "", line 1 SyntaxError: f-string: expecting '}' The error message seems wrong because a "]" is missing rather than a "}". -- components: Interpreter Core messages: 331827 nosy: seblin priority: normal severity: normal status: open title: Inaccurate error message for f-string versions: Python 3.7 ___ Python tracker <https://bugs.python.org/issue35494> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25898] Check for subsequence inside a sequence
Sebastian Linke added the comment: Slightly modified the implementation to return the index rather than a boolean. -- Added file: http://bugs.python.org/file41374/subseq_index.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25898> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25898] Check for subsequence inside a sequence
Sebastian Linke added the comment: @Josh What is the point of using iterators here? If the user wants an iterator to be checked then he can throw that iterator right away because it was exhausted by the function. I think that in most cases the user wants to do some postprocessing on a hairstack after being checked. This is why I restricted the arguments to be sequences. Keeping that restriction in mind a pure Python implementation could look like this: def has_subsequence(seq, subseq): if not subseq: return True if len(subseq) > len(seq): return False start = 0 while True: try: start = seq.index(subseq[0], start) except ValueError: # seq.index() did not match return False stop = start + len(subseq) if seq[stop - 1] == subseq[-1] and seq[start:stop] == subseq: return True start += 1 Unfortunately, this version potentially creates lots of subseqences for checking equality with the `subseq` argument. I tried to minimise the occurrence of those cases by pre-checking the first and the last element of a candidate. Anyway, this seems to be faster for small needles compared to your `deque`-based suggestion. -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25898> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25898] Check for subsequence inside a sequence
New submission from Sebastian Linke: With the attached patch I propose to add a new function to the "collections" module. It is meant to be used for determining whether a given subsequence is part of a particular sequence (with respect to the ordering of the subsequence). Doing this in pure Python (using the CPython interpreter) is relatively slow. So I did the implementation in C. -- components: Library (Lib) files: has_subsequence.patch keywords: patch messages: 256633 nosy: seblin priority: normal severity: normal status: open title: Check for subsequence inside a sequence type: enhancement versions: Python 3.6 Added file: http://bugs.python.org/file41342/has_subsequence.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25898> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com