0

What's the proper type hints in PEP8 to type hint variable defined within the for loop or in nested for loop.

a: int
for a in iterable_A:
    for b in iterable_B:
        pass

what would be the proper PEP8 standard type hints use for b?
I've tried both seem to be working.

a: int
for a in iterable_A:
    b: int
    for b in iterable_B:
        pass

OR in nested for loop.

a: int
b: int
for a in iterable_A:
    for b in iterable_B:
        pass
Kun
  • 1
  • 1
  • 2
  • Either way is fine. – Barmar Nov 15 '21 at 23:40
  • this will just come down to preference really, https://www.python.org/dev/peps/pep-0526/#where-annotations-aren-t-allowed, it just says that they can be annotated ahead of time of the loop, where you choose to do that will just be down to your preference – Chris Doyle Nov 15 '21 at 23:42
  • I wouldn't do either, and would instead make sure that `iterable_A` and `iterable_B` have useful generic types. – Samwise Nov 16 '21 at 00:04

0 Answers0