Python Forum
Generator function in camel case
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generator function in camel case
#4
(Jul-16-2018, 08:37 PM)porton Wrote: I mean if I rewrite a generator function as an iterator class or vice versa, I need to change its casing.
As per PEP 8, I would change it.

A little more reason on why this might not be cargo-culty - as a client of your generator, I can assume that your generator is going to act like a normal Python generator. It won't have any additional methods (even if I want them) and if there's a bug I have a hint about where to start looking (there's not going to be any behavior overrides). If it's a class, I might want to look at the API more, if there are any behaviors I'm surprised by I will know that there might be more methods or behavior overrides involved, etc.

If you prefer following the logic that the name shouldn't change because the signature/interface didn't change, I'd just be sure to document that in your project. Especially if you're not confident that you can easily and completely do the rename, this seems like a reasonable time to violate PEP 8, which is a suggestion more than a rule.

Lastly, you can split the difference - name your thing as a class and then either wrap it with the function that returns an instance of your new generator class, or else include in the file it's imported from a line like
generator = Generator
which will allow existing clients to not have to be changed, potentially with a comment about the name being deprecated.
Reply


Messages In This Thread
Generator function in camel case - by porton - Jul-16-2018, 08:28 PM
RE: Generator function in camel case - by micseydel - Jul-16-2018, 08:34 PM
RE: Generator function in camel case - by porton - Jul-16-2018, 08:37 PM
RE: Generator function in camel case - by micseydel - Jul-16-2018, 09:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Switch case or match case? Frankduc 9 4,553 Jan-20-2022, 01:56 PM
Last Post: Frankduc
  Tuple generator, and function/class syntax quazirfan 3 3,900 Aug-10-2021, 09:32 AM
Last Post: buran
  list call problem in generator function using iteration and recursive calls postta 1 1,922 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  basic random number generator in replace function krug123 2 2,052 Jul-31-2020, 01:02 PM
Last Post: deanhystad
  Generator function for even numbers mp3909 4 6,030 Mar-21-2020, 07:40 PM
Last Post: buran
  how to make my function be a generator Skaperen 2 2,037 Jan-27-2020, 01:07 AM
Last Post: Skaperen
  generator function that yield from a list buran 9 4,218 Jun-04-2019, 10:26 PM
Last Post: snippsat
  receive from a generator, send to a generator Skaperen 9 5,527 Feb-05-2018, 06:26 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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