Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Type hinting style and PEP8
#1
Hi,

I was wondering if there was a preferred style for type hinting. In particular inline:

def process(self, items: Iterator[T], items2: Iterator[T]) -> Iterator[T]:
or on a seperate line via @overload:

@overload
def process(self, items: Iterator[T], items2: Iterator[T]) -> Iterator[T]: ...
def process(self, items, items2):
There is obviously pros and cons; e.g. 1st form is shorter, but 2nd reads more like traditional Python and is less cluttered making it easier to see the arguments.

Also I'm using PyCharm and its PEP8 warning wants an added space, i.e. PyCharm wants:

@overload
def process(self, items: Iterator[T], items2: Iterator[T]) -> Iterator[T]: ...

def process(self, items, items2):
Should PEP8 be modified to allow no blank line for overloads? PEP8 considerable pre-dates type hints! The no-blank for overloads style is what typeshed uses. Also typeshed uses the inline style unless the function actually requires @overload to type it correctly.

Thanks in advance for any advice,

Howard.
Reply


Messages In This Thread
Type hinting style and PEP8 - by hlovatt - May-06-2020, 04:26 AM
RE: Type hinting style and PEP8 - by micseydel - May-06-2020, 11:18 PM
RE: Type hinting style and PEP8 - by hlovatt - May-07-2020, 08:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  New to python, question regarding PEP8 AthertonH 3 1,499 Apr-14-2022, 06:49 AM
Last Post: buran
  Noob warning: trying to use pip to install pytest and pep8 in Command Prompt adifrank 4 5,336 Dec-20-2020, 04:23 AM
Last Post: adifrank
  Type hints and style MaxPowers 1 1,865 Feb-19-2020, 06:56 PM
Last Post: micseydel
  Type hinting - return type based on parameter micseydel 2 2,492 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Visual Studio Code - PEP8 Lambda Issue Qui_Ten 1 2,731 Jan-28-2019, 08:17 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020