New in Python 3.13 /u/sohang-3112 Python Education

Obviously this is a quite subjective list of what jumped out to me, you can check out the full list in official docs.

import copy from argparse import ArgumentParser from dataclasses import dataclass

  • __static_attributes__ lists attributes from all methods, new __name__ in @property:

“` @dataclass class Test: def foo(self): self.x = 0

def bar(self): self.message = 'hello world' @property def is_ok(self): return self.q 

Get list of attributes set in any method

print(Test.static_attributes) # Outputs: ‘x’, ‘message’

new __name__ attribute in @property fields, can be useful in external functions

def printproperty_name(prop): print(prop.name_)

print_property_name(Test.is_ok) # Outputs: is_ok “`

  • copy.replace() can be used instead of dataclasses.replace(), custom classes can implement __replace__() so it works with them too:

“` @dataclass class Point: x: int y: int z: int

copy with fields replaced

print(copy.replace(Point(x=0,y=1,z=10), y=-1, z=0)) “`

  • argparse now supports deprecating CLI options:

parser = ArgumentParser() parser.add_argument('--baz', deprecated=True, help="Deprecated option example") args = parser.parse_args()

configparser now supports unnamed sections for top-level key-value pairs:

from configparser import ConfigParser config = ConfigParser(allow_unnamed_section=True) config.read_string(""" key1 = value1 key2 = value2 """) print(config["DEFAULT"]["key1"]) # Outputs: value1

HONORARY (Brief mentions)

  • Improved REPL (multiline editing, colorized tracebacks) in native python REPL, previously had to use ipython etc. for this
  • doctest output is now colorized by default
  • Default type hints supported (although IMO syntax for it is ugly)
  • (Experimental) Disable GIL for true multithreading (but it slows down single-threaded performance)
  • Official support for Android and iOS
  • Common leading whitespace in docstrings is stripped automatically

EXPERIMENTAL / PLATFORM-SPECIFIC

  • New Linux-only API for time notification file descriptors in os.
  • PyTime API for system clock access in the C API.

submitted by /u/sohang-3112
[link] [comments]

​r/learnpython Obviously this is a quite subjective list of what jumped out to me, you can check out the full list in official docs. import copy from argparse import ArgumentParser from dataclasses import dataclass __static_attributes__ lists attributes from all methods, new __name__ in @property: “` @dataclass class Test: def foo(self): self.x = 0 def bar(self): self.message = ‘hello world’ @property def is_ok(self): return self.q Get list of attributes set in any method print(Test.static_attributes) # Outputs: ‘x’, ‘message’ new __name__ attribute in @property fields, can be useful in external functions def printproperty_name(prop): print(prop.name_) print_property_name(Test.is_ok) # Outputs: is_ok “` copy.replace() can be used instead of dataclasses.replace(), custom classes can implement __replace__() so it works with them too: “` @dataclass class Point: x: int y: int z: int copy with fields replaced print(copy.replace(Point(x=0,y=1,z=10), y=-1, z=0)) “` argparse now supports deprecating CLI options: parser = ArgumentParser() parser.add_argument(‘–baz’, deprecated=True, help=”Deprecated option example”) args = parser.parse_args() configparser now supports unnamed sections for top-level key-value pairs: from configparser import ConfigParser config = ConfigParser(allow_unnamed_section=True) config.read_string(“”” key1 = value1 key2 = value2 “””) print(config[“DEFAULT”][“key1”]) # Outputs: value1 HONORARY (Brief mentions) Improved REPL (multiline editing, colorized tracebacks) in native python REPL, previously had to use ipython etc. for this doctest output is now colorized by default Default type hints supported (although IMO syntax for it is ugly) (Experimental) Disable GIL for true multithreading (but it slows down single-threaded performance) Official support for Android and iOS Common leading whitespace in docstrings is stripped automatically EXPERIMENTAL / PLATFORM-SPECIFIC New Linux-only API for time notification file descriptors in os. PyTime API for system clock access in the C API. submitted by /u/sohang-3112 [link] [comments] 

Obviously this is a quite subjective list of what jumped out to me, you can check out the full list in official docs.

import copy from argparse import ArgumentParser from dataclasses import dataclass

  • __static_attributes__ lists attributes from all methods, new __name__ in @property:

“` @dataclass class Test: def foo(self): self.x = 0

def bar(self): self.message = 'hello world' @property def is_ok(self): return self.q 

Get list of attributes set in any method

print(Test.static_attributes) # Outputs: ‘x’, ‘message’

new __name__ attribute in @property fields, can be useful in external functions

def printproperty_name(prop): print(prop.name_)

print_property_name(Test.is_ok) # Outputs: is_ok “`

  • copy.replace() can be used instead of dataclasses.replace(), custom classes can implement __replace__() so it works with them too:

“` @dataclass class Point: x: int y: int z: int

copy with fields replaced

print(copy.replace(Point(x=0,y=1,z=10), y=-1, z=0)) “`

  • argparse now supports deprecating CLI options:

parser = ArgumentParser() parser.add_argument('--baz', deprecated=True, help="Deprecated option example") args = parser.parse_args()

configparser now supports unnamed sections for top-level key-value pairs:

from configparser import ConfigParser config = ConfigParser(allow_unnamed_section=True) config.read_string(""" key1 = value1 key2 = value2 """) print(config["DEFAULT"]["key1"]) # Outputs: value1

HONORARY (Brief mentions)

  • Improved REPL (multiline editing, colorized tracebacks) in native python REPL, previously had to use ipython etc. for this
  • doctest output is now colorized by default
  • Default type hints supported (although IMO syntax for it is ugly)
  • (Experimental) Disable GIL for true multithreading (but it slows down single-threaded performance)
  • Official support for Android and iOS
  • Common leading whitespace in docstrings is stripped automatically

EXPERIMENTAL / PLATFORM-SPECIFIC

  • New Linux-only API for time notification file descriptors in os.
  • PyTime API for system clock access in the C API.

submitted by /u/sohang-3112
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *