Questions tagged [pep]

Python Enhancement Proposals are used to propose and document Python language features, development processes and best practices. Use [pep8] for questions about the style guide for Python code.

Python Enhancement Proposals are used to propose and document Python language features, development processes and best practices.

Some important PEPs are:

At a given moment, the status of a PEP can be any one of Draft, Deferred, Accepted, Rejected, Withdrawn, Accepted, Final or Replaced. Informational PEPs which are expected to continue being updated may alternatively have a status of Active.

This flowchart shows how the status of a PEP may evolve:

enter image description here

A public Mercurial repository contains a record of changes to PEPs.

Use for questions about the style guide for Python code.

243 questions
9
votes
1 answer

Partial stub in PyCharm

I would like to introduce partial type annotation to my project. For example for overloading. I found that pep561 introduce partial stub file support. I develop my project with PyCharm and I add corresponding *.pyi file. And got expected…
Grzegorz Bokota
  • 1,736
  • 11
  • 19
9
votes
1 answer

Why does sqlite3 still use __conform__?

I noticed that the sqlite3-library still uses the __conform__-method to adapt objects for storage in a database. Then you need to give your class a method __conform__(self, protocol) which must return the converted value. ^ Python docs 12.6.6.2.1…
Tess E. Duursma
  • 186
  • 1
  • 8
9
votes
6 answers

Is it bad practice in Python to define a function in the middle of operational code?

I learned from a similar question on imports that one should not mix "operational code" and import (they should be at the top). What is the consensus around defining functions in the middle of "operational code"? I have a case where a function is…
WoJ
  • 27,165
  • 48
  • 180
  • 345
8
votes
3 answers

Zen of Python 'Explicit is better than implicit'

I'm trying to understand what 'implicit' and 'explicit' really means in the context of Python. a = [] # my understanding is that this is implicit if not a: print("list is empty") # my understanding is that this is explicit if len(a) == 0: …
8
votes
1 answer

Python >= 3.3 Internal String Representation

I was looking into how Python represents string after PEP 393 and I am not understanding the difference between PyASCIIObject and PyCompactUnicodeObject. My understanding is that strings are represented with the following structures: typedef struct…
Alberto O.
  • 835
  • 1
  • 8
  • 14
8
votes
1 answer

Capitalization of filenames storing Python classes

C++ I use a rigorous rule of capitalizing class names. Over many years I tried to use the somewhat inconsistent rule of using lowercase names for the files—when writing in C++. For example, class Stopwatch would be in the files stopwatch.hpp and…
Calaf
  • 10,113
  • 15
  • 57
  • 120
7
votes
2 answers

How to structure python project with dot "." or underscore "-" in project/package name?

PEP 423 states that project names and package names should be the same and later gives an example where the project/package name contains a dot: Yes: Package name: "kheops.pyramid", i.e. import kheops.pyramid Project name: "kheops.pyramid", i.e.…
Pedro Cattori
  • 2,735
  • 1
  • 25
  • 43
7
votes
3 answers

XEP-0080 User Location in Smack Library

I would like to create a simple XMPP client in java that shares his location (XEP-0080) with other clients. I already know I can use the smack library for XMPP and that it supports PEP, which is needed for XEP-0080. Does anyone have an example how…
Kristof
  • 557
  • 6
  • 14
6
votes
1 answer

Which implementation of OrderedDict should be used in python2.6?

As some of you may know in python2.7/3.2 we'll get OrderedDict with PEP372 however one of the reason the PEP existed was because everyone did their own implementation and they were all sightly incompatible. So which one of the 8 current…
Jorge Vargas
  • 6,712
  • 7
  • 32
  • 29
5
votes
1 answer

Python type annotations style for functions with long arguments

What is the canon (based on some PEP) way to style a function definition with long type annotations? Some alternatives I can conceive: Option 1: def my_long_function_name_super_important( first_long_argument_to_my_function: Union[int, str], …
ibarrond
  • 6,617
  • 4
  • 26
  • 45
5
votes
3 answers

What is this Python type hinting syntax, two types enclosed in parenthesis?

I have a method with signature as follows: def get_users_for_survey(survey_id: (int, str),show_deleted_users: bool = False) -> list: pass I have avoided the method body because I am only interested in the type hinting part for survey_id? Looks…
Subhendu Mahanta
  • 961
  • 1
  • 18
  • 44
5
votes
1 answer

PEP 3106 suggests slower way? Why?

Recently, I had to convert the values of a dictionary to a list in Python 3.6 and an use case where this is supposed to happen a lot. Trying to be a good guy I wanted to use a solution which is close to the PEP. Now, PEP 3106…
d4tm4x
  • 458
  • 4
  • 14
5
votes
1 answer

What is the standard docstring for a django model metaclass?

Models in django can come with a meta class like so: class Address(models.Model): """Address model.""" class Meta: """Meta McMetaface.""" verbose_name = "Address" verbose_name_plural = "Addresses" address_line…
AncientSwordRage
  • 7,086
  • 19
  • 90
  • 173
5
votes
1 answer

Any reason to put code before the docstring in Python?

I see in some other people's Python code that they paste some checks before the docstring of the function; something like this: def func(args): if x_version != 1.7: return """docstring is here""" # function body code # ... Are there any…
Alex Tereshenkov
  • 3,340
  • 8
  • 36
  • 61
5
votes
1 answer

Has there been any Python proposal for conditional "except" blocks?

In systems programming it is common to invoke some library function which may fail, and if it does fail, to check errno for the exact cause. This is true even in Python, and I think it's more cumbersome than it needs to be. Let's take for example…
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
1 2
3
16 17