Trên màn hình đầu tiên của trình cài đặt, tôi khuyên bạn nên đánh dấu vào ô “Thêm Python 3. 9 đến CON ĐƯỜNG” [3. 9 có thể khác tùy thuộc vào phiên bản bạn đang cài đặt] nhưng là tùy chọn. Điều này giúp việc chạy và sử dụng Python sau này trở nên dễ dàng hơn
Và sau khi kết thúc, nó cũng là tùy chọn nhưng tôi khuyên bạn nên tắt giới hạn độ dài đường dẫn bằng cách nhấp vào tùy chọn đó, xem bên dưới. Không có nó, Windows có thể không cho phép mã Python của bạn chạy nếu mã của bạn nằm trong một thư mục nằm sâu trong máy tính của bạn [có tên “PATH” dài hơn 260 ký tự]
Bây giờ, hãy chuyển đến thanh tìm kiếm Windows ở cuối màn hình của bạn và nhập “cmd”. Nhấp vào ứng dụng “Command Prompt” và nó sẽ mở ra một hộp đen. Thông tin thêm về dấu nhắc lệnh tại đây
Nhập nội dung sau và nhấn enter
python --version
Bạn sẽ thấy một cái gì đó như thế này trong đó "3. 9. 5” [đó là phiên bản trong trường hợp của tôi] xuất hiện sau khi chạy lệnh
Cũng tùy chọn, pip bây giờ sẽ được cài đặt. Pip là trình cài đặt gói cho Python [trình cài đặt đã bao gồm nó trong ảnh chụp màn hình đầu tiên ở trên]
Pip được sử dụng để cài đặt và quản lý các gói phần mềm mà bạn sử dụng trong mã Python của mình 🙂 và bằng cách đó bạn có thể xây dựng tất cả các loại ứng dụng Python thú vị
Để kiểm tra xem pip đã được cài đặt chưa, trong dấu nhắc lệnh của bạn, hãy nhập lệnh này và nhấn enter
pip --version
Và bây giờ bạn đã cài đặt Python trên máy tính Windows 10 của mình.
Nhân tiện, nếu bạn đang tìm một cuốn sách hay về Python, chúng tôi đã liệt kê chúng ở đây [mỗi cuốn cũng bao gồm cách cài đặt Python]
Trong lập trình, chúng tôi giải quyết các vấn đề khi chúng tôi phải làm việc với các tệp và mô-đun bên ngoài. Do đó, chúng ta cần biết vị trí của các tệp được lưu trữ trên đĩa được chỉ định bởi đường dẫn tệp
Một lỗi rất phổ biến trong Python trong quá trình biên dịch là khoảng
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed64. Điều này là do tên đường dẫn hoặc tên tệp chỉ có thể có độ dài cụ thể là khoảng 260 ký tự. Sự cố này không phải là sự cố đối với các hệ thống dựa trên macOS hoặc Linux và chỉ tồn tại trong Windows. Giới hạn này được đưa ra do hạn chế về giới hạn đường dẫn trong các phiên bản đầu tiên của HĐH Windows
Trong Python, chúng tôi có tùy chọn tắt giới hạn độ dài này sau khi cài đặt Python. Kích hoạt tính năng này có thể giúp tương thích đa nền tảng giữa các chương trình và cho phép chương trình chạy bình thường trên phiên bản Windows cũ hơn
Để khắc phục những sự cố như vậy, chúng tôi có thể rút ngắn đường dẫn hoặc tên tệp để đáp ứng độ dài yêu cầu
Tuy nhiên, nếu ai đó muốn loại bỏ giới hạn này, thì đó cũng chưa hẳn là điều xấu. Nếu ai đó đã cài đặt Python trong một thư mục vượt quá giới hạn độ dài đường dẫn, thì nên tắt nó khi tùy chọn được cung cấp
Do không có ai hầu như không làm việc trên các phiên bản Windows ban đầu, nên việc tắt giới hạn đường dẫn không có bất kỳ tác động có hại nào khi chạy mã của bạn và cũng có thể giúp gỡ lỗi để tránh các sự cố như vậy
12:55:27.834684 60:8d:26:a7:c1:88 [oui Unknown] > 33:33:00:00:00:01 [oui Unknown], ethertype IPv6 [0x86dd], length 174: [hlim 255, next-header ICMPv6 [58] payload length: 120] bthub.home > ip6-allnodes: [icmp6 sum ok] ICMP6, router advertisement, length 120 hop limit 64, Flags [other stateful], pref medium, router lifetime 180s, reachable time 0ms, retrans timer 0ms prefix info option [3], length 32 [4]: 2a00:23c5:ee00:5001::/64, Flags [onlink, auto, router], valid time 300s, pref. time 120s 0x0000: 40e0 0000 012c 0000 0078 0000 0000 2a00 0x0010: 23c5 ee00 5001 0000 0000 0000 0000 prefix info option [3], length 32 [4]: fd4d:869:6f93::/64, Flags [onlink, auto, router], valid time 10080s, pref. time 2880s 0x0000: 40e0 0000 2760 0000 0b40 0000 0000 fd4d 0x0010: 0869 6f93 0000 0000 0000 0000 0000 rdnss option [25], length 24 [3]: lifetime 60s, addr: bthub.home 0x0000: 0000 0000 003c fe80 0000 0000 0000 628d 0x0010: 26ff fea7 c188 mtu option [5], length 8 [1]: 1492 0x0000: 0000 0000 05d4 source link-address option [1], length 8 [1]: 60:8d:26:a7:c1:88 0x0000: 608d 26a7 c188
Sử dụng dấu ngoặc đơn kèm theo để tiếp tục trên nhiều dòng trong trình quản lý ngữ cảnh hiện được hỗ trợ. Điều này cho phép định dạng một bộ sưu tập dài các trình quản lý bối cảnh trong nhiều dòng theo cách tương tự như trước đây có thể thực hiện với các câu lệnh nhập. Chẳng hạn, tất cả những ví dụ này hiện có giá trị
with [CtxManager[] as example]: ... with [ CtxManager1[], CtxManager2[] ]: ... with [CtxManager1[] as example, CtxManager2[]]: ... with [CtxManager1[], CtxManager2[] as example]: ... with [ CtxManager1[] as example1, CtxManager2[] as example2 ]: ...
cũng có thể sử dụng dấu phẩy ở cuối nhóm kèm theo
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
Cú pháp mới này sử dụng khả năng không phải LL[1] của trình phân tích cú pháp mới. Kiểm tra PEP 617 để biết thêm chi tiết
[Đóng góp bởi Guido van Rossum, Pablo Galindo và Lysandros Nikolaou trong bpo-12782 và bpo-40334. ]
Thông báo lỗi tốt hơn¶
Lỗi cú pháp¶
Khi phân tích mã có chứa dấu ngoặc đơn hoặc dấu ngoặc đơn không đóng, trình thông dịch hiện bao gồm vị trí của dấu ngoặc đơn không đóng thay vì hiển thị SyntaxError. EOF bất ngờ trong khi phân tích cú pháp hoặc trỏ đến một số vị trí không chính xác. Chẳng hạn, hãy xem xét đoạn mã sau [chú ý '{']
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
Các phiên bản trước của trình thông dịch đã báo cáo những chỗ khó hiểu là vị trí của lỗi cú pháp
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
nhưng trong Python 3. 10 một lỗi nhiều thông tin hơn được phát ra
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
Theo cách tương tự, các lỗi liên quan đến chuỗi ký tự không được đóng dấu [trích dẫn đơn và ba] hiện trỏ đến phần đầu của chuỗi thay vì báo cáo EOF/EOL
Những cải tiến này được lấy cảm hứng từ công việc trước đó trong trình thông dịch PyPy
[Đóng góp bởi Pablo Galindo trong bpo-42864 và Batuhan Taskaya trong bpo-40176. ]
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed4 ngoại lệ do trình thông dịch đưa ra giờ đây sẽ làm nổi bật toàn bộ phạm vi lỗi của biểu thức tạo thành lỗi cú pháp, thay vì chỉ nơi phát hiện sự cố. Theo cách này, thay vì hiển thị [trước Python 3. 10]
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
bây giờ Python 3. 10 sẽ hiển thị ngoại lệ như
pip --version
0Cải tiến này được đóng góp bởi Pablo Galindo trong bpo-43914
Một số lượng đáng kể các thông báo chuyên biệt mới cho
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed4 ngoại lệ đã được kết hợp. Một số trong những cái đáng chú ý nhất như sau
Thiếu
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
6 trước các khối
3pip --version
[Đóng góp bởi Pablo Galindo trong bpo-42997. ]
Các bộ dữ liệu không có dấu ngoặc đơn trong các mục tiêu hiểu
4pip --version
[Đóng góp bởi Pablo Galindo trong bpo-43017. ]
Thiếu dấu phẩy trong tập hợp chữ và giữa các biểu thức
5pip --version
[Đóng góp bởi Pablo Galindo trong bpo-43822. ]
Nhiều loại ngoại lệ không có dấu ngoặc đơn
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
0[Đóng góp bởi Pablo Galindo trong bpo-43149. ]
Thiếu
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
6 và các giá trị trong từ điểnwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
1[Đóng góp bởi Pablo Galindo trong bpo-43823. ]
Khối
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
8 không có khốiFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
9 hoặc>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
0with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
2[Đóng góp bởi Pablo Galindo trong bpo-44305. ]
Cách sử dụng
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
1 thay vì>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
2 trong so sánhwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
3[Đóng góp bởi Pablo Galindo trong bpo-43797. ]
Cách sử dụng
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
3 trong chuỗi fwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
4[Đóng góp bởi Pablo Galindo trong bpo-41064. ]
Lỗi thụt đầu dòng¶
Nhiều ngoại lệ
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized4 hiện có nhiều ngữ cảnh hơn liên quan đến loại khối nào đang mong đợi một vết lõm, bao gồm cả vị trí của câu lệnh
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...5
Lỗi thuộc tính¶
Khi in
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized5,
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized6 sẽ đưa ra gợi ý về các tên thuộc tính tương tự trong đối tượng mà ngoại lệ được đưa ra từ
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...6
[Đóng góp bởi Pablo Galindo trong bpo-38530. ]
Cảnh báo
Lưu ý rằng điều này sẽ không hoạt động nếu
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized6 không được gọi để hiển thị lỗi, điều này có thể xảy ra nếu một số chức năng hiển thị lỗi tùy chỉnh khác được sử dụng. Đây là một kịch bản phổ biến trong một số REPL như IPython
TênLỗi¶
Khi in
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized8 do trình thông dịch đưa ra,
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized6 sẽ đưa ra gợi ý về các tên biến tương tự trong hàm mà ngoại lệ được đưa ra từ
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...7
[Đóng góp bởi Pablo Galindo trong bpo-38530. ]
Cảnh báo
Lưu ý rằng điều này sẽ không hoạt động nếu
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized6 không được gọi để hiển thị lỗi, điều này có thể xảy ra nếu một số chức năng hiển thị lỗi tùy chỉnh khác được sử dụng. Đây là một kịch bản phổ biến trong một số REPL như IPython
PEP 626. Số dòng chính xác để gỡ lỗi và các công cụ khác¶
PEP 626 mang lại số dòng chính xác và đáng tin cậy hơn cho các công cụ gỡ lỗi, định hình và bảo hiểm. Các sự kiện theo dõi, với số dòng chính xác, được tạo cho tất cả các dòng mã được thực thi và chỉ cho các dòng mã được thực thi
Thuộc tính
pip --version
01 của các đối tượng khung sẽ luôn chứa số dòng dự kiếnThuộc tính
pip --version
02 của các đối tượng mã không được dùng nữa và sẽ bị xóa sau 3. 12. Mã cần chuyển đổi từ offset sang số dòng nên sử dụng phương thức pip --version
03 mới để thay thếPEP 634. Kết hợp mô hình cấu trúc¶
Kết hợp mẫu cấu trúc đã được thêm vào dưới dạng câu lệnh khớp và câu lệnh trường hợp của các mẫu có hành động liên quan. Các mẫu bao gồm các chuỗi, ánh xạ, kiểu dữ liệu nguyên thủy cũng như các thể hiện của lớp. Khớp mẫu cho phép các chương trình trích xuất thông tin từ các loại dữ liệu phức tạp, phân nhánh theo cấu trúc dữ liệu và áp dụng các hành động cụ thể dựa trên các dạng dữ liệu khác nhau
Cú pháp và thao tác¶
Cú pháp chung của khớp mẫu là
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...8
Câu lệnh so khớp lấy một biểu thức và so sánh giá trị của nó với các mẫu liên tiếp được đưa ra dưới dạng một hoặc nhiều khối trường hợp. Cụ thể, khớp mẫu hoạt động bởi
sử dụng dữ liệu có loại và hình dạng [các
04]pip --version
đánh giá
04 trong câu lệnhpip --version
06pip --version
so sánh đối tượng với từng mẫu trong câu lệnh
07 từ trên xuống dưới cho đến khi xác nhận khớppip --version
thực hiện hành động được liên kết với mẫu của kết quả khớp đã xác nhận
Nếu đối sánh chính xác không được xác nhận, trường hợp cuối cùng, ký tự đại diện
08, nếu được cung cấp, sẽ được sử dụng làm trường hợp đối sánh. Nếu một đối sánh chính xác không được xác nhận và trường hợp ký tự đại diện không tồn tại, thì toàn bộ khối đối sánh là không hoạt độngpip --version
Cách tiếp cận khai báo¶
Người đọc có thể biết về khớp mẫu thông qua ví dụ đơn giản về khớp chủ đề [đối tượng dữ liệu] với nghĩa đen [mẫu] với câu lệnh chuyển đổi được tìm thấy trong C, Java hoặc JavaScript [và nhiều ngôn ngữ khác]. Thông thường, câu lệnh chuyển đổi được sử dụng để so sánh một đối tượng/biểu thức với các câu lệnh trường hợp có chứa các ký tự
Có thể tìm thấy các ví dụ mạnh mẽ hơn về khớp mẫu trong các ngôn ngữ như Scala và Elixir. Với đối sánh mẫu cấu trúc, cách tiếp cận là “khai báo” và nêu rõ các điều kiện [mẫu] để dữ liệu khớp
Mặc dù một loạt hướng dẫn "bắt buộc" sử dụng các câu lệnh "nếu" lồng nhau có thể được sử dụng để thực hiện điều gì đó tương tự như đối sánh mẫu cấu trúc, nhưng nó không rõ ràng bằng cách tiếp cận "khai báo". Thay vào đó, cách tiếp cận "khai báo" nêu rõ các điều kiện để đáp ứng cho một trận đấu và dễ đọc hơn thông qua các mẫu rõ ràng của nó. Mặc dù khớp mẫu cấu trúc có thể được sử dụng ở dạng đơn giản nhất so sánh một biến với một chữ trong câu lệnh tình huống, nhưng giá trị thực sự của nó đối với Python nằm ở việc xử lý loại và hình dạng của đối tượng.
hoa văn đơn giản. phù hợp với một nghĩa đen¶
Hãy xem ví dụ này dưới dạng đối sánh mẫu ở dạng đơn giản nhất. một giá trị, chủ đề, được khớp với một số nghĩa đen, các mẫu. Trong ví dụ dưới đây,
pip --version
09 là chủ ngữ của câu đối sánh. Các mẫu là từng câu lệnh tình huống, trong đó chữ đại diện cho mã trạng thái yêu cầu. Hành động liên quan đến trường hợp được thực hiện sau một trận đấuwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...9
Nếu chức năng trên được thông qua một
pip --version
09 của 418, "Tôi là một ấm trà" được trả về. Nếu hàm trên được truyền vào một pip --version
09 trên 500, câu lệnh tình huống với pip --version
08 sẽ khớp với nhau dưới dạng ký tự đại diện và "Đã xảy ra lỗi với internet" được trả về. Lưu ý khối cuối cùng. tên biến, pip --version
08, hoạt động như một ký tự đại diện và đảm bảo chủ đề sẽ luôn khớp. Việc sử dụng pip --version
08 là tùy chọnBạn có thể kết hợp nhiều chữ trong một mẫu duy nhất bằng cách sử dụng
pip --version
35 [“hoặc”]expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]0
Nếu chúng tôi sửa đổi ví dụ trên bằng cách loại bỏ khối trường hợp cuối cùng, ví dụ sẽ trở thành
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]1
Nếu không sử dụng
pip --version
08 trong câu lệnh tình huống, một kết quả trùng khớp có thể không tồn tại. Nếu không có trận đấu nào tồn tại, hành vi này là không hoạt động. Ví dụ: nếu pip --version
09 trên 500 được thông qua, thì sẽ xảy ra lỗi không hoạt độngCác mẫu có chữ và biến¶
Các mẫu có thể trông giống như các bài tập giải nén và một mẫu có thể được sử dụng để liên kết các biến. Trong ví dụ này, một điểm dữ liệu có thể được giải nén theo tọa độ x và tọa độ y của nó
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]2
Mẫu đầu tiên có hai chữ,
pip --version
38, và có thể được coi là phần mở rộng của mẫu chữ được hiển thị ở trên. Hai mẫu tiếp theo kết hợp một chữ và một biến, và biến liên kết một giá trị từ chủ thể [pip --version
39]. Mẫu thứ tư nắm bắt hai giá trị, khiến nó tương tự về mặt khái niệm với bài tập giải nén pip --version
40Mẫu và lớp¶
Nếu bạn đang sử dụng các lớp để cấu trúc dữ liệu của mình, bạn có thể sử dụng tên lớp làm mẫu theo sau là danh sách đối số giống như hàm tạo. Mẫu này có khả năng nắm bắt các thuộc tính của lớp thành các biến
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]3
Bạn có thể sử dụng các tham số vị trí với một số lớp dựng sẵn cung cấp thứ tự cho các thuộc tính của chúng [e. g. lớp dữ liệu]. Bạn cũng có thể xác định một vị trí cụ thể cho các thuộc tính trong các mẫu bằng cách đặt thuộc tính đặc biệt
pip --version
41 trong các lớp của bạn. Nếu nó được đặt thành [“x”, “y”], tất cả các mẫu sau đều tương đương [và tất cả đều liên kết thuộc tính pip --version
42 với biến pip --version
43]expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]4
Các mẫu lồng nhau¶
Các mẫu có thể được lồng vào nhau tùy ý. Ví dụ: nếu dữ liệu của chúng tôi là một danh sách ngắn các điểm, nó có thể được so khớp như thế này
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]5
Các mẫu phức tạp và ký tự đại diện¶
Đến thời điểm này, các ví dụ chỉ sử dụng
pip --version
08 trong câu lệnh tình huống cuối cùng. Ký tự đại diện có thể được sử dụng trong các mẫu phức tạp hơn, chẳng hạn như pip --version
45. Ví dụexpected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]6
Trong trường hợp trên,
pip --version
46 sẽ khớp với [‘error’, code, 100] và [‘error’, code, 800]Bảo vệ¶
Chúng ta có thể thêm một mệnh đề
pip --version
47 vào một mẫu, được gọi là “bảo vệ”. Nếu bảo vệ là sai, pip --version
06 tiếp tục thử khối trường hợp tiếp theo. Note that value capture happens before the guard is evaluatedexpected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]7
Other Key Features¶
Several other key features
Like unpacking assignments, tuple and list patterns have exactly the same meaning and actually match arbitrary sequences. Về mặt kỹ thuật, chủ đề phải là một chuỗi. Therefore, an important exception is that patterns don’t match iterators. Also, to prevent a common mistake, sequence patterns don’t match strings
Sequence patterns support wildcards.
49 andpip --version
50 work similar to wildcards in unpacking assignments. The name afterpip --version
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
3 may also be
08, sopip --version
53 matches a sequence of at least two items without binding the remaining itemspip --version
Mapping patterns.
54 captures thepip --version
55 andpip --version
56 values from a dict. Unlike sequence patterns, extra keys are ignored. A wildcardpip --version
57 is also supported. [Butpip --version
58 would be redundant, so is not allowed. ]pip --version
Subpatterns may be captured using the
59 keywordpip --version
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
8This binds x1, y1, x2, y2 like you would expect without the
59 clause, and p2 to the entire second item of the subjectpip --version
Hầu hết các nghĩa đen được so sánh bằng bình đẳng. However, the singletons
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
01,with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
02 andwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
03 are compared by identityNamed constants may be used in patterns. These named constants must be dotted names to prevent the constant from being interpreted as a capture variable
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
9
For the full specification see PEP 634. Motivation and rationale are in PEP 635, and a longer tutorial is in PEP 636
Optional with [
CtxManager1[] as example1,
CtxManager2[] as example2,
CtxManager3[] as example3,
]:
...
04 and with [
CtxManager1[] as example1,
CtxManager2[] as example2,
CtxManager3[] as example3,
]:
...
05 option¶
The default encoding of
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...06 and
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...07 is platform and locale dependent. Since UTF-8 is used on most Unix platforms, omitting
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...08 option when opening UTF-8 files [e. g. JSON, YAML, TOML, Markdown] is a very common bug. For example
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax0
To find this type of bug, an optional
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...04 is added. It is emitted when
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...10 is true and locale-specific default encoding is used
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...11 option and
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...12 are added to enable the warning
See Text Encoding for more information.
New Features Related to Type Hints¶
This section covers major changes affecting PEP 484 type hints and the
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...13 module
PEP 604. New Type Union Operator¶
A new type union operator was introduced which enables the syntax
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...14. This provides a cleaner way of expressing ‘either type X or type Y’ instead of using
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...15, especially in type hints
In previous versions of Python, to apply a type hint for functions accepting arguments of multiple types,
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...15 was used
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax1
Type hints can now be written in a more succinct manner
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax2
This new syntax is also accepted as the second argument to
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...17 and
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...18
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax3
See Union Type and PEP 604 for more details.
[Contributed by Maggie Moss and Philippe Prados in bpo-41428, with additions by Yurii Karabas and Serhiy Storchaka in bpo-44490. ]
PEP 612. Parameter Specification Variables¶
Two new options to improve the information provided to static type checkers for PEP 484‘s
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...19 have been added to the
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...13 module
The first is the parameter specification variable. They are used to forward the parameter types of one callable to another callable – a pattern commonly found in higher order functions and decorators. Examples of usage can be found in
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...21. Previously, there was no easy way to type annotate dependency of parameter types in such a precise manner
The second option is the new
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...22 operator. It’s used in conjunction with parameter specification variables to type annotate a higher order callable which adds or removes parameters of another callable. Ví dụ về cách sử dụng có thể được tìm thấy trong
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...23
See
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...24,
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...21,
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...23,
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...27,
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...28, and PEP 612 for more details
[Được đóng góp bởi Ken Jin trong bpo-41559, với những cải tiến nhỏ của Jelle Zijlstra trong bpo-43783. PEP written by Mark Mendoza. ]
PEP 613. TypeAlias¶
PEP 484 introduced the concept of type aliases, only requiring them to be top-level unannotated assignments. This simplicity sometimes made it difficult for type checkers to distinguish between type aliases and ordinary assignments, especially when forward references or invalid types were involved. Compare
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax4
Now the
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...13 module has a special value
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...30 which lets you declare type aliases more explicitly
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax5
See PEP 613 for more details
[Contributed by Mikhail Golubev in bpo-41923. ]
PEP 647. User-Defined Type Guards¶
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...31 has been added to the
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...13 module to annotate type guard functions and improve information provided to static type checkers during type narrowing. For more information, please see
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...31‘s documentation, and PEP 647
[Contributed by Ken Jin and Guido van Rossum in bpo-43766. PEP written by Eric Traut. ]
Other Language Changes¶
The
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
34 type has a new methodwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
35, returning the number of ones in the binary expansion of a given integer, also known as the population count. [Contributed by Niklas Fiekas in bpo-29882. ]The views returned by
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
36,with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
37 andwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
38 now all have awith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
39 attribute that gives awith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
40 object wrapping the original dictionary. [Contributed by Dennis Sweeney in bpo-40890. ]PEP 618. The
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
41 function now has an optionalwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
42 flag, used to require that all the iterables have an equal lengthBuiltin and extension functions that take integer arguments no longer accept
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
43s,with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
44s and other objects that can be converted to integers only with a loss [e. g. có phương thứcwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
45 nhưng không có phương thứcwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
46]. [Contributed by Serhiy Storchaka in bpo-37999. ]If
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
47 returnswith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
48, the operator will correctly fall back towith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
49 andwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
50 as expected. [Đóng góp bởi Alex Shkop trong bpo-38302. ]Giờ đây, các biểu thức gán có thể được sử dụng không được mở trong ngoặc đơn trong các bộ chữ và bộ hiểu, cũng như trong các chỉ mục trình tự [nhưng không phải lát]
Các hàm có một thuộc tính
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
51 mới được sử dụng để tìm kiếm các ký hiệu dựng sẵn khi một hàm được thực thi, thay vì tìm kiếm trongwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
52. Thuộc tính được khởi tạo từwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
53 nếu nó tồn tại, khác từ nội trang hiện tại. [Đóng góp bởi Mark Shannon trong bpo-42990. ]Hai chức năng dựng sẵn mới –
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
54 vàwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
55 đã được thêm vào để cung cấp các bản sao không đồng bộ chowith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
56 vàwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
57, tương ứng. [Đóng góp bởi Joshua Bronson, Daniel Pope và Justin Wang trong bpo-31861. ]Các phương thức tĩnh [
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
58] và phương thức lớp [with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
59] hiện kế thừa các thuộc tính phương thức [with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
60,with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
61,with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
62,with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
63,with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
64] và có thuộc tínhwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
65 mới. Hơn nữa, các phương thức tĩnh hiện có thể gọi được như các hàm thông thường. [Đóng góp bởi Victor Stinner trong bpo-43682. ]Chú thích cho các mục tiêu phức tạp [mọi thứ bên cạnh các mục tiêu
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
66 được xác định bởi PEP 526] không còn gây ra bất kỳ hiệu ứng thời gian chạy nào vớiwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
67. [Đóng góp bởi Batuhan Taskaya trong bpo-42737. ]Các đối tượng lớp và mô-đun hiện lười tạo các chú thích trống theo yêu cầu. Các ký hiệu chú thích được lưu trữ trong đối tượng
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
68 để tương thích ngược. Điều này cải thiện các phương pháp hay nhất để làm việc vớiwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
64; . [Đóng góp bởi Larry Hastings trong bpo-43901. ]Annotations Best Practices. [Contributed by Larry Hastings in bpo-43901.]Các chú thích bao gồm
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
70,with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
71,with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
72 hoặc các biểu thức được đặt tên hiện bị cấm theowith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
67 do tác dụng phụ của chúng. [Đóng góp bởi Batuhan Taskaya trong bpo-42725. ]Việc sử dụng các biến không liên kết,
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
74 và các biểu thức khác có thể thay đổi quá trình xử lý bảng ký hiệu dưới dạng các chú thích hiện không có hiệu lực theowith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
67. [Đóng góp bởi Batuhan Taskaya trong bpo-42725. ]Băm giá trị NaN của cả loại
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
76 và loạiwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
77 hiện phụ thuộc vào danh tính đối tượng. Trước đây, chúng luôn được băm thànhwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
78 mặc dù các giá trị NaN không bằng nhau. Điều này có thể gây ra hành vi thời gian chạy bậc hai do xung đột hàm băm quá mức khi tạo từ điển và bộ chứa nhiều NaN. [Đóng góp bởi Raymond Hettinger trong bpo-43475. ]Một
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
4 [thay vì một>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
8] sẽ được nâng lên khi xóa hằng sốwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
81. [Đóng góp bởi Dong-hee Na trong bpo-45000. ]Các ngoại lệ của
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
4 hiện có các thuộc tínhwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
83 vàwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
84. Họ sẽ làwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
03 nếu không được xác định. [Đóng góp bởi Pablo Galindo trong bpo-43914. ]
Mô-đun mới¶
chưa có
Mô-đun cải tiến¶
không đồng bộ¶
Thêm phương thức
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...86 bị thiếu. [Đóng góp bởi Alex Grönholm trong bpo-41332. ]
argparse¶
Cụm từ gây hiểu lầm "đối số tùy chọn" đã được thay thế bằng "tùy chọn" trong trợ giúp argparse. Một số thử nghiệm có thể yêu cầu điều chỉnh nếu chúng dựa vào khớp đầu ra chính xác. [Đóng góp bởi Raymond Hettinger trong bpo-9694. ]
mảng¶
Phương thức
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...87 của
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...88 hiện có các tham số bắt đầu và dừng tùy chọn. [Đóng góp bởi Anders Lorentsen và Zackery Spytz trong bpo-31956. ]
không đồng bộ, không đồng bộ, smtpd¶
Các mô-đun này đã được đánh dấu là không dùng nữa trong tài liệu mô-đun của chúng kể từ Python 3. 6. Một
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...89 thời gian nhập khẩu hiện đã được thêm vào cả ba mô-đun này
đế64¶
Thêm
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...90 và
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...91 để hỗ trợ Mã hóa Base32 với Bảng chữ cái Hex mở rộng
bdb¶
Thêm
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...92 để đặt lại tất cả các điểm dừng đã đặt. [Contributed by Irit Katriel in bpo-24160. ]
bisect¶
Đã thêm khả năng cung cấp chức năng chính cho API trong mô-đun
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...93. [Đóng góp bởi Raymond Hettinger trong bpo-4356. ]
codec¶
Thêm chức năng
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...94 để hủy đăng ký chức năng tìm kiếm codec. [Đóng góp bởi Hai Shi trong bpo-41842. ]
bộ sưu tập. abc¶
The
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...95 of the parameterized generic for
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...96 are now consistent with
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...24.
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...96 chung hiện làm phẳng các tham số loại, tương tự như những gì mà
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...24 hiện đang làm. Điều này có nghĩa là
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]00 sẽ có
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...95 của
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]02; . Để cho phép thay đổi này,
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]04 hiện có thể được phân lớp và một lớp con sẽ được trả về khi đăng ký loại
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...96. Lưu ý rằng một
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]06 có thể được nâng lên đối với các dạng tham số hóa không hợp lệ
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...96 có thể đã âm thầm chuyển qua trong Python 3. 9. [Đóng góp bởi Ken Jin trong bpo-42195. ]
contextlib¶
Thêm một trình quản lý ngữ cảnh
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]08 để đóng các trình tạo không đồng bộ một cách an toàn và các đối tượng đại diện cho các tài nguyên được giải phóng không đồng bộ. [Đóng góp bởi Joongi Kim và John Belmonte trong bpo-41229. ]
Thêm hỗ trợ trình quản lý bối cảnh không đồng bộ vào
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]09. [Đóng góp bởi Tom Gringauz trong bpo-41543. ]
Thêm
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]10, để hỗ trợ sử dụng trình quản lý bối cảnh không đồng bộ làm trình trang trí
nguyền rủa¶
Các chức năng màu mở rộng được thêm vào trong ncurses 6. 1 sẽ được sử dụng minh bạch bởi
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]11,
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]12,
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]13 và
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]14. Một chức năng mới,
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]15, cho biết liệu thư viện ncurses cơ bản có hỗ trợ màu mở rộng hay không. [Được đóng góp bởi Jeffrey Kintscher và Hans Petter Jansson trong bpo-36982. ]
Các hằng số
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]16 hiện được hiển thị trong mô-đun
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]17 nếu chúng được cung cấp bởi thư viện lời nguyền cơ bản. [Đóng góp bởi Zackery Spytz trong bpo-39273. ]
lớp dữ liệu¶
__slots__¶
Đã thêm tham số
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]18 trong trình trang trí
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]19. [Đóng góp bởi Yurii Karabas trong bpo-42269]
Các trường chỉ có từ khóa¶
các lớp dữ liệu hiện hỗ trợ các trường chỉ có từ khóa trong phương thức __init__ được tạo. Có một số cách chỉ định các trường chỉ từ khóa
Bạn có thể nói rằng mọi trường chỉ có từ khóa
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax6
Cả
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]20 và
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]21 đều là tham số chỉ từ khóa đối với phương thức __init__ được tạo
Bạn có thể chỉ định chỉ từ khóa trên cơ sở từng trường
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax7
Ở đây chỉ có
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]21 là từ khóa duy nhất. Nếu bạn đặt
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]23 trên các trường riêng lẻ, hãy lưu ý rằng có các quy tắc về sắp xếp lại các trường do các trường chỉ có từ khóa cần tuân theo các trường không chỉ có từ khóa. See the full dataclasses documentation for details
You can also specify that all fields following a KW_ONLY marker are keyword-only. This will probably be the most common usage
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax8
Here,
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]24 and
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]25 are keyword-only parameters, while
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]26 and
pip --version
42 are not. [Contributed by Eric V. Smith in bpo-43532. ]distutils¶
The entire
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]28 package is deprecated, to be removed in Python 3. 12. Its functionality for specifying package builds has already been completely replaced by third-party packages
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]29 and
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]30, and most other commonly used APIs are available elsewhere in the standard library [such as
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]31,
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]32,
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]33 or
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]34]. There are no plans to migrate any other functionality from
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]28, and applications that are using other functions should plan to make private copies of the code. Refer to PEP 632 for discussion
The
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]36 command deprecated in Python 3. 8 has been removed. The
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]37 command is now recommended to distribute binary packages on Windows. [Contributed by Victor Stinner in bpo-42802. ]
doctest¶
When a module does not define
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]38, fall back to
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]39. [Contributed by Brett Cannon in bpo-42133. ]
encodings¶
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]40 now ignores non-ASCII characters. [Contributed by Hai Shi in bpo-39337. ]
enum¶
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]41
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]42 hiện trả về
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]43 và
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]44 hiện trả về
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]45. Stdlib enums available as module constants have a
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]46 of
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]47. [Contributed by Ethan Furman in bpo-40066. ]
Add
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]48 for enums where all members are strings. [Đóng góp bởi Ethan Furman trong bpo-41816. ]
fileinput¶
Add encoding and errors parameters in
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]49 and
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]50. [Contributed by Inada Naoki in bpo-43712. ]
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]51 now returns
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...06 object when mode is “r” and file is compressed, like uncompressed files. [Contributed by Inada Naoki in bpo-5758. ]
faulthandler¶
The
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]53 module now detects if a fatal error occurs during a garbage collector collection. [Contributed by Victor Stinner in bpo-44466. ]
gc¶
Thêm móc kiểm tra cho
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]54,
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]55 và
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]56. [Contributed by Pablo Galindo in bpo-43439. ]
glob¶
Thêm tham số root_dir và dir_fd trong
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]57 và
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]58 cho phép chỉ định thư mục gốc để tìm kiếm. [Contributed by Serhiy Storchaka in bpo-38144. ]
hashlib¶
The hashlib module requires OpenSSL 1. 1. 1 or newer. [Contributed by Christian Heimes in PEP 644 and bpo-43669. ]
The hashlib module has preliminary support for OpenSSL 3. 0. 0. [Contributed by Christian Heimes in bpo-38820 and other issues. ]
Dự phòng Python thuần túy của
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]59 không được dùng nữa. Trong tương lai, PBKDF2-HMAC sẽ chỉ khả dụng khi Python được xây dựng với hỗ trợ OpenSSL. [Đóng góp bởi Christian Heimes trong bpo-43880. ]
hmac¶
The hmac module now uses OpenSSL’s HMAC implementation internally. [Đóng góp bởi Christian Heimes trong bpo-40645. ]
IDLE và idlib¶
Tạo IDLE gọi
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]60 [khi bắt đầu không có '-n']. User hooks were previously ignored. [Đóng góp bởi Ken Hilton trong bpo-43008. ]
Rearrange the settings dialog. Split the General tab into Windows and Shell/Ed tabs. Move help sources, which extend the Help menu, to the Extensions tab. Tạo khoảng trống cho các tùy chọn mới và rút ngắn hộp thoại. Cái sau làm cho hộp thoại phù hợp hơn với màn hình nhỏ. [Contributed by Terry Jan Reedy in bpo-40468. ] Di chuyển cài đặt khoảng cách thụt lề từ tab Phông chữ sang tab Windows mới. [Đóng góp bởi Mark Roseman và Terry Jan Reedy trong bpo-33962. ]
Những thay đổi ở trên đã được nhập vào 3. 9 phát hành bảo trì
Thêm thanh bên Shell. Di chuyển lời nhắc chính [‘>>>’] sang thanh bên. Thêm lời nhắc phụ ['…'] vào thanh bên. Nhấp chuột trái và kéo tùy chọn chọn một hoặc nhiều dòng văn bản, như với thanh bên số dòng của trình soạn thảo. Nhấp chuột phải sau khi chọn dòng văn bản sẽ hiển thị menu ngữ cảnh với 'sao chép bằng lời nhắc'. This zips together prompts from the sidebar with lines from the selected text. Tùy chọn này cũng xuất hiện trên menu ngữ cảnh cho văn bản. [Contributed by Tal Einat in bpo-37903. ]
Sử dụng khoảng trắng thay vì tab để thụt lề mã tương tác. This makes interactive code entries ‘look right’. Làm cho điều này khả thi là một động lực chính để thêm thanh bên shell. [Đóng góp bởi Terry Jan Reedy trong bpo-37892. ]
Làm nổi bật từ khóa mềm
pip --version
06, pip --version
07 và pip --version
08 mới trong các câu đối sánh mẫu. Tuy nhiên, phần đánh dấu này không hoàn hảo và sẽ không chính xác trong một số trường hợp hiếm gặp, bao gồm một số mẫu pip --version
08 trong mẫu pip --version
07. [Đóng góp bởi Tal Einat trong bpo-44010. ]New in 3. 10 bản phát hành bảo trì
Áp dụng tô sáng cú pháp cho các tệp
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]66. [Đóng góp bởi Alex Waygood và Terry Jan Reedy trong bpo-45447. ]
Bao gồm lời nhắc khi lưu Shell với đầu vào và đầu ra. [Đóng góp bởi Terry Jan Reedy trong gh-95191. ]
nhập khẩu. metadata¶
Tính năng tương đương với
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]67 4. 6 [lịch sử]
importlib. điểm nhập siêu dữ liệu hiện cung cấp trải nghiệm tốt hơn để chọn điểm nhập theo nhóm và tên thông qua lớp
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]68 mới. Xem Ghi chú tương thích trong tài liệu để biết thêm thông tin về việc ngừng sử dụng và sử dụng.
Đã thêm
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]69 để giải quyết các gói và mô-đun Python cấp cao nhất cho
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]70 của họ
quan sát¶
When a module does not define
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]38, fall back to
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]39. [Contributed by Brett Cannon in bpo-42133. ]
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]76,
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]77, and
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]78 now call
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]73 to retrieve annotations. This means
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]76 and
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]77 can also now un-stringize stringized annotations. [Contributed by Larry Hastings in bpo-43817.]
itertools¶
Thêm
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]82. [Đóng góp bởi Raymond Hettinger trong bpo-38200. ]
bộ đệm dòng¶
When a module does not define
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]38, fall back to
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]39. [Contributed by Brett Cannon in bpo-42133. ]
os¶
Thêm hỗ trợ
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]85 cho VxWorks RTOS. [Đóng góp bởi Peixing Xin trong bpo-41440. ]
Thêm chức năng mới
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]86 và các trình trợ giúp có liên quan để bao bọc tòa nhà chọc trời
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]87 trên Linux. [Đóng góp bởi Christian Heimes trong bpo-41001. ]
Thêm
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]88 cho phép di chuyển dữ liệu giữa hai bộ mô tả tệp mà không cần sao chép giữa không gian địa chỉ hạt nhân và không gian địa chỉ người dùng, trong đó một trong các bộ mô tả tệp phải tham chiếu đến một đường ống. [Đóng góp bởi Pablo Galindo trong bpo-41625. ]
Thêm
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]89,
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]90,
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]91 và
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]92 cho macOS. [Đóng góp bởi Dong-hee Na trong bpo-43106. ]
hệ điều hành. con đường¶
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]93 hiện chấp nhận đối số chỉ từ khóa nghiêm ngặt. Khi được đặt thành
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...01,
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]95 được nâng lên nếu đường dẫn không tồn tại hoặc gặp phải vòng lặp liên kết tượng trưng. [Đóng góp bởi Barney Gale trong bpo-43757. ]
pathlib¶
Thêm hỗ trợ lát cắt vào
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]96. [Đóng góp bởi Joshua Cannon trong bpo-35498. ]
Thêm hỗ trợ lập chỉ mục tiêu cực vào
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]96. [Đóng góp bởi Yaroslav Pankovych trong bpo-21041. ]
Thêm phương thức
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]98 thay thế cho
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]99. Phương thức mới có cùng thứ tự đối số như
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax00. [Đóng góp bởi Barney Gale trong bpo-39950. ]
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax01 và
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax02 hiện chấp nhận đối số chỉ từ khóa follow_symlinks để thống nhất với các chức năng tương ứng trong mô-đun
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax03. [Đóng góp bởi Barney Gale trong bpo-39906. ]
nền tảng¶
Thêm
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax04 để truy xuất nhận dạng hệ điều hành từ freedesktop. tập tin tiêu chuẩn phát hành hệ điều hành org. [Đóng góp bởi Christian Heimes trong bpo-28468. ]
pprint¶
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax05 hiện chấp nhận đối số từ khóa
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax06 mới. [Đóng góp bởi sblondon trong bpo-42914. ]
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax07 hiện có thể in đẹp các phiên bản
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax08. [Đóng góp bởi Lewis Gaul trong bpo-43080. ]
py_compile¶
Thêm tùy chọn
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax09 vào giao diện dòng lệnh của
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax10. [Đóng góp bởi Gregory Schevchenko trong bpo-38731. ]
pyclbr¶
Thêm một thuộc tính
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...83 vào các đối tượng
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax12 và
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax13 trong cây được trả về bởi
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax14 và
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax15. Nó phù hợp với [bắt đầu]
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax16 hiện có. [Đóng góp bởi Aviral Srivastava trong bpo-38307. ]
xiên¶
Mô-đun
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax17 hiện sử dụng
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax18 theo mặc định thay vì giao thức
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax19
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax20 khi tạo giá. [Đóng góp bởi Zackery Spytz trong bpo-34204. ]
số liệu thống kê¶
Thêm các hàm
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax21,
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax22 của Pearson và các hàm
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax23 đơn giản. [Đóng góp bởi Tymoteusz Wołodźko trong bpo-38490. ]
Địa điểm¶
When a module does not define
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]38, fall back to
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]39. [Contributed by Brett Cannon in bpo-42133. ]
ổ cắm¶
Ngoại lệ
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax26 hiện là bí danh của
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax27. [Đóng góp bởi Christian Heimes trong bpo-42413. ]
Thêm tùy chọn tạo socket MPTCP với
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax28 [Rui Cunha đóng góp trong bpo-43571. ]
Thêm tùy chọn
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax29 để nhận các trường loại dịch vụ [ToS] hoặc DSCP/ECN [Được đóng góp bởi Georg Sauthoff trong bpo-44077. ]
ssl¶
Mô-đun ssl yêu cầu OpenSSL 1. 1. 1 hoặc mới hơn. [Đóng góp bởi Christian Heimes trong PEP 644 và bpo-43669. ]
Mô-đun ssl có hỗ trợ sơ bộ cho OpenSSL 3. 0. 0 và tùy chọn mới
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax30. [Được đóng góp bởi Christian Heimes trong bpo-38820, bpo-43794, bpo-43788, bpo-43791, bpo-43799, bpo-43920, bpo-43789 và bpo-43811. ]
Hàm không dùng nữa và việc sử dụng các hằng số không dùng nữa hiện dẫn đến
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...89.
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax32 có
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax33 và
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax34 được đặt theo mặc định và do đó không thể cảnh báo về việc đặt lại cờ. phần không dùng nữa có danh sách các tính năng không dùng nữa. [Đóng góp bởi Christian Heimes trong bpo-43880. ]
Mô-đun ssl hiện có cài đặt mặc định an toàn hơn. Ciphers without forward secrecy or SHA-1 MAC are disabled by default. Mức bảo mật 2 cấm các khóa RSA, DH và ECC yếu có bảo mật dưới 112 bit.
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax35 mặc định là phiên bản giao thức tối thiểu TLS 1. 2. Cài đặt dựa trên nghiên cứu của Hynek Schlawack. [Contributed by Christian Heimes in bpo-43998. ]
The deprecated protocols SSL 3. 0, TLS 1. 0 và TLS 1. 1 are no longer officially supported. Python không chủ động chặn chúng. However OpenSSL build options, distro configurations, vendor patches, and cipher suites may prevent a successful handshake
Add a timeout parameter to the
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax36 function. [Đóng góp bởi Zackery Spytz trong bpo-31870. ]
Mô-đun ssl sử dụng kiểu heap và khởi tạo nhiều pha. [Đóng góp bởi Christian Heimes trong bpo-42333. ]
A new verify flag
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax37 has been added. [Đóng góp bởi l0x trong bpo-40849. ]
sqlite3¶
Add audit events for
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax38,
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax39, and
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax40. [Đóng góp bởi Erlend E. Aasland trong bpo-43762. ]
hệ thống¶
Add
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax41 attribute. the list of the original command line arguments passed to the Python executable. [Contributed by Victor Stinner in bpo-23427. ]
Add
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax42, containing the list of the standard library module names. [Contributed by Victor Stinner in bpo-42955. ]
_thread¶
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax43 hiện có một số tín hiệu tùy chọn để mô phỏng [mặc định vẫn là
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax44]. [Đóng góp bởi Antoine Pitrou trong bpo-43356. ]
luồng¶
Add
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax45 and
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax46 to retrieve the functions set by
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax47 and
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax48 respectively. [Đóng góp bởi Mario Corchero trong bpo-42251. ]
Thêm
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax49 để cho phép truy xuất giá trị ban đầu của
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax50 trong trường hợp nó được đặt thành một giá trị bị hỏng hoặc khác. [Đóng góp bởi Mario Corchero trong bpo-42308. ]
tìm lại¶
Các hàm
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax51,
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax52 và
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax53 hiện có thể lấy một đối tượng ngoại lệ làm đối số chỉ vị trí. [Đóng góp bởi Zackery Spytz và Matthias Bussonnier trong bpo-26389. ]
các loại¶
Giới thiệu lại các lớp
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax54,
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax55 và
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax56, cung cấp một tập hợp các loại mới mà người kiểm tra loại có thể dễ dàng hiểu được. [Đóng góp bởi Bas van Beek trong bpo-41810. ]
đánh máy¶
For major changes, see New Features Related to Type Hints .
The behavior of
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax57 was changed to conform with PEP 586 and to match the behavior of static type checkers specified in the PEP
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
58 hiện loại bỏ các tham số trùng lặpEquality comparisons between
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
58 objects are now order independentFile "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
58 so sánh bây giờ tôn trọng các loại. Ví dụ:File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
61 trước đây được đánh giá thànhwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
01. It is nowwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
02. Để hỗ trợ thay đổi này, bộ đệm loại được sử dụng nội bộ hiện hỗ trợ các loại khác nhauFile "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
58 giờ đây sẽ đưa ra một ngoại lệexpected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
06 trong quá trình so sánh đẳng thức nếu bất kỳ tham số nào của chúng không có thể băm . Lưu ý rằng việc khai báoFile "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
58 với các tham số không thể sửa đổi sẽ không gây ra lỗi.File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
9
[Contributed by Yurii Karabas in bpo-42345. ]
Add new function
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax67 to introspect if an annotation is a
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax68. [Đóng góp bởi Patrick Reader trong bpo-41792. ]
Các lớp con của
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax69 chỉ có các biến dữ liệu được khai báo giờ đây sẽ tăng
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]06 khi được kiểm tra bằng
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax71 trừ khi chúng được trang trí bằng
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax72. Previously, these checks passed silently. Users should decorate their subclasses with the
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax72 decorator if they want runtime protocols. [Đóng góp bởi Yurii Karabas trong bpo-38908. ]
Việc nhập từ các mô-đun con
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax74 và
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax75 giờ đây sẽ phát ra
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...89. Các mô hình con này không được dùng nữa kể từ Python 3. 8 và sẽ bị xóa trong phiên bản tương lai của Python. Anything belonging to those submodules should be imported directly from
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...13 instead. [Đóng góp bởi Sebastian Rittau trong bpo-38291. ]
đơn vị nhất¶
Thêm phương thức mới
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax78 để bổ sung cho
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax79 hiện có. [Đóng góp bởi Kit Yan Choi trong bpo-39385. ]
urllib. phân tích cú pháp¶
Các phiên bản Python sớm hơn Python 3. 10 được phép sử dụng cả
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax80 và
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax81 làm dấu tách tham số truy vấn trong
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax82 và
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax83. Due to security concerns, and to conform with newer W3C recommendations, this has been changed to allow only a single separator key, with
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax81 as the default. Thay đổi này cũng ảnh hưởng đến
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax85 và
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax86 khi họ sử dụng các chức năng bị ảnh hưởng trong nội bộ. Để biết thêm chi tiết, vui lòng xem tài liệu tương ứng của họ. [Đóng góp bởi Adam Goldschmidt, Senthil Kumaran và Ken Jin trong bpo-42967. ]
xml¶
Add a
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax87 class to the
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax88 module. [Contributed by Jonathan Gossage and Zackery Spytz in bpo-35018. ]
zipimport¶
Thêm các phương thức liên quan đến PEP 451.
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax89,
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax90 và
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax91. [Đóng góp bởi Brett Cannon trong bpo-42131. ]
Thêm phương thức
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax92. [Contributed by Desmond Cheong in bpo-14678. ]
Optimizations¶
Constructors
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
93,File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
94 andFile "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
95 are now faster [around 30–40% for small objects]. [Đóng góp bởi Serhiy Storchaka trong bpo-41334. ]Mô-đun
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
96 hiện nhập ít mô-đun hơn. Thời gian khởi động lệnhFile "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
97 là 1. Trung bình nhanh gấp 4 lần. On Linux,File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
98 imports 69 modules on Python 3. 9, trong khi nó chỉ nhập 51 mô-đun [-18] trên Python 3. 10. [Contributed by Victor Stinner in bpo-41006 and bpo-41718. ]Lệnh
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
99 hiện sử dụng cơ chế “per opcode cache” mới. It is about 36% faster now for regular attributes and 44% faster for slots. [Contributed by Pablo Galindo and Yury Selivanov in bpo-42093 and Guido van Rossum in bpo-42927, based on ideas implemented originally in PyPy and MicroPython. ]When building Python with
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
00 nowFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
01 is added to both the compile and link line. Điều này tăng tốc độ xây dựng trình thông dịch Python được tạo bằngFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
02 vớiFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
03 lên tới 30%. Xem bài viết này để biết thêm chi tiết. [Đóng góp bởi Victor Stinner và Pablo Galindo trong bpo-38980. ]Sử dụng mã quản lý bộ đệm đầu ra mới cho các mô-đun
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
04 /File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
05 /File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
06 và thêm hàmFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
07 vào lớpFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
08. giải nén bz2 bây giờ là 1. 09x~1. Nhanh hơn 17 lần, giải nén lzma 1. 20x~1. Nhanh hơn 32 lần,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
09 1. 11x~1. nhanh hơn 18 lần. [Đóng góp bởi Ma Lin, đánh giá bởi Gregory P. Smith, trong bpo-41486]When using stringized annotations, annotations dicts for functions are no longer created when the function is created. Thay vào đó, chúng được lưu trữ dưới dạng một bộ chuỗi và đối tượng hàm sẽ chuyển đổi một cách lười biếng chuỗi này thành chú thích chính tả theo yêu cầu. Sự tối ưu hóa này cắt giảm một nửa thời gian CPU cần thiết để xác định một hàm được chú thích. [Đóng góp bởi Yurii Karabas và Inada Naoki trong bpo-42202. ]
Các chức năng tìm kiếm chuỗi con như
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
10 vàFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
11 đôi khi sử dụng thuật toán tìm kiếm chuỗi “Hai chiều” của Crochemore & Perrin để tránh hành vi bậc hai trên các chuỗi dài. [Đóng góp bởi Dennis Sweeney trong bpo-41972]Add micro-optimizations to
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
12 to improve type attribute cache lookup performance in the common case of cache hits. Điều này làm cho thông dịch viên 1. Trung bình nhanh gấp 04 lần. [Đóng góp bởi Dino Viehland trong bpo-43452. ]Các chức năng tích hợp sau hiện hỗ trợ quy ước gọi vectorcall PEP 590 nhanh hơn.
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
13,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
14,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
15,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
16 vàFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
17. [Đóng góp bởi Dong-hee Na và Jeroen Demeyer trong bpo-43575, bpo-43287, bpo-41922, bpo-41873 và bpo-41870. ]Hiệu suất của
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
18 được cải thiện bằng cách loại bỏ nội bộFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
19. Điều này làm cho chuỗiFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
18 không an toàn khi đối mặt với nhiều người đọc hoặc người viết đồng thời, giống như các lớp tương đương của nó trongFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
21 vàFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
05 luôn là. [Đóng góp bởi Inada Naoki trong bpo-43785. ]
Deprecated¶
Currently Python accepts numeric literals immediately followed by keywords, for example
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
23,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
24,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
25. It allows confusing and ambiguous expressions likeFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
26 [which can be interpreted asFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
27 orFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
28]. Bắt đầu từ bản phát hành này, cảnh báo không dùng nữa sẽ được đưa ra nếu chữ số ngay sau đó là một trong các từ khóaFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
29,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
30,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
31,
47,pip --version
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
33,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
34 vàFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
35. Trong các bản phát hành trong tương lai, nó sẽ được thay đổi thành cảnh báo cú pháp và cuối cùng là lỗi cú pháp. [Đóng góp bởi Serhiy Storchaka trong bpo-43833. ]Bắt đầu từ bản phát hành này, sẽ có một nỗ lực phối hợp để bắt đầu làm sạch ngữ nghĩa nhập cũ được lưu giữ cho Python 2. 7 khả năng tương thích. Specifically,
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
36/File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
37 [superseded byFile "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
89],File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
39 [superseded byFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
40],File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
41 [which the import system takes care of for you], theFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
42 attribute [superseded byFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
43], theexpected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
38 attribute [superseded byexpected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
39], and theFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
46 attribute [superseded byFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
47] will slowly be removed [as well as other classes and methods inFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
48].File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
49 và/hoặcwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
89 sẽ được nâng lên khi thích hợp để giúp xác định mã cần cập nhật trong quá trình chuyển đổi nàyToàn bộ không gian tên
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
28 không được dùng nữa, sẽ bị xóa trong Python 3. 12. Tham khảo phần các thay đổi của mô-đun để biết thêm thông tin.Non-integer arguments to
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
52 are deprecated.File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
53 không được dùng nữa để thay thế bằngexpected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
06. [Đóng góp bởi Serhiy Storchaka và Raymond Hettinger trong bpo-37319. ]The various
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
39 methods ofFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
48 have been documented as deprecated since Python 3. 6, but will now also trigger awith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
89. Sử dụngFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
40 thay thế. [Đóng góp bởi Brett Cannon trong bpo-26131. ]File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
59 không được dùng để ưu tiên choFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
40. [Contributed by Brett Cannon in bpo-26131. ]Việc sử dụng
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
39 bởi hệ thống nhập hiện kích hoạtFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
49 vìFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
40 được ưu tiên. [Đóng góp bởi Brett Cannon trong bpo-26131. ]Việc sử dụng
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
64 vàFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
65 bởi hệ thống nhập khẩu hiện kích hoạt mộtFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
49 vìFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
67 vàFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
68 được ưu tiên tương ứng. Bạn có thể sử dụngFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
69 để trợ giúp chuyển. [Đóng góp bởi Brett Cannon trong bpo-42134. ]Việc sử dụng
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
70 bởi hệ thống nhập hiện kích hoạtFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
49 vìFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
68 được ưu tiên. You can useFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
69 to help in porting. [Đóng góp bởi Brett Cannon trong bpo-43672. ]The various implementations of
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
64 [File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
75,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
76,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
77,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
78,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
64 ],File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
65 [File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
81 ], andFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
70 [File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
83 ] now raisewith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
89 and are slated for removal in Python 3. 12 [trước đây chúng được ghi lại là không dùng nữa trong Python 3. 4]. [Đóng góp bởi Brett Cannon trong bpo-42135. ]File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
85 không được dùng nữa [bao gồm cả phương pháp duy nhất của nó,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
37]. CảFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
87 vàFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
88 không còn kế thừa từ lớp. Thay vào đó, người dùng nên kế thừa từ một trong hai lớp này khi thích hợp. [Đóng góp bởi Brett Cannon trong bpo-42135. ]The deprecations of
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
89,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
90,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
91,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
92,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
93,File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
94, andFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
95 have all been updated to list Python 3. 12 là phiên bản loại bỏ dự kiến [họ đã bắt đầu tăngwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
89 trong các phiên bản Python trước đó]. [Đóng góp bởi Brett Cannon trong bpo-43720. ]The import system now uses the
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
97 attribute on modules before falling back onFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
41 for a module’sexpected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
42 method. Removal of the use ofFile "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
41 is scheduled for Python 3. 12. [Đóng góp bởi Brett Cannon trong bpo-42137. ]>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
01,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
02, and>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
03 are deprecated and slated for removal in Python 3. 12. [Đóng góp bởi Brett Cannon trong bpo-42136. ]>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
04 đã không có giấy tờ và lỗi thời kể từ Python 3. 3, khi nó được tạo bí danh cho>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
05. Nó hiện không được dùng nữa, được lên lịch xóa trong Python 3. 12. [Đóng góp bởi Erlend E. Aasland in bpo-42264. ]>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
06 hiện phát ra cảnh báo không dùng nữa nếu không có vòng lặp sự kiện nào đang chạy. Trong tương lai nó sẽ là bí danh của>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
07.>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
08 functions which implicitly create>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
09 or>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
10 objects now emit a deprecation warning if there is no running event loop and no explicit loop argument is passed.>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
11,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
12,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
13,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
14,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
15 và các nhà xây dựng của>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
09,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
10,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
18,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
19. [Đóng góp bởi Serhiy Storchaka trong bpo-39529. ]Hàm tích hợp không có giấy tờ
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
20 hiện không được dùng nữa, được lên lịch xóa trong Python 3. 12. Việc sử dụng nó không được khuyến khích mạnh mẽ bởi tài liệu SQLite3. Xem tài liệu SQLite3 để biết thêm chi tiết. Nếu phải sử dụng bộ đệm ẩn dùng chung, hãy mở cơ sở dữ liệu ở chế độ URI bằng cách sử dụng tham số truy vấn>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
21. [Đóng góp bởi Erlend E. Aasland trong bpo-24464. ]The following
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
22 methods are now deprecated>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
23 =>>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
24>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
25 =>>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
26>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
27 =>>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
28>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
29 =>>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
30>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
31 =>>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
32>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
33 =>>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
32>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
35 =>>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
36>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
37 =>>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
36
[Đóng góp bởi Jelle Zijlstra trong gh-87889. ]
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
39 is deprecated and slated for removal in Python 3. 12. Sử dụng>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
40 để thay thế. [Đóng góp bởi Barney Gale trong bpo-39950. ]>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
41 is deprecated and slated for removal in Python 3. 12. [Đóng góp bởi Inada Naoki trong bpo-41139. ]Các tính năng
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
42 sau không được dùng nữa kể từ Python 3. 6, Python 3. 7, or OpenSSL 1. 1. 0 và sẽ bị xóa sau 3. 11File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
33,File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
34,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
45,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
46,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
47 và>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
48 được thay thế bằng>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
49 và>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
50>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
51,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
52,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
53,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
54,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
55,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
56, and>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
57 are deprecated in favor of>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
58 and>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
59>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
60 được thay thế bằng>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
61>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
62>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
63,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
64Các tính năng NPN như
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
65 và>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
66 được thay thế bằng ALPN
Gỡ lỗi luồng [biến môi trường ____967] không được dùng trong Python 3. 10 và sẽ bị xóa trong Python 3. 12. Tính năng này yêu cầu bản dựng gỡ lỗi của Python . [Đóng góp bởi Victor Stinner trong bpo-44584. ]
Việc nhập từ các mô-đun con
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
74 vàFile "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
75 giờ đây sẽ phát rawith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
89. Các mô hình con này sẽ bị xóa trong phiên bản tương lai của Python. Thay vào đó, mọi thứ thuộc về các mô-đun con này nên được nhập trực tiếp từwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
13. [Đóng góp bởi Sebastian Rittau trong bpo-38291. ]
Loại bỏ¶
Loại bỏ các phương thức đặc biệt
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
72,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
73,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
74,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
75,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
76,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
77,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
78 và>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
79 của lớp>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
80. Họ luôn nuôi mộtexpected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
06. [Đóng góp bởi Serhiy Storchaka trong bpo-41974. ]Phương thức
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
82 từ mô-đun>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
83 riêng tư và không có giấy tờ đã bị xóa.>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
84 là lớp con duy nhất của>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
85 và việc triển khai>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
86 của nó đã bị xóa trong Python 3. 5. [Đóng góp bởi Berker Peksag trong bpo-31844. ]Đã xóa thuộc tính
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
87 là một đối tượng PyCapsule bên trong. Cấu trúc>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
88 riêng tư có liên quan đã được chuyển sang API C nội bộ. [Đóng góp bởi Victor Stinner trong bpo-42157. ]Đã xóa mô-đun
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
89 không được dùng nữa trong 3. 9 do chuyển sang trình phân tích cú pháp PEG mới, cũng như tất cả các tệp tiêu đề và nguồn C chỉ được sử dụng bởi trình phân tích cú pháp cũ, bao gồm>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
90,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
91,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
92 và>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
93Đã xóa các chức năng API C công khai
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
94,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
95,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
96 và>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
97 không được dùng trong 3. 9 do chuyển sang trình phân tích cú pháp PEG mớiĐã xóa mô-đun
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
98 không được dùng trong Python 3. 4. Nó hơi lỗi thời, ít được sử dụng và không được thử nghiệm. Ban đầu nó được lên kế hoạch xóa trong Python 3. 6, nhưng việc xóa như vậy đã bị trì hoãn cho đến sau Python 2. 7 EOL. Người dùng hiện tại nên sao chép bất kỳ lớp nào họ sử dụng vào mã của họ. [Đóng góp bởi Dong-hee Na và Terry J. Reedy trong bpo-42299. ]Đã xóa chức năng
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
99 hiện đã vô dụng do mô-đun _warnings đã được chuyển đổi thành mô-đun dựng sẵn trong 2. 6. [Đóng góp bởi Hai Shi trong bpo-42599. ]Xóa các bí danh không dùng nữa đối với Lớp cơ sở trừu tượng của bộ sưu tập khỏi mô-đun
000. [Đóng góp bởi Victor Stinner trong bpo-37324. ]pip --version
Tham số
001 đã bị xóa khỏi hầu hết API cấp caocủapip --version
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
08 sau khi ngừng sử dụng Python 3. 8. Động lực đằng sau sự thay đổi này là nhiều mặt. của>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
08 sau khi ngừng sử dụng Python 3. 8. Động lực đằng sau sự thay đổi này là nhiều mặt. following deprecation in Python 3.8. The motivation behind this change is multifold:Điều này đơn giản hóa API cấp cao
Các hàm trong API cấp cao đã ngầm nhận vòng lặp sự kiện đang chạy của luồng hiện tại kể từ Python 3. 7. Không cần chuyển vòng lặp sự kiện tới API trong hầu hết các trường hợp sử dụng thông thường
Truyền vòng lặp sự kiện dễ xảy ra lỗi, đặc biệt khi xử lý các vòng lặp chạy trong các luồng khác nhau
Lưu ý rằng API cấp thấp sẽ vẫn chấp nhận
001. See Changes in the Python API for examples of how to replace existing code.pip --version
[Contributed by Yurii Karabas, Andrew Svetlov, Yury Selivanov and Kyle Stanley in bpo-42392. ]
Porting to Python 3. 10¶
This section lists previously described changes and other bugfixes that may require changes to your code
Changes in the Python syntax¶
Deprecation warning is now emitted when compiling previously valid syntax if the numeric literal is immediately followed by a keyword [like in
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
23]. In future releases it will be changed to syntax warning, and finally to a syntax error. To get rid of the warning and make the code compatible with future releases just add a space between the numeric literal and the following keyword. [Contributed by Serhiy Storchaka in bpo-43833. ]
Changes in the Python API¶
The etype parameters of the
File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
51,File "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
52, andFile "example.py", line 3 some_other_code = foo[] ^ SyntaxError: invalid syntax
53 functions in the
008 module have been renamed to exc. [Contributed by Zackery Spytz and Matthias Bussonnier in bpo-26389. ]pip --version
009. At Python exit, if a callback registered withpip --version
010 fails, its exception is now logged. Previously, only some exceptions were logged, and the last exception was always silently ignored. [Contributed by Victor Stinner in bpo-42639. ]pip --version
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
96 generic now flattens type parameters, similar to whatwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
24 currently does. This means thatexpected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
00 will havewith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
95 ofexpected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
02; previously this wasexpected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
03. Code which accesses the arguments via
017 orpip --version
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
95 need to account for this change. Furthermore,expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
06 may be raised for invalid forms of parameterizingwith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
96 which may have passed silently in Python 3. 9. [Contributed by Ken Jin in bpo-42195. ]
021 vàpip --version
022 hiện tăngpip --version
023 thay vìpip --version
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
89 nếu tham số đã cho không vừa với số nguyên không dấu 16 bit. [Contributed by Erlend E. Aasland in bpo-42393. ]The
001 parameter has been removed from most ofpip --version
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
08‘s high-level API following deprecation in Python 3. 8.A coroutine that currently looks like this
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
0Should be replaced with this
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
1If
027 was specifically designed not to run in the current thread’s running event loop [e. g. running in another thread’s event loop], consider usingpip --version
028 insteadpip --version
[Contributed by Yurii Karabas, Andrew Svetlov, Yury Selivanov and Kyle Stanley in bpo-42392. ]
The
029 constructor now inherits the current builtins if the globals dictionary has nopip --version
030 key, rather than usingpip --version
031 as builtins. same behavior aspip --version
032 andpip --version
033 functions. Defining a function withpip --version
034 in Python is not affected, globals cannot be overridden with this syntax. it also inherits the current builtins. [Contributed by Victor Stinner in bpo-42990. ]pip --version
Changes in the C API¶
The C API functions
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
94,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
95,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
96,>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
97 and the type used by these functions,
039, were removed due to the switch to the new PEG parserpip --version
Source should be now be compiled directly to a code object using, for example,
040. The resulting code object can then be evaluated using, for example,pip --version
041pip --version
Specifically
A call to
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
94 followed by>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
97 can be replaced by calling
040pip --version
There is no direct replacement for
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
96. To compile code from a
046 argument, you will need to read the file in C and pass the resulting buffer topip --version
040pip --version
To compile a file given a
048 filename, explicitly open the file, read it and compile the result. One way to do this is using thepip --version
049 module withpip --version
050,pip --version
051,pip --version
052 andpip --version
040, as sketched below. [Declarations and error handling are omitted. ]pip --version
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
2For
054 objects, thepip --version
055 member now represents a wordcode offset instead of a simple offset into the bytecode string. This means that this number needs to be multiplied by 2 to be used with APIs that expect a byte offset instead [likepip --version
056 for example]. Notice as well that thepip --version
055 member ofpip --version
054 objects is not considered stable. please usepip --version
059 insteadpip --version
CPython bytecode changes¶
The
060 instruction now accepts either a dict or a tuple of strings as the function’s annotations. [Contributed by Yurii Karabas and Inada Naoki in bpo-42202. ]pip --version
Build Changes¶
PEP 644. Python now requires OpenSSL 1. 1. 1 or newer. OpenSSL 1. 0. 2 is no longer supported. [Contributed by Christian Heimes in bpo-43669. ]
The C99 functions
061 andpip --version
062 are now required to build Python. [Contributed by Victor Stinner in bpo-36020. ]pip --version
063 requires SQLite 3. 7. 15 or higher. [Contributed by Sergey Fedoseev and Erlend E. Aasland in bpo-40744 and bpo-40810. ]pip --version
The
009 module must now always be built as a built-in module. [Đóng góp bởi Victor Stinner trong bpo-42639. ]pip --version
Add
065 option to thepip --version
066 script. don’t build nor install test modules. [Contributed by Xavier de Gaye, Thomas Petazzoni and Peixing Xin in bpo-27640. ]pip --version
Add
067 to thepip --version
068 script. If specified, thepip --version
069 module looks forpip --version
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, 38: 4, 39: 4, 45: 5, 46: 5, 47: 5, 48: 5, 49: 5, 54: 6, some_other_code = foo[]
29 and
071 wheel packages in this directory. if both are present, these wheel packages are used instead of ensurepip bundled wheel packagespip --version
Some Linux distribution packaging policies recommend against bundling dependencies. For example, Fedora installs wheel packages in the
072 directory and don’t install thepip --version
073 packagepip --version
[Contributed by Victor Stinner in bpo-42856. ]
Add a new
074 to not build thepip --version
075 static library and not install thepip --version
076 object filepip --version
[Contributed by Victor Stinner in bpo-43103. ]
The
066 script now uses thepip --version
078 utility, if available, to detect the location of Tcl/Tk headers and libraries. As before, those locations can be explicitly specified with thepip --version
079 andpip --version
080 configuration options. [Contributed by Manolis Stamatogiannakis in bpo-42603. ]pip --version
Add
081 option topip --version
066 script. The option simplifies building Python with a custom OpenSSL installation, e. g.pip --version
083. [Đóng góp bởi Christian Heimes trong bpo-43466. ]pip --version
Thay đổi API C¶
PEP 652. Duy trì ABI ổn định¶
ABI ổn định [Giao diện nhị phân ứng dụng] cho các mô-đun mở rộng hoặc nhúng Python hiện được xác định rõ ràng. Tính ổn định của API C mô tả các đảm bảo về độ ổn định của API C và ABI cùng với các phương pháp hay nhất để sử dụng ABI ổn định.
[Đóng góp bởi Petr Viktorin trong PEP 652 và bpo-43795. ]
Các tính năng mới¶
Kết quả của
084 bây giờ luôn có kiểu chính xác làpip --version
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
34. Trước đây, kết quả có thể là một thể hiện của một lớp con củawith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
34. [Đóng góp bởi Serhiy Storchaka trong bpo-40792. ]Thêm thành viên
087 mới vào cấu trúcpip --version
088. danh sách các đối số dòng lệnh ban đầu được truyền cho tệp thực thi Python. [Đóng góp bởi Victor Stinner trong bpo-23427. ]pip --version
Các macro
089 vàpip --version
090 đã được thêm vào để truy cập các thuộc tínhpip --version
091 của các đối tượngpip --version
092 vàpip --version
093. [Đóng góp bởi Zackery Spytz trong bpo-30155. ]pip --version
Thêm chức năng
094 để hủy đăng ký chức năng tìm kiếm codec. [Đóng góp bởi Hai Shi trong bpo-41842. ]pip --version
Hàm
095 đã được thêm vào để cho phép gửi giá trị vào iterator mà không tăng ngoại lệpip --version
096. [Đóng góp bởi Vladimir Matveev trong bpo-41756. ]pip --version
Thêm
097 vào API C giới hạn. [Đóng góp bởi Alex Gaynor trong bpo-41784. ]pip --version
Thêm chức năng
098. tương tự nhưpip --version
099 nhưng không ăn cắp tham chiếu đến giá trị thành công. [Đóng góp bởi Victor Stinner trong bpo-1635741. ]pip --version
Thêm các hàm
300 vàpip --version
301 để tăng số lượng tham chiếu của một đối tượng và trả về đối tượng. [Đóng góp bởi Victor Stinner trong bpo-42262. ]pip --version
Các hàm
302 vàpip --version
303 hiện chấp nhận một lớp duy nhất làm đối số cơ sở. [Đóng góp bởi Serhiy Storchaka trong bpo-42423. ]pip --version
Hàm
303 hiện chấp nhận vị trí NULLpip --version
305. [Đóng góp bởi Hai Shi trong bpo-41832. ]pip --version
Hàm
306 có thể chấp nhận các loại tĩnh . [Đóng góp bởi Hai Shi và Petr Viktorin trong bpo-41073. ]pip --version
Thêm một hàm
307 mới vào C-API để kiểm tra xem một đối tượng có phải là phiên bản củapip --version
308 mà không phải là phiên bản của kiểu con không. [Đóng góp bởi Pablo Galindo trong bpo-43277. ]pip --version
Thêm
309 cho phép chuyển số tín hiệu để mô phỏng. [Đóng góp bởi Antoine Pitrou trong bpo-43356. ]pip --version
API C giới hạn hiện được hỗ trợ nếu Python được xây dựng ở chế độ gỡ lỗi [nếu macro
310 được xác định]. Trong API C giới hạn, các hàmpip --version
311 vàpip --version
312 hiện được triển khai dưới dạng các lệnh gọi hàm không rõ ràng, thay vì truy cập trực tiếp vào thành viênpip --version
313, nếu Python được xây dựng ở chế độ gỡ lỗi và macropip --version
314 nhắm mục tiêu Python 3. 10 hoặc mới hơn. Có thể hỗ trợ API C giới hạn trong chế độ gỡ lỗi vì cấu trúcpip --version
315 giống nhau trong chế độ phát hành và gỡ lỗi kể từ Python 3. 8 [xem bpo-36465].pip --version
API C hạn chế vẫn không được hỗ trợ trong bản dựng đặc biệt
316 [macro ____1317]. [Đóng góp bởi Victor Stinner trong bpo-43688. ]pip --version
Thêm hàm
318 để kiểm tra xem đối tượng x có phải là đối tượng y hay không, giống như hàmpip --version
319 trong Python. Thêm cả các hàmpip --version
320,pip --version
321,pip --version
322 để kiểm tra xem một đối tượng tương ứng làpip --version
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
03 singleton,with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
01 singleton haywith [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
02 singleton. [Đóng góp bởi Victor Stinner trong bpo-43753. ]Thêm chức năng mới để kiểm soát bộ thu gom rác từ mã C.
326,pip --version
327,pip --version
328. Các chức năng này cho phép kích hoạt, hủy kích hoạt và truy vấn trạng thái của trình thu gom rác từ mã C mà không cần phải nhập mô-đunpip --version
329pip --version
Thêm cờ loại
330 mới để không cho phép tạo các thể hiện loại. [Đóng góp bởi Victor Stinner trong bpo-43916. ]pip --version
Thêm cờ loại
331 mới để tạo đối tượng loại bất biến. thuộc tính loại không thể được đặt cũng như bị xóa. [Đóng góp bởi Victor Stinner và Erlend E. Aasland trong bpo-43908. ]pip --version
Porting to Python 3. 10¶
Macro
332 hiện phải được xác định để sử dụng các định dạngpip --version
333 vàpip --version
334 sử dụngpip --version
335.pip --version
336,pip --version
337,pip --version
338,pip --version
339,pip --version
340,pip --version
341,pip --version
342 vàpip --version
343. Xem Phân tích đối số và xây dựng giá trị và PEP 353. [Đóng góp bởi Victor Stinner trong bpo-40943. ]pip --version
Vì
344 được thay đổi thành hàm tĩnh nội tuyến, nên phải thay thếpip --version
345 bằngpip --version
346. xempip --version
347 [có sẵn kể từ Python 3. 9]. Để tương thích ngược, macro này có thể được sử dụngpip --version
File "example.py", line 1 expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4, ^ SyntaxError: '{' was never closed
3[Đóng góp bởi Victor Stinner trong bpo-39573. ]
Gọi
348 mà không có GIL được cho phép vì lý do lịch sử. Nó không còn được phép. [Đóng góp bởi Victor Stinner trong bpo-40839. ]pip --version
349 vàpip --version
350 nâng caopip --version
with [ CtxManager1[] as example1, CtxManager2[] as example2, CtxManager3[] as example3, ]: ...
89 ngay bây giờ. Sử dụng
352 để phân bổ đối tượng Unicode mà không cần dữ liệu ban đầu. [Đóng góp bởi Inada Naoki trong bpo-36346. ]pip --version
Cấu trúc
>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
88 riêng của API PyCapsule>>> foo[x, z for z in range[10], t, w] File "", line 1 foo[x, z for z in range[10], t, w] ^ SyntaxError: Generator expression must be parenthesized
87 đã được chuyển sang API C nội bộ. [Đóng góp bởi Victor Stinner trong bpo-42157. ]
355,pip --version
356,pip --version
357,pip --version
358,pip --version
359 vàpip --version
360 hiện trả vềpip --version
361 nếu được gọi trướcpip --version
362 [trước khi Python được khởi tạo]. Sử dụng API Cấu hình khởi tạo Python mới để nhận Cấu hình đường dẫn Python . [Đóng góp bởi Victor Stinner trong bpo-42260. ]pip --version
Các macro
363,pip --version
364 vàpip --version
365 không còn có thể được sử dụng làm giá trị l hoặc giá trị r. Ví dụ:pip --version
366 vàpip --version
367 hiện không thành công do lỗi trình biên dịch. Nó ngăn chặn các lỗi như thử nghiệmpip --version
368. [Đóng góp bởi Zackery Spytz và Victor Stinner trong bpo-30459. ]pip --version
Các tệp API không giới hạn
369,pip --version
370,pip --version
371,pip --version
372,pip --version
373,pip --version
374,pip --version
375 vàpip --version
376 đã được chuyển đến thư mụcpip --version
377. Không được đưa trực tiếp các tệp này vào vì chúng đã được đưa vào trongpip --version
378; . Nếu chúng đã được bao gồm trực tiếp, hãy xem xét bao gồmpip --version
378 để thay thế. [Đóng góp bởi Nicholas Sim trong bpo-35134. ]Include Files. If they have been included directly, consider includingpip --version
378 instead. [Contributed by Nicholas Sim in bpo-35134.]pip --version
Sử dụng cờ loại
331 để tạo các đối tượng loại bất biến. Không dựa vàopip --version
381 để quyết định xem một đối tượng loại có thể thay đổi hay không; . [Đóng góp bởi Victor Stinner và Erlend E. Aasland trong bpo-43908. ]pip --version
Chức năng không có giấy tờ
383 đã bị xóa khỏi API hạn chế. Chức năng này chủ yếu hữu ích cho các bản dựng Python tùy chỉnh. [Đóng góp bởi Petr Viktorin trong bpo-26241. ]pip --version
Deprecated¶
Hàm
384 hiện không được dùng nữa và sẽ bị xóa trong Python 3. 12. sử dụngpip --version
385 thay thế. [Đóng góp bởi Victor Stinner trong bpo-41692. ]pip --version
Loại bỏ¶
Đã xóa các hàm
386 thao tác chuỗipip --version
387. [Đóng góp bởi Inada Naoki trong bpo-41123. ]pip --version
388. sử dụngpip --version
389 hoặcpip --version
390pip --version
391. sử dụngpip --version
392 hoặcpip --version
393pip --version
394,pip --version
395. sử dụngpip --version
392 hoặcpip --version
397pip --version
398. sử dụngpip --version
399pip --version
400. sử dụngpip --version
401pip --version
402,pip --version
403. sử dụngpip --version
404pip --version
Đã xóa
405. Vui lòng chuyển sang API mới [PEP 393]. [Đóng góp bởi Inada Naoki trong bpo-41103. ]pip --version
Đã xóa
406. Vui lòng chuyển sangpip --version
407. [Đóng góp bởi Inada Naoki trong bpo-41103. ]pip --version
Đã xóa
408. Vui lòng sử dụngpip --version
409 hoặcpip --version
410 [Đóng góp bởi Inada Naoki trong bpo-41103. ]pip --version
Đã xóa biến
411. nó đã được thay thế bởipip --version
412 của cấu trúcpip --version
413. [Đóng góp bởi Victor Stinner trong bpo-41834. ]pip --version
Đã xóa các macro không có giấy tờ
414 vàpip --version
415 và trườngpip --version
416 của cấu trúcpip --version
413. [Đóng góp bởi Serhiy Storchaka trong bpo-41936. ]pip --version
Đã xóa chức năng
418 không có giấy tờ. Đang khởi tạo Python đã cài đặt ngầm bộ xử lý tín hiệu. xempip --version
419. [Đóng góp bởi Victor Stinner trong bpo-41713. ]pip --version
Xóa chức năng
420. Không còn có thể xây dựng đối tượng AST [loại ____1421] với API C công khai. Hàm này đã bị loại trừ khỏi API C giới hạn [PEP 384]. [Đóng góp bởi Victor Stinner trong bpo-43244. ]pip --version
Xóa tệp tiêu đề
422 và các chức năng không có giấy tờpip --version
423pip --version
424pip --version
425pip --version
426pip --version
427pip --version
428pip --version
Hàm
427 là một phần của ABI ổn định do nhầm lẫn nhưng không thể sử dụng hàm này vì tệp tiêu đềpip --version
422 đã bị loại trừ khỏi API C hạn chếpip --version
Thay vào đó, hãy sử dụng mô-đun Python
431. [Đóng góp bởi Victor Stinner trong bpo-43244. ]pip --version
Xóa
432 khỏi các tiêu đề API C hạn chế và khỏipip --version
433, thư viện cung cấp ABI ổn định trên Windows. Vì hàm nhận đối sốpip --version
434 nên không thể đảm bảo tính ổn định ABI của nó. [Đóng góp bởi Petr Viktorin trong bpo-43868. ]pip --version
Xóa các tệp tiêu đề
435,pip --version
436 vàpip --version
437. Các chức năng này không có giấy tờ và bị loại khỏi API C hạn chế. Hầu hết các tên được xác định bởi các tệp tiêu đề này không có tiền tố làpip --version
438 và do đó có thể tạo ra xung đột tên. Ví dụ:pip --version
437 đã xác định macropip --version
440 xung đột với tênpip --version
440 được sử dụng bởi tiêu đề Windowspip --version
442. Thay vào đó, hãy sử dụng mô-đun Pythonpip --version
443. [Đóng góp bởi Victor Stinner trong bpo-43244. ]pip --version
Xóa các hàm trình biên dịch và trình phân tích cú pháp bằng cách sử dụng loại
444, vì API AST C công khai đã bị xóapip --version
445pip --version
446pip --version
447pip --version
448pip --version
449pip --version
450pip --version
451pip --version
452pip --version
453pip --version
454pip --version
Các chức năng này không có giấy tờ và bị loại khỏi API C hạn chế. [Đóng góp bởi Victor Stinner trong bpo-43244. ]
Xóa tệp tiêu đề
372 bằng các chức năngpip --version
456pip --version
457pip --version
458pip --version
459pip --version
Các chức năng này không có giấy tờ, bị loại trừ khỏi API C hạn chế và chỉ được trình biên dịch sử dụng nội bộ. [Đóng góp bởi Victor Stinner trong bpo-43244. ]
Thành viên
460 đã bị xóa để tối ưu hóa Python. [Đóng góp bởi Mark Shannon trong bpo-43760. ]pip --version
Tôi có nên tắt giới hạn độ dài đường dẫn Python không?
Bạn nên tắt độ dài giới hạn đường dẫn sau khi thiết lập Python thành công , vì nếu python được cài đặt trong thư mục có độ dài đường dẫn lớn hơn 260 ký tự, việc thêm nó vào đường dẫn có thể .Vô hiệu hóa giới hạn độ dài đường dẫn Windows là gì?
Tùy chọn "Tắt giới hạn độ dài đường dẫn" đề cập đến độ dài tối đa của đường dẫn tệp mà Windows có thể xử lý . Vô hiệu hóa giới hạn này có thể cho phép đường dẫn tệp dài hơn, điều này có thể hữu ích nếu bạn đang làm việc với các tệp có tên rất dài hoặc được lưu trữ trong các thư mục được lồng sâu.Tôi có nên tắt reddit giới hạn độ dài đường dẫn không?
Về cơ bản, những gì nó làm là cho phép Python bỏ qua giới hạn độ dài đường dẫn tệp 260 ký tự cổ xưa. Nếu Python được cài đặt ở đâu đó yêu cầu nhiều hơn số lượng ký tự đó, nó sẽ không hoạt động từ PATH trừ khi giới hạn bị vô hiệu hóa. Nói cách khác, Tôi khuyên bạn nên tắt giới hạn . Nó rất có thể không thể làm tổn thương.Giới hạn đường dẫn tối đa trong Python là gì?
Xóa giới hạn MAX_PATH. Windows trước đây có độ dài đường dẫn giới hạn ở 260 ký tự. Điều này có nghĩa là các đường dẫn dài hơn đường dẫn này sẽ không giải quyết được và sẽ xảy ra lỗi. Trong các phiên bản Windows mới nhất, giới hạn này có thể được mở rộng thành khoảng 32.000 ký tự .