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
0
votes
1 answer

Python Annotations: return type as an instance

Does there is a way to let the return value know its type should belong to some isinstance? for example,def myfunction(...) -> instance[MyClass]: (It's an informal grammar, I just example I want the syntax is something like that) that means it only…
Carson
  • 6,105
  • 2
  • 37
  • 45
0
votes
1 answer

Python Expression that returns a value if condition is met but otherwise continues a for loop

This is going to sound like a dumb and horrible idea and that's probably because it is. Is there a way in Python (preferably a one-liner) to create an expression that resolves to a value if a condition is met but if the condition is not met it will…
0
votes
1 answer

How does the f-string in this Python function work?

Hi I found the below function on some website somewhere and just have a couple of questions. The function returns a diamond of n lines made from asterisks. Is that a concatenated for loop? Is that a thing you can do? What is going on in that…
0
votes
1 answer

How to use getattr or getattribute to correctly raise ImportError while calling some methods

Hello their thanks in advance for helping me, Please see below code: import types _MSG = ("Failed importing {name}. Please install {name}." " Using pip install {name}") class Empty(): # pylint: disable=too-few-public-methods """Empty…
Eshan Agarwal
  • 43
  • 1
  • 5
0
votes
2 answers

How to add a long comment to a statement properly in Python?

I am trying to follow PEP-8 in my project. E.g. there is some statement which should have a long comment (so line length more than 79 characters now): fields_to_display = ['id', 'order_item'] # set here a list of fields to display when…
pospolitaki
  • 313
  • 2
  • 9
0
votes
0 answers

Coding guidelines for high nesting/parentheses

Does python have any suggestions on how highly nested calls should look? For example, here is an example: handler = SAXEventHandler( target=to_dict( target=dict_filter(key='title', value='Brown Christmas', …
David542
  • 104,438
  • 178
  • 489
  • 842
0
votes
1 answer

Are Python PEPs implemented as proposed/amended or is there wiggle room?

I just noticed in PEP 3127 (the one that rationalised radix calculations on literals and int() arguments so that, for example, 010 is no longer a valid literal and must instead be 0o10 if octal is desired), that one particular part of the PEP was…
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
0
votes
1 answer

Type warning Pycharm

Given the following example: class A: def __init__(self, x: (float, np.ndarray) = 0.05): self.x = x what i intend with it is to give a hint to the user that the argument x can be a float or a numpy array. If nothing is given, set…
JustANoob
  • 580
  • 1
  • 4
  • 19
0
votes
0 answers

How to fix pipenv failure to install pyarrow?

I am trying to install pyarrow using pipenv: pipenv install pyarrow And I get the following error : ...... cmake -DPYTHON_EXECUTABLE=c:\\users\\myuser\\.virtualenvs\\myproject-z1aqfj6n\\scripts\\python.exe -G "Visual Studio 14 2015 Win64"…
Farah
  • 2,469
  • 5
  • 31
  • 52
0
votes
1 answer

Too complex PEP257 error, unsure how to fix it

I'm getting PEP257 error with this part of code. I'm aware that adding more than 3 if/elifs causes this, but I'm unsure how to properly fix this. I've tried to group up the ifs/elifs but that made it too complicated for me and I havent found any…
Martin
  • 23
  • 1
  • 6
0
votes
1 answer

a PEP 8 "import formatting" plugin for VIM

I am looking for a plugin which would help me format the order of imports in my python file following given guidelines: Imports should be grouped in the following order: 1 Standard library imports. 2 Related third party imports. 3 Local…
Hubert
  • 142
  • 1
  • 12
0
votes
1 answer

PEP3101 checker installation

I want to check PEP-3101 standard for some codes that I have, for this, I want to install flake8-pep3101. I can not directly install it as it requires PIP upgrade, so I upgrade my PIP from 19.0.3 to 19.1.1. After upgrade, I began to install it by…
padjee
  • 125
  • 2
  • 12
0
votes
1 answer

How to document python module using reStructuredText?

I want to know how is the correct way to document a python module using reStructuredText format. In PEP there is a general description but no explanation about format for module documentation.
eduardosufan
  • 1,441
  • 2
  • 23
  • 51
0
votes
2 answers

Pythonic way to structure if statement for changing variable values?

As title says, what's the pythonic way to write the following code? if x == 1: myvar = "a string" elif x == 2: myvar = "another string" elif x == 3: myvar = "yet another string" else: raise Exception("arg x must be 1, 2 or 3") It…
John Muir
  • 55
  • 1
  • 3
0
votes
1 answer

How to solve this Python problem using functions?

import json def get_stored_username(): """Get stored username if available.""" filename = 'username.json' try: with open(filename) as f_obj: username = json.load(f_obj) except FileNotFoundError: return…
Nacka
  • 5
  • 1
  • 6