8 ms·
What’s New in Python 3.7
- fulafel 9y agoSwitching the default encoding from ASCII to utf-8 sounds like a pretty big change.
- akx 9y agoNot really, imho. It makes more things work out of the box, but input and output for things that used to be ASCII anyway remain the same.
- user5994461 9y agoAre you American? Americans always think that changing the encoding is a minor detail. Guess what, changing the default encoding breaks every language that is not English.
- noselasd 9y agoIf it was changed from ascii to utf-8, how does it break everyting else ?
- user5994461 9y agoASCII doesn't exist as such. Characters are encoded in one byte and ascii leaves the highest 128 characters undefined. They are interpreted system-wise, depends on the locale and user settings.
- warbiscuit 9y ago"ascii" the codec does exist under python. It's strictly defined as byte values 0-127, anything in the 128-255 range causes a decoding error... >>> b"abc\xf0".decode("ascii") UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 3 Thus, moving the default from "ascii" to an ASCII-superset should have no decoding issues for previously valid files, since those bytes were never valid to start with.
- noselasd 9y agoASCII very much exists - but what you describe is an entierly different thing. Sure - if the change is from default-user-locale to UTF-8, things would break. But if the changelog is truthful, and the change is from ASCII to UTF-8, things should not break - at least not to any great extent.
- deleted 9y ago[deleted]
- akx 9y agoI'm Finnish, thank you for asking, so I'm quite aware of different encodings.
- JupiterMoon 9y agoIs Finnish representable in Latin1? If so you might be missing some of the suitabilities of converting from "asci" (most things around Europe weren't asci but latin1) to utf.
- coldtea 9y agoIsn't ASCII a strict subset of UTF-8? If anything this should make sure programs don't break because they read some utf-8 extended character when expecting just ascii -- which is the most common case.
- fulafel 9y agoI didn't say it's a bad change! But since you raise the issue, there are downsides: Many programs developed on 3.7 will inadvertently break on pre-3.7 Python versions. As we know, this is a big thing on parts of the Python ecosystem because users frequently rely on the Python version that come with their OS or framework (eg AWS Lambda), and many developers want to stay compatible with the most common platform-shipped Python versions.
- ericfrederich 9y agoIt's a good assumption for 3.7. In isolation this is a pragmatic decision and makes sense. You are correct though. A .py file which uses non-ascii and doesn't declare the encoding should be considered an error though. Hopefully everybody's dev tools will pick this up (even on 3.7 where they wouldn't need to)
- VHRanger 9y agoThe only real question is: When am I going to be able to name my variable as emojis?
- agumonkey 9y agoWhen Apple releases a MacBook Pro emoji keys only
- dbcurtis 9y agoYou've been able to do that for a while. edit: I take that back. Apparently thebunicode allowed in identifers is not unrestricted..... in my defense I don't use unicode identifiers as a rule....
- masklinn 9y agoYou can use non-ascii characters but not emoji as arbitrary symbols are not generally classified as either XID_Start or XID_Continue.
- masklinn 9y agoWell Python 3 broadly follows UAX 31 "UNICODE IDENTIFIER AND PATTERN SYNTAX", and emoji don't have the xid_start or xid_continue properties, so… never unless you decide to be the change to believe in and get the Unicode consortium to change its ways?
- dorfsmay 9y ago"More than 255 arguments can now be passed to a function, and a function can now have more than 255 parameters." There are human devs who needed this? Or is this a sign that AI bots are now involved in language design?
- akx 9y agoCould be useful for code autogeneration of some ilk.
- orf 9y agoPerhaps it could trigger if you do function(*iterable), with a huge iterable?
- drizze 9y agoI think *iterable would just pass one argument that's a list, not pass each argument individually
- fiddlerwoaroof 9y ago>>> print([1,2,3]) [1,2,3] >>> print(*[1,2,3]) 1 2 3
- aisofteng 9y agoThat doesn't tell you anything about when the list is expanded.
- dragonwriter 9y agoThe asterisk at the call site (where it turns an iterable into multiple passed arguments) not the function definition site (where it collects otherwise unconsumed arguments into a single list.)
- orf 9y agoThere may be some optimization at the interpreter level, but it appears to Python that each element of 'iterable' is passed as an individual argument
- Kpourdeilami 9y agoUnrelated to python 3.7, but they recently added this feature that you can add two dictionaries together in 3.5 by doing: new_dict = {**dict1, **dict2} It is so handy and nice
- agumonkey 9y agoI didn't know about that. It's also unbounded: >>> d = {**{1:2,2:2,3:2} ,**{4:2,5:2,6:2} ,**{7:2,8:2,9:2}} >>> d { 1: 2, 2: 2, 3: 2 , 4: 2, 5: 2, 6: 2 , 7: 2, 8: 2, 9: 2}
- JupiterMoon 9y agoWhat happens to duplicate keys?
- dave_sullivan 9y agoI think it raises an exception. https://www.python.org/dev/peps/pep-0448/ https://www.python.org/dev/peps/pep-0448/ EDIT: yeah, nvm, it's what everyone else said.
- skrause 9y agoNo it doesn't, you simply get the value from the last dict: >>> a = {'x': 1} >>> b = {'x': 2} >>> {**a, **b} {'x': 2} >>> {**b, **a} {'x': 1}
- Kpourdeilami 9y agoThey get overwritten by the value of the dictionary that came last. >>> dict1 = {"key1": 1, "key2": "hello", "key3": [1, 2, 3]} >>> dict2 = {key1": 1, "key2": "world", "key3": [1, 4], "key4": "4"} >>> {**dict1, **dict2} {'key1': 1, 'key2': 'world', 'key3': [1, 4], 'key4': '4'}
- ericfrederich 9y agoLots of code to show that. How 'bout this: ;-) >>> {**{'a': 'first'}, **{'a': 'second'}} {'a': 'second'}
- Twirrim 9y agoSome nice optimisations included: Added two new opcodes: LOAD_METHOD and CALL_METHOD to avoid instantiation of bound method objects for method calls, which results in method calls being faster up to 20%. (Contributed by Yury Selivanov and INADA Naoki in bpo-26110.) Searching some unlucky Unicode characters (like Ukrainian capital “Є”) in a string was to 25 times slower than searching other characters. Now it is slower only by 3 times in worst case. (Contributed by Serhiy Storchaka in bpo-24821.) Fast implementation from standard C library is now used for functions erf() and erfc() in the math module. (Contributed by Serhiy Storchaka in bpo-26121.) The os.fwalk() function has been sped up by 2 times. This was done using the os.scandir() function. (Contributed by Serhiy Storchaka in bpo-25996.) Optimized case-insensitive matching and searching of regular expressions. Searching some patterns can now be up to 20 times faster. (Contributed by Serhiy Storchaka in bpo-30285.) selectors.EpollSelector.modify(), selectors.PollSelector.modify() and selectors.DevpollSelector.modify() may be around 10% faster under heavy loads. (Contributed by Giampaolo Rodola’ in bpo-30014) edit: That one around the unlucky Unicode characters is fascinating. https://bugs.python.org/issue24821 https://bugs.python.org/issue24821 Due to the way that regex searching is optimised, it trips up because: ".. the lowest byte of the code of Ukrainian capital letter Є (U+0404) matches the highest byte of codes of most Cyrillic letters (U+04xx). There are similar issues with some other scripts ..."
- CaliforniaKarl 9y ago> Support for building --without-threads is removed. (Contributed by Antoine Pitrou in bpo-31370.). Woooo! That means, at some future time, I'll be able to remove code checks for non-threading Pythons.
- viraptor 9y agoWhat kind of checks did you use?
- raymondh 9y agoThis patch was a little aggressive and may get reverted (it caused immediate code breakage in downstream distros and projects). Changes like this typically need a deprecation period (that said, to the extent the current feature didn't really work in the first place, we can immediately take it out).
- Dowwie 9y agoWhat version will contain dataclasses?
- ericfrederich 9y agoWhat do you mean by this? Do namedtuples not give you this? >>> class MyClass(namedtuple('_MyClass', ['x', 'y', 'z'])): ... def foo(self): ... return self.x * self.y + self.z ... >>> x = MyClass(4, 5, 6) >>> x.foo() 26 ... or an attrs decorated class with frozen=True? >>> import attr >>> @attr.s(frozen=True) ... class MyClass: ... x = attr.ib() ... y = attr.ib() ... z = attr.ib() ... def foo(self): ... return self.x * self.y + self.z ... >>> x = MyClass(4, 5, 6) >>> x.foo() 26
- Dowwie 9y agoClose! ericvsmith, gvr, et al were inspired by attrs and have since been implementing a stdlib version of it, calling it "dataclass" see: https://github.com/ericvsmith/dataclasses https://github.com/ericvsmith/dataclasses and this comment thread is revealing: https://github.com/ericvsmith/dataclasses/issues/19 https://github.com/ericvsmith/dataclasses/issues/19
- ericfrederich 9y agoThanks for that link. Very informative interesting discussion. There must be a lot of desire for attrs from the stdlib developers.