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
21
votes
2 answers

Tool for automatically check docstring style according to PEP257

Tools like pep8 can check source code style, but they don't check if docstrings are fromatted according to pep257, pep287. Are there such tools? Update I decided to implement such a static analysis tool on my own,…
Vladimir Keleshev
  • 13,753
  • 17
  • 64
  • 93
20
votes
2 answers

Python - define constant inside function

Given that there are no real constants in Python, the convention is to name them in CAPS for conveying the intentions. In following sample code, FIRST and SECOND are constants: def fibonacci_generator(count): FIRST, SECOND = 0, 1 a, b =…
Sagar Gupta
  • 1,352
  • 1
  • 12
  • 26
19
votes
2 answers

Numpy type hints in Python (PEP 484)

I would like to add type hints to a method that takes a numpy array as an input, and returns a string. This numpy array contains floats so I tried: import numpy as np def foo(array: np.ndarray[np.float64]) -> str: But it will not work due to a…
sidou
  • 201
  • 1
  • 2
  • 4
18
votes
1 answer

What will be the benefits of type hinting in Python?

I was reading through the PEP 484 -- Type Hints when it is implemented, the function specifies the type of arguments it accept and return. def greeting(name: str) -> str: return 'Hello ' + name My question is, What are the benefits of type…
user5539517
17
votes
2 answers

Assignment with line continuation - Python

What is the preferred style for assigning values to variables when the variables are nested several levels deep, have fairly long names, and are being assigned fairly long values/expressions. For example: if this: if that: if here: …
SheffDoinWork
  • 743
  • 2
  • 8
  • 19
15
votes
2 answers

Regex to match PEP440 compliant version strings

PEP 440 lays out what is the accepted format for version strings of Python packages. These can be simple, like: 0.0.1 Or complicated, like: 2016!1.0-alpha1.dev2 What is a suitable regex which could be used for finding and validating such strings?
Leo
  • 1,077
  • 11
  • 24
13
votes
1 answer

Type annotation style (to space or not to space)

Having the following function: def foo(x=1): print(x) It is clearly stated in PEP 8 that no spaces should be used around the = sign when used to indicate a keyword argument or a default parameter value. If we want to type-annotate the x…
Peque
  • 13,638
  • 11
  • 69
  • 105
13
votes
1 answer

Python PEP 8: Blank lines at the beginning of a module

There is a question who treat about this but not talk about all the points I interested. PEP 8 says about blank lines: Separate top-level function and class definitions with two blank lines. Then if you have: A module with only a class: # -*-…
Super User
  • 147
  • 1
  • 2
  • 7
11
votes
6 answers

error: command 'clang' failed with exit status 1 : On installing pandas on MacOS Big Sur M1

I install pandas using pip install pandas or pip3 install pandas. I get following infinite like error : (Note : I run these installations in virtualenv, created using python3 -m venv myenv) /* DISABLES CODE */ ( ) …
Ruchit Patel
  • 733
  • 1
  • 11
  • 26
11
votes
2 answers

how to avoid python numeric literals beginning with "0" being treated as octal?

I am trying to write a small Python 2.x API to support fetching a job by jobNumber, where jobNumber is provided as an integer. Sometimes the users provide ajobNumber as an integer literal beginning with 0, e.g. 037537. (This is because they have…
David Alexander
  • 358
  • 1
  • 12
10
votes
2 answers

How to annotate variadic parameters in Python using typing annotations?

How to annotate parameters of the variadic function? Example: def foo(*args): # Each arg expected to be of type T ... Are there any typing annotations for that?
kuza
  • 2,761
  • 3
  • 22
  • 56
10
votes
1 answer

What is "__docformat__" used for in Python?

I have been coding for about a year now in Python and I have just come across some code in a Theano tutorial that declares a variable at the top of the file: __docformat__ = 'restructedtext en' Searching the internet produced this PEP…
Alexander McFarlane
  • 10,643
  • 9
  • 59
  • 100
10
votes
1 answer

Python PEP 273 and Amazon BotoCore

On a small embedded Linux device with limited space, I am trying to place the large [10 Mb] Amazon (AWS) BotoCore library (https://github.com/boto/botocore) in a zip file to compress it and then import it in my Python Scripts using zipimport as…
PhilBot
  • 748
  • 18
  • 85
  • 173
10
votes
7 answers

how can I make a suggestion for a new feature in python

Suppose I think I have a great idea for some feature that should be in python's standard library. Not something of the magnitude of a new keyword etc, just a suggestion for another decorator that would help a lot, IMO. How can I suggest such a…
olamundo
  • 23,991
  • 34
  • 108
  • 149
9
votes
1 answer

Why does unpacking give a list instead of a tuple in Python?

This is really strange to me, because by default I thought unpacking gives tuples. In my case I want to use the prefix keys for caching, so a tuple is preferred. # The r.h.s is a tuple, equivalent to (True, True, 100) *prefix, seed =…
episodeyang
  • 642
  • 8
  • 15
1
2
3
16 17